mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
commit
3e94b09d3b
1 changed files with 12 additions and 29 deletions
41
helpers.lua
41
helpers.lua
|
@ -598,26 +598,20 @@ function ensure_user_password_uses_strong_hash(ldap, user, password)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Read result of a command after given it securely the password
|
-- Read result of a command after given it securely the password
|
||||||
function secure_cmd_password(cmd, password)
|
function secure_cmd_password(cmd, password, start)
|
||||||
-- Check password validity
|
-- Check password validity
|
||||||
math.randomseed( os.time() )
|
math.randomseed( os.time() )
|
||||||
local tmp_file = "/tmp/ssowat_"..math.random()
|
local tmp_file = "/tmp/ssowat_"..math.random()
|
||||||
local w_pwd = io.popen(string.format(cmd, tmp_file), 'w')
|
local w_pwd = io.popen("("..cmd..") tee -a "..tmp_file, 'w')
|
||||||
w_pwd:write(password)
|
w_pwd:write(password)
|
||||||
|
-- This second write is just to validate the password question
|
||||||
|
-- Do not remove
|
||||||
w_pwd:write("")
|
w_pwd:write("")
|
||||||
w_pwd:close()
|
w_pwd:close()
|
||||||
local r_pwd = io.open(tmp_file, 'r')
|
local r_pwd = io.open(tmp_file, 'r')
|
||||||
local i = 0
|
text = r_pwd:read "*a"
|
||||||
local text = ""
|
|
||||||
for line in io.lines(tmp_file) do
|
|
||||||
i = i + 1
|
|
||||||
if i > 4 then
|
|
||||||
text = text..line.."\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
r_pwd:close()
|
r_pwd:close()
|
||||||
os.remove(tmp_file)
|
os.remove(tmp_file)
|
||||||
ngx.log(ngx.STDERR, text)
|
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -651,19 +645,11 @@ function edit_user()
|
||||||
-- and the new password against the confirmation field's content
|
-- and the new password against the confirmation field's content
|
||||||
if args.newpassword == args.confirm then
|
if args.newpassword == args.confirm then
|
||||||
-- Check password validity
|
-- Check password validity
|
||||||
local valid_result = secure_cmd_password("( python /usr/lib/moulinette/yunohost/utils/password.py 2>&1 || echo ::ERROR:: ) | tee -a %s", args.newpassword)
|
local result_msg = secure_cmd_password("python /usr/lib/moulinette/yunohost/utils/password.py", args.newpassword)
|
||||||
-- We remove 4 lines due to a Warning message
|
validation_error = true
|
||||||
local i = 0
|
|
||||||
local validation_error = nil
|
|
||||||
local result_msg = nil
|
|
||||||
|
|
||||||
for line in string.gmatch(valid_result, "[^\n]+") do
|
if result_msg == 'password_advice' or result_msg == nil or result_msg == "" then
|
||||||
if i == 0 then
|
validation_error = nil
|
||||||
result_msg = line
|
|
||||||
else
|
|
||||||
validation_error = line
|
|
||||||
end
|
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
if validation_error == nil then
|
if validation_error == nil then
|
||||||
|
|
||||||
|
@ -883,11 +869,8 @@ end
|
||||||
-- hash the user password using sha-512 and using {CRYPT} to uses linux auth system
|
-- hash the user password using sha-512 and using {CRYPT} to uses linux auth system
|
||||||
-- because ldap doesn't support anything stronger than sha1
|
-- because ldap doesn't support anything stronger than sha1
|
||||||
function hash_password(password)
|
function hash_password(password)
|
||||||
-- TODO is the password checked by regex? we don't want to
|
local hashed_password = secure_cmd_password("mkpasswd --method=sha-512", password)
|
||||||
-- allow shell injection
|
hashed_password = "{CRYPT}"..hashed_password
|
||||||
local mkpasswd = io.popen("mkpasswd --method=sha-512 '" ..password:gsub("'", "'\\''").."'")
|
|
||||||
local hashed_password = "{CRYPT}"..mkpasswd:read()
|
|
||||||
mkpasswd:close()
|
|
||||||
return hashed_password
|
return hashed_password
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -901,7 +884,7 @@ function login()
|
||||||
local uri_args = ngx.req.get_uri_args()
|
local uri_args = ngx.req.get_uri_args()
|
||||||
|
|
||||||
args.user = string.lower(args.user)
|
args.user = string.lower(args.user)
|
||||||
|
|
||||||
local user = authenticate(args.user, args.password)
|
local user = authenticate(args.user, args.password)
|
||||||
if user then
|
if user then
|
||||||
ngx.status = ngx.HTTP_CREATED
|
ngx.status = ngx.HTTP_CREATED
|
||||||
|
|
Loading…
Reference in a new issue