From ffa2bbf1e4ee60e8fb99c4a28c4a4edec9918c95 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 15 Jun 2016 16:48:02 +0800 Subject: [PATCH 1/2] support mongo auth_scram_sha1 --- lualib-src/lua-crypt.c | 20 +++++++++++ lualib/mongo.lua | 81 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/lualib-src/lua-crypt.c b/lualib-src/lua-crypt.c index 5322b2d6..7910d367 100644 --- a/lualib-src/lua-crypt.c +++ b/lualib-src/lua-crypt.c @@ -878,6 +878,25 @@ lb64decode(lua_State *L) { return 1; } +static int +lxor_str(lua_State *L) { + size_t len1,len2; + const char *s1 = luaL_checklstring(L,1,&len1); + const char *s2 = luaL_checklstring(L,2,&len2); + if (len2 == 0) { + return luaL_error(L, "Can't xor empty string"); + } + luaL_Buffer b; + char * buffer = luaL_buffinitsize(L, &b, len1); + int i; + for (i=0;i Date: Wed, 15 Jun 2016 17:58:58 +0800 Subject: [PATCH 2/2] add authmod in conf --- lualib/mongo.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lualib/mongo.lua b/lualib/mongo.lua index a8acee9e..877982f4 100644 --- a/lualib/mongo.lua +++ b/lualib/mongo.lua @@ -84,11 +84,15 @@ end local function mongo_auth(mongoc) local user = rawget(mongoc, "username") local pass = rawget(mongoc, "password") + local authmod = rawget(mongoc, "authmod") or "scram_sha1" + authmod = "auth_" .. authmod return function() if user ~= nil and pass ~= nil then --- assert(mongoc:auth(user, pass)) - assert(mongoc:auth_scram_sha1(user, pass)) + -- autmod can be "mongodb_cr" or "scram_sha1" + local auth_func = mongoc[authmod] + assert(auth_func , "Invalid authmod") + assert(auth_func(mongoc,user, pass)) end local rs_data = mongoc:runCommand("ismaster") if rs_data.ok == 1 then @@ -124,6 +128,7 @@ function mongo.client( conf ) port = first.port or 27017, username = first.username, password = first.password, + authmod = first.authmod, } obj.__id = 0 @@ -174,7 +179,7 @@ function mongo_client:runCommand(...) return self.admin:runCommand(...) end -function mongo_client:auth(user,password) +function mongo_client:auth_mongodb_cr(user,password) local password = md5.sumhexa(string.format("%s:mongo:%s",user,password)) local result= self:runCommand "getnonce" if result.ok ~=1 then