diff options
| author | ruki <[email protected]> | 2022-04-30 11:05:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-30 11:05:37 +0800 |
| commit | 52e0611c6c6bc51fa235db770bec1583bd6a32fa (patch) | |
| tree | 880d7d0e47ee9314d52555f9d924b3eba7f700c0 /xmake/modules/private/service/server.lua | |
| parent | ffd4cc4ac71259be018ebba4a5176bb40adfc7cc (diff) | |
verify remote server user
Diffstat (limited to 'xmake/modules/private/service/server.lua')
| -rw-r--r-- | xmake/modules/private/service/server.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/xmake/modules/private/service/server.lua b/xmake/modules/private/service/server.lua index 4a80cd98a..92ebdec82 100644 --- a/xmake/modules/private/service/server.lua +++ b/xmake/modules/private/service/server.lua @@ -21,6 +21,7 @@ -- imports import("core.base.object") import("core.base.bytes") +import("core.base.base64") import("core.base.socket") import("core.base.scheduler") import("private.service.message") @@ -67,6 +68,55 @@ function server:port() return self._PORT end +-- set users +function server:users_set(users) + self._USERS = users +end + +-- get the user information +function server:user(name) + if name and self._USERS then + return self._USERS[name] + end +end + +-- we need verify user +function server:need_verfiy() + return self._USERS ~= nil +end + +-- verify user +function server:verify_user(auth) + if not auth then + return false, "client has no authorization, this remote server need user authorization!" + end + + -- decode authorization + local authstr = base64.decode(auth) + local splitinfo = authstr:str():split(":") + if not splitinfo or #splitinfo ~= 2 then + return false, "invalid authorization!" + end + + -- get client user and password + local client_user = splitinfo[1] + local client_pass = splitinfo[2] + if not client_user or not client_pass then + return false, "invalid user and password!" + end + + -- get server user and password + local server_userinfo = self:user(client_user) + assert(server_userinfo, "user(%s) is unknown!", client_user) + local server_pass = server_userinfo.pass + if client_pass ~= server_pass then + return false, "password is incorrect!" + end + + -- TODO check known_hosts + return true +end + -- run main loop function server:runloop() assert(self._HANDLER, "no handler found!") |
