Esempio n. 1
0
def test_loads_0():
    keys = load_jwks(json.dumps(JWK))
    assert len(keys) == 1
    key = keys[0]
    assert key.kid == "abc"
    assert key.kty == "RSA"

    _ckey = x509_rsa_loads(open(CERT).read())

    print key
    _n = long_to_mpi(base64_to_long(str(key.n)))
    assert _n == _ckey.n
    _e = long_to_mpi(base64_to_long(str(key.e)))
    assert _e == _ckey.e
Esempio n. 2
0
def test_loads_0():
    keys = load_jwks(json.dumps(JWK))
    assert len(keys) == 1
    key = keys[0]
    assert key.kid == "abc"
    assert key.kty == "RSA"

    _ckey = pem_cert2rsa(CERT)

    print key
    _n = base64_to_long(str(key.n))
    assert _n == _ckey.n
    _e = base64_to_long(str(key.e))
    assert _e == _ckey.e
Esempio n. 3
0
def test_urlsafe_base64decode():
    l = base64_to_long(JWK["keys"][0]["n"])
    # convert it to base64
    bys = byte_arr(l)
    data = struct.pack('%sB' % len(bys), *bys)
    if not len(data):
        data = '\x00'
    s0 = base64.b64encode(data)
    # try to convert it back to long, should throw an exception
    try:
        l = base64_to_long(s0)
    except ValueError:
        pass
    else:
        assert False
Esempio n. 4
0
def test_urlsafe_base64decode():
    l = base64_to_long(N)
    # convert it to base64
    bys = long2intarr(l)
    data = struct.pack('%sB' % len(bys), *bys)
    if not len(data):
        data = '\x00'
    s0 = base64.b64encode(data)
    # try to convert it back to long, should throw an exception if the strict
    # function is used
    with pytest.raises(ValueError):
        base64url_to_long(s0)

    # Not else, should not raise exception
    l = base64_to_long(s0)
    assert l
Esempio n. 5
0
def test_urlsafe_base64decode():
    l = base64_to_long(N)
    # convert it to base64
    bys = long2intarr(l)
    data = struct.pack("%sB" % len(bys), *bys)
    if not len(data):
        data = "\x00"
    s0 = base64.b64encode(data)
    # try to convert it back to long, should throw an exception if the strict
    # function is used
    with pytest.raises(ValueError):
        base64url_to_long(s0)

    # Not else, should not raise exception
    l = base64_to_long(s0)
    assert l
Esempio n. 6
0
def test_urlsafe_base64decode():
    l = base64_to_long(N)
    # convert it to base64
    bys = long2intarr(l)
    data = struct.pack('%sB' % len(bys), *bys)
    if not len(data):
        data = '\x00'
    s0 = base64.b64encode(data)
    # try to convert it back to long, should throw an exception if the strict
    # function is used
    try:
        l = base64url_to_long(s0)
    except ValueError:
        pass
    else:
        assert False
    # Not else
    l = base64_to_long(s0)
Esempio n. 7
0
def test_urlsafe_base64decode():
    l = base64_to_long(N)
    # convert it to base64
    bys = long2intarr(l)
    data = struct.pack('%sB' % len(bys), *bys)
    if not len(data):
        data = '\x00'
    s0 = base64.b64encode(data)
    # try to convert it back to long, should throw an exception if the strict
    # function is used
    try:
        l = base64url_to_long(s0)
    except ValueError:
        pass
    else:
        assert False
    # Not else
    l = base64_to_long(s0)
Esempio n. 8
0
def test_extract_rsa_from_cert_2():
    _ckey = pem_cert2rsa(CERT)
    _jwk = RSAKey(key=_ckey)
    _jwk.serialize()

    print _jwk

    _n = base64_to_long(str(_jwk.n))

    assert _ckey.n == _n
Esempio n. 9
0
def test_x509_rsa_loads_2():
    _ckey = x509_rsa_loads(open(CERT).read())
    _jwk = RSA_key(key=_ckey)
    _jwk.decomp()

    print _jwk

    _n = long_to_mpi(base64_to_long(str(_jwk.n)))

    cn = jwe.hd2ia(hexlify(_ckey.n))
    jn = jwe.hd2ia(hexlify(_n))

    assert cn == jn