Skip to content

Commit d02ed8d

Browse files
Aurélien LAJOIEutix
authored andcommitted
Allow to not encrypt by setting the recipient certificate as optional
1 parent b91484d commit d02ed8d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

doc/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ used to encrypt outgoing messages and verify the signature on incoming
112112
messages.
113113

114114
Note that ``WssePlugin`` is currently hardcoded to sign the ``wsu:Timestamp``
115-
and ``soap:Body`` elements, and to encrypt only the first child of the
116-
``soap:Body`` element. Pull requests to add more flexibility are welcome.
115+
and ``soap:Body`` elements, and to optionally encrypt only the first child of
116+
the ``soap:Body`` element. Pull requests to add more flexibility are welcome.
117117

118118

119119
Standalone functions

wsse/suds.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
class WssePlugin(MessagePlugin):
1111
"""Suds message plugin that performs WS-Security signing and encryption.
1212
13-
Encrypts and signs outgoing messages (the soap:Body and the wsu:Timestamp
14-
security token, which must be present); decrypts and verifies signature on
15-
incoming messages.
13+
Encrypts (optional) and signs outgoing messages (the soap:Body and the
14+
wsu:Timestamp security token, which must be present); decrypts and verifies
15+
signature on incoming messages.
16+
Encryption is done if their_certfile is set.
1617
1718
Uses X509 certificates for both encryption and signing. Requires our cert
1819
and its private key, and their cert (all as file paths).
@@ -39,7 +40,13 @@ class WssePlugin(MessagePlugin):
3940
only the first child element of the soap:Body will be encrypted).
4041
4142
"""
42-
def __init__(self, keyfile, certfile, their_certfile):
43+
def __init__(self, keyfile, certfile, their_certfile = None):
44+
"""
45+
@param keyfile path to the private key to sign the content
46+
@param certfile path to the certificate to sign the content
47+
@param their_certfile Optional, path to the recipient certificate to
48+
encrypt, if not set no encryption is done
49+
"""
4350
self.keyfile = keyfile
4451
self.certfile = certfile
4552
self.their_certfile = their_certfile
@@ -48,7 +55,8 @@ def sending(self, context):
4855
"""Sign and encrypt outgoing message envelope."""
4956
context.envelope = sign(
5057
context.envelope, self.keyfile, self.certfile)
51-
context.envelope = encrypt(context.envelope, self.their_certfile)
58+
if their_certfile != None:
59+
context.envelope = encrypt(context.envelope, self.their_certfile)
5260

5361
def received(self, context):
5462
"""Decrypt and verify signature of incoming reply envelope."""

0 commit comments

Comments
 (0)