def __init__(self, filename, session=None,
readers_public_key=None,
writers_private_key=None):
self.fd = standard.WritableAddressSpace(
filename=filename, session=session, mode="w+b")
self.session = session
self.profile = AgentProfile(session=session)
self.cipher = CipherProperties(session=session).generate_keys()
self.readers_public_key = readers_public_key
self.writers_private_key = writers_private_key
# Cipher is encrypted with the reader's public key - only the reader can
# read it. It is also signed with the sender's private key.
signature = Signature(session=session)
cipher_plain_text = self.cipher.to_json()
signature.encrypted_cipher = readers_public_key.encrypt(
cipher_plain_text)
signature.signature = writers_private_key.sign(cipher_plain_text)
serialized_signature = signature.to_json()
self.write_part(serialized_signature, "EncryptedCipher")
self.hmac = hmac.HMAC(self.cipher.hmac_key.RawBytes(),
hashes.SHA256(),
backend=openssl.backend)
self.hmac.update(serialized_signature)
评论列表
文章目录