コード例 #1
0
ファイル: restcrypto_test.py プロジェクト: jdavid/ably-python
    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({'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)
コード例 #2
0
ファイル: restcrypto_test.py プロジェクト: ably/ably-python
    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({'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)

        assert expected_ciphertext == actual_ciphertext
コード例 #3
0
ファイル: channel.py プロジェクト: vintasoftware/ably-python
    def options(self, options):
        self.__options = options

        if options and options.encrypted:
            self.__cipher = get_cipher(options.cipher_params)
        else:
            self.__cipher = None
コード例 #4
0
ファイル: channel.py プロジェクト: ably/ably-python
    def options(self, options):
        self.__options = options

        if options and 'cipher' in options:
            cipher = options.get('cipher')
            if cipher is not None:
                cipher = get_cipher(cipher)
            self.__cipher = cipher
コード例 #5
0
ファイル: channel.py プロジェクト: abordeau/ably-python
    def options(self, options):
        self.__options = options

        if options and 'cipher' in options:
            cipher = options.get('cipher')
            if cipher is not None:
                cipher = get_cipher(cipher)
            self.__cipher = cipher
コード例 #6
0
ファイル: channel.py プロジェクト: jdavid/ably-python
    def options(self, options):
        self.__options = options

        if options and 'cipher' in options:
            if options.get('cipher') is not None:
                self.__cipher = get_cipher(options.get('cipher'))
            else:
                self.__cipher = None
コード例 #7
0
ファイル: channel.py プロジェクト: avsd/ably-python
    def __init__(self, ably, name, options):
        self.__ably = ably
        self.__name = name
        self.__options = options
        self.__base_path = '/channels/%s/' % quote(name)
        self.__presence = Presence(self)

        if options and options.encrypted:
            self.__cipher = get_cipher(options.cipher_params)
        else:
            self.__cipher = None
コード例 #8
0
ファイル: restcrypto_test.py プロジェクト: jdavid/ably-python
 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']
コード例 #9
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"]
コード例 #10
0
ファイル: restcrypto_test.py プロジェクト: jdavid/ably-python
 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'])
コード例 #11
0
ファイル: restcrypto_test.py プロジェクト: ably/ably-python
 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()
         assert as_dict['data'] == expected['data']
         assert as_dict['encoding'] == expected['encoding']
コード例 #12
0
ファイル: restcrypto_test.py プロジェクト: ably/ably-python
 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']
コード例 #13
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"])
コード例 #14
0
ファイル: restcrypto_test.py プロジェクト: ably/ably-python
    def test_crypto_encrypted_unhandled(self):
        channel_name = self.get_channel_name('persisted:crypto_send_encrypted_unhandled')
        key = six.b('0123456789abcdef')
        data = six.u('foobar')
        publish0 = self.ably.channels.get(channel_name, cipher={'key': key})

        publish0.publish("publish0", data)

        rx_channel = self.ably2.channels[channel_name]
        history = rx_channel.history()
        message = history.items[0]
        cipher = get_cipher(get_default_params({'key': key}))
        assert cipher.decrypt(message.data).decode() == data
        assert message.encoding == 'utf-8/cipher+aes-128-cbc'
コード例 #15
0
ファイル: restcrypto_test.py プロジェクト: ably/ably-python
    async def test_crypto_encrypted_unhandled(self):
        channel_name = self.get_channel_name('persisted:crypto_send_encrypted_unhandled')
        key = b'0123456789abcdef'
        data = 'foobar'
        publish0 = self.ably.channels.get(channel_name, cipher={'key': key})

        await publish0.publish("publish0", data)

        rx_channel = self.ably2.channels[channel_name]
        history = await rx_channel.history()
        message = history.items[0]
        cipher = get_cipher(get_default_params({'key': key}))
        assert cipher.decrypt(message.data).decode() == data
        assert message.encoding == 'utf-8/cipher+aes-128-cbc'
コード例 #16
0
ファイル: restcrypto_test.py プロジェクト: jdavid/ably-python
    def test_crypto_encrypted_unhandled(self):
        channel_name = self.protocol_channel_name('persisted:crypto_send_encrypted_unhandled')
        key = six.b('0123456789abcdef')
        data = six.u('foobar')
        publish0 = self.ably.channels.get(channel_name, cipher={'key': key})

        publish0.publish("publish0", data)

        rx_channel = self.ably2.channels[channel_name]
        history = rx_channel.history()
        message = history.items[0]
        cipher = get_cipher(get_default_params({'key': key}))
        self.assertEqual(cipher.decrypt(message.data).decode(), data)
        self.assertEqual(message.encoding, 'utf-8/cipher+aes-128-cbc')
コード例 #17
0
    def test_crypto_encrypted_unhandled(self):
        channel_name = self.protocol_channel_name("persisted:crypto_send_encrypted_unhandled")
        key = "0123456789abcdef"
        data = six.u("foobar")
        channel_options = ChannelOptions(encrypted=True, cipher_params=get_default_params(key))
        publish0 = self.ably.channels.get(channel_name, channel_options)

        publish0.publish("publish0", data)

        rx_channel = self.ably2.channels[channel_name]
        history = rx_channel.history()
        message = history.items[0]
        cipher = get_cipher(get_default_params(key))
        self.assertEqual(cipher.decrypt(message.data).decode(), data)
        self.assertEqual(message.encoding, "utf-8/cipher+aes-128-cbc")
コード例 #18
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)
コード例 #19
0
 def decrypt(self, payload, options={}):
     cipher = get_cipher({'key': b'keyfordecrypt_16'})
     return cipher.decrypt(payload)
コード例 #20
0
 def decrypt(self, payload, options={}):
     ciphertext = base64.b64decode(payload.encode('ascii'))
     cipher = get_cipher({'key': b'keyfordecrypt_16'})
     return cipher.decrypt(ciphertext)
コード例 #21
0
 def decrypt(self, payload, options=None):
     if options is None:
         options = {}
     cipher = get_cipher({'key': b'keyfordecrypt_16'})
     return cipher.decrypt(payload)
コード例 #22
0
ファイル: encoders_test.py プロジェクト: ably/ably-python
 def decrypt(self, payload, options={}):
     ciphertext = base64.b64decode(payload.encode('ascii'))
     cipher = get_cipher({'key': b'keyfordecrypt_16'})
     return cipher.decrypt(ciphertext)
コード例 #23
0
ファイル: encoders_test.py プロジェクト: ably/ably-python
 def decrypt(self, payload, options={}):
     cipher = get_cipher({'key': b'keyfordecrypt_16'})
     return cipher.decrypt(payload)
コード例 #24
0
 def decrypt(self, payload, options={}):
     ciphertext = base64.b64decode(payload.encode('ascii'))
     cipher = get_cipher(get_default_params('keyfordecrypt_16'))
     return cipher.decrypt(ciphertext)
コード例 #25
0
 def decrypt(self, payload, options={}):
     cipher = get_cipher(get_default_params('keyfordecrypt_16'))
     return cipher.decrypt(payload)