Skip to content

Commit ce93950

Browse files
author
Roland Hedberg
committed
A tool that verifies the correctness of a metadata file is the file is fetched from somewhere the process of signature verification is expected.
1 parent 67dfae8 commit ce93950

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tools/verify_metadata.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python
2+
from saml2.sigver import _get_xmlsec_cryptobackend, SecurityContext
3+
from saml2.httpbase import HTTPBase
4+
5+
from saml2 import saml
6+
from saml2 import md
7+
from saml2.attribute_converter import ac_factory
8+
from saml2.extension import dri
9+
from saml2.extension import idpdisc
10+
from saml2.extension import mdattr
11+
from saml2.extension import mdrpi
12+
from saml2.extension import mdui
13+
from saml2.extension import shibmd
14+
from saml2.extension import ui
15+
import xmldsig
16+
import xmlenc
17+
18+
import argparse
19+
20+
from saml2.mdstore import MetaDataFile, MetaDataExtern
21+
22+
__author__ = 'rolandh'
23+
24+
"""
25+
A script that imports and verifies metadata.
26+
"""
27+
28+
29+
ONTS = {
30+
saml.NAMESPACE: saml,
31+
mdui.NAMESPACE: mdui,
32+
mdattr.NAMESPACE: mdattr,
33+
mdrpi.NAMESPACE: mdrpi,
34+
dri.NAMESPACE: dri,
35+
ui.NAMESPACE: ui,
36+
idpdisc.NAMESPACE: idpdisc,
37+
md.NAMESPACE: md,
38+
xmldsig.NAMESPACE: xmldsig,
39+
xmlenc.NAMESPACE: xmlenc,
40+
shibmd.NAMESPACE: shibmd
41+
}
42+
43+
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument('-t', dest='type')
46+
parser.add_argument('-u', dest='url')
47+
parser.add_argument('-c', dest='cert')
48+
parser.add_argument('-a', dest='attrsmap')
49+
parser.add_argument('-o', dest='output')
50+
parser.add_argument('-x', dest='xmlsec')
51+
parser.add_argument('-i', dest='ignore_valid', action='store_true')
52+
parser.add_argument(dest="item")
53+
args = parser.parse_args()
54+
55+
56+
metad = None
57+
58+
if args.ignore_valid:
59+
kwargs = {"check_validity": False}
60+
else:
61+
kwargs = {}
62+
63+
if args.type == "local":
64+
metad = MetaDataFile(ONTS.values(), args.item, args.item, **kwargs)
65+
elif args.type == "external":
66+
ATTRCONV = ac_factory(args.attrsmap)
67+
httpc = HTTPBase()
68+
crypto = _get_xmlsec_cryptobackend(args.xmlsec)
69+
sc = SecurityContext(crypto)
70+
metad = MetaDataExtern(ONTS.values(), ATTRCONV, args.url,
71+
sc, cert=args.cert, http=httpc, **kwargs)
72+
73+
if metad:
74+
try:
75+
metad.load()
76+
except:
77+
raise
78+
else:
79+
print "OK"
80+
81+
82+

0 commit comments

Comments
 (0)