Skip to content

Commit 52a9299

Browse files
authored
Merge pull request #87 from skoranda/signature_digest_configuration
Signing signature and digest algorithm configuration
2 parents 1a91de6 + bd4303a commit 52a9299

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/satosa/frontends/saml2.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
from urllib.parse import urlparse
99

10-
from saml2 import SAMLError
10+
from saml2 import SAMLError, xmldsig
1111
from saml2.config import IdPConfig
1212
from saml2.extension.ui import NAMESPACE as UI_NAMESPACE
1313
from saml2.metadata import create_metadata_string
@@ -284,7 +284,46 @@ def _handle_authn_response(self, context, internal_response, idp):
284284
name_qualifier=None)
285285

286286
satosa_logging(logger, logging.DEBUG, "returning attributes %s" % json.dumps(ava), context.state)
287-
resp = idp.create_authn_response(ava, name_id=name_id, authn=auth_info, sign_response=True, **resp_args)
287+
288+
# Construct arguments for method create_authn_response on IdP Server instance
289+
args = {
290+
'identity' : ava,
291+
'name_id' : name_id,
292+
'authn' : auth_info,
293+
'sign_response' : True
294+
}
295+
296+
# Add the SP details
297+
args.update(**resp_args)
298+
299+
# Default signing and digest algorithms
300+
args['sign_alg'] = xmldsig.SIG_RSA_SHA256
301+
args['digest_alg'] = xmldsig.DIGEST_SHA256
302+
303+
# Override if SAML2 IdP frontend has a configured default
304+
try:
305+
args['sign_alg'] = getattr(xmldsig, self.config['idp_config']['service']['idp']['policy']['default']['sign_alg'])
306+
except (KeyError, AttributeError):
307+
pass
308+
try:
309+
args['digest_alg'] = getattr(xmldsig, self.config['idp_config']['service']['idp']['policy']['default']['digest_alg'])
310+
except (KeyError, AttributeError):
311+
pass
312+
313+
# Override if SAML2 IdP frontend has a per-sp configuration
314+
try:
315+
args['sign_alg'] = getattr(xmldsig, self.config['idp_config']['service']['idp']['policy'][resp_args['sp_entity_id']]['sign_alg'])
316+
except (KeyError, AttributeError):
317+
pass
318+
try:
319+
args['digest_alg'] = getattr(xmldsig, self.config['idp_config']['service']['idp']['policy'][resp_args['sp_entity_id']]['digest_alg'])
320+
except (KeyError, AttributeError):
321+
pass
322+
323+
satosa_logging(logger, logging.DEBUG, "signing with algorithm %s" % args['sign_alg'], context.state)
324+
satosa_logging(logger, logging.DEBUG, "using digest algorithm %s" % args['digest_alg'], context.state)
325+
326+
resp = idp.create_authn_response(**args)
288327
http_args = idp.apply_binding(resp_args["binding"], str(resp), resp_args["destination"],
289328
request_state["relay_state"], response=True)
290329
del context.state[self.name]

0 commit comments

Comments
 (0)