Skip to content

Commit d6b5879

Browse files
committed
change options "sign_asertion" and "sign_response" to be dependent on their value, not just on their existence (previously "sign_response=False" would still generate a response signature). Change from boolean to string, to allow for future optional signatures (e.g. like in shibboleth: sing on front channel, but not over https/soap)
make dsgi algorithms configurable (config args.AuthnResponse.sign_signature_alg etc.)
1 parent 9d6487e commit d6b5879

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/sp_test/base.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from saml2test.interaction import Interaction
2121
from saml2test.interaction import InteractionNeeded
2222

23+
import xmldsig as ds
24+
2325
from sp_test.tests import ErrorResponse
2426
from sp_test.check import VerifyEchopageContents
2527

@@ -276,27 +278,39 @@ def send_idp_response(self, req, resp):
276278
_op = camel2underscore.sub(r'_\1', req._class.c_tag).lower()
277279
func = getattr(self.instance, "create_%s_response" % _op)
278280

281+
# get from config which parts shall be signed
279282
sign = []
280283
for styp in ["sign_assertion", "sign_response"]:
281284
if styp in args:
285+
if args[styp].lower() == "always":
286+
sign.append(styp)
282287
del args[styp]
283-
sign.append(styp)
284288

285289
response = func(**args)
286290
response = resp(self).pre_processing(response)
287291
# and now for signing
288292
if sign:
289293
to_sign = []
294+
try:
295+
_digest_alg=args["sign_digest_alg"]
296+
except KeyError:
297+
_digest_alg=None
298+
try:
299+
_sign_alg=args["sign_signature_alg"]
300+
except KeyError:
301+
_sign_alg=None
290302
# Order is important, first assertion and then response if both
291303
if "sign_assertion" in sign:
292304
to_sign = [(class_name(response.assertion),
293305
response.assertion.id)]
294306
response.assertion.signature = pre_signature_part(
295-
response.assertion.id, self.instance.sec.my_cert, 1)
307+
response.assertion.id, self.instance.sec.my_cert, 1,
308+
digest_alg=_digest_alg, sign_alg=_sign_alg)
296309
if "sign_response" in sign:
297310
to_sign = [(class_name(response), response.id)]
298311
response.signature = pre_signature_part(
299-
response.id, self.instance.sec.my_cert, 1)
312+
response.id, self.instance.sec.my_cert, 1,
313+
digest_alg=_digest_alg, sign_alg=_sign_alg)
300314

301315
response = signed_instance_factory(response, self.instance.sec,
302316
to_sign)

0 commit comments

Comments
 (0)