def __init__(self, keys=None, source="", type="rsa", src_type="", cache_time=300, usage="", verify_ssl=True): """ :param keys: A dictionary :param source: Where the key can be fetch from :param type: What type of key it is (rsa, ec, hmac,..) :param src_type: How the key is packed (x509, jwk,..) :param usage: What the key should be used for (enc, dec, sig, ver) :param verify_ssl: Verify the SSL cert used by the server """ self._key = {} self.remote = False self.verify_ssl = verify_ssl type = type.lower() src_type = src_type.lower() if keys: self.source = None self.orig_type = None for typ, inst in keys.items(): try: self._key[typ].append(inst) except KeyError: self._key[typ] = [inst] else: self.orig_type = type if source.startswith("file://"): self.source = source[7:] elif source.startswith("http://") or source.startswith("https://"): self.source = source self.remote = True else: raise Exception("Unsupported source type: %s" % source) self.src_type = src_type if not self.remote: # local file if src_type == "jwk": for typ, inst in loads(source): try: self._key[type].append(inst) except KeyError: self._key[type] = [inst] else: # native format self.do_native(type, src_type) if usage: if isinstance(usage, basestring): self.usage = [usage] else: self.usage = usage else: self.usage = [] self.etag = "" self.cache_control = [] self.time_out = 0 self.cache_time = cache_time
def test1(): kj = KeyJar() part,res = key_export("http://example.com/keys/", "outbound", "secret", keyjar=kj, sig={"alg":"rsa", "format":["x509", "jwk"]}) print part print res cert = "keys/outbound/cert.pem" jwk_def = "keys/outbound/jwk.json" _ckey = x509_rsa_loads(open(cert).read()) _jkey = jwk.loads(open(jwk_def).read())[0][1] print jwe.hd2ia(hexlify(_ckey.n)) print jwe.hd2ia(hexlify(_jkey.n)) assert _ckey.n == _jkey.n