Skip to content

Instantly share code, notes, and snippets.

@VulBusters
Created August 9, 2023 08:28
Show Gist options
  • Save VulBusters/c65beee7794e7e64a90a246a8b76a5a0 to your computer and use it in GitHub Desktop.
Save VulBusters/c65beee7794e7e64a90a246a8b76a5a0 to your computer and use it in GitHub Desktop.
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