Skip to content

Commit f5296ca

Browse files
tpazderkamvantellingen
authored andcommitted
Fix bad reference in BinarySignature
1 parent 2c405f1 commit f5296ca

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/zeep/wsse/signature.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,12 @@ def _sign_envelope_with_key_binary(envelope, key):
233233
ref = etree.SubElement(sec_token_ref, QName(ns.WSSE, 'Reference'),
234234
{'ValueType': 'http://docs.oasis-open.org/wss/2004/01/'
235235
'oasis-200401-wss-x509-token-profile-1.0#X509v3'})
236-
ref_id = ensure_id(ref)
237236
bintok = etree.Element(QName(ns.WSSE, 'BinarySecurityToken'), {
238-
QName(ns.WSU, 'Id'): ref_id,
239237
'ValueType': 'http://docs.oasis-open.org/wss/2004/01/'
240238
'oasis-200401-wss-x509-token-profile-1.0#X509v3',
241239
'EncodingType': 'http://docs.oasis-open.org/wss/2004/01/'
242240
'oasis-200401-wss-soap-message-security-1.0#Base64Binary'})
241+
ref.attrib['URI'] = '#' + ensure_id(bintok)
243242
bintok.text = x509_data.find(QName(ns.DS, 'X509Certificate')).text
244243
security.insert(1, bintok)
245244
x509_data.getparent().remove(x509_data)

tests/test_wsse_signature.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import pytest
55

6+
from lxml.etree import QName
67
from tests.utils import load_xml
7-
from zeep import wsse
8+
from zeep import ns, wsse
89
from zeep.exceptions import SignatureVerificationFailed
910
from zeep.wsse import signature
1011

@@ -135,3 +136,10 @@ def test_signature_binary():
135136
plugin = wsse.BinarySignature(KEY_FILE_PW, KEY_FILE_PW, 'geheim')
136137
envelope, headers = plugin.apply(envelope, {})
137138
plugin.verify(envelope)
139+
# Test the reference
140+
bintok = envelope.xpath('soapenv:Header/wsse:Security/wsse:BinarySecurityToken',
141+
namespaces={'soapenv': ns.SOAP_ENV_11, 'wsse': ns.WSSE})[0]
142+
ref = envelope.xpath('soapenv:Header/wsse:Security/ds:Signature/ds:KeyInfo/wsse:SecurityTokenReference'
143+
'/wsse:Reference',
144+
namespaces={'soapenv': ns.SOAP_ENV_11, 'wsse': ns.WSSE, 'ds': ns.DS})[0]
145+
assert '#' + bintok.attrib[QName(ns.WSU, 'Id')] == ref.attrib['URI']

0 commit comments

Comments
 (0)