1
1
import inspect
2
+ import logging
2
3
import sys
3
4
from time import mktime
4
5
from saml2 .response import AttributeResponse
38
39
39
40
M2_TIME_FORMAT = "%b %d %H:%M:%S %Y"
40
41
42
+ logger = logging .getLogger (__name__ )
41
43
42
44
def to_time (_time ):
43
45
assert _time .endswith (" GMT" )
@@ -556,6 +558,47 @@ def _func(self, conv):
556
558
return {}
557
559
558
560
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
+
559
602
class VerifySignatureAlgorithm (Check ):
560
603
"""
561
604
verify that the used signature algorithm was one from an approved set.
@@ -574,8 +617,15 @@ def _sig_algo(self, signature, allowed):
574
617
575
618
def _func (self , conv ):
576
619
if "signature_algorithm" not in conv .idp_constraints :
620
+ logger .info ("Not verifying signature_algorithm (not configured)" )
577
621
return {}
578
622
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 {}
579
629
_algs = conv .idp_constraints ["signature_algorithm" ]
580
630
581
631
response = conv .saml_response [- 1 ].response
0 commit comments