def gendigest(digest, password, salt): assert password and salt salt = memoryview_to_bytes(salt) password = strtobytes(password) if digest=="des": from xpra.net.d3des import generate_response #pylint: disable=import-outside-toplevel password = password.ljust(8, b"\x00")[:8] salt = salt.ljust(16, b"\x00")[:16] v = generate_response(password, salt) return hexstr(v) if digest in ("xor", "kerberos", "gss"): #kerberos and gss use xor because we need to use the actual token #at the other end salt = salt.ljust(len(password), b"\x00")[:len(password)] from xpra.buffers.cyxor import xor_str #@UnresolvedImport pylint: disable=import-outside-toplevel v = xor_str(password, salt) return memoryview_to_bytes(v) digestmod = get_digest_module(digest) if not digestmod: log("invalid digest module '%s'", digest) return None #warn_server_and_exit(EXIT_UNSUPPORTED, # "server requested digest '%s' but it is not supported" % digest, "invalid digest") v = hmac.HMAC(password, salt, digestmod=digestmod).hexdigest() return v
def gendigest(digest, password, salt): assert digest and password and salt salt = memoryview_to_bytes(salt) password = strtobytes(password) if digest == "des": from xpra.net.d3des import generate_response password = password.ljust(8, "\x00")[:8] salt = salt.ljust(16, "\x00")[:16] v = generate_response(password, salt) return hexstr(v) elif digest == "xor": salt = salt.ljust(16, "\x00")[:len(password)] return memoryview_to_bytes(xor(password, salt)) digestmod = get_digest_module(digest) if not digestmod: log("invalid digest module '%s': %s", digest) return None #warn_server_and_exit(EXIT_UNSUPPORTED, "server requested digest '%s' but it is not supported" % digest, "invalid digest") v = hmac.HMAC(strtobytes(password), strtobytes(salt), digestmod=digestmod).hexdigest() return v
def gendigest(digest, password, salt): assert digest and password and salt salt = memoryview_to_bytes(salt) password = strtobytes(password) if digest=="des": from xpra.net.d3des import generate_response password = password.ljust(8, b"\x00")[:8] salt = salt.ljust(16, b"\x00")[:16] v = generate_response(password, salt) return hexstr(v) elif digest in ("xor", "kerberos", "gss"): #kerberos and gss use xor because we need to use the actual token #at the other end salt = salt.ljust(len(password), b"\x00")[:len(password)] v = xor(password, salt) return memoryview_to_bytes(v) digestmod = get_digest_module(digest) if not digestmod: log("invalid digest module '%s': %s", digest) return None #warn_server_and_exit(EXIT_UNSUPPORTED, "server requested digest '%s' but it is not supported" % digest, "invalid digest") v = hmac.HMAC(strtobytes(password), strtobytes(salt), digestmod=digestmod).hexdigest() return v
def test_generate_response(self): challange = b"helloworld0123456789"[:16] for passwd in (b"", b"0" * 32): r = generate_response(passwd, challange) assert r assert decrypt_passwd(b"helloworld"[:8])