Esempio n. 1
0
    def setup_class(self):
        with closing(Server("idp_conf")) as server:
            name_id = server.ident.transient_nameid(
                "urn:mace:example.com:saml:roland:sp", "id12")

            self._resp_ = server.create_authn_response(
                IDENTITY,
                "id12",  # in_response_to
                "http://lingon.catalogix.se:8087/",
                # consumer_url
                "urn:mace:example.com:saml:roland:sp",
                # sp_entity_id
                name_id=name_id)

            self._sign_resp_ = server.create_authn_response(
                IDENTITY,
                "id12",  # in_response_to
                "http://lingon.catalogix.se:8087/",  # consumer_url
                "urn:mace:example.com:saml:roland:sp",  # sp_entity_id
                name_id=name_id,
                sign_assertion=True)

            self._resp_authn = server.create_authn_response(
                IDENTITY,
                "id12",  # in_response_to
                "http://lingon.catalogix.se:8087/",  # consumer_url
                "urn:mace:example.com:saml:roland:sp",  # sp_entity_id
                name_id=name_id,
                authn=AUTHN)

            conf = config.SPConfig()
            conf.load_file("server_conf")
            self.conf = conf
Esempio n. 2
0
def test_xmlsec_err_non_ascii_ava():
    conf = config.SPConfig()
    conf.load_file("server_conf")
    md = MetadataStore([saml, samlp], None, conf)
    md.load("local", full_path("idp_example.xml"))

    conf.metadata = md
    conf.only_use_keys_in_metadata = False
    sec = sigver.security_context(conf)

    assertion = factory(
        saml.Assertion, version="2.0", id="11111",
        issue_instant="2009-10-30T13:20:28Z",
        signature=sigver.pre_signature_part("11111", sec.my_cert, 1),
        attribute_statement=do_attribute_statement(
            {("", "", "surName"): ("Föö", ""),
             ("", "", "givenName"): ("Bär", ""), })
    )

    try:
        sec.sign_statement(assertion, class_name(assertion),
                           key_file=full_path("tes.key"),
                           node_id=assertion.id)
    except (XmlsecError, SigverError) as err:  # should throw an exception
        pass
    else:
        assert False
Esempio n. 3
0
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        self.sp = Saml2Client(conf)

        vo_name = list(conf.vorg.keys())[0]
        self.vo = conf.vorg[vo_name]
        add_derek_info(self.sp)
Esempio n. 4
0
def test_xbox_non_ascii_ava():
    conf = config.SPConfig()
    conf.load_file("server_conf")
    md = MetadataStore([saml, samlp], None, conf)
    md.load("local", full_path("idp_example.xml"))

    conf.metadata = md
    conf.only_use_keys_in_metadata = False
    sec = sigver.security_context(conf)

    assertion = factory(
        saml.Assertion, version="2.0", id="11111",
        issue_instant="2009-10-30T13:20:28Z",
        signature=sigver.pre_signature_part("11111", sec.my_cert, 1),
        attribute_statement=do_attribute_statement(
            {("", "", "surName"): ("Föö", ""),
             ("", "", "givenName"): ("Bär", ""), })
    )

    sigass = sec.sign_statement(assertion, class_name(assertion),
                                key_file=full_path("test.key"),
                                node_id=assertion.id)

    _ass0 = saml.assertion_from_string(sigass)

    encrypted_assertion = EncryptedAssertion()
    encrypted_assertion.add_extension_element(_ass0)

    _, pre = make_temp(str(pre_encryption_part()).encode('utf-8'), decode=False)
    enctext = sec.crypto.encrypt(
        str(encrypted_assertion), conf.cert_file, pre, "des-192",
        '/*[local-name()="EncryptedAssertion"]/*[local-name()="Assertion"]')

    decr_text = sec.decrypt(enctext)
    _seass = saml.encrypted_assertion_from_string(decr_text)
    assertions = []
    assers = extension_elements_to_elements(_seass.extension_elements,
                                            [saml, samlp])

    sign_cert_file = full_path("test.pem")

    for ass in assers:
        _ass = "%s" % ass
        #_ass = _ass.replace('xsi:nil="true" ', '')
        #assert sigass == _ass
        _txt = sec.verify_signature(_ass, sign_cert_file,
                                    node_name=class_name(assertion))
        if _txt:
            assertions.append(ass)

    print(assertions)
 def setup_class(self):
     self.server = Server("idp_conf")
     sign_alg = Mock()
     sign_alg.return_value = ds.SIG_RSA_SHA512
     digest_alg = Mock()
     digest_alg.return_value = ds.DIGEST_SHA512
     self.restet_default = ds.DefaultSignature
     ds.DefaultSignature = MagicMock()
     ds.DefaultSignature().get_sign_alg = sign_alg
     ds.DefaultSignature().get_digest_alg = digest_alg
     conf = config.SPConfig()
     conf.load_file("server_conf")
     self.client = client.Saml2Client(conf)
     self.name_id = self.server.ident.transient_nameid(
         "urn:mace:example.com:saml:roland:sp", "id12")
     self.ava = {"givenName": ["Derek"], "surName": ["Jeter"],
            "mail": ["*****@*****.**"], "title": "The man"}
