Beispiel #1
0
 def test_aes_cbc_decrypt(self):
     self.assertEquals(aes_cbc_decrypt('datamustbe16byte', sha256(b'b'),
         'ivmustbe16bytesl'),
         b'x]\xb5\xa6\xe3\x10\xf4\x88\x91_\x03\xc6\xb9\xfb`)')
     self.assertEquals(aes_cbc_decrypt('datamustbe16byte', sha256(b'c'),
         'ivmustbe16bytesl'),
         b'\x06\x91 \xd9\\\xd8\x14\xa0\xdc\xd7\x82\xa0\x92\xfb\xe8l')
Beispiel #2
0
 def test_aes_cbc_decrypt(self):
     self.assertEqual(aes_cbc_decrypt(b'datamustbe16byte', sha256(b'b'),
                                       b'ivmustbe16bytesl'),
                       b'x]\xb5\xa6\xe3\x10\xf4\x88\x91_\x03\xc6\xb9\xfb`)')
     self.assertEqual(aes_cbc_decrypt(b'datamustbe16byte', sha256(b'c'),
                                       b'ivmustbe16bytesl'),
                       b'\x06\x91 \xd9\\\xd8\x14\xa0\xdc\xd7\x82\xa0\x92\xfb\xe8l')
Beispiel #3
0
    def _decrypt(self, stream):
        """
        Build the master key from header settings and key-hash list.
        
        Start reading from `stream` after the header and decrypt all the data.
        Remove padding as needed and feed into hashed block reader, set as
        in-buffer.
        """
        super(KDB4File, self)._decrypt(stream)

        ciphername = self.header.ciphers.get(self.header.CipherID,
                                             self.header.CipherID)
        if ciphername == 'AES':
            data = aes_cbc_decrypt(stream.read(), self.master_key,
                                   self.header.EncryptionIV)
            data = unpad(data)
        elif ciphername == 'Twofish':
            data = twofish_cbc_decrypt(stream.read(), self.master_key,
                                       self.header.EncryptionIV)
            data = unpad(data)
        else:
            raise IOError('Unsupported decryption type: %s' %
                          codecs.encode(ciphername, 'hex'))

        length = len(self.header.StreamStartBytes)
        if self.header.StreamStartBytes == data[:length]:
            # skip startbytes and wrap data in a hashed block io
            self.in_buffer = HashedBlockIO(initial_bytes=data[length:])
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Beispiel #4
0
 def _decrypt(self, stream):
     super(KDB3File, self)._decrypt(stream)
     
     data = aes_cbc_decrypt(stream.read(), self.master_key, 
         self.header.EncryptionIV)
     data = unpad(data)
     
     if self.header.ContentHash == sha256(data):
         # put data in bytes io
         self.in_buffer = io.BytesIO(data)
         # set successful decryption flag
         self.opened = True
     else:
         raise IOError('Master key invalid.')
Beispiel #5
0
    def _decrypt(self, stream):
        super(KDB3File, self)._decrypt(stream)

        data = aes_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
        data = unpad(data)

        if self.header.ContentHash == sha256(data):
            # put data in bytes io
            self.in_buffer = io.BytesIO(data)
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Beispiel #6
0
    def _decrypt(self, stream):
        super(KDB3File, self)._decrypt(stream)

        if self.header.encryption_flags[self.header.Flags-1] == 'AES':
            data = aes_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
            data = unpad(data)
        elif self.header.encryption_flags[self.header.Flags-1] == 'Twofish':
            data = twofish_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
            data = unpad(data)
        else:
            raise IOError('Unsupported encryption type: %s'%self.header.encryption_flags.get(self.header['Flags']-1, self.header['Flags']-1))

        if self.header.ContentHash == sha256(data):
            # put data in bytes io
            self.in_buffer = io.BytesIO(data)
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Beispiel #7
0
    def _decrypt(self, stream):
        """
        Build the master key from header settings and key-hash list.
        
        Start reading from `stream` after the header and decrypt all the data.
        Remove padding as needed and feed into hashed block reader, set as
        in-buffer.
        """
        super(KDB4File, self)._decrypt(stream)

        data = aes_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
        data = unpad(data)

        length = len(self.header.StreamStartBytes)
        if self.header.StreamStartBytes == data[:length]:
            # skip startbytes and wrap data in a hashed block io
            self.in_buffer = HashedBlockIO(initial_bytes=data[length:])
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Beispiel #8
0
 def _decrypt(self, stream):
     """
     Build the master key from header settings and key-hash list.
     
     Start reading from `stream` after the header and decrypt all the data.
     Remove padding as needed and feed into hashed block reader, set as
     in-buffer.
     """
     super(KDB4File, self)._decrypt(stream)
     
     data = aes_cbc_decrypt(stream.read(), self.master_key, 
         self.header.EncryptionIV)
     data = unpad(data)
     
     length = len(self.header.StreamStartBytes)
     if self.header.StreamStartBytes == data[:length]:
         # skip startbytes and wrap data in a hashed block io
         self.in_buffer = HashedBlockIO(bytes=data[length:])
         # set successful decryption flag
         self.opened = True
     else:
         raise IOError('Master key invalid.')
Beispiel #9
0
 def decrypt(self, encrypted_message):
     encrypted_message = base64.b64decode(encrypted_message)
     message = libkeepass_crypto.aes_cbc_decrypt(encrypted_message,
                                                 self.key, self.iv)
     return libkeepass_crypto.unpad(message)
Beispiel #10
0
 def decrypt(self, encrypted_message):
     encrypted_message = base64.b64decode(encrypted_message)
     message = libkeepass_crypto.aes_cbc_decrypt(encrypted_message, self.key, self.iv)
     return libkeepass_crypto.unpad(message)