Example #1
0
    def test_multi(self):
        '''
        nose2 jose.tests.test_jwe.TestJweMessage.test_multi
        '''

        payload = "All you need is love."

        jku= "http://test.multi.com/jwkset",
        receiver =  TestEntity(
            identifier="http://test.multi.com", jku=jku, 
        )
        fake =  TestEntity(
            identifier="http://test.fake.com", jku=jku, 
        )

        enc = EncEnum.all()[0]

        for enc in EncEnum.all():
            message = Message(
                protected=Jwe(enc=enc, zip="DEF",),
                unprotected=Jwe(typ="text"),
                plaintext=_BE(payload)
            )

            for alg in KeyEncEnum.all():
                if alg.single:
                    continue

                recipient = Recipient(
                    header=Jwe(alg=alg, jku=jku,),
                    recipient=receiver
                )
                message.add_recipient(recipient)

            json_message = message.serialize_json(indent=2)

            receivers = [fake, receiver]
            for me in receivers:
                message2 = Message.from_token(
                    json_message, sender=None, receiver=me)

                self.assertEqual(
                    len(message.recipients), len(message2.recipients))
                try:
                    print _BD(message2.plaintext), enc, me
                except:
                    print traceback.format_exc()
Example #2
0
File: gcm.py Project: hdknr/jose
    for e in encs:
        enc = EncEnum.create(e).encryptor
        cek, iv = enc.create_key_iv()
        assert len(cek) == enc._KEY_LEN
        assert len(iv) == enc._IV_LEN
        print(enc.__name__)
        print("CEK =", base64.urlsafe_b64encode(cek))
        print("IV=", base64.urlsafe_b64encode(iv))

    import itertools
    from jose.jwk import Jwk
    from jose.jwe import Jwe
    jwk = Jwk.generate(kty="oct")
    for a, e in list(itertools.product(algs, encs)):
        jwe = Jwe(
            alg=KeyEncEnum.create(a),
            enc=EncEnum.create(e),
        )
        cek, iv, cek_ci, kek = jwe.provide_key(jwk)

        print("alg=", a, "enc=", e)
        print("CEK=", base64.base64url_encode(cek))
        print("IV=", base64.base64url_encode(iv))
        print("CEK_CI=", base64.base64url_encode(cek_ci))
        print("Jwe.iv=",  jwe.iv)
        print("Jwe.tag=",  jwe.tag)

        cek2 = jwe.agree_key(jwk, cek_ci)
        print("CEK AGREED=", base64.base64url_encode(cek2))