Esempio n. 6
0
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        md = MetadataStore([saml, samlp], None, conf)
        md.load("local", full_path("metadata_cert.xml"))

        conf.metadata = md
        conf.only_use_keys_in_metadata = False
        self.sec = sigver.security_context(conf)

        assertion = factory(
            saml.Assertion, version="2.0", id="11111",
            issue_instant="2009-10-30T13:20:28Z",
            signature=sigver.pre_signature_part("11111", self.sec.my_cert, 1),
            attribute_statement=do_attribute_statement(
                {("", "", "surName"): ("Föö", ""),
                 ("", "", "givenName"): ("Bär", ""), })
        )
Esempio n. 7
0
def test_nsprefix2():
    conf = config.SPConfig()
    conf.load_file("servera_conf")
    client = Saml2Client(conf)

    selected_idp = "urn:mace:example.com:saml:roland:idp"

    destination = client._sso_location(selected_idp, BINDING_HTTP_POST)

    reqid, req = client.create_authn_request(
        destination,
        nameid_format=NAMEID_FORMAT_TRANSIENT,
        nsprefix={
            "saml2_tophat": saml.NAMESPACE,
            "saml2p": samlp.NAMESPACE
        })

    txt = "%s" % req

    assert "saml2p:AuthnRequest" in txt
    assert "saml2_tophat:Issuer" in txt
Esempio n. 8
0
def test_sha256_signing_non_ascii_ava():
    conf = config.SPConfig()
    conf.load_file("server_conf")
    md = MetadataStore([saml, samlp], None, conf)
    md.load("local", full_path("idp_example.xml"))

    conf.metadata = md
    conf.only_use_keys_in_metadata = False
    sec = sigver.security_context(conf)

    assertion = factory(
        saml.Assertion, version="2.0", id="11111",
        issue_instant="2009-10-30T13:20:28Z",
        signature=sigver.pre_signature_part("11111", sec.my_cert, 1,
                                            sign_alg=SIG_RSA_SHA256),
        attribute_statement=do_attribute_statement(
            {("", "", "surName"): ("Föö", ""),
             ("", "", "givenName"): ("Bär", ""), })
    )

    s = sec.sign_statement(assertion, class_name(assertion),
                           key_file=full_path("test.key"),
                           node_id=assertion.id)
    assert s
Esempio n. 9
0
 def setup_class(self):
     conf = config.SPConfig()
     conf.load_file("server_conf")
     vo_name = list(conf.vorg.keys())[0]
     self.sp = Saml2Client(conf, virtual_organization=vo_name)
     add_derek_info(self.sp)
Esempio n. 10
0
from saml2_tophat import xmldsig as ds
from saml2_tophat import config
from saml2_tophat import extension_elements_to_elements
from saml2_tophat import element_to_extension_element
from saml2_tophat import saml
from saml2_tophat.client import Saml2Client
from saml2_tophat.extension import pefim
from saml2_tophat.extension.pefim import SPCertEnc
from saml2_tophat.samlp import Extensions
from saml2_tophat.samlp import authn_request_from_string
from saml2_tophat.sigver import read_cert_from_file
from pathutils import full_path

__author__ = 'roland'

conf = config.SPConfig()
conf.load_file("server_conf")
client = Saml2Client(conf)

# place a certificate in an authn request
cert = read_cert_from_file(full_path("test.pem"), "pem")

spcertenc = SPCertEnc(x509_data=ds.X509Data(
    x509_certificate=ds.X509Certificate(text=cert)))

extensions = Extensions(
    extension_elements=[element_to_extension_element(spcertenc)])

req_id, req = client.create_authn_request(
    "http://www.example.com/sso",
    "urn:mace:example.com:it:tek",