No need to have avoid timing side-channel attack in user_add. We're just going to tell you if the user already exists anyway.

This commit is contained in:
James Valleroy authored and Nick Daly committed 2013-11-11 07:34:27 -06:00
1 parent 96edae33ed
commit 2f7b56e6a9
2 files changed
+18 -20

No files matched your search

+17 -19
View File
@@ -23,29 +23,27 @@ def add_user(username, passphrase, name='', email='', expert=False):
if not username: error = "Must specify a username!"
if not passphrase: error = "Must specify a passphrase!"
if error is None:
# hash the password whether the user exists, to foil timing
# side-channel attacks
try:
pass_hash = bcrypt.encrypt(passphrase)
except PasswordSizeError:
error = "Password is too long."
if error is None:
if username in map(lambda x: x[0], cfg.users.get_all()):
error = "User already exists!"
else:
di = {
'username':username,
'name':name,
'email':email,
'expert':'on' if expert else 'off',
'groups':['expert'] if expert else [],
'passphrase':pass_hash,
'salt':pass_hash[7:29], # for bcrypt
}
new_user = User(di)
cfg.users.set(username,new_user)
try:
pass_hash = bcrypt.encrypt(passphrase)
except PasswordSizeError:
error = "Password is too long."
if error is None:
di = {
'username':username,
'name':name,
'email':email,
'expert':'on' if expert else 'off',
'groups':['expert'] if expert else [],
'passphrase':pass_hash,
'salt':pass_hash[7:29], # for bcrypt
}
new_user = User(di)
cfg.users.set(username,new_user)
if error:
cfg.log(error)