Skip to content

Commit eafae45

Browse files
author
Florent
committed
Modify signature reference URI only when use inner signature certificate
When Response should be verifiy with the IdP certificate and the signature reference URI is empty we can not modify the Response content or it will be considered as invalid, ex.: $ xmlsec1 --sign \ --id-attr:ID urn:oasis:names:tc:SAML:2.0:protocol:Response \ --privkey-pem python-saml/metadata.key \ --output python-saml/signed_assertion.xml \ python-saml/unsigned_assertion.xml $ xmlsec1 --verify \ --id-attr:ID urn:oasis:names:tc:SAML:2.0:protocol:Response \ --pubkey-cert python-saml/metadata.crt \ python-saml/signed_assertion.xml OK $ python -c " from onelogin.saml2.utils import OneLogin_Saml2_Utils with open('python-saml/signed_assertion.xml') as assertion: with open('python-saml/metadata.crt') as cert: print OneLogin_Saml2_Utils.validate_sign(assertion.read(), cert.read(), debug=True) " signatures.c:346(xmlSecOpenSSLEvpSignatureVerify) obj=rsa-sha1 subject=EVP_VerifyFinal msg=signature do not match errno=18 False On another hand we should continue to do that if we validate the xml with an internal certificate.
1 parent 6b6c2fa commit eafae45

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/onelogin/saml2/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,15 +1051,15 @@ def validate_node_sign(signature_node, elem, cert=None, fingerprint=None, finger
10511051
if fingerprint == x509_fingerprint_value:
10521052
cert = OneLogin_Saml2_Utils.format_cert(x509_cert_value)
10531053

1054+
# Check if Reference URI is empty
1055+
reference_elem = OneLogin_Saml2_Utils.query(signature_node, '//ds:Reference')
1056+
if len(reference_elem) > 0:
1057+
if reference_elem[0].get('URI') == '':
1058+
reference_elem[0].set('URI', '#%s' % signature_node.getparent().get('ID'))
1059+
10541060
if cert is None or cert == '':
10551061
return False
10561062

1057-
# Check if Reference URI is empty
1058-
reference_elem = OneLogin_Saml2_Utils.query(signature_node, '//ds:Reference')
1059-
if len(reference_elem) > 0:
1060-
if reference_elem[0].get('URI') == '':
1061-
reference_elem[0].set('URI', '#%s' % signature_node.getparent().get('ID'))
1062-
10631063
dsig_ctx = xmlsec.DSigCtx()
10641064

10651065
file_cert = OneLogin_Saml2_Utils.write_temp_file(cert)

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,12 @@ def testIsValidSignWithEmptyReferenceURI(self):
12181218
response = OneLogin_Saml2_Response(settings, xml)
12191219
self.assertTrue(response.is_valid(self.get_request_data()))
12201220

1221+
def testIsValidSignWithEmptyReferenceURIAndIdPCert(self):
1222+
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
1223+
xml = self.file_contents(join(self.data_path, 'responses', 'valid_response_with_unsigned_assertion.xml.base64'))
1224+
response = OneLogin_Saml2_Response(settings, xml)
1225+
self.assertTrue(response.is_valid(self.get_request_data()))
1226+
12211227
def testIsValidWithoutInResponseTo(self):
12221228
"""
12231229
If assertion contains InResponseTo but not the Response tag, we should

0 commit comments

Comments
 (0)