From 40e6be67ddb5828d25095163a221854cf550365a Mon Sep 17 00:00:00 2001 From: dynamikdev Date: Wed, 20 Jul 2016 09:32:11 +0000 Subject: [PATCH 1/2] Adding x509 support adding support for x509 create a specific authenticate_mongo_x509 as other mecanism --- txmongo/protocol.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/txmongo/protocol.py b/txmongo/protocol.py index 3909b58..a0a56c7 100644 --- a/txmongo/protocol.py +++ b/txmongo/protocol.py @@ -493,6 +493,16 @@ def authenticate_scram_sha1(self, database_name, username, password): if not result["done"]: raise MongoAuthenticationError("TxMongo: SASL conversation failed to complete.") + @defer.inlineCallbacks + def authenticate_mongo_x509(self, database_name, username, password): + query = SON([('authenticate', 1), + ('mechanism', 'MONGODB-X509'), + ('user', username)]) + result = yield self.__run_command('$external', query) + if not result["ok"]: + raise txmongo.MongoProtocol.MongoAuthenticationError(result["errmsg"]) + defer.returnValue(result) + @defer.inlineCallbacks def authenticate(self, database_name, username, password, mechanism): database_name = str(database_name) @@ -506,6 +516,8 @@ def authenticate(self, database_name, username, password, mechanism): auth_func = self.authenticate_mongo_cr elif mechanism == "SCRAM-SHA-1": auth_func = self.authenticate_scram_sha1 + elif mechanism == "MONGODB-X509": + auth_func = self.authenticate_mongo_x509 elif mechanism == "DEFAULT": if self.max_wire_version >= 3: auth_func = self.authenticate_scram_sha1 From 1bd192ab413f94ba386a20e0f42ab88ab26c65e2 Mon Sep 17 00:00:00 2001 From: dynamikdev Date: Wed, 20 Jul 2016 10:10:26 +0000 Subject: [PATCH 2/2] Update protocol.py --- txmongo/protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txmongo/protocol.py b/txmongo/protocol.py index a0a56c7..8a362b8 100644 --- a/txmongo/protocol.py +++ b/txmongo/protocol.py @@ -500,7 +500,7 @@ def authenticate_mongo_x509(self, database_name, username, password): ('user', username)]) result = yield self.__run_command('$external', query) if not result["ok"]: - raise txmongo.MongoProtocol.MongoAuthenticationError(result["errmsg"]) + raise MongoAuthenticationError(result["errmsg"]) defer.returnValue(result) @defer.inlineCallbacks