|
|
|
@ -9,8 +9,8 @@ from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
|
|
|
|
from cryptography.hazmat.primitives import hashes
|
|
|
|
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
|
|
|
|
|
|
|
def encrypt_distribution_archive(args):
|
|
|
|
|
with open(args.provisioning_key, "rb") as provisioning_key_file:
|
|
|
|
|
def encrypt_distribution_archive(**kwargs):
|
|
|
|
|
with open(kwargs['provisioning_key'], "rb") as provisioning_key_file:
|
|
|
|
|
provisioning_key = serialization.load_der_public_key(provisioning_key_file.read())
|
|
|
|
|
|
|
|
|
|
distribution_key = AESGCM.generate_key(bit_length=256)
|
|
|
|
@ -19,10 +19,10 @@ def encrypt_distribution_archive(args):
|
|
|
|
|
padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
|
|
|
|
algorithm=hashes.SHA256(), label=None))
|
|
|
|
|
|
|
|
|
|
with open(args.distribution_key, 'wb') as distribution_key_file:
|
|
|
|
|
with open(kwargs['distribution_key'], 'wb') as distribution_key_file:
|
|
|
|
|
distribution_key_file.write(encrypted_distribution_key)
|
|
|
|
|
|
|
|
|
|
with open(args.distribution_archive, 'rb') as distribution_archive_file:
|
|
|
|
|
with open(kwargs['distribution_archive'], 'rb') as distribution_archive_file:
|
|
|
|
|
distribution_archive = distribution_archive_file.read()
|
|
|
|
|
|
|
|
|
|
aesgcm = AESGCM(distribution_key)
|
|
|
|
@ -30,7 +30,7 @@ def encrypt_distribution_archive(args):
|
|
|
|
|
encrypted_archive = aesgcm.encrypt(nonce, distribution_archive, None)
|
|
|
|
|
distribution_archive = None
|
|
|
|
|
|
|
|
|
|
with open(args.output, 'wb') as encrypted_archive_file:
|
|
|
|
|
with open(kwargs['output'], 'wb') as encrypted_archive_file:
|
|
|
|
|
encrypted_archive_file.write(nonce)
|
|
|
|
|
encrypted_archive_file.write(encrypted_archive)
|
|
|
|
|
|
|
|
|
@ -54,4 +54,4 @@ if __name__ == '__main__':
|
|
|
|
|
help='name of output file for distribution key')
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
encrypt_distribution_archive(args)
|
|
|
|
|
encrypt_distribution_archive(**args.__dict__)
|
|
|
|
|