Skip to content

Commit 77a00f6

Browse files
committed
Parse SignedParts for bindings and assign
1 parent 29976d9 commit 77a00f6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/zeep/ns.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
MIME = 'http://schemas.xmlsoap.org/wsdl/mime/'
1313

1414
WSA = 'http://www.w3.org/2005/08/addressing'
15+
WSP = 'http://schemas.xmlsoap.org/ws/2004/09/policy'
16+
SP = 'http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702'
1517

1618

1719
DS = 'http://www.w3.org/2000/09/xmldsig#'

src/zeep/wsdl/definitions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def __init__(self, wsdl, name, port_name):
119119
self.port_type = None
120120
self.wsdl = wsdl
121121
self._operations = {}
122+
self.signatures = {
123+
'header': [], # Elements of header, that should be signed
124+
'body': False, # If body should be signed
125+
'everything': False, # If every header should be signed
126+
}
122127

123128
def resolve(self, definitions):
124129
self.port_type = definitions.get('port_types', self.port_name.text)

src/zeep/wsdl/wsdl.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import six
1515
from lxml import etree
1616

17+
from zeep import ns
1718
from zeep.exceptions import IncompleteMessage
1819
from zeep.loader import absolute_location, is_relative_path, load_external
1920
from zeep.settings import Settings
@@ -23,7 +24,10 @@
2324

2425

2526
NSMAP = {
26-
'wsdl': 'http://schemas.xmlsoap.org/wsdl/',
27+
'wsdl': ns.WSDL,
28+
'wsp': ns.WSP,
29+
'sp': ns.SP,
30+
'wsu': ns.WSU,
2731
}
2832

2933
logger = logging.getLogger(__name__)
@@ -422,6 +426,25 @@ def parse_binding(self, doc):
422426
logger.debug("Ignoring binding: %s", exc)
423427
continue
424428

429+
# Begin heuristics for signed parts...
430+
binding_policy = binding.name.localname + '_policy'
431+
signed_parts = doc.xpath('wsp:Policy[@wsu:Id="{}"]//sp:SignedParts'.format(binding_policy),
432+
namespaces=NSMAP)
433+
for sign in signed_parts:
434+
if len(sign.getchildren()) == 0:
435+
# No children, we should sign everything
436+
binding.signatures['body'] = True
437+
binding.signatures['everything'] = True
438+
break
439+
440+
for child in sign.iterchildren():
441+
if len(child.items()) > 0:
442+
# Header ...
443+
part = {attr: value for attr, value in child.items()}
444+
binding.signatures['header'].append(part)
445+
elif child.tag.split('}')[-1].lower() == 'body':
446+
# Body ...
447+
binding.signatures['body'] = True
425448
logger.debug("Adding binding: %s", binding.name.text)
426449
result[binding.name.text] = binding
427450
break

0 commit comments

Comments
 (0)