Skip to content

Commit

Permalink
remove unused "is_unsupported_legacy_hash"
Browse files Browse the repository at this point in the history
Change-Id: I2598f8c35e327535e4b07b4c7f8737e59faaad19
  • Loading branch information
hrantzsch committed Aug 20, 2024
1 parent 2797ee2 commit 69149b0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
15 changes: 0 additions & 15 deletions packages/cmk-crypto/cmk/crypto/password_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

import logging
import re
from typing import NewType

import bcrypt
Expand Down Expand Up @@ -92,17 +91,3 @@ def matches(password: Password, password_hash: PasswordHash) -> bool:
raise ValueError("Null character identified in password hash.")

return bcrypt.checkpw(password.raw_bytes, password_hash.encode("utf-8"))


def is_unsupported_legacy_hash(password_hash: PasswordHash) -> bool:
"""Was the hash algorithm used for this hash once supported but isn't anymore?"""
regex_list = [
r"^\$5\$(rounds=[0-9]+\$)?[a-zA-Z0-9\/.]{0,16}\$[a-zA-Z0-9\/.]{43}$", # SHA256 crypt
r"^\$1\$[a-zA-Z0-9\/.]{0,8}\$[a-zA-Z0-9\/.]{22}", # MD5 crypt
r"^\$apr1\$[a-zA-Z0-9\/.]{0,8}\$[a-zA-Z0-9\/.]{22}$", # Apache MD5
r"^[a-zA-Z0-9\/.]{13}$", # DES crypt
]
for regex in regex_list:
if re.match(regex, password_hash):
return True
return False
23 changes: 0 additions & 23 deletions packages/cmk-crypto/tests/test_password_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,3 @@ def test_verify_null_bytes(password: str, password_hash: str) -> None:
def test_verify_invalid_rounds(password: str, pw_hash: str) -> None:
with pytest.raises(ValueError, match="Invalid salt"):
ph.verify(Password(password), ph.PasswordHash(pw_hash))


@pytest.mark.parametrize(
"unsupported,pw_hash",
[
(True, "$1$49rn5.0y$XoUJMucpN.aQUEOquaj5C/"),
(True, "$apr1$EpPwa/X9$TB2UcQxmrSTJWQQcwHzJM/"),
(True, "WsbFVbJdvDcpY"),
(True, "48c/R8JAv757A"), # Des crypt
(True, "$1$28772684$iEwNOgGugqO9.bIz5sk8k/"), # MD5 Crypt
(
True,
"$5$rounds=5000$GX7BopJZJxPc/KEK$le16UF8I2Anb.rOrn22AUPWvzUETDGefUmAV8AZkGcD",
), # Sha256 crypt
(True, "$5$rounds=1000$.J4mcfJGFGgWJA7R$bDhUCLMe2v1.L3oWclfsVYMyOhsS/6RmyzqFRyCgDi/"),
(False, "foobar"), # ignore unrecognized algorithms
(False, ""),
(False, "$2b$04$5LiM0CX3wUoO55cGCwrkDeZIU5zyBqPDZfV9zU4Q2WH/Lkkn2lypa"),
(False, "$2y$04$5LiM0CX3wUoO55cGCwrkDeZIU5zyBqPDZfV9zU4Q2WH/Lkkn2lypa"),
],
)
def test_is_unsupported_legacy_hash(unsupported: bool, pw_hash: str) -> None:
assert ph.is_unsupported_legacy_hash(ph.PasswordHash(pw_hash)) == unsupported

0 comments on commit 69149b0

Please sign in to comment.