Exemple #1
0
    def setUp(self):
        self.privkey = KEY
        self.pubkey = self.privkey.public_key()

        from acme.jose.jws import JWS

        self.unprotected = JWS.sign(payload=b"foo", key=self.privkey, alg=jwa.RS256)
        self.protected = JWS.sign(payload=b"foo", key=self.privkey, alg=jwa.RS256, protect=frozenset(["jwk", "alg"]))
        self.mixed = JWS.sign(payload=b"foo", key=self.privkey, alg=jwa.RS256, protect=frozenset(["alg"]))
Exemple #2
0
    def test_json_omitempty(self):
        protected_jobj = self.protected.to_partial_json(flat=True)
        unprotected_jobj = self.unprotected.to_partial_json(flat=True)

        self.assertTrue('protected' not in unprotected_jobj)
        self.assertTrue('header' not in protected_jobj)

        unprotected_jobj['header'] = unprotected_jobj['header'].to_json()

        from acme.jose.jws import JWS
        self.assertEqual(JWS.from_json(protected_jobj), self.protected)
        self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
    def test_json_omitempty(self):
        protected_jobj = self.protected.to_partial_json(flat=True)
        unprotected_jobj = self.unprotected.to_partial_json(flat=True)

        self.assertTrue('protected' not in unprotected_jobj)
        self.assertTrue('header' not in protected_jobj)

        unprotected_jobj['header'] = unprotected_jobj['header'].to_json()

        from acme.jose.jws import JWS
        self.assertEqual(JWS.from_json(protected_jobj), self.protected)
        self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
    def setUp(self):
        self.privkey = KEY
        self.pubkey = self.privkey.public_key()

        from acme.jose.jws import JWS
        self.unprotected = JWS.sign(
            payload=b'foo', key=self.privkey, alg=jwa.RS256)
        self.protected = JWS.sign(
            payload=b'foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(
            payload=b'foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['alg']))
    def setUp(self):
        self.privkey = jwk.JWKRSA(key=RSA512_KEY)
        self.pubkey = self.privkey.public()

        from acme.jose.jws import JWS
        self.unprotected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256)
        self.protected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['alg']))
Exemple #6
0
    def setUp(self):
        self.privkey = KEY
        self.pubkey = self.privkey.public_key()

        from acme.jose.jws import JWS
        self.unprotected = JWS.sign(payload=b'foo',
                                    key=self.privkey,
                                    alg=jwa.RS256)
        self.protected = JWS.sign(payload=b'foo',
                                  key=self.privkey,
                                  alg=jwa.RS256,
                                  protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(payload=b'foo',
                              key=self.privkey,
                              alg=jwa.RS256,
                              protect=frozenset(['alg']))
Exemple #7
0
    def setUp(self):
        self.privkey = jwk.JWKRSA(key=RSA512_KEY)
        self.pubkey = self.privkey.public()

        from acme.jose.jws import JWS
        self.unprotected = JWS.sign(payload='foo',
                                    key=self.privkey,
                                    alg=jwa.RS256)
        self.protected = JWS.sign(payload='foo',
                                  key=self.privkey,
                                  alg=jwa.RS256,
                                  protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(payload='foo',
                              key=self.privkey,
                              alg=jwa.RS256,
                              protect=frozenset(['alg']))
Exemple #8
0
    def test_json_not_flat(self):
        jobj_to = {"signatures": (self.mixed.signature,), "payload": json_util.encode_b64jose(b"foo")}
        jobj_from = jobj_to.copy()
        jobj_from["signatures"] = [jobj_to["signatures"][0].to_json()]

        self.assertEqual(self.mixed.to_partial_json(flat=False), jobj_to)
        from acme.jose.jws import JWS

        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Exemple #9
0
    def test_json_not_flat(self):
        jobj_to = {
            'signatures': (self.mixed.signature, ),
            'payload': json_util.encode_b64jose(b'foo'),
        }
        jobj_from = jobj_to.copy()
        jobj_from['signatures'] = [jobj_to['signatures'][0].to_json()]

        self.assertEqual(self.mixed.to_partial_json(flat=False), jobj_to)
        from acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
    def test_json_not_flat(self):
        jobj_to = {
            'signatures': (self.mixed.signature,),
            'payload': b64.b64encode('foo'),
        }
        jobj_from = jobj_to.copy()
        jobj_from['signatures'] = [jobj_to['signatures'][0].to_json()]

        self.assertEqual(self.mixed.to_partial_json(flat=False), jobj_to)
        from acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Exemple #11
0
    def test_json_flat(self):
        jobj_to = {
            'signature': b64.b64encode(self.mixed.signature.signature),
            'payload': b64.b64encode('foo'),
            'header': self.mixed.signature.header,
            'protected': b64.b64encode(self.mixed.signature.protected),
        }
        jobj_from = jobj_to.copy()
        jobj_from['header'] = jobj_from['header'].to_json()

        self.assertEqual(self.mixed.to_partial_json(flat=True), jobj_to)
        from acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Exemple #12
0
    def test_compact_lost_unprotected(self):
        compact = self.mixed.to_compact()
        self.assertEqual(
            b'eyJhbGciOiAiUlMyNTYifQ.Zm9v.OHdxFVj73l5LpxbFp1AmYX4yJM0Pyb'
            b'_893n1zQjpim_eLS5J1F61lkvrCrCDErTEJnBGOGesJ72M7b6Ve1cAJA',
            compact)

        from acme.jose.jws import JWS
        mixed = JWS.from_compact(compact)

        self.assertNotEqual(self.mixed, mixed)
        self.assertEqual(set(['alg']),
                         set(mixed.signature.combined.not_omitted()))
    def test_json_flat(self):
        jobj_to = {
            'signature': b64.b64encode(self.mixed.signature.signature),
            'payload': b64.b64encode('foo'),
            'header': self.mixed.signature.header,
            'protected': b64.b64encode(self.mixed.signature.protected),
        }
        jobj_from = jobj_to.copy()
        jobj_from['header'] = jobj_from['header'].to_json()

        self.assertEqual(self.mixed.to_partial_json(flat=True), jobj_to)
        from acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
    def test_compact_lost_unprotected(self):
        compact = self.mixed.to_compact()
        self.assertEqual(
            'eyJhbGciOiAiUlMyNTYifQ.Zm9v.OHdxFVj73l5LpxbFp1AmYX4yJM0Pyb'
            '_893n1zQjpim_eLS5J1F61lkvrCrCDErTEJnBGOGesJ72M7b6Ve1cAJA',
            compact)

        from acme.jose.jws import JWS
        mixed = JWS.from_compact(compact)

        self.assertNotEqual(self.mixed, mixed)
        self.assertEqual(
            set(['alg']), set(mixed.signature.combined.not_omitted()))
Exemple #15
0
    def test_json_flat(self):
        jobj_to = {
            "signature": json_util.encode_b64jose(self.mixed.signature.signature),
            "payload": json_util.encode_b64jose(b"foo"),
            "header": self.mixed.signature.header,
            "protected": json_util.encode_b64jose(self.mixed.signature.protected.encode("utf-8")),
        }
        jobj_from = jobj_to.copy()
        jobj_from["header"] = jobj_from["header"].to_json()

        self.assertEqual(self.mixed.to_partial_json(flat=True), jobj_to)
        from acme.jose.jws import JWS

        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Exemple #16
0
 def test_from_json_hashable(self):
     from acme.jose.jws import JWS
     hash(JWS.from_json(self.mixed.to_json()))
 def test_from_json_hashable(self):
     from acme.jose.jws import JWS
     hash(JWS.from_json(self.mixed.to_json()))