forked from jrconlin/vapid
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from web-push-libs/bug/49a
bug: Several important patches were lost. Reapplying
- Loading branch information
Showing
5 changed files
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,8 @@ | |
from nose.tools import eq_, ok_ | ||
from mock import patch, Mock | ||
|
||
from cryptography.hazmat.primitives.asymmetric import ec, utils | ||
from cryptography.hazmat.primitives import hashes | ||
|
||
from py_vapid import Vapid01, Vapid02, VapidException | ||
from py_vapid.jwt import decode | ||
from py_vapid.utils import b64urldecode | ||
|
||
# This is a private key in DER form. | ||
T_DER = """ | ||
|
@@ -126,17 +122,6 @@ def test_from_raw(self): | |
v = Vapid01.from_raw(T_RAW) | ||
self.check_keys(v) | ||
|
||
def test_validate(self): | ||
v = Vapid01.from_file("/tmp/private") | ||
msg = "foobar".encode('utf8') | ||
vtoken = v.validate(msg) | ||
ok_(v.public_key.verify( | ||
base64.urlsafe_b64decode(self.repad(vtoken).encode()), | ||
msg, | ||
ec.ECDSA(hashes.SHA256()))) | ||
# test verify | ||
ok_(v.verify_token(msg, vtoken)) | ||
|
||
def test_sign_01(self): | ||
v = Vapid01.from_file("/tmp/private") | ||
claims = {"aud": "https://example.com", | ||
|
@@ -152,6 +137,12 @@ def test_sign_01(self): | |
result = v.sign(claims) | ||
eq_(result['Crypto-Key'], | ||
'p256ecdsa=' + T_PUBLIC_RAW.decode('utf8')) | ||
# Verify using the same function as Integration | ||
# this should ensure that the r,s sign values are correctly formed | ||
ok_(Vapid01.verify( | ||
key=result['Crypto-Key'].split('=')[1], | ||
auth=result['Authorization'] | ||
)) | ||
|
||
def test_sign_02(self): | ||
v = Vapid02.from_file("/tmp/private") | ||
|
@@ -174,26 +165,17 @@ def test_sign_02(self): | |
for k in claims: | ||
eq_(t_val[k], claims[k]) | ||
|
||
def test_alt_sign(self): | ||
"""ecdsa uses a raw key pair to sign, openssl uses a DER.""" | ||
v = Vapid01.from_file("/tmp/private") | ||
claims = {"aud": "https://example.com", | ||
"sub": "mailto:[email protected]", | ||
"foo": "extra value"} | ||
# Get a signed token. | ||
result = v.sign(claims) | ||
# Convert the dss into raw. | ||
auth, sig = result.get('Authorization').split(' ')[1].rsplit('.', 1) | ||
ss = utils.decode_dss_signature(b64urldecode(sig.encode('utf8'))) | ||
new_sig = binascii.b2a_base64( | ||
binascii.unhexlify("%064x%064x" % ss) | ||
).strip().strip(b'=').decode() | ||
new_auth = auth + '.' + new_sig | ||
# phew, all that done, now check | ||
pkey = result.get("Crypto-Key").split('=')[1] | ||
items = decode(new_auth, pkey) | ||
|
||
eq_(items, claims) | ||
def test_integration(self): | ||
# These values were taken from a test page. DO NOT ALTER! | ||
key = ("BDd3_hVL9fZi9Ybo2UUzA284WG5FZR30_95YeZJsiApwXKpNcF1rRPF3foI" | ||
"iBHXRdJI2Qhumhf6_LFTeZaNndIo") | ||
|
||
auth = ("WebPush eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJod" | ||
"HRwczovL3VwZGF0ZXMucHVzaC5zZXJ2aWNlcy5tb3ppbGxhLmNvbSIsImV" | ||
"4cCI6MTQ5NDY3MTQ3MCwic3ViIjoibWFpbHRvOnNpbXBsZS1wdXNoLWRlb" | ||
"W9AZ2F1bnRmYWNlLmNvLnVrIn0.LqPi86T-HJ71TXHAYFptZEHD7Wlfjcc" | ||
"4u5jYZ17WpqOlqDcW-5Wtx3x1OgYX19alhJ9oLumlS2VzEvNioZolQA") | ||
ok_(Vapid01.verify(key=key, auth=auth)) | ||
|
||
def test_bad_sign(self): | ||
v = Vapid01.from_file("/tmp/private") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters