Exemple #1
0
#!/usr/bin/env python

import jose.jwp
from jose.serialize import serialize_compact

# This should pass, with compression

header = {"alg": "none", "zip": "DEF"}
payload = "a" * 512

p1 = jose.jwp.bundle(header, payload)
c1 = serialize_compact(p1)
u1 = jose.jwp.unbundle(c1)
print c1
print u1
print

# This should fail (bad "alg")

header = {"alg": "RS256"}
payload = "payload"

try:
    p2 = jose.jwp.bundle(header, payload)
    c2 = serialize_compact(p2)
    u2 = jose.jwp.unbundle(c2)
    print c2
    print u2
except Exception as e:
    print e
print
Exemple #2
0
from jose.serialize import serialize_compact

plaintext = "Attack at dawn!"
jwe_header = {"alg": "A128KW", "enc": "A128GCM"}
jws_header = {"alg": "HS256"}
keys = [{"kty": "oct", "k": "i-ueSNQgcr0q7auC8YUrYg"}]

# Encrypt into the JSON serialization
jwe1 = jose.encrypt(jwe_header, keys, plaintext)
dec1 = jose.decrypt(jwe1, keys)
print jwe1
print dec1
print

# Encrypt into the compact serialization
jwe2 = serialize_compact( \
        jose.encrypt(jwe_header, keys, plaintext, protect="*"))
dec2 = jose.decrypt(jwe2, keys)
print jwe2
print dec2
print

# Sign into the JSON serialization
jws1 = jose.sign(jws_header, keys, plaintext)
ver1 = jose.verify(jws1, keys)
print jws1
print ver1
print

# Sign into the compact serialization
jws2 = serialize_compact( \
        jose.sign(jws_header, keys, plaintext, protect="*"))
Exemple #3
0
import jose
from jose.serialize import serialize_compact
import json

# Compression test

plaintext = "Kh" + ("a" * 512) + "n!"
jwe_header = {"alg": "A128KW", "enc": "A128GCM", "zip": "DEF"}
keys = [{"kty": "oct", "k": "i-ueSNQgcr0q7auC8YUrYg"}]

jwe1 = jose.encrypt(jwe_header, keys, plaintext, protect="*")
dec1 = jose.decrypt(jwe1, keys)

print "Compact JWE with compression:"
#print json.dumps(jwe1, indent=4, sort_keys=True)
print serialize_compact(jwe1)
print

print "Decrypted, decompressed JWE:"
print dec1
print

# Criticality test

payload = "Some day you may pass validation.  Today is not that day."
jws_header1 = {"alg": "HS256", "crit": ["alg"]}
jws_header2 = {"alg": "HS256", "true_rings": 1, "crit": ["true_rings"]}
keys = [{"kty": "oct", "k": "i-ueSNQgcr0q7auC8YUrYg"}]

# Test 1: Should fail on sign
try:
Exemple #4
0
#!/usr/bin/env python

import jose.jwp
from jose.serialize import serialize_compact

# This should pass, with compression

header = {"alg":"none", "zip": "DEF"}
payload = "a" * 512

p1 = jose.jwp.bundle(header, payload)
c1 = serialize_compact(p1)
u1 = jose.jwp.unbundle(c1)
print c1
print u1
print


# This should fail (bad "alg")

header = {"alg": "RS256"}
payload = "payload" 

try:
    p2 = jose.jwp.bundle(header, payload)
    c2 = serialize_compact(p2)
    u2 = jose.jwp.unbundle(c2)
    print c2
    print u2
except Exception as e:
    print e
Exemple #5
0
import jose
from jose.serialize import serialize_compact
import json

# Compression test

plaintext = "Kh" + ("a" * 512) + "n!"
jwe_header = {"alg": "A128KW", "enc": "A128GCM", "zip": "DEF"}
keys = [{"kty": "oct", "k": "i-ueSNQgcr0q7auC8YUrYg"}]

jwe1 = jose.encrypt(jwe_header, keys, plaintext, protect="*")
dec1 = jose.decrypt(jwe1, keys)

print("Compact JWE with compression:")
#print json.dumps(jwe1, indent=4, sort_keys=True)
print(serialize_compact(jwe1))
print()

print("Decrypted, decompressed JWE:")
print(dec1)
print()

# Criticality test

payload = "Some day you may pass validation.  Today is not that day."
jws_header1 = {"alg": "HS256", "crit": ["alg"]}
jws_header2 = {"alg": "HS256", "true_rings": 1, "crit": ["true_rings"]}
keys = [{"kty": "oct", "k": "i-ueSNQgcr0q7auC8YUrYg"}]

# Test 1: Should fail on sign
try:
Exemple #6
0
import jose
from jose.serialize import serialize_compact
import json

# Compression test

plaintext = "Kh" + ("a" * 512) + "n!"
jwe_header = { "alg":"A128KW", "enc":"A128GCM", "zip": "DEF" }
keys = [{ "kty":"oct", "k":"i-ueSNQgcr0q7auC8YUrYg" }]

jwe1 = jose.encrypt(jwe_header, keys, plaintext, protect="*")
dec1 = jose.decrypt(jwe1, keys)

print "Compact JWE with compression:"
#print json.dumps(jwe1, indent=4, sort_keys=True)
print serialize_compact(jwe1)
print

print "Decrypted, decompressed JWE:"
print dec1
print


# Criticality test

payload = "Some day you may pass validation.  Today is not that day."
jws_header1 = { "alg":"HS256", "crit": ["alg"] }
jws_header2 = { "alg":"HS256", "true_rings": 1, "crit": ["true_rings"] }
keys = [{ "kty":"oct", "k":"i-ueSNQgcr0q7auC8YUrYg" }]

# Test 1: Should fail on sign