Example #1
0
    def handle_metadata_save(self, environ, start_response, qs):
        """
        Takes the input for the page metadata.mako.
        Encrypts entity id and secret information for the social services.
        Creates the partial xml to be added to the metadata for the service
        provider.
        :param environ: wsgi enviroment
        :param start_response: wsgi start respons
        :param qs: Query parameters in a dictionary.
        :return: wsgi response for the mako file metadatasave.mako.
        """
        resp = Response(mako_template="metadatasave.mako",
                        template_lookup=self.lookup,
                        headers=[])
        if "entityId" not in qs or "secret" not in qs:
            xml = ("Xml could not be generated because no entityId or secret"
                   "has been sent to the service.")
            _logger.warning(xml)
        else:
            try:
                secret_data = json.dumps({
                    "entityId": json.loads(qs["entityId"]),
                    "secret": json.loads(qs["secret"])
                })

                # create a JWE
                jwe = JWE(secret_data, alg=self.alg, enc=self.enc)
                secret_data_encrypted = jwe.encrypt([self.key])

                val = AttributeValue()
                val.set_text(secret_data_encrypted)
                attr = Attribute(name_format=NAME_FORMAT_URI,
                                 name="http://social2saml.nordu.net/customer",
                                 attribute_value=[val])
                eattr = mdattr.EntityAttributes(attribute=[attr])
                nspair = {
                    "mdattr": "urn:oasis:names:tc:SAML:metadata:attribute",
                    "samla": "urn:oasis:names:tc:SAML:2.0:assertion",
                }
                xml = eattr.to_string(nspair)
                xml_list = xml.split("\n", 1)

                if len(xml_list) == 2:
                    xml = xml_list[1]

            except Exception:
                _logger.fatal('Unknown error in handle_metadata_save.',
                              exc_info=True)
                xml = "Xml could not be generated."
        argv = {
            "home": CONST_METADATA,
            "action": CONST_METADATAVERIFY,
            "xml": xml
        }
        return resp(environ, start_response, **argv)
Example #2
0
    def handle_metadata_save(self, environ, start_response, qs):
        """
        Takes the input for the page metadata.mako.
        Encrypts entity id and secret information for the social services.
        Creates the partial xml to be added to the metadata for the service
        provider.
        :param environ: wsgi enviroment
        :param start_response: wsgi start respons
        :param qs: Query parameters in a dictionary.
        :return: wsgi response for the mako file metadatasave.mako.
        """
        resp = Response(mako_template="metadatasave.mako",
                        template_lookup=self.lookup,
                        headers=[])
        if "entityId" not in qs or "secret" not in qs:
            xml = ("Xml could not be generated because no entityId or secret"
                   "has been sent to the service.")
            _logger.warning(xml)
        else:
            try:
                secret_data = json.dumps({"entityId": json.loads(qs["entityId"]),
                                          "secret": json.loads(qs["secret"])})

                # create a JWE
                jwe = JWE(secret_data, alg=self.alg, enc=self.enc)
                secret_data_encrypted = jwe.encrypt([self.key])

                val = AttributeValue()
                val.set_text(secret_data_encrypted)
                attr = Attribute(
                    name_format=NAME_FORMAT_URI,
                    name="http://social2saml.nordu.net/customer",
                    attribute_value=[val])
                eattr = mdattr.EntityAttributes(attribute=[attr])
                nspair = {
                    "mdattr": "urn:oasis:names:tc:SAML:metadata:attribute",
                    "samla": "urn:oasis:names:tc:SAML:2.0:assertion",
                }
                xml = eattr.to_string(nspair)
                xml_list = xml.split("\n", 1)

                if len(xml_list) == 2:
                    xml = xml_list[1]

            except Exception:
                _logger.fatal('Unknown error in handle_metadata_save.',
                                  exc_info=True)
                xml = "Xml could not be generated."
        argv = {
            "home": CONST_METADATA,
            "action": CONST_METADATAVERIFY,
            "xml": xml
        }
        return resp(environ, start_response, **argv)
