Example #1
0
def encrypt_file_with_pgp(state, fd, key, fingerprint, dest_path):
    """
    Encrypt the file for a specific key
    """
    pgpctx = PGPContext(state.settings.tmp_path)

    pgpctx.load_key(key)

    pgpctx.encrypt_file(fingerprint, fd, dest_path)
Example #2
0
def encrypt_file_with_pgp(state, fd, key, fingerprint, dest_path):
    """
    Encrypt the file for a specific key
    """
    pgpctx = PGPContext(state.settings.tmp_path)

    pgpctx.load_key(key)

    pgpctx.encrypt_file(fingerprint, fd, dest_path)
Example #3
0
    def test_encrypt_file(self):
        file_src = os.path.join(os.getcwd(), 'test_plaintext_file.txt')
        file_dst = os.path.join(os.getcwd(), 'test_encrypted_file.txt')

        fake_receiver_desc = {
            'pgp_key_public': helpers.PGPKEYS['VALID_PGP_KEY1_PRV'],
            'pgp_key_fingerprint': u'BFB3C82D1B5F6A94BDAC55C6E70460ABF9A4C8C1',
            'username': u'*****@*****.**',
        }

        # these are the same lines used in delivery.py
        pgpctx = PGPContext()
        pgpctx.load_key(helpers.PGPKEYS['VALID_PGP_KEY1_PRV'])

        with open(file_src, 'w+') as f:
            f.write(self.secret_content)
            f.seek(0)

            pgpctx.encrypt_file(fake_receiver_desc['pgp_key_fingerprint'], f, file_dst)

        with open(file_dst, 'r') as f:
            self.assertEqual(str(pgpctx.gnupg.decrypt_file(f)), self.secret_content)
Example #4
0
def fsops_pgp_encrypt(state, sf, key, fingerprint):
    """
    Encrypt the file for a speficic key

    return
        path of encrypted file,
        length of the encrypted file
    """
    pgpctx = PGPContext(state.settings.tmp_path)

    pgpctx.load_key(key)

    with sf.open('r') as f:
        encrypted_file_path = os.path.join(os.path.abspath(state.settings.attachments_path), "pgp_encrypted-%s" % generateRandomKey(16))
        _, encrypted_file_size = pgpctx.encrypt_file(fingerprint, f, encrypted_file_path)

    return encrypted_file_path, encrypted_file_size