def test_load_remote_encoding(): crypto = sigver._get_xmlsec_cryptobackend() sc = sigver.SecurityContext(crypto, key_type="", cert_type="") httpc = HTTPBase() mds = MetaDataExtern(ATTRCONV, 'http://metadata.aai.switch.ch/metadata.aaitest.xml', sc, full_path('SWITCHaaiRootCA.crt.pem'), httpc) mds.load()
def test_load_remote_encoding(mock_request): filepath = os.path.join(TESTS_DIR, "remote_data/metadata.aaitest.xml") with open(filepath) as fd: data = fd.read() mock_request.return_value.ok = True mock_request.return_value.status_code = 200 mock_request.return_value.content = data crypto = sigver._get_xmlsec_cryptobackend() sc = sigver.SecurityContext(crypto, key_type="", cert_type="") httpc = HTTPBase() mds = MetaDataExtern(ATTRCONV, 'http://metadata.aai.switch.ch/metadata.aaitest.xml', sc, full_path('SWITCHaaiRootCA.crt.pem'), httpc) mds.load()
def validate_metadata_url(url: str) -> bool: """Validates metadata URL Args: url (str): Metadata URL Returns: bool: Wether the metadata URL is valid or not """ try: http_client = HTTPBase() metadata = MetaDataExtern(None, url=url, http=http_client) metadata.load() except: return False return True
def main(): item = MDIMPORT[sys.argv[1]] metad = None if item["type"] == "local": metad = MetaDataFile(sys.argv[1], ONTS.values(), item["file"]) elif item["type"] == "external": metad = MetaDataExtern(sys.argv[1], ONTS.values(), item["url"], "/opt/local/bin/xmlsec1", item["cert"]) if metad: metad.load() print metad.dumps()
parser.add_argument('-c', dest='cert') parser.add_argument('-a', dest='attrsmap') parser.add_argument('-o', dest='output') parser.add_argument('-x', dest='xmlsec') parser.add_argument(dest="item") args = parser.parse_args() metad = None if args.type == "local": metad = MetaDataFile(list(ONTS.values()), args.item, args.item) elif args.type == "external": ATTRCONV = ac_factory(args.attrsmap) httpc = HTTPBase() crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto) metad = MetaDataExtern(list(ONTS.values()), ATTRCONV, args.url, sc, cert=args.cert, http=httpc) if metad: try: metad.load() except: raise else: print("OK")
if args.ignore_valid: kwargs = {"check_validity": False} else: kwargs = {} if spec[0] == "local": metad = MetaDataFile(ONTS.values(), spec[1], spec[1], **kwargs) elif spec[0] == "remote": ATTRCONV = ac_factory(args.attrsmap) httpc = HTTPBase() crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto, key_type="", cert_type="") metad = MetaDataExtern(ONTS.values(), ATTRCONV, spec[1], sc, cert=spec[2], http=httpc, **kwargs) if metad: try: metad.load() except: raise output.entity_descriptor.extend(metad.entities_descr.entity_descriptor) print output
parser = argparse.ArgumentParser() parser.add_argument('-t', dest='type') parser.add_argument('-u', dest='url') parser.add_argument('-c', dest='cert') parser.add_argument('-a', dest='attrsmap') parser.add_argument('-o', dest='output') parser.add_argument('-x', dest='xmlsec') parser.add_argument(dest="item") args = parser.parse_args() metad = None if args.type == "local": metad = MetaDataFile(args.item, args.item) elif args.type == "external": ATTRCONV = ac_factory(args.attrsmap) httpc = HTTPBase() crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto) metad = MetaDataExtern(ATTRCONV, args.url, sc, cert=args.cert, http=httpc) if metad is not None: metad.load() txt = metad.dumps() if args.output: f = open(args.output, "w") f.write(txt) f.close() else: print(txt)
spec = line.split(" ") if args.ignore_valid: kwargs = {"check_validity": False} else: kwargs = {} if spec[0] == "local": metad = MetaDataFile(spec[1], spec[1], **kwargs) elif spec[0] == "remote": ATTRCONV = ac_factory(args.attrsmap) httpc = HTTPBase() crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto, key_type="", cert_type="") metad = MetaDataExtern(ATTRCONV, spec[1], sc, cert=spec[2], http=httpc, **kwargs) if metad is not None: try: metad.load() except: raise mds.metadata[spec[1]] = metad print(mds.dumps(args.output))
MDIMPORT = { "swamid": { "url": "https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2", "cert": "kalmar2.pem", "type": "external" }, "incommon": { "file": "InCommon-metadata.xml", "type": "local" }, "test": { "file": "mdtest.xml", "type": "local" } } item = MDIMPORT[sys.argv[1]] metad = None if item["type"] == "local": metad = MetaDataFile(sys.argv[1], list(ONTS.values()), item["file"]) elif item["type"] == "external": metad = MetaDataExtern(sys.argv[1], list(ONTS.values()), item["url"], "/opt/local/bin/xmlsec1", item["cert"]) if metad: metad.load() print(metad.dumps())
crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto) metad = MetaDataFile(ONTS.values(), args.item, args.item, cert=args.cert, security=sc, **kwargs) else: metad = MetaDataFile(ONTS.values(), args.item, args.item, **kwargs) elif args.type == "external": ATTRCONV = ac_factory(args.attrsmap) httpc = HTTPBase() crypto = _get_xmlsec_cryptobackend(args.xmlsec) sc = SecurityContext(crypto) metad = MetaDataExtern(ONTS.values(), ATTRCONV, args.url, sc, cert=args.cert, http=httpc, **kwargs) if metad: try: metad.load() except: raise else: print "OK"
def test_load_remote_encoding(): crypto = sigver._get_xmlsec_cryptobackend() sc = sigver.SecurityContext(crypto, key_type="", cert_type="") httpc = HTTPBase() mds = MetaDataExtern(ATTRCONV, 'http://metadata.aai.switch.ch/metadata.aaitest.xml', sc, full_path('SWITCHaaiRootCA.crt.pem'), httpc) mds.load()