Ejemplo n.º 1
0
 def test_sign_01(self):
     v = Vapid01.from_string(T_DER)
     claims = {"aud": "https://example.com",
               "sub": "mailto:[email protected]"}
     result = v.sign(claims, "id=previous")
     eq_(result['Crypto-Key'],
         'id=previous;p256ecdsa=' + T_PUBLIC_RAW.decode('utf8'))
     pkey = binascii.b2a_base64(
         v.public_key.public_bytes(
             serialization.Encoding.X962,
             serialization.PublicFormat.UncompressedPoint
         )
     ).decode('utf8').replace('+', '-').replace('/', '_').strip()
     items = decode(result['Authorization'].split(' ')[1], pkey)
     for k in claims:
         eq_(items[k], claims[k])
     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']
     ))
Ejemplo n.º 2
0
 def test_bad_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-5Wtx3x1OgYX19alhJ9oLumlS2VzEvNioZ_BAD")
     eq_(Vapid01.verify(key=key, auth=auth), False)
Ejemplo n.º 3
0
 def test_sign_01(self):
     v = Vapid01.from_file("/tmp/private")
     claims = {
         "aud": "https://example.com",
         "sub": "mailto:[email protected]"
     }
     result = v.sign(claims, "id=previous")
     eq_(result['Crypto-Key'],
         'id=previous;p256ecdsa=' + T_PUBLIC_RAW.decode('utf8'))
     pkey = binascii.b2a_base64(
         v.public_key.public_numbers().encode_point()).decode(
             'utf8').replace('+', '-').replace('/', '_').strip()
     items = decode(result['Authorization'].split(' ')[1], pkey)
     eq_(items, claims)
     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']))