Skip to content

Commit e1d7834

Browse files
committed
Parse SignedParts for bindings and assign
1 parent 6f421ce commit e1d7834

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-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
@@ -126,6 +126,11 @@ def __init__(self, wsdl, name, port_name):
126126
self.port_type = None
127127
self.wsdl = wsdl
128128
self._operations = {}
129+
self.signatures = {
130+
'header': [], # Elements of header, that should be signed
131+
'body': False, # If body should be signed
132+
'everything': False, # If every header should be signed
133+
}
129134

130135
def resolve(self, definitions):
131136
self.port_type = definitions.get("port_types", self.port_name.text)

src/zeep/wsdl/wsdl.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@
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
2021
from zeep.utils import findall_multiple_ns
2122
from zeep.wsdl import parse
2223
from zeep.xsd import Schema
2324

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

2632
logger = logging.getLogger(__name__)
2733

@@ -423,6 +429,25 @@ def parse_binding(self, doc):
423429
logger.debug("Ignoring binding: %s", exc)
424430
continue
425431

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

0 commit comments

Comments
 (0)