def test_items(self):
        issuer = KeyIssuer()
        issuer.add_kb(
            KeyBundle([
                {
                    "kty": "oct",
                    "key": "abcdefghijklmnop",
                    "use": "sig"
                },
                {
                    "kty": "oct",
                    "key": "ABCDEFGHIJKLMNOP",
                    "use": "enc"
                },
            ]))
        issuer.add_kb(
            KeyBundle([
                {
                    "kty": "oct",
                    "key": "0123456789012345",
                    "use": "sig"
                },
                {
                    "kty": "oct",
                    "key": "1234567890123456",
                    "use": "enc"
                },
            ]))
        issuer.add_kb(keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]))

        assert len(issuer.all_keys()) == 5
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-r",
                        dest="rsa_file",
                        help="File containing a RSA key")
    parser.add_argument("-k",
                        dest="hmac_key",
                        help="If using a HMAC algorithm this is the key")
    parser.add_argument("-i", dest="kid", help="key id")
    parser.add_argument("-j", dest="jwk", help="JSON Web Key")
    parser.add_argument("-J", dest="jwks", help="JSON Web Keys")
    parser.add_argument("-u", dest="jwks_url", help="JSON Web Keys URL")
    parser.add_argument("-f", dest="msg", help="The message")
    parser.add_argument(
        "-q",
        dest="quiet",
        help="Quiet mode -- only show the RAW but prettified JSON",
        action="store_true",
    )

    args = parser.parse_args()

    if args.kid:
        _kid = args.kid
    else:
        _kid = ""

    keys = []
    if args.rsa_file:
        keys.append(RSAKey(key=import_rsa_key(args.rsa_file), kid=_kid))
    if args.hmac_key:
        keys.append(SYMKey(key=args.hmac_key, kid=_kid))

    if args.jwk:
        _key = key_from_jwk_dict(open(args.jwk).read())
        keys.append(_key)

    if args.jwks:
        _iss = KeyIssuer()
        _iss.import_jwks(open(args.jwks).read())
        keys.extend(_iss.all_keys())

    if args.jwks_url:
        _kb = KeyBundle(source=args.jwks_url)
        keys.extend(_kb.get())

    if not args.msg:  # If nothing specified assume stdin
        message = sys.stdin.read()
    elif args.msg == "-":
        message = sys.stdin.read()
    else:
        if os.path.isfile(args.msg):
            message = open(args.msg).read().strip("\n")
        else:
            message = args.msg

    message = message.strip()
    message = message.strip('"')
    process(message, keys, args.quiet)
def test_contains():
    issuer = KeyIssuer()
    issuer.add_kb(KeyBundle(JWK1["keys"]))
    for k in issuer.all_keys():
        assert k in issuer
def test_load_unknown_keytype():
    issuer = KeyIssuer()
    issuer.import_jwks(JWK_UK)
    assert len(issuer.all_keys()) == 1
def test_import_jwks():
    issuer = KeyIssuer()
    issuer.import_jwks(JWK1)
    assert len(issuer.all_keys()) == 2
 def test_keyissuer_add(self):
     issuer = KeyIssuer()
     kb = keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"])
     issuer.add_kb(kb)
     assert len(issuer.all_keys()) == 1