Пример #1
0
    def public_key(self):
        cached_key = self._cached_public_key
        if cached_key is not None:
            return cached_key

        # Convert the JWK into a public key and cache it (since the conversion can take > 200ms).
        public_key = jwtutil.jwk_dict_to_public_key(self._service_key.jwk)
        self._cached_public_key = public_key
        return public_key
Пример #2
0
def _validate_jwt(encoded_jwt, jwk, service):
    public_key = jwtutil.jwk_dict_to_public_key(jwk)

    try:
        jwtutil.decode(encoded_jwt,
                       public_key,
                       algorithms=['RS256'],
                       audience=JWT_AUDIENCE,
                       issuer=service)
    except jwtutil.InvalidTokenError:
        logger.exception('JWT validation failure')
        abort(400)
Пример #3
0
def test_jwk_dict_to_public_key(private_key, private_key_pem):
  public_key = private_key.publickey()
  jwk = RSAKey(key=private_key.publickey()).serialize()
  converted = jwk_dict_to_public_key(jwk)

  # Encode with the test private key.
  token = jwt.encode(_token_data('aud', 'subject', 'someissuer'), private_key_pem, 'RS256')

  # Decode with the converted key.
  max_exp = exp_max_s_option(3600)
  decode(token, converted, algorithms=['RS256'], audience='aud',
         issuer='someissuer', options=max_exp, leeway=60)
Пример #4
0
def test_jwk_dict_to_public_key(private_key, private_key_pem):
    public_key = private_key.public_key()
    key_dict = jwk.dumps(
        public_key.public_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PublicFormat.SubjectPublicKeyInfo,
        )
    )
    converted = jwk_dict_to_public_key(key_dict)

    # Encode with the test private key.
    token = jwt.encode(_token_data("aud", "subject", "someissuer"), private_key_pem, "RS256")

    # Decode with the converted key.
    max_exp = exp_max_s_option(3600)
    decode(
        token,
        converted,
        algorithms=["RS256"],
        audience="aud",
        issuer="someissuer",
        options=max_exp,
        leeway=60,
    )