示例#1
0
 def setUp(self):
     self.cleartext = BytesIO('rosa de foc')
     self.secret = 'A' * 96
     self.blob = _crypto.BlobEncryptor(self.doc_info,
                                       self.cleartext,
                                       armor=False,
                                       secret='A' * 96)
示例#2
0
    def test_blob_encryptor(self):

        inf = BytesIO(snowden1)

        blob = _crypto.BlobEncryptor(self.doc_info, inf, secret='A' * 96)

        encrypted = yield blob.encrypt()
        preamble, ciphertext = _crypto._split(encrypted.getvalue())
        ciphertext = ciphertext[:-16]

        assert len(preamble) == _crypto.PACMAN.size
        unpacked_data = _crypto.PACMAN.unpack(preamble)
        magic, sch, meth, ts, iv, doc_id, rev, _ = unpacked_data
        assert magic == _crypto.BLOB_SIGNATURE_MAGIC
        assert sch == 1
        assert meth == _crypto.ENC_METHOD.aes_256_gcm
        assert iv == blob.iv
        assert doc_id == 'D-deadbeef'
        assert rev == self.doc_info.rev

        aes_key = _crypto._get_sym_key_for_doc(self.doc_info.doc_id, 'A' * 96)
        assert ciphertext == _aes_encrypt(aes_key, blob.iv, snowden1)[0]

        decrypted = _aes_decrypt(aes_key, blob.iv, blob.tag, ciphertext,
                                 preamble)
        assert str(decrypted) == snowden1
示例#3
0
 def test_get_unarmored_ciphertext_size(self):
     for size_to_test in xrange(20):  # test from 0 to above tag size
         test_content = '\x00' * size_to_test
         size = _crypto.get_unarmored_ciphertext_size(len(test_content))
         inf = BytesIO(test_content)
         blob = _crypto.BlobEncryptor(self.doc_info,
                                      inf,
                                      armor=False,
                                      secret='A' * 96)
         encrypted = yield blob.encrypt()
         assert len(encrypted.getvalue()) == size, size_to_test
示例#4
0
    def test_blob_decryptor(self):

        inf = BytesIO(snowden1)

        blob = _crypto.BlobEncryptor(self.doc_info, inf, secret='A' * 96)
        ciphertext = yield blob.encrypt()

        decryptor = _crypto.BlobDecryptor(self.doc_info,
                                          ciphertext,
                                          secret='A' * 96)
        decrypted = yield decryptor.decrypt()
        assert decrypted == snowden1
示例#5
0
 def setUp(self):
     self.cleartext = BytesIO(snowden1)
     self.blob = _crypto.BlobEncryptor(self.doc_info,
                                       self.cleartext,
                                       secret='A' * 96)
示例#6
0
 def setUp(self):
     self.inf = BytesIO(snowden1)
     self.blob = _crypto.BlobEncryptor(self.doc_info,
                                       self.inf,
                                       armor=True,
                                       secret='A' * 96)