Skip to content

Commit 444d017

Browse files
committed
Prefer signing_algorithm and digest_algorithm over sign_alg and digest_alg
Continuing the deprecation of saml2 frontend sign_alg and digest_alg configuration options (see, 04850ee). The values of the new options should be preferred when set. Otherwise, we fall back to the deprecate options. Notice that the new configuration options expect the algothim identifier, not an internal symbol. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 580c166 commit 444d017

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

src/satosa/frontends/saml2.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,21 @@ def _handle_authn_response(self, context, internal_response, idp):
362362
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
363363
logger.debug(logline)
364364

365-
policies = self.idp_config.get(
366-
'service', {}).get('idp', {}).get('policy', {})
365+
idp_conf = self.idp_config.get('service', {}).get('idp', {})
366+
policies = idp_conf.get('policy', {})
367367
sp_policy = policies.get('default', {})
368368
sp_policy.update(policies.get(sp_entity_id, {}))
369369

370370
sign_assertion = sp_policy.get('sign_assertion', False)
371371
sign_response = sp_policy.get('sign_response', True)
372-
sign_alg = sp_policy.get('sign_alg', 'SIG_RSA_SHA256')
373-
digest_alg = sp_policy.get('digest_alg', 'DIGEST_SHA256')
374372
encrypt_assertion = sp_policy.get('encrypt_assertion', False)
375373
encrypted_advice_attributes = sp_policy.get('encrypted_advice_attributes', False)
376374

375+
signing_algorithm = idp_conf.get('signing_algorithm')
376+
digest_algorithm = idp_conf.get('digest_algorithm')
377+
sign_alg_attr = sp_policy.get('sign_alg', 'SIG_RSA_SHA256')
378+
digest_alg_attr = sp_policy.get('digest_alg', 'DIGEST_SHA256')
379+
377380
# Construct arguments for method create_authn_response
378381
# on IdP Server instance
379382
args = {
@@ -389,31 +392,35 @@ def _handle_authn_response(self, context, internal_response, idp):
389392
'encrypted_advice_attributes': encrypted_advice_attributes,
390393
}
391394

392-
try:
393-
args['sign_alg'] = getattr(xmldsig, sign_alg)
394-
except AttributeError as e:
395-
msg = "Unsupported sign algorithm {}".format(sign_alg)
396-
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
397-
logger.error(logline)
398-
raise Exception(msg) from e
399-
else:
400-
msg = "signing with algorithm {}".format(args['sign_alg'])
401-
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
402-
logger.debug(logline)
395+
args['sign_alg'] = signing_algorithm
396+
if not args['sign_alg']:
397+
try:
398+
args['sign_alg'] = getattr(xmldsig, sign_alg_attr)
399+
except AttributeError as e:
400+
msg = "Unsupported sign algorithm {}".format(sign_alg)
401+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
402+
logger.error(logline)
403+
raise Exception(msg) from e
404+
405+
msg = "signing with algorithm {}".format(args['sign_alg'])
406+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
407+
logger.debug(logline)
403408

404-
try:
405-
args['digest_alg'] = getattr(xmldsig, digest_alg)
406-
except AttributeError as e:
407-
msg = "Unsupported digest algorithm {}".format(digest_alg)
408-
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
409-
logger.error(logline)
410-
raise Exception(msg) from e
411-
else:
412-
msg = "using digest algorithm {}".format(args['digest_alg'])
413-
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
414-
logger.debug(logline)
409+
args['digest_alg'] = digest_algorithm
410+
if not args['digest_alg']:
411+
try:
412+
args['digest_alg'] = getattr(xmldsig, digest_alg_attr)
413+
except AttributeError as e:
414+
msg = "Unsupported digest algorithm {}".format(digest_alg)
415+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
416+
logger.error(logline)
417+
raise Exception(msg) from e
418+
419+
msg = "using digest algorithm {}".format(args['digest_alg'])
420+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
421+
logger.debug(logline)
415422

416-
if 'sign_alg' in args or 'digest_alg' in args:
423+
if sign_alg_attr or digest_alg_attr:
417424
msg = (
418425
"sign_alg and digest_alg are deprecated; "
419426
"instead, use signing_algorithm and digest_algorithm "

0 commit comments

Comments
 (0)