Created
August 9, 2023 08:28
-
-
Save VulBusters/c65beee7794e7e64a90a246a8b76a5a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def key_exchange(self, client_pub_key) -> tuple[bool, dict]: | |
try: | |
_salt = os.urandom(16) | |
shared_secret = self.get_shared_secret(client_pub_key) | |
session_key = self.get_shared_secret_kdf(_salt, shared_secret) | |
keyId = self.generate_kid(session_key) | |
kex_result = { | |
'KeyId': keyId, | |
'Salt': _salt.hex(), | |
'ServerPublicKey': self.serv_priv_key.public_key().public_bytes( | |
encoding = serialization.Encoding.DER, | |
format = serialization.PublicFormat.SubjectPublicKeyInfo | |
).hex() | |
} | |
return (True, kex_result) | |
except ValueError: | |
return (False, msg_config.KEX_INVALID_DER) | |
except UnsupportedAlgorithm: | |
return (False, msg_config.KEX_INVALID_ALG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment