def test_compact(self): ''' nose2 jose.tests.test_jws.TestJwsMessage.test_compact''' jku="https://me.com/jwkset" signer = TestEntity( identifier="https://me.com", jku=jku, ) for alg in SigDict.values(): alg = SigEnum.create(alg) plaintext = "This is a message to be signed by %s" % alg.value msg = Message( payload=_BE(plaintext), sender=signer) msg.add_signature( sender=signer, protected=Jws(alg=alg, kid=None, jku=jku), header=Jws(typ="text"), ) token = msg.serialize_compact() msg2 = Message.from_token(token, sender=signer) print "TOKEN=", token self.assertTrue(msg2.verify())
def test_json(self): ''' nose2 jose.tests.test_jws.TestJwsMessage.test_json ''' plaintext = "This is a message to be signed by me" jku="https://me.com/jwkset" signer = TestEntity( identifier="https://me.com", jku=jku, ) msg = Message(payload=plaintext, sender=signer) for alg in SigDict.values(): alg = SigEnum.create(alg) msg.add_signature( sender=signer, protected=Jws(alg=alg, kid=None, jku=jku), header=Jws(typ="text"), ) json_msg = msg.serialize_json(indent=2) with open("/tmp/test_json.json", "w") as out: out.write(json_msg) msg2 = Message.from_token(json_msg, sender=signer) self.assertTrue(msg2.verify())
def test_algs(self): ''' nose2 jose.tests.test_jws.TestJwsMessage.test_algs''' for alg in SigDict.values(): alg = SigEnum.create(alg) signer = "https://%s.com" % alg.name jku = signer + "/jwkset" jwk = Jwk.generate(alg.key_type) plaintext = "This is a message to be signed by %s" % alg.value signature = alg.signer.sign(jwk, plaintext) self.assertTrue(alg.signer.verify(jwk, plaintext, signature)) print alg.value, jwk.kty.value, len(signature), _BE(signature)
def __init__(self, **kwargs): super(Jws, self).__init__(**kwargs) if isinstance(self.alg, basestring): self.alg = SigEnum.create(self.alg)