Skip to content

Commit

Permalink
User: Populate the SHA-256 and SHA-512-256 digest hashes on 3.2+ DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Jul 13, 2022
1 parent a3e0c7d commit 5254a88
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions opensipscli/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
USER_PASS_COL = "password"
USER_HA1_COL = "ha1"
USER_HA1B_COL = "ha1b"
USER_HA1_SHA256_COL = "ha1_sha256"
USER_HA1_SHA512T256_COL = "ha1_sha512t256"
USER_RPID_COL = "rpid"

class user(Module):
Expand Down Expand Up @@ -108,6 +110,16 @@ def user_get_ha1b(self, user, domain, password):
string = "{}@{}:{}:{}".format(user, domain, domain, password)
return hashlib.md5(string.encode('utf-8')).hexdigest()

def user_get_ha1_sha256(self, user, domain, password):
string = "{}:{}:{}".format(user, domain, password)
return hashlib.sha256(string.encode('utf-8')).hexdigest()

def user_get_ha1_sha512t256(self, user, domain, password):
string = "{}:{}:{}".format(user, domain, password)
o = hashlib.new("sha512_256")
o.update(string.encode('utf-8'))
return o.hexdigest()

def do_add(self, params=None, modifiers=None):

if len(params) < 1:
Expand Down Expand Up @@ -149,6 +161,11 @@ def do_add(self, params=None, modifiers=None):
if osips_ver < '3.2':
insert_dict[USER_HA1B_COL] = \
self.user_get_ha1b(username, domain, password)
else:
insert_dict[USER_HA1_SHA256_COL] = \
self.user_get_ha1_sha256(username, domain, password)
insert_dict[USER_HA1_SHA512T256_COL] = \
self.user_get_ha1_sha512t256(username, domain, password)

insert_dict[USER_PASS_COL] = \
password if cfg.getBool("plain_text_passwords") else ""
Expand Down

0 comments on commit 5254a88

Please sign in to comment.