MaximilianClemens / checkmk_fritzbox

Extended CheckMK FritzBox Agent for SmartHome Devices.
GNU General Public License v2.0
10 stars 3 forks source link

Implement Support for PBKDF2-Challenge #4

Open MaximilianClemens opened 3 years ago

MaximilianClemens commented 3 years ago

Added with Fritz!OS 7.24 AVM_Technical_Note - German, Englisch

They also removed the login option without username, there is now a feature to query the username before login. Recommendation - German, Englisch

MaximilianClemens commented 3 years ago

Sample Code from the AVM Document

def calculate_pbkdf2_response(challenge: str, password:str) -> str:
    """ Calculate the response for a given challenge via PBKDF2 """
    challenge_parts = challenge.split("$")
    # Extract all necessary values encoded into the challenge
    iter1 = int(challenge_parts[1])
    salt1 = bytes.fromhex(challenge_parts[2])
    iter2 = int(challenge_parts[3])
    salt2 = bytes.fromhex(challenge_parts[4])
    # Hash twice, once with static salt...
    hash1 = hashlib.pbkdf2_hmac("sha256",password.encode(),salt1,iter1)
    # Once with dynamic salt.
    hash2 = hashlib.pbkdf2_hmac("sha256",hash1,salt2,iter2)
    return f"{challenge_parts[4]}${hash2.hex()}"