From e6267bdc2578ee6e7291f228c1b0bc43207cb486 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 21 Sep 2024 21:14:33 +0200 Subject: [PATCH] If timestamp is not listed in sp, don't sign --- src/zeep/wsse/signature.py | 7 +------ tests/test_wsse_signature.py | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/zeep/wsse/signature.py b/src/zeep/wsse/signature.py index 31a17c1e..c83fc6d4 100644 --- a/src/zeep/wsse/signature.py +++ b/src/zeep/wsse/signature.py @@ -247,12 +247,7 @@ def _signature_prepare(envelope, key, signature_method, digest_method, signature # Perform the actual signing. ctx = xmlsec.SignatureContext() ctx.key = key - # Sign default elements if present - timestamp = security.find(QName(ns.WSU, "Timestamp")) - if timestamp != None: - _sign_node(ctx, signature, timestamp, digest_method) - - # Sign extra elements defined in WSDL + # Sign elements defined in WSDL if signatures is not None: if signatures["body"] or signatures["everything"]: _sign_node( diff --git a/tests/test_wsse_signature.py b/tests/test_wsse_signature.py index 4bfa5218..06a8a101 100644 --- a/tests/test_wsse_signature.py +++ b/tests/test_wsse_signature.py @@ -74,6 +74,7 @@ def test_sign_timestamp_if_present( """ ) + signatures = {"everything": False, "body": True, "header": [{'Name': 'Timestamp', 'Namespace': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'}]} signature.sign_envelope( envelope, KEY_FILE, @@ -81,6 +82,7 @@ def test_sign_timestamp_if_present( None, signature_method=getattr(xmlsec.Transform, signature_method), digest_method=getattr(xmlsec.Transform, digest_method), + signatures=signatures, ) signature.verify_envelope(envelope, KEY_FILE) digests = envelope.xpath("//ds:DigestMethod", namespaces={"ds": ns.DS})