Beispiel #1
0
 'JWT_ES384_RAW':
 jwt.raw_jwt_es384_template(),
 'JWT_ES512':
 jwt.jwt_es512_template(),
 'JWT_ES512_RAW':
 jwt.raw_jwt_es512_template(),
 'JWT_RS256_2048_F4':
 jwt.jwt_rs256_2048_f4_template(),
 'JWT_RS256_2048_F4_RAW':
 jwt.raw_jwt_rs256_2048_f4_template(),
 'JWT_RS256_3072_F4':
 jwt.jwt_rs256_3072_f4_template(),
 'JWT_RS256_3072_F4_RAW':
 jwt.raw_jwt_rs256_3072_f4_template(),
 'JWT_RS384_3072_F4':
 jwt.jwt_rs384_3072_f4_template(),
 'JWT_RS384_3072_F4_RAW':
 jwt.raw_jwt_rs384_3072_f4_template(),
 'JWT_RS512_4096_F4':
 jwt.jwt_rs512_4096_f4_template(),
 'JWT_RS512_4096_F4_RAW':
 jwt.raw_jwt_rs512_4096_f4_template(),
 'JWT_PS256_2048_F4':
 jwt.jwt_ps256_2048_f4_template(),
 'JWT_PS256_2048_F4_RAW':
 jwt.raw_jwt_ps256_2048_f4_template(),
 'JWT_PS256_3072_F4':
 jwt.jwt_ps256_3072_f4_template(),
 'JWT_PS256_3072_F4_RAW':
 jwt.raw_jwt_ps256_3072_f4_template(),
 'JWT_PS384_3072_F4':
class JwtKeyTemplatesTest(parameterized.TestCase):

  @parameterized.parameters([
      ('JWT_HS256', jwt.jwt_hs256_template()),
      ('JWT_HS384', jwt.jwt_hs384_template()),
      ('JWT_HS512', jwt.jwt_hs512_template()),
      ('JWT_ES256', jwt.jwt_es256_template()),
      ('JWT_ES384', jwt.jwt_es384_template()),
      ('JWT_ES512', jwt.jwt_es512_template()),
      ('JWT_RS256_2048_F4', jwt.jwt_rs256_2048_f4_template()),
      ('JWT_RS256_3072_F4', jwt.jwt_rs256_3072_f4_template()),
      ('JWT_RS384_3072_F4', jwt.jwt_rs384_3072_f4_template()),
      ('JWT_RS512_4096_F4', jwt.jwt_rs512_4096_f4_template()),
      ('JWT_PS256_2048_F4', jwt.jwt_ps256_2048_f4_template()),
      ('JWT_PS256_3072_F4', jwt.jwt_ps256_3072_f4_template()),
      ('JWT_PS384_3072_F4', jwt.jwt_ps384_3072_f4_template()),
      ('JWT_PS512_4096_F4', jwt.jwt_ps512_4096_f4_template()),
  ])
  def test_template(self, template_name, template):
    self.assertEqual(template,
                     helper.template_from_testdata(template_name, 'jwt'))

  @parameterized.named_parameters(('0', 0, b'\x00'), ('256', 256, b'\x01\x00'),
                                  ('65537', 65537, b'\x01\x00\x01'))
  def test_num_to_bytes(self, number, expected):
    self.assertEqual(jwt._jwt_key_templates._num_to_bytes(number),
                     expected)

  @parameterized.named_parameters([
      ('JWT_HS256', jwt.jwt_hs256_template()),
      ('JWT_HS384', jwt.jwt_hs384_template()),
      ('JWT_HS512', jwt.jwt_hs512_template()),
  ])
  def test_mac_success(self, key_template):
    keyset_handle = tink.new_keyset_handle(key_template)
    jwt_hmac = keyset_handle.primitive(jwt.JwtMac)
    token = jwt.new_raw_jwt(
        issuer='issuer', subject='subject', without_expiration=True)
    compact = jwt_hmac.compute_mac_and_encode(token)
    output_token = jwt_hmac.verify_mac_and_decode(
        compact,
        jwt.new_validator(
            expected_issuer='issuer',
            expected_subject='subject',
            allow_missing_expiration=True))
    self.assertEqual(output_token.issuer(), token.issuer())
    self.assertEqual(output_token.subject(), token.subject())

  @parameterized.named_parameters([
      ('JWT_ES256', jwt.jwt_es256_template()),
      ('JWT_ES384', jwt.jwt_es384_template()),
      ('JWT_ES512', jwt.jwt_es512_template()),
  ])
  def test_new_keydata_primitive_success(self, template):
    private_handle = tink.new_keyset_handle(template)
    sign = private_handle.primitive(jwt.JwtPublicKeySign)
    verify = private_handle.public_keyset_handle().primitive(
        jwt.JwtPublicKeyVerify)
    raw_jwt = jwt.new_raw_jwt(
        issuer='issuer', subject='subject', without_expiration=True)
    compact = sign.sign_and_encode(raw_jwt)
    verified_jwt = verify.verify_and_decode(
        compact,
        jwt.new_validator(
            expected_issuer='issuer',
            expected_subject='subject',
            allow_missing_expiration=True))
    self.assertEqual(verified_jwt.issuer(), 'issuer')
    self.assertEqual(verified_jwt.subject(), 'subject')
Beispiel #3
0
        prf.prf_key_templates.AES_CMAC,
    'HMAC_PRF_SHA256':
        prf.prf_key_templates.HMAC_SHA256,
    'HMAC_PRF_SHA512':
        prf.prf_key_templates.HMAC_SHA512,
    'HKDF_PRF_SHA256':
        prf.prf_key_templates.HKDF_SHA256,
    'JWT_HS256': jwt.jwt_hs256_template(),
    'JWT_HS384': jwt.jwt_hs384_template(),
    'JWT_HS512': jwt.jwt_hs512_template(),
    'JWT_ES256': jwt.jwt_es256_template(),
    'JWT_ES384': jwt.jwt_es384_template(),
    'JWT_ES512': jwt.jwt_es512_template(),
    'JWT_RS256_2048_F4': jwt.jwt_rs256_2048_f4_template(),
    'JWT_RS256_3072_F4': jwt.jwt_rs256_3072_f4_template(),
    'JWT_RS384_3072_F4': jwt.jwt_rs384_3072_f4_template(),
    'JWT_RS512_4096_F4': jwt.jwt_rs512_4096_f4_template(),
    'JWT_PS256_2048_F4': jwt.jwt_ps256_2048_f4_template(),
    'JWT_PS256_3072_F4': jwt.jwt_ps256_3072_f4_template(),
    'JWT_PS384_3072_F4': jwt.jwt_ps384_3072_f4_template(),
    'JWT_PS512_4096_F4': jwt.jwt_ps512_4096_f4_template(),
}


# Key template names for which the list of supported languages is different from
# the list of supported languages of the whole key type.
_CUSTOM_SUPPORTED_LANGUAGES_BY_TEMPLATE_NAME = {
    'ECIES_P256_HKDF_HMAC_SHA256_XCHACHA20_POLY1305': ['cc', 'python'],
}