Ejemplo n.º 1
0
    def gpg_cycle(self, s, profile=None):
        u"""Test encryption/decryption cycle on string s"""
        epath = path.Path(u"testfiles/output/encrypted_file")
        if not profile:
            profile = self.default_profile
        encrypted_file = gpg.GPGFile(1, epath, profile)
        encrypted_file.write(s)
        encrypted_file.close()

        epath2 = path.Path(u"testfiles/output/encrypted_file")
        decrypted_file = gpg.GPGFile(0, epath2, profile)
        dec_buf = decrypted_file.read()
        decrypted_file.close()

        assert s == dec_buf, (len(s), len(dec_buf))
Ejemplo n.º 2
0
    def test_gpg_signing(self):
        u"""Test to make sure GPG reports the proper signature key"""
        plaintext = b"hello" * 50000

        signing_profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
                                         sign_key=self.sign_key,
                                         recipients=[self.encrypt_key1])

        epath = path.Path(u"testfiles/output/encrypted_file")
        encrypted_signed_file = gpg.GPGFile(1, epath, signing_profile)
        encrypted_signed_file.write(plaintext)
        encrypted_signed_file.close()

        decrypted_file = gpg.GPGFile(0, epath, signing_profile)
        assert decrypted_file.read() == plaintext
        decrypted_file.close()
        sig = decrypted_file.get_signature()
        assert sig == self.sign_key, sig
Ejemplo n.º 3
0
    def test_gpg_signing_and_hidden_encryption(self):
        """Test to make sure GPG reports the proper signature key even with hidden encryption key id"""
        plaintext = "hello" * 50000

        signing_profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
                                         sign_key=self.sign_key,
                                         hidden_recipients=[self.encrypt_key1])

        epath = path.Path("testfiles/output/encrypted_file")
        encrypted_signed_file = gpg.GPGFile(1, epath, signing_profile)
        encrypted_signed_file.write(plaintext)
        encrypted_signed_file.close()

        decrypted_file = gpg.GPGFile(0, epath, signing_profile)
        assert decrypted_file.read() == plaintext
        decrypted_file.close()
        sig = decrypted_file.get_signature()
        assert sig == self.sign_key, sig[-8:]
Ejemplo n.º 4
0
    def filtered_open(self, mode="rb", gpg_profile=None):
        """
        Return fileobj with appropriate encryption/compression

        If encryption is specified but no gpg_profile, use
        globals.default_profile.
        """
        assert not self.opened and not self.fileobj
        assert not (self.pr.encrypted and self.pr.compressed)
        if gpg_profile:
            assert self.pr.encrypted

        if self.pr.compressed:
            return gzip.GzipFile(self.name, mode)
        elif self.pr.encrypted:
            if not gpg_profile:
                gpg_profile = globals.gpg_profile
            if mode == "rb":
                return gpg.GPGFile(False, self, gpg_profile)
            elif mode == "wb":
                return gpg.GPGFile(True, self, gpg_profile)
        else:
            return self.open(mode)