Skip to content

Commit 98d89d6

Browse files
author
Roland Hedberg
committed
Added algsupport
1 parent 048797c commit 98d89d6

File tree

4 files changed

+101
-21
lines changed

4 files changed

+101
-21
lines changed

src/saml2/algsupport.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from subprocess import Popen, PIPE
2+
from saml2.sigver import get_xmlsec_binary
3+
from saml2.extension.algsupport import SigningMethod
4+
from saml2.extension.algsupport import DigestMethod
5+
6+
__author__ = 'roland'
7+
8+
DIGEST_METHODS = {
9+
"hmac-md5": 'http://www.w3.org/2001/04/xmldsig-more#md5', # test framework only!
10+
"hmac-sha1": 'http://www.w3.org/2000/09/xmldsig#sha1',
11+
"hmac-sha224": 'http://www.w3.org/2001/04/xmldsig-more#sha224',
12+
"hmac-sha256": 'http://www.w3.org/2001/04/xmlenc#sha256',
13+
"hmac-sha384": 'http://www.w3.org/2001/04/xmldsig-more#sha384',
14+
"hmac-sha512": 'http://www.w3.org/2001/04/xmlenc#sha512',
15+
"hmac-ripemd160": 'http://www.w3.org/2001/04/xmlenc#ripemd160'
16+
}
17+
18+
SIGNING_METHODS = {
19+
"rsa-md5": 'http://www.w3.org/2001/04/xmldsig-more#rsa-md5',
20+
"rsa-ripemd160": 'http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160',
21+
"rsa-sha1": 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',
22+
"rsa-sha224": 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha224',
23+
"rsa-sha256": 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
24+
"rsa-sha384": 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384',
25+
"rsa-sha512": 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512',
26+
"dsa-sha1": 'http,//www.w3.org/2000/09/xmldsig#dsa-sha1',
27+
'dsa-sha256': 'http://www.w3.org/2009/xmldsig11#dsa-sha256',
28+
'ecdsa_sha1': 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha1',
29+
'ecdsa_sha224': 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha224',
30+
'ecdsa_sha256': 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha256',
31+
'ecdsa_sha384': 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha384',
32+
'ecdsa_sha512': 'http://www.w3.org/2001/04/xmldsig-more#ECDSA_sha512',
33+
}
34+
35+
36+
def get_algorithm_support(xmlsec):
37+
com_list = [xmlsec, '--list-transforms']
38+
pof = Popen(com_list, stderr=PIPE, stdout=PIPE)
39+
40+
p_out = pof.stdout.read().decode('utf-8')
41+
p_err = pof.stderr.read().decode('utf-8')
42+
43+
if not p_err:
44+
p = p_out.split('\n')
45+
algs = [x.strip('"') for x in p[1].split(',')]
46+
digest = []
47+
signing = []
48+
for alg in algs:
49+
if alg in DIGEST_METHODS:
50+
digest.append(alg)
51+
elif alg in SIGNING_METHODS:
52+
signing.append(alg)
53+
54+
return {"digest": digest, "signing": signing}
55+
56+
raise SystemError(p_err)
57+
58+
59+
def algorithm_support_in_metadata(xmlsec):
60+
if xmlsec is None:
61+
return []
62+
63+
support = get_algorithm_support(xmlsec)
64+
element_list = []
65+
for alg in support["digest"]:
66+
element_list.append(DigestMethod(algorithm=DIGEST_METHODS[alg]))
67+
for alg in support["signing"]:
68+
element_list.append(SigningMethod(algorithm=SIGNING_METHODS[alg]))
69+
return element_list
70+
71+
if __name__ == '__main__':
72+
xmlsec = get_xmlsec_binary()
73+
res = get_algorithm_support(xmlsec)
74+
print(res)
75+
for a in algorithm_support_in_metadata(xmlsec):
76+
print(a)

tests/server2_conf.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
from pathutils import full_path
22

33
CONFIG = {
4-
"entityid" : "urn:mace:example.com:saml:roland:sp",
5-
"name" : "urn:mace:example.com:saml:roland:sp",
4+
"entityid": "urn:mace:example.com:saml:roland:sp",
5+
"name": "urn:mace:example.com:saml:roland:sp",
66
"description": "My own SP",
77
"service": {
88
"sp": {
9-
"endpoints":{
10-
"assertion_consumer_service": ["http://lingon.catalogix.se:8087/"],
9+
"endpoints": {
10+
"assertion_consumer_service": [
11+
"http://lingon.catalogix.se:8087/"],
1112
},
1213
"required_attributes": ["surName", "givenName", "mail"],
1314
"optional_attributes": ["title"],
14-
"idp":["urn:mace:example.com:saml:roland:idp"],
15+
"idp": ["urn:mace:example.com:saml:roland:idp"],
1516
"subject_data": "subject_data.db",
1617
}
1718
},
18-
"debug" : 1,
19-
"key_file" : full_path("test.key"),
20-
"cert_file" : full_path("test.pem"),
21-
"xmlsec_binary" : None,
19+
"debug": 1,
20+
"key_file": full_path("test.key"),
21+
"cert_file": full_path("test.pem"),
22+
"xmlsec_binary": None,
2223
"metadata": {
2324
"local": [full_path("idp_soap.xml"), full_path("vo_metadata.xml")],
2425
},
25-
"virtual_organization" : {
26-
"urn:mace:example.com:it:tek":{
27-
"nameid_format" : "urn:oid:1.3.6.1.4.1.1466.115.121.1.15-NameID",
26+
"virtual_organization": {
27+
"urn:mace:example.com:it:tek": {
28+
"nameid_format": "urn:oid:1.3.6.1.4.1.1466.115.121.1.15-NameID",
2829
"common_identifier": "umuselin",
2930
}
3031
},
3132
"accepted_time_diff": 60,
32-
"attribute_map_dir" : full_path("attributemaps"),
33+
"attribute_map_dir": full_path("attributemaps"),
3334
"organization": {
3435
"name": ("AB Exempel", "se"),
3536
"display_name": ("AB Exempel", "se"),
3637
"url": "http://www.example.org",
3738
},
3839
"contact_person": [{
39-
"given_name": "Roland",
40-
"sur_name": "Hedberg",
41-
"telephone_number": "+46 70 100 0000",
42-
"email_address": ["[email protected]", "[email protected]"],
43-
"contact_type": "technical"
44-
},
40+
"given_name": "Roland",
41+
"sur_name": "Hedberg",
42+
"telephone_number": "+46 70 100 0000",
43+
"email_address": ["[email protected]", "[email protected]"],
44+
"contact_type": "technical"
45+
},
4546
]
4647
}

tests/sp_mdext_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pathutils import full_path
1+
from pathutils import full_path, xmlsec_path
22

33
CONFIG = {
44
"entityid": "urn:mace:example.com:saml:roland:sp",
@@ -38,7 +38,7 @@
3838
"debug": 1,
3939
"key_file": full_path("test.key"),
4040
"cert_file": full_path("test.pem"),
41-
"xmlsec_binary": None,
41+
"xmlsec_binary": xmlsec_path,
4242
"metadata": {
4343
"local": [full_path("idp_2.xml")],
4444
},

tests/test_83_md_extensions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
assert ed.spsso_descriptor.extensions
1414
assert len(ed.spsso_descriptor.extensions.extension_elements) == 3
15+
16+
assert ed.extensions
17+
assert len(ed.extensions.extension_elements) > 1

0 commit comments

Comments
 (0)