示例#1
0
 def filter_write(self, cleartext, repo, toplevel):
     if not self.keyid:
         return cleartext
     symmetric_key = self.get_symmetric_key(repo, toplevel)
     return obnamlib.encrypt_symmetric(cleartext,
                                       symmetric_key,
                                       gpghome=self.gnupghome)
示例#2
0
 def test_encrypts_into_different_string_than_cleartext(self):
     cleartext = 'hello world'
     key = 'sekr1t'
     encrypted = obnamlib.encrypt_symmetric(cleartext,
                                            key,
                                            gpghome=self.gpghome)
     self.assertNotEqual(cleartext, encrypted)
示例#3
0
 def test_encrypt_decrypt_round_trip(self):
     cleartext = 'hello, world'
     key = 'sekr1t'
     encrypted = obnamlib.encrypt_symmetric(cleartext, key,
                                            gpghome=self.gpghome)
     decrypted = obnamlib.decrypt_symmetric(encrypted, key,
                                            gpghome=self.gpghome)
     self.assertEqual(decrypted, cleartext)
示例#4
0
 def test_encrypt_decrypt_round_trip(self):
     cleartext = 'hello, world'
     key = 'sekr1t'
     encrypted = obnamlib.encrypt_symmetric(cleartext,
                                            key,
                                            gpghome=self.gpghome)
     decrypted = obnamlib.decrypt_symmetric(encrypted,
                                            key,
                                            gpghome=self.gpghome)
     self.assertEqual(decrypted, cleartext)
示例#5
0
    def toplevel_init(self, repo, toplevel):
        '''Initialize a new toplevel for encryption.'''

        if not self.keyid:
            return

        pubkeys = obnamlib.Keyring()
        pubkeys.add(self.pubkey)

        symmetric_key = obnamlib.generate_symmetric_key(
            self.symmetric_key_bits, filename=self.devrandom)
        encrypted = obnamlib.encrypt_with_keyring(symmetric_key, pubkeys)
        self._write_file(repo, os.path.join(toplevel, 'key'), encrypted)

        encoded = str(pubkeys)
        encrypted = obnamlib.encrypt_symmetric(encoded, symmetric_key)
        self._write_file(repo, os.path.join(toplevel, 'userkeys'), encrypted)
示例#6
0
    def toplevel_init(self, repo, toplevel):
        '''Initialize a new toplevel for encryption.'''

        if not self.keyid:
            return

        pubkeys = obnamlib.Keyring()
        pubkeys.add(self.pubkey)

        symmetric_key = obnamlib.generate_symmetric_key(
            self.symmetric_key_bits, filename=self.devrandom)
        encrypted = obnamlib.encrypt_with_keyring(symmetric_key, pubkeys)
        self._write_file(repo, os.path.join(toplevel, 'key'), encrypted)

        encoded = str(pubkeys)
        encrypted = obnamlib.encrypt_symmetric(encoded, symmetric_key)
        self._write_file(repo, os.path.join(toplevel, 'userkeys'), encrypted)
示例#7
0
 def test_encrypts_into_different_string_than_cleartext(self):
     cleartext = 'hello world'
     key = 'sekr1t'
     encrypted = obnamlib.encrypt_symmetric(cleartext, key)
     self.assertNotEqual(cleartext, encrypted)
示例#8
0
 def filter_write(self, cleartext, repo, toplevel):
     if not self.keyid:
         return cleartext
     symmetric_key = self.get_symmetric_key(repo, toplevel)
     return obnamlib.encrypt_symmetric(cleartext, symmetric_key)