def sign(self, claims, crypto_key=None): """Sign a set of claims. :param claims: JSON object containing the JWT claims to use. :type claims: dict :param crypto_key: Optional existing crypto_key header content. The vapid public key will be appended to this data. :type crypto_key: str :returns: a hash containing the header fields to use in the subscription update. :rtype: dict """ sig = sign(self._base_sign(claims), self.private_key) pkey = 'p256ecdsa=' pkey += b64urlencode( self.public_key.public_bytes( serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint )) if crypto_key: crypto_key = crypto_key + ';' + pkey else: crypto_key = pkey return {"Authorization": "{} {}".format(self._schema, sig.strip('=')), "Crypto-Key": crypto_key}
def sign(claims, key): """Sign the claims :param claims: list of JWS claims :type claims: dict :param key: Private key for signing :type key: ec.EllipticCurvePrivateKey :param algorithm: JWT "alg" descriptor :type algorithm: str """ header = b64urlencode(b"""{"typ":"JWT","alg":"ES256"}""") claims = b64urlencode( json.dumps(claims, separators=(',', ':')).encode('utf8')) token = "{}.{}".format(header, claims) rsig = key.sign(token.encode('utf8'), ec.ECDSA(hashes.SHA256())) sig = b64urlencode(rsig) return "{}.{}".format(token, sig)
def sign(self, claims, crypto_key=None): sig = sign(self._base_sign(claims), self.private_key) pkey = self.public_key.public_numbers().encode_point() return { "Authorization": "{schema} t={t},k={k}".format(schema=self._schema, t=sig, k=b64urlencode(pkey)) }
def sign(self, claims, crypto_key=None): sig = sign(self._base_sign(claims), self.private_key) pkey = self.public_key.public_bytes( serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint) return { "Authorization": "{schema} t={t},k={k}".format(schema=self._schema, t=sig, k=b64urlencode(pkey)) }
def sign(claims, key): """Sign the claims :param claims: list of JWS claims :type claims: dict :param key: Private key for signing :type key: ec.EllipticCurvePrivateKey :param algorithm: JWT "alg" descriptor :type algorithm: str """ header = b64urlencode(b"""{"typ":"JWT","alg":"ES256"}""") # Unfortunately, chrome seems to require the claims to be sorted. claims = b64urlencode( json.dumps(claims, separators=(',', ':'), sort_keys=True).encode('utf8')) token = "{}.{}".format(header, claims) rsig = key.sign(token.encode('utf8'), ec.ECDSA(hashes.SHA256())) (r, s) = utils.decode_dss_signature(rsig) sig = b64urlencode(num_to_bytes(r) + num_to_bytes(s)) return "{}.{}".format(token, sig)
def sign(claims, key): """Sign the claims :param claims: list of JWS claims :type claims: dict :param key: Private key for signing :type key: ec.EllipticCurvePrivateKey :param algorithm: JWT "alg" descriptor :type algorithm: str """ header = b64urlencode(b"""{"typ":"JWT","alg":"ES256"}""") # Unfortunately, chrome seems to require the claims to be sorted. claims = b64urlencode(json.dumps(claims, separators=(',', ':'), sort_keys=True).encode('utf8')) token = "{}.{}".format(header, claims) rsig = key.sign(token.encode('utf8'), ec.ECDSA(hashes.SHA256())) (r, s) = utils.decode_dss_signature(rsig) sig = b64urlencode(num_to_bytes(r) + num_to_bytes(s)) return "{}.{}".format(token, sig)
def sign(self, claims, crypto_key=None): sig = sign(self._base_sign(claims), self.private_key) pkey = self.public_key.public_bytes( serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint ) return{ "Authorization": "{schema} t={t},k={k}".format( schema=self._schema, t=sig, k=b64urlencode(pkey) ) }
def validate(self, validation_token): """Sign a Valdiation token from the dashboard :param validation_token: Short validation token from the dev dashboard :type validation_token: str :returns: corresponding token for key verification :rtype: str """ sig = self.private_key.sign( validation_token, signature_algorithm=ec.ECDSA(hashes.SHA256())) verification_token = b64urlencode(sig) return verification_token