Esempio n. 1
0
    def test_cipher_params(self):
        params = CipherParams(secret_key='0123456789abcdef')
        assert params.algorithm == 'AES'
        assert params.mode == 'CBC'
        assert params.key_length == 128

        params = CipherParams(secret_key='0123456789abcdef' * 2)
        assert params.algorithm == 'AES'
        assert params.mode == 'CBC'
        assert params.key_length == 256
Esempio n. 2
0
    def test_cipher_params(self):
        params = CipherParams(secret_key='0123456789abcdef')
        self.assertEqual(params.algorithm, 'AES')
        self.assertEqual(params.mode, 'CBC')
        self.assertEqual(params.key_length, 128)

        params = CipherParams(secret_key='0123456789abcdef' * 2)
        self.assertEqual(params.algorithm, 'AES')
        self.assertEqual(params.mode, 'CBC')
        self.assertEqual(params.key_length, 256)
Esempio n. 3
0
 def test_encode(self):
     for item in self.items:
         # need to reset iv
         self.cipher_params = CipherParams(**self.params)
         self.cipher = get_cipher(self.cipher_params)
         data = self.get_encoded(item['encoded'])
         expected = item['encrypted']
         message = Message(item['encoded']['name'], data)
         message.encrypt(self.cipher)
         as_dict = message.as_dict()
         self.assertEqual(as_dict['data'], expected['data'])
         self.assertEqual(as_dict['encoding'], expected['encoding'])
Esempio n. 4
0
 def setUpClass(cls):
     with open(os.path.dirname(__file__) + '/../../submodules/test-resources/%s' % cls.fixture_file, 'r') as f:
         cls.fixture = json.loads(f.read())
         cls.params = {
             'secret_key': base64.b64decode(cls.fixture['key'].encode('ascii')),
             'mode': cls.fixture['mode'],
             'algorithm': cls.fixture['algorithm'],
             'iv': base64.b64decode(cls.fixture['iv'].encode('ascii')),
         }
         cls.cipher_params = CipherParams(**cls.params)
         cls.cipher = get_cipher(cls.cipher_params)
         cls.items = cls.fixture['items']
Esempio n. 5
0
    def test_cbc_channel_cipher(self):
        key = six.b('\x93\xe3\x5c\xc9\x77\x53\xfd\x1a'
                    '\x79\xb4\xd8\x84\xe7\xdc\xfd\xdf')
        iv = six.b('\x28\x4c\xe4\x8d\x4b\xdc\x9d\x42'
                   '\x8a\x77\x6b\x53\x2d\xc7\xb5\xc0')
        log.debug("KEY_LEN: %d" % len(key))
        log.debug("IV_LEN: %d" % len(iv))
        cipher = get_cipher(CipherParams(secret_key=key, iv=iv))

        plaintext = six.b("The quick brown fox")
        expected_ciphertext = six.b('\x28\x4c\xe4\x8d\x4b\xdc\x9d\x42'
                                    '\x8a\x77\x6b\x53\x2d\xc7\xb5\xc0'
                                    '\x83\x5c\xcf\xce\x0c\xfd\xbe\x37'
                                    '\xb7\x92\x12\x04\x1d\x45\x68\xa4'
                                    '\xdf\x7f\x6e\x38\x17\x4a\xff\x50'
                                    '\x73\x23\xbb\xca\x16\xb0\xe2\x84')

        actual_ciphertext = cipher.encrypt(plaintext)

        self.assertEqual(expected_ciphertext, actual_ciphertext)