1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/usr/bin/env python
import sys
from saml2 import metadata
from saml2 import saml
from saml2 import md
from saml2.attribute_converter import ac_factory
from saml2.mdie import to_dict
from saml2.extension import mdui
from saml2.extension import idpdisc
from saml2.extension import dri
from saml2.extension import mdattr
from saml2.extension import ui
import xmldsig
import xmlenc
__author__ = 'rolandh'
"""
A script that imports and verifies metadata and dumps it in a basic
dictionary format.
"""
MDIMPORT = {
"swamid": {
"url": "https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
"cert":"kalmar2.pem"
},
"incommon": {
"url": "file://InCommon-metadata.xml"
},
"test": {
"url": "file://mdtest.xml"
}
}
ATTRCONV = ac_factory("attributemaps")
ONTS = {
saml.NAMESPACE: saml,
mdui.NAMESPACE: mdui,
mdattr.NAMESPACE: mdattr,
dri.NAMESPACE: dri,
ui.NAMESPACE: ui,
idpdisc.NAMESPACE: idpdisc,
md.NAMESPACE: md,
xmldsig.NAMESPACE: xmldsig,
xmlenc.NAMESPACE: xmlenc
}
metad = metadata.MetaData(xmlsec_binary="/opt/local/bin/xmlsec1",
attrconv=ATTRCONV)
for src in sys.argv[1:]:
spec = MDIMPORT[src]
url = spec["url"]
if url.startswith("file://"):
metad.import_metadata(open(url[7:]).read(), src)
else:
metad.import_external_metadata(url, spec["cert"])
_dict = to_dict(metad.entity, ONTS.values())
import json
print json.dumps(_dict, indent=2)
|