コード例 #1
0
    def setUp(self):
        self._fixtures_dir = pjoin(BASE_DIR, 'fixtures/')

        self._dir1 = pjoin(self._fixtures_dir, 'public/')
        self._dir2 = pjoin(self._fixtures_dir, 'private/')

        self._encrypter = HybridCryptoEncrypter(keys_path=self._dir1)
        self._decrypter = HybridCryptoDecrypter(keys_path=self._dir2)
コード例 #2
0
    def get(self, account_uuid):
        refresh_token = get_refresh_token_for_user(account_uuid=account_uuid)

        if not refresh_token:
            raise HTTPError(status_code=httplib.NOT_FOUND,
                            log_message='Token not found')

        decrypter = HybridCryptoDecrypter(keys_path=options.private_keys_path)
        refresh_token = decrypter.decrypt(data=refresh_token)

        data = {'refresh_token': refresh_token}
        self.write_json(data, status_code=201)
コード例 #3
0
class HybridCryptoTestCase(unittest.TestCase):
    def setUp(self):
        self._fixtures_dir = pjoin(BASE_DIR, 'fixtures/')

        self._dir1 = pjoin(self._fixtures_dir, 'public/')
        self._dir2 = pjoin(self._fixtures_dir, 'private/')

        self._encrypter = HybridCryptoEncrypter(keys_path=self._dir1)
        self._decrypter = HybridCryptoDecrypter(keys_path=self._dir2)

    def test_aes_encrypt_and_decrypt_round_trip(self):
        test_data = [
            'foo',
            'foo bar ponies',
            'ponies bar foo ponies',
            'abcd12345'
            'test99',
            'a' * 500 + 'b' * 500 + 'c' * 1000
        ]

        key = RandBytes(n=(256/8))

        for plain_text in test_data:
            encrypted = self._encrypter._aes_encrypt(key=key, data=plain_text)
            self.assertNotEqual(encrypted, plain_text)

            decrypted = self._decrypter._aes_decrypt(key=key, data=encrypted)
            self.assertEqual(decrypted, plain_text)

    def test_encrypt_and_decrypt_round_trip(self):
        test_data = [
            # Short messages (only public-key cryptography is used)
            'foo',
            'foo bar ponies',
            'ponies bar foo ponies',
            'abcd12345'
            'test99',
            'a' * 214,  # 2048 / 8 - 41

            # Long messages (PKC + AES CBC is used)
            'a' * 500 + 'b' * 500 + 'c' * 500,
            'test' * 100
        ]

        for data in test_data:
            encrypted = self._encrypter.encrypt(data=data)
            self.assertNotEqual(encrypted, data)

            decrypted = self._decrypter.decrypt(data=encrypted)
            self.assertEqual(decrypted, data)
コード例 #4
0
    def get(self, account_uuid):
        refresh_token = get_refresh_token_for_user(account_uuid=account_uuid)

        if not refresh_token:
            raise HTTPError(status_code=httplib.NOT_FOUND,
                            log_message='Token not found')

        decrypter = HybridCryptoDecrypter(keys_path=options.private_keys_path)
        refresh_token = decrypter.decrypt(data=refresh_token)

        # TODO: Prevent thundering herd from multiple requests
        result = yield Task(get_new_access_token, refresh_token=refresh_token)

        data = {'access_token': result['access_token']}
        self.write_json(data, status_code=httplib.OK)
コード例 #5
0
    def setUp(self):
        self._fixtures_dir = pjoin(BASE_DIR, 'fixtures/')

        self._dir1 = pjoin(self._fixtures_dir, 'public/')
        self._dir2 = pjoin(self._fixtures_dir, 'private/')

        self._encrypter = HybridCryptoEncrypter(keys_path=self._dir1)
        self._decrypter = HybridCryptoDecrypter(keys_path=self._dir2)
コード例 #6
0
class HybridCryptoTestCase(unittest.TestCase):
    def setUp(self):
        self._fixtures_dir = pjoin(BASE_DIR, 'fixtures/')

        self._dir1 = pjoin(self._fixtures_dir, 'public/')
        self._dir2 = pjoin(self._fixtures_dir, 'private/')

        self._encrypter = HybridCryptoEncrypter(keys_path=self._dir1)
        self._decrypter = HybridCryptoDecrypter(keys_path=self._dir2)

    def test_aes_encrypt_and_decrypt_round_trip(self):
        test_data = [
            'foo', 'foo bar ponies', 'ponies bar foo ponies', 'abcd12345'
            'test99', 'a' * 500 + 'b' * 500 + 'c' * 1000
        ]

        key = RandBytes(n=(256 / 8))

        for plain_text in test_data:
            encrypted = self._encrypter._aes_encrypt(key=key, data=plain_text)
            self.assertNotEqual(encrypted, plain_text)

            decrypted = self._decrypter._aes_decrypt(key=key, data=encrypted)
            self.assertEqual(decrypted, plain_text)

    def test_encrypt_and_decrypt_round_trip(self):
        test_data = [
            # Short messages (only public-key cryptography is used)
            'foo',
            'foo bar ponies',
            'ponies bar foo ponies',
            'abcd12345'
            'test99',
            'a' * 214,  # 2048 / 8 - 41

            # Long messages (PKC + AES CBC is used)
            'a' * 500 + 'b' * 500 + 'c' * 500,
            'test' * 100
        ]

        for data in test_data:
            encrypted = self._encrypter.encrypt(data=data)
            self.assertNotEqual(encrypted, data)

            decrypted = self._decrypter.decrypt(data=encrypted)
            self.assertEqual(decrypted, data)