Example #1
0
    def setUpClass(cls):
        cls.ec_private_json, cls.ec_public_json = load_json("ec")
        cls.oct_secret_json = load_json("oct")
        cls.rsa_private_json, cls.rsa_public_json = load_json("rsa")

        cls.ec_private_pem, cls.ec_public_pem = load_pem("ec")
        cls.oct_secret_pem = load_pem("oct")
        cls.rsa_private_pem, cls.rsa_public_pem = load_pem("rsa")
Example #2
0
    def test_dump(self):
        k0 = JsonWebKey.parse(load_pem("rsa")[1],
                              "RSA",
                              True,
                              use="sig",
                              kid="key0")
        k1 = JsonWebKey.parse(load_pem("ec")[1],
                              "EC",
                              True,
                              use="sig",
                              kid="key1")

        jwks = JsonWebKeySet([k0, k1])

        self.assertDictEqual(jwks.dump(), {"keys": [k0.dump(), k1.dump()]})
Example #3
0
    def test_get_key(self):
        k0 = JsonWebKey.parse(load_pem("ec")[0],
                              "EC",
                              False,
                              use="sig",
                              kid="key0")
        k1 = JsonWebKey.parse(load_pem("rsa")[0],
                              "RSA",
                              False,
                              use="sig",
                              kid="key1")

        jwks = JsonWebKeySet([k0, k1])

        self.assertEqual(jwks.get_key("key0"), k0)
        self.assertIsNone(jwks.get_key("idontknow"))
Example #4
0
    def test_instantiate(self):
        k0 = JsonWebKey.parse(load_pem("ec")[1],
                              "EC",
                              True,
                              use="sig",
                              kid="key0")
        k1 = JsonWebKey.parse(load_pem("rsa")[1],
                              "RSA",
                              True,
                              use="sig",
                              kid="key1")
        k2 = JsonWebKey.generate("RSA", 2048)

        jwks0 = JsonWebKeySet([k0, k1])

        self.assertListEqual(jwks0.keys, [k0, k1])
        self.assertRaises(InvalidKeySet, JsonWebKeySet, [k0, k1, k2])

        k30 = JsonWebKey.generate("EC", "P-256", kid="key2")
        k31 = JsonWebKey.generate("RSA", 2048, kid="key2")

        self.assertRaises(InvalidKeySet, JsonWebKeySet, [k30, k31])
Example #5
0
    def test_parse(self):
        key = OCTKey.parse(self.oct_pem)

        self.assertDictEqual(key.dump(public=False), self.oct_json)

        # Invalid format case.
        self.assertRaises(UnsupportedParsingMethod,
                          OCTKey.parse,
                          self.oct_pem,
                          format="BaP(QUiEi'X")

        # Unmatching algorithm and raw key case.
        self.assertRaises(InvalidKey, OCTKey.parse, load_pem("rsa")[0])
Example #6
0
    def test_parse(self):
        private_key = ECKey.parse(self.priv_pem)
        public_key = ECKey.parse(self.pub_pem)

        self.assertDictEqual(private_key.dump(public=False), self.priv_json)
        self.assertDictEqual(public_key.dump(), self.pub_json)

        # Invalid format case.
        self.assertRaises(UnsupportedParsingMethod,
                          ECKey.parse,
                          self.pub_pem,
                          format="BaP(QUiEi'X")

        # Unmatching algorithm and raw key case.
        self.assertRaises(InvalidKey, ECKey.parse, load_pem("rsa")[0])
Example #7
0
 def setUpClass(cls):
     cls.oct_json = load_json("oct")
     cls.oct_pem = load_pem("oct")
Example #8
0
 def setUpClass(cls):
     cls.priv_json, cls.pub_json = load_json("rsa")
     cls.priv_pem, cls.pub_pem = load_pem("rsa")