Skip to content

Commit 64249f7

Browse files
tpazderkablaggacao
authored andcommitted
Parse SignedParts for bindings and assign
1 parent 377d931 commit 64249f7

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
@@ -11,6 +11,8 @@
1111
MIME = "http://schemas.xmlsoap.org/wsdl/mime/"
1212

1313
WSA = "http://www.w3.org/2005/08/addressing"
14+
WSP = "http://schemas.xmlsoap.org/ws/2004/09/policy"
15+
SP = "http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
1416

1517

1618
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
@@ -135,6 +135,11 @@ def __init__(self, wsdl, name, port_name):
135135
self.port_type = None
136136
self.wsdl = wsdl
137137
self._operations = {}
138+
self.signatures = {
139+
'header': [], # Elements of header, that should be signed
140+
'body': False, # If body should be signed
141+
'everything': False, # If every header should be signed
142+
}
138143

139144
def resolve(self, definitions: Definition) -> None:
140145
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,6 +14,7 @@
1414

1515
from lxml import etree
1616

17+
from zeep import ns
1718
from zeep.exceptions import IncompleteMessage
1819
from zeep.loader import (
1920
absolute_location,
@@ -30,7 +31,12 @@
3031
if typing.TYPE_CHECKING:
3132
from zeep.transports import Transport
3233

33-
NSMAP = {"wsdl": "http://schemas.xmlsoap.org/wsdl/"}
34+
NSMAP = {
35+
'wsdl': ns.WSDL,
36+
'wsp': ns.WSP,
37+
'sp': ns.SP,
38+
'wsu': ns.WSU,
39+
}
3440

3541
logger = logging.getLogger(__name__)
3642

@@ -440,6 +446,25 @@ def parse_binding(
440446
logger.debug("Ignoring binding: %s", exc)
441447
continue
442448

449+
# Begin heuristics for signed parts...
450+
binding_policy = binding.name.localname + '_policy'
451+
signed_parts = doc.xpath('wsp:Policy[@wsu:Id="{}"]//sp:SignedParts'.format(binding_policy),
452+
namespaces=NSMAP)
453+
for sign in signed_parts:
454+
if len(sign.getchildren()) == 0:
455+
# No children, we should sign everything
456+
binding.signatures['body'] = True
457+
binding.signatures['everything'] = True
458+
break
459+
460+
for child in sign.iterchildren():
461+
if len(child.items()) > 0:
462+
# Header ...
463+
part = {attr: value for attr, value in child.items()}
464+
binding.signatures['header'].append(part)
465+
elif child.tag.split('}')[-1].lower() == 'body':
466+
# Body ...
467+
binding.signatures['body'] = True
443468
logger.debug("Adding binding: %s", binding.name.text)
444469
result[binding.name.text] = binding
445470
break

0 commit comments

Comments
 (0)