Example #3
0
    def handleMetadataSave(self, environ, start_response, qs):
        """
        Takes the input for the page metadata.mako.
        Encrypts entity id and secret information for the social services.
        Creates the partial xml to be added to the metadata for the service provider.
        :param environ: wsgi enviroment
        :param start_response: wsgi start respons
        :param qs: Query parameters in a dictionary.
        :return: wsgi response for the mako file metadatasave.mako.
        """
        resp = Response(mako_template="metadatasave.mako",
                        template_lookup=self.lookup,
                        headers=[])
        if "entityId" not in qs or "secret" not in qs:
            xml = "Xml could not be generated because no entityId or secret has been sent to the service."
            self.logger.warning(xml)
        else:
            try:
                secretData = '{"entityId": ' + qs["entityId"] + ', "secret":' + qs["secret"] + '}'
                secretDataEncrypted = encrypt(
                    secretData,
                    {"rsa": [self.publicKey]},
                    MetadataGeneration.CONST_ALG,
                    MetadataGeneration.CONST_ENCRYPT,
                    "public",
                    debug=False)
                val = AttributeValue()
                val.set_text(secretDataEncrypted)
                attr = Attribute(name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                                 name="http://social2saml.nordu.net/customer",
                                 attribute_value=[val])
                eattr = mdattr.EntityAttributes(attribute=[attr])
                nspair = {
                    "mdattr": "urn:oasis:names:tc:SAML:metadata:attribute",
                    "samla": "urn:oasis:names:tc:SAML:2.0:assertion"
                }
                xml = eattr.to_string(nspair)
                xmlList = xml.split("\n", 1)

                if len(xmlList) == 2:
                    xml = xmlList[1]

            except Exception as exp:
                self.logger.fatal('Unknown error in handleMetadataSave.',
                                  exc_info=True)
                xml = "Xml could not be generated."
        argv = {
            "home": MetadataGeneration.CONST_METADATA,
            "action": MetadataGeneration.CONST_METADATAVERIFY,
            "xml": xml
        }
        return resp(environ, start_response, **argv)
Example #4
0
    def test_set_text(self):
        av = AttributeValue()
        av.set_text(True)
        assert av.text == "true"
        av.set_text(False)
        assert av.text == "false"
        # can't change value to another type
        raises(AssertionError, "av.set_text(491)")

        av = AttributeValue()
        av.set_text(None)
        assert av.text == ""
#!/usr/bin/env python

__author__ = 'rohe0002'

import sys

from saml2.extension import mdattr
from saml2.saml import Attribute
from saml2.saml import AttributeValue

consumer = sys.stdin.read()

val = AttributeValue()
val.set_text(consumer)

attr = Attribute(name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                 name="http://social2saml.nordu.net/customer",
                 attribute_value=[val])

eattr = mdattr.EntityAttributes(attribute=[attr])

nspair = {
    "mdattr": "urn:oasis:names:tc:SAML:metadata:attribute",
    "samla":"urn:oasis:names:tc:SAML:2.0:assertion"
}
print eattr.to_string(nspair)
Example #6
0
#!/usr/bin/env python

__author__ = 'rohe0002'

import sys

from saml2.extension import mdattr
from saml2.saml import Attribute
from saml2.saml import AttributeValue

consumer = sys.stdin.read()

val = AttributeValue()
val.set_text(consumer)

attr = Attribute(name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                 name="http://social2saml.nordu.net/customer",
                 attribute_value=[val])

eattr = mdattr.EntityAttributes(attribute=[attr])

nspair = {
    "mdattr": "urn:oasis:names:tc:SAML:metadata:attribute",
    "samla": "urn:oasis:names:tc:SAML:2.0:assertion"
}
print eattr.to_string(nspair)