|
7 | 7 | import logging
|
8 | 8 | from urllib.parse import urlparse
|
9 | 9 |
|
10 |
| -from saml2 import SAMLError |
| 10 | +from saml2 import SAMLError, xmldsig |
11 | 11 | from saml2.config import IdPConfig
|
12 | 12 | from saml2.extension.ui import NAMESPACE as UI_NAMESPACE
|
13 | 13 | from saml2.metadata import create_metadata_string
|
@@ -284,7 +284,46 @@ def _handle_authn_response(self, context, internal_response, idp):
|
284 | 284 | name_qualifier=None)
|
285 | 285 |
|
286 | 286 | 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) |
288 | 327 | http_args = idp.apply_binding(resp_args["binding"], str(resp), resp_args["destination"],
|
289 | 328 | request_state["relay_state"], response=True)
|
290 | 329 | del context.state[self.name]
|
|
0 commit comments