Skip to content

Commit cbb0c8e

Browse files
author
Roland Hedberg
committed
Added extension schema for the PE_FIM use case and a test of the same. More about PE-FIM here http://arxiv.org/abs/1401.4726
1 parent bfa31ef commit cbb0c8e

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/saml2/extension/pefim.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
3+
import saml2
4+
from saml2 import SamlBase
5+
from xmldsig import X509Data
6+
7+
NAMESPACE = 'urn:net:eustix:names:tc:PEFIM:0.0:assertion'
8+
9+
10+
class SPCertEncType_(SamlBase):
11+
"""The urn:net:eustix:names:tc:PEFIM:0.0:assertion:SPCertEncType element """
12+
13+
c_tag = 'SPCertEncType'
14+
c_namespace = NAMESPACE
15+
c_children = SamlBase.c_children.copy()
16+
c_attributes = SamlBase.c_attributes.copy()
17+
c_child_order = SamlBase.c_child_order[:]
18+
c_cardinality = SamlBase.c_cardinality.copy()
19+
c_children['{http://www.w3.org/2000/09/xmldsig#}X509Data'] = ('x509_data',
20+
[X509Data])
21+
22+
def __init__(self,
23+
x509_data=None,
24+
text=None,
25+
extension_elements=None,
26+
extension_attributes=None):
27+
SamlBase.__init__(self,
28+
text=text,
29+
extension_elements=extension_elements,
30+
extension_attributes=extension_attributes)
31+
self.x509_data = x509_data
32+
33+
34+
def spcertenc_type__from_string(xml_string):
35+
return saml2.create_class_from_xml_string(SPCertEncType_, xml_string)
36+
37+
38+
class SPCertEnc(SPCertEncType_):
39+
"""The urn:net:eustix:names:tc:PEFIM:0.0:assertion:SPCertEnc element """
40+
41+
c_tag = 'SPCertEnc'
42+
c_namespace = NAMESPACE
43+
c_children = SPCertEncType_.c_children.copy()
44+
c_attributes = SPCertEncType_.c_attributes.copy()
45+
c_child_order = SPCertEncType_.c_child_order[:]
46+
c_cardinality = SPCertEncType_.c_cardinality.copy()
47+
48+
49+
def spcertenc_from_string(xml_string):
50+
return saml2.create_class_from_xml_string(SPCertEnc, xml_string)
51+
52+
53+
ELEMENT_FROM_STRING = {
54+
SPCertEnc.c_tag: spcertenc_from_string,
55+
SPCertEncType_.c_tag: spcertenc_type__from_string,
56+
}
57+
58+
ELEMENT_BY_TAG = {
59+
'SPCertEnc': SPCertEnc,
60+
'SPCertEncType': SPCertEncType_,
61+
}
62+
63+
64+
def factory(tag, **kwargs):
65+
return ELEMENT_BY_TAG[tag](**kwargs)
66+

tests/test_82_pefim.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import xmldsig as ds
2+
from saml2 import config
3+
from saml2 import extension_elements_to_elements
4+
from saml2 import element_to_extension_element
5+
from saml2 import saml
6+
from saml2.client import Saml2Client
7+
from saml2.extension import pefim
8+
from saml2.extension.pefim import SPCertEnc
9+
from saml2.samlp import Extensions
10+
from saml2.samlp import authn_request_from_string
11+
from saml2.sigver import read_cert_from_file
12+
13+
__author__ = 'roland'
14+
15+
conf = config.SPConfig()
16+
conf.load_file("server_conf")
17+
client = Saml2Client(conf)
18+
19+
# place a certificate in an authn request
20+
cert = read_cert_from_file("test.pem", "pem")
21+
22+
spcertenc = SPCertEnc(
23+
x509_data=ds.X509Data(
24+
x509_certificate=ds.X509Certificate(text=cert)))
25+
26+
extensions = Extensions(
27+
extension_elements=[element_to_extension_element(spcertenc)])
28+
29+
req = client.create_authn_request(
30+
"http://www.example.com/sso",
31+
"urn:mace:example.com:it:tek",
32+
nameid_format=saml.NAMEID_FORMAT_PERSISTENT,
33+
message_id="666",
34+
extensions=extensions)
35+
36+
37+
print req
38+
39+
# Get a certificate from an authn request
40+
41+
xml = "%s" % req
42+
43+
parsed = authn_request_from_string(xml)
44+
45+
_elem = extension_elements_to_elements(parsed.extensions.extension_elements,
46+
[pefim, ds])
47+
48+
assert len(_elem) == 1
49+
_spcertenc = _elem[0]
50+
_cert = _spcertenc.x509_data[0].x509_certificate.text
51+
assert cert == _cert

0 commit comments

Comments
 (0)