Beispiel #1
0
    def to_jwt(self, key=None, algorithm="", lev=0):
        """
        Create a signed JWT representation of the class instance

        :param key: The signing key
        :param algorithm: The signature algorithm to use
        :return: A signed JWT
        """

        if algorithm:
            return jws.sign(self.to_json(lev), key, algorithm)
        else:
            return jwkest.pack(self.to_json(lev))
Beispiel #2
0

def lrequest(url, method="GET", **kwargs):
    return requests.request(method, url, **kwargs)


if __name__ == "__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('-a', dest="alg", help="The signing algorithm")
    parser.add_argument("message", nargs="?", help="The message to encrypt")

    args = parser.parse_args()

    keys = {}
    if args.rsa_file:
        keys = {"rsa": [rsa_load(args.rsa_file)]}
    elif args.hmac_key:
        keys = {"hmac": [args.hmac_key]}
    else:
        print >> sys.stderr, "Needs encryption key"
        exit()

    # payload, keys, alg=None
    print sign(args.message, keys, args.alg)
Beispiel #3
0
            keys[typ].append(key)
        except KeyError:
            keys[typ] = [key]
    return keys


def lrequest(url, method="GET", **kwargs):
    return requests.request(method, url, **kwargs)


if __name__ == "__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("-a", dest="alg", help="The signing algorithm")
    parser.add_argument("message", nargs="?", help="The message to encrypt")

    args = parser.parse_args()

    keys = {}
    if args.rsa_file:
        keys = {"rsa": [rsa_load(args.rsa_file)]}
    elif args.hmac_key:
        keys = {"hmac": [args.hmac_key]}
    else:
        print >> sys.stderr, "Needs encryption key"
        exit()

    # payload, keys, alg=None
    print sign(args.message, keys, args.alg)