def test_encode(self): for content_encoding in ["aesgcm", "aes128gcm"]: recv_key = ec.generate_private_key(ec.SECP256R1, default_backend()) subscription_info = self._gen_subscription_info(recv_key) data = "Mary had a little lamb, with some nice mint jelly" push = WebPusher(subscription_info) encoded = push.encode(data, content_encoding=content_encoding) """ crypto_key = base64.urlsafe_b64encode( self._get_pubkey_str(recv_key) ).strip(b'=') """ # Convert these b64 strings into their raw, binary form. raw_salt = None if 'salt' in encoded: raw_salt = base64.urlsafe_b64decode( push._repad(encoded['salt'])) raw_dh = base64.urlsafe_b64decode( push._repad(encoded['crypto_key'])) raw_auth = base64.urlsafe_b64decode( push._repad(subscription_info['keys']['auth'])) decoded = http_ece.decrypt(encoded['body'], salt=raw_salt, dh=raw_dh, private_key=recv_key, auth_secret=raw_auth, version=content_encoding) eq_(decoded.decode('utf8'), data)
def test_encode(self): recv_key = pyelliptic.ECC(curve="prime256v1") subscription_info = self._gen_subscription_info(recv_key) data = "Mary had a little lamb, with some nice mint jelly" push = WebPusher(subscription_info) encoded = push.encode(data) keyid = base64.urlsafe_b64encode(recv_key.get_pubkey()[1:]) http_ece.keys[keyid] = recv_key http_ece.labels[keyid] = 'P-256' # Convert these b64 strings into their raw, binary form. raw_salt = base64.urlsafe_b64decode(push._repad(encoded['salt'])) raw_dh = base64.urlsafe_b64decode(push._repad(encoded['crypto_key'])) raw_auth = base64.urlsafe_b64decode( push._repad(subscription_info['keys']['auth'])) decoded = http_ece.decrypt( buffer=encoded['body'], salt=raw_salt, dh=raw_dh, keyid=keyid, authSecret=raw_auth ) eq_(decoded, data)
def test_encode(self): recv_key = pyelliptic.ECC(curve="prime256v1") subscription_info = self._gen_subscription_info(recv_key) data = "Mary had a little lamb, with some nice mint jelly" push = WebPusher(subscription_info) encoded = push.encode(data) keyid = base64.urlsafe_b64encode(recv_key.get_pubkey()[1:]) http_ece.keys[keyid] = recv_key http_ece.labels[keyid] = 'P-256' # Convert these b64 strings into their raw, binary form. raw_salt = base64.urlsafe_b64decode(push._repad(encoded['salt'])) raw_dh = base64.urlsafe_b64decode(push._repad(encoded['crypto_key'])) raw_auth = base64.urlsafe_b64decode( push._repad(subscription_info['keys']['auth'])) decoded = http_ece.decrypt(buffer=encoded['body'], salt=raw_salt, dh=raw_dh, keyid=keyid, authSecret=raw_auth) eq_(decoded.decode('utf8'), data)
def test_encode(self): for content_encoding in ["aesgcm", "aes128gcm"]: recv_key = ec.generate_private_key( ec.SECP256R1, default_backend()) subscription_info = self._gen_subscription_info(recv_key) data = "Mary had a little lamb, with some nice mint jelly" push = WebPusher(subscription_info) encoded = push.encode(data, content_encoding=content_encoding) """ crypto_key = base64.urlsafe_b64encode( self._get_pubkey_str(recv_key) ).strip(b'=') """ # Convert these b64 strings into their raw, binary form. raw_salt = None if 'salt' in encoded: raw_salt = base64.urlsafe_b64decode( push._repad(encoded['salt'])) raw_dh = None if content_encoding != "aes128gcm": raw_dh = base64.urlsafe_b64decode( push._repad(encoded['crypto_key'])) raw_auth = base64.urlsafe_b64decode( push._repad(subscription_info['keys']['auth'])) decoded = http_ece.decrypt( encoded['body'], salt=raw_salt, dh=raw_dh, private_key=recv_key, auth_secret=raw_auth, version=content_encoding ) eq_(decoded.decode('utf8'), data)