implement DH and report functions
This commit is contained in:
+28
-2
@@ -11,6 +11,9 @@ CURVE = ec.SECP256R1()
|
||||
def GENERATE_DH():
|
||||
return ec.generate_private_key(CURVE)
|
||||
|
||||
def DH(dh_pair, dh_pub):
|
||||
return dh_pair.exchange(ec.ECDH(), dh_pub)
|
||||
|
||||
class MessengerServer:
|
||||
def __init__(self, server_signing_key, server_decryption_key):
|
||||
self.server_signing_key = server_signing_key
|
||||
@@ -54,5 +57,28 @@ class MessengerClient:
|
||||
return
|
||||
|
||||
def report(self, name, message):
|
||||
raise Exception("not implemented!")
|
||||
return
|
||||
report = (name, message)
|
||||
plaintext = pickle.dumps(report)
|
||||
temp_key = GENERATE_DH()
|
||||
temp_bytes = temp_key.public_key().public_bytes(
|
||||
serialization.Encoding.X962,
|
||||
serialization.PublicFormat.UncompressedPoint,
|
||||
)
|
||||
shared_secret = DH(temp_key, self.server_encryption_pk)
|
||||
hkdf = HKDF(
|
||||
algorithm=hashes.SHA256(),
|
||||
length=32,
|
||||
salt=None,
|
||||
info=b""
|
||||
)
|
||||
key = hkdf.derive(shared_secret)
|
||||
nonce = os.urandom(12)
|
||||
aesgcm = AESGCM(key)
|
||||
ciphertext = aesgcm.encrypt(nonce, plaintext, temp_bytes) # not sure if passing in temp_bytes is correct, but it seems like it should be
|
||||
data = {
|
||||
"bytes": temp_bytes,
|
||||
"nonce": nonce,
|
||||
"ciphertext": ciphertext
|
||||
}
|
||||
return plaintext.decode("latin1"), pickle.dumps(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user