Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/pyff/samlmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ def entitiesdescriptor(
for entity in entities:
nsmap.update(entity.nsmap)

# The xml prefix is bound by definition and must never be declared. An explicit
# xmlns:xml is legal XML, but .NET's exclusive c14n keeps it in the canonical
# form, so consumers such as ADFSToolkit compute a different digest and reject
# the signature.
nsmap.pop('xml', None)

log.debug("selecting %d entities before validation" % len(entities))

attrs = dict(Name=name, nsmap=nsmap)
Expand Down
20 changes: 20 additions & 0 deletions src/pyff/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,26 @@ def test_entitiesdescriptor_copies_shared_entities(self):
[e.get('entityID') for e in first],
)

def test_entitiesdescriptor_does_not_declare_xml_prefix(self):
"""The aggregate root must not carry an explicit xmlns:xml declaration.

.NET's SignedXml keeps it in the exclusive c14n output, so a signature
over such a root fails to verify in ADFSToolkit although libxml2 based
verifiers accept it.
"""
from pyuppsala import etree

from pyff.samlmd import entitiesdescriptor

t = entitiesdescriptor(self._entities(), 'https://md.example.org/first', lookup_fn=None, validate=False)

self.assertNotIn('xml', t.nsmap)
serialized = etree.tostring(t, encoding='unicode')
self.assertNotIn('xmlns:xml=', serialized)
# the other pyff prefixes are still declared on the root
self.assertEqual(NS['md'], t.nsmap.get('md'))
self.assertEqual(NS['ds'], t.nsmap.get('ds'))

def test_entitiesdescriptor_copy_false_moves(self):
"""copy=False keeps the historical (lxml) move behaviour for callers that want it."""
from pyff.samlmd import entitiesdescriptor
Expand Down
Loading