From 40a2a2690451d108c7c78cf0d875d6ac705ecbaa Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 20 Feb 2020 17:05:11 +0100 Subject: [PATCH] sources/saml: fix Metadata cert including PEM header --- .../templates/saml/sp/xml/spssodescriptor.xml | 58 ++----------------- passbook/sources/saml/views.py | 6 +- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/passbook/sources/saml/templates/saml/sp/xml/spssodescriptor.xml b/passbook/sources/saml/templates/saml/sp/xml/spssodescriptor.xml index e990f5a91..23e8e6090 100644 --- a/passbook/sources/saml/templates/saml/sp/xml/spssodescriptor.xml +++ b/passbook/sources/saml/templates/saml/sp/xml/spssodescriptor.xml @@ -1,10 +1,7 @@ - - + xmlns:ds="http://www.w3.org/2000/09/xmldsig#" entityID="{{ entity_id }}"> + @@ -19,52 +16,7 @@ - - urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress - - -{% comment %} - - - - urn:oasis:names:tc:SAML:2.0:nameid-format:transient - - - - - - Service Provider Portal - - - - -{% endcomment %} + urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress + -{% comment %} - -{# if org #} - - {{ org.name }} - {{ org.display_name }} - {{ org.url }} - -{# endif #} - -{# for contact in contacts #} - - {{ contact.given_name }} - {{ contact.sur_name }} - {{ contact.email }} - -{# endfor #} -{% endcomment %} diff --git a/passbook/sources/saml/views.py b/passbook/sources/saml/views.py index 18a07f5ba..eb5bacae4 100644 --- a/passbook/sources/saml/views.py +++ b/passbook/sources/saml/views.py @@ -8,6 +8,7 @@ from django.shortcuts import get_object_or_404, redirect, render, reverse from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.csrf import csrf_exempt +from signxml.util import strip_pem_header from passbook.providers.saml.utils import get_random_id, render_xml from passbook.providers.saml.utils.encoding import nice64 @@ -97,12 +98,15 @@ class MetadataView(View): """Replies with the XML Metadata SPSSODescriptor.""" source: SAMLSource = get_object_or_404(SAMLSource, slug=source_slug) entity_id = get_entity_id(request, source) + cert_stripped = strip_pem_header(source.signing_cert.replace("\r", "")).replace( + "\n", "" + ) return render_xml( request, "saml/sp/xml/spssodescriptor.xml", { "acs_url": build_full_url("acs", request, source), "entity_id": entity_id, - "cert_public_key": source.signing_cert, + "cert_public_key": cert_stripped, }, )