Skip to content

Commit b167bf3

Browse files
committed
added digest alg validation
improved error handling VerifySignature Alogrithm
1 parent c42cb80 commit b167bf3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/idp_test/check.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import logging
23
import sys
34
from time import mktime
45
from saml2.response import AttributeResponse
@@ -38,6 +39,7 @@
3839

3940
M2_TIME_FORMAT = "%b %d %H:%M:%S %Y"
4041

42+
logger = logging.getLogger(__name__)
4143

4244
def to_time(_time):
4345
assert _time.endswith(" GMT")
@@ -556,6 +558,47 @@ def _func(self, conv):
556558
return {}
557559

558560

561+
class VerifyDigestAlgorithm(Check):
562+
"""
563+
verify that the used digest algorithm was one from the approved set.
564+
"""
565+
566+
def _digest_algo(self, signature, allowed):
567+
try:
568+
assert signature.signed_info.reference[0].digest_method.algorithm in allowed
569+
except AssertionError:
570+
self._message = "signature digest algorithm not allowed: '%s'" % \
571+
signature.signed_info.reference[0].digest_method.algorithm
572+
self._status = CRITICAL
573+
return False
574+
return True
575+
576+
def _func(self, conv):
577+
if "digest_algorithm" not in conv.idp_constraints:
578+
logger.info("Not verifying digest_algorithm (not configured)")
579+
return {}
580+
else:
581+
try:
582+
assert len(conv.idp_constraints["digest_algorithm"]) > 0
583+
except AssertionError:
584+
self._message = "List of allowed digest algorithm must not be empty"
585+
self._status = CRITICAL
586+
return {}
587+
_algs = conv.idp_constraints["digest_algorithm"]
588+
589+
response = conv.saml_response[-1].response
590+
591+
if response.signature:
592+
if not self._digest_algo(response.signature, _algs):
593+
return {}
594+
595+
for assertion in response.assertion:
596+
if not self._digest_algo(assertion.signature, _algs):
597+
return {}
598+
599+
return {}
600+
601+
559602
class VerifySignatureAlgorithm(Check):
560603
"""
561604
verify that the used signature algorithm was one from an approved set.
@@ -574,8 +617,15 @@ def _sig_algo(self, signature, allowed):
574617

575618
def _func(self, conv):
576619
if "signature_algorithm" not in conv.idp_constraints:
620+
logger.info("Not verifying signature_algorithm (not configured)")
577621
return {}
578622
else:
623+
try:
624+
assert len(conv.idp_constraints["signature_algorithm"]) > 0
625+
except AssertionError:
626+
self._message = "List of allowed signature algorithm must not be empty"
627+
self._status = CRITICAL
628+
return {}
579629
_algs = conv.idp_constraints["signature_algorithm"]
580630

581631
response = conv.saml_response[-1].response

0 commit comments

Comments
 (0)