7
7
import binascii
8
8
import time
9
9
import re
10
+ import copy
10
11
11
12
from cryptography .hazmat .backends import default_backend
12
13
from cryptography .hazmat .primitives .asymmetric import ec , utils as ecutils
@@ -254,23 +255,24 @@ def verify_token(self, validation_token, verification_token):
254
255
return False
255
256
256
257
def _base_sign (self , claims ):
257
- if not claims .get ('exp' ):
258
- claims ['exp' ] = str (int (time .time ()) + 86400 )
258
+ cclaims = copy .deepcopy (claims )
259
+ if not cclaims .get ('exp' ):
260
+ cclaims ['exp' ] = str (int (time .time ()) + 86400 )
259
261
if not re .match ("mailto:.+@.+\..+" ,
260
- claims .get ('sub' , '' ),
262
+ cclaims .get ('sub' , '' ),
261
263
re .IGNORECASE ):
262
264
raise VapidException (
263
265
"Missing 'sub' from claims. "
264
266
"'sub' is your admin email as a mailto: link." )
265
267
if not re .match ("^https?:\/\/[^\/\.:]+\.[^\/:]+(:\d+)?$" ,
266
- claims .get ("aud" , "" ),
268
+ cclaims .get ("aud" , "" ),
267
269
re .IGNORECASE ):
268
270
raise VapidException (
269
271
"Missing 'aud' from claims. "
270
272
"'aud' is the scheme, host and optional port for this "
271
273
"transaction e.g. https://example.com:8080" )
272
274
273
- return claims
275
+ return cclaims
274
276
275
277
def sign (self , claims , crypto_key = None ):
276
278
"""Sign a set of claims.
@@ -284,8 +286,7 @@ def sign(self, claims, crypto_key=None):
284
286
:rtype: dict
285
287
286
288
"""
287
- claims = self ._base_sign (claims )
288
- sig = sign (claims , self .private_key )
289
+ sig = sign (self ._base_sign (claims ), self .private_key )
289
290
pkey = 'p256ecdsa='
290
291
pkey += b64urlencode (
291
292
self .public_key .public_numbers ().encode_point ())
@@ -307,8 +308,7 @@ class Vapid02(Vapid01):
307
308
_schema = "vapid"
308
309
309
310
def sign (self , claims , crypto_key = None ):
310
- claims = self ._base_sign (claims )
311
- sig = sign (claims , self .private_key )
311
+ sig = sign (self ._base_sign (claims ), self .private_key )
312
312
pkey = self .public_key .public_numbers ().encode_point ()
313
313
return {
314
314
"Authorization" : "{schema} t={t},k={k}" .format (
0 commit comments