4242
4343from tempfile import NamedTemporaryFile
4444from subprocess import Popen , PIPE
45+
46+ from xmldsig import digest_default
47+ from xmldsig import sig_default
48+ from xmldsig import SIG_RSA_SHA1
49+ from xmldsig import SIG_RSA_SHA224
50+ from xmldsig import SIG_RSA_SHA256
51+ from xmldsig import SIG_RSA_SHA384
52+ from xmldsig import SIG_RSA_SHA512
4553from xmlenc import EncryptionMethod
4654from xmlenc import EncryptedKey
4755from xmlenc import CipherData
4856from xmlenc import CipherValue
4957from xmlenc import EncryptedData
5058
59+ from Crypto .Hash import SHA
60+ from Crypto .Hash import SHA224
5161from Crypto .Hash import SHA256
5262from Crypto .Hash import SHA384
5363from Crypto .Hash import SHA512
54- from Crypto .Hash import SHA
5564
5665logger = logging .getLogger (__name__ )
5766
5867SIG = "{%s#}%s" % (ds .NAMESPACE , "Signature" )
5968
60- RSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
61- RSA_SHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
62- RSA_SHA384 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
63- RSA_SHA512 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
64-
6569RSA_1_5 = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
6670TRIPLE_DES_CBC = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
6771XMLTAG = "<?xml version='1.0'?>"
@@ -595,10 +599,11 @@ def verify(self, msg, sig, key):
595599
596600
597601SIGNER_ALGS = {
598- RSA_SHA1 : RSASigner (SHA ),
599- RSA_SHA256 : RSASigner (SHA256 ),
600- RSA_SHA384 : RSASigner (SHA384 ),
601- RSA_SHA512 : RSASigner (SHA512 ),
602+ SIG_RSA_SHA1 : RSASigner (SHA ),
603+ SIG_RSA_SHA224 : RSASigner (SHA224 ),
604+ SIG_RSA_SHA256 : RSASigner (SHA256 ),
605+ SIG_RSA_SHA384 : RSASigner (SHA384 ),
606+ SIG_RSA_SHA512 : RSASigner (SHA512 ),
602607}
603608
604609REQ_ORDER = ["SAMLRequest" , "RelayState" , "SigAlg" ]
@@ -619,7 +624,7 @@ def verify_redirect_signature(saml_msg, cert):
619624 except KeyError :
620625 raise Unsupported ("Signature algorithm: %s" % saml_msg ["SigAlg" ])
621626 else :
622- if saml_msg ["SigAlg" ][0 ] == RSA_SHA1 :
627+ if saml_msg ["SigAlg" ][0 ] == SIG_RSA_SHA1 :
623628 if "SAMLRequest" in saml_msg :
624629 _order = REQ_ORDER
625630 elif "SAMLResponse" in saml_msg :
@@ -1682,7 +1687,8 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None):
16821687# ===========================================================================
16831688
16841689
1685- def pre_signature_part (ident , public_key = None , identifier = None ):
1690+ def pre_signature_part (ident , public_key = None , identifier = None ,
1691+ digest_alg = None , sign_alg = None ):
16861692 """
16871693 If an assertion is to be signed the signature part has to be preset
16881694 with which algorithms to be used, this function returns such a
@@ -1695,13 +1701,17 @@ def pre_signature_part(ident, public_key=None, identifier=None):
16951701 :return: A preset signature part
16961702 """
16971703
1698- signature_method = ds .SignatureMethod (algorithm = ds .SIG_RSA_SHA1 )
1704+ if not digest_alg :
1705+ digest_alg = ds .digest_default
1706+ if not sign_alg :
1707+ sign_alg = ds .sig_default
1708+ signature_method = ds .SignatureMethod (algorithm = sign_alg )
16991709 canonicalization_method = ds .CanonicalizationMethod (
17001710 algorithm = ds .ALG_EXC_C14N )
17011711 trans0 = ds .Transform (algorithm = ds .TRANSFORM_ENVELOPED )
17021712 trans1 = ds .Transform (algorithm = ds .ALG_EXC_C14N )
17031713 transforms = ds .Transforms (transform = [trans0 , trans1 ])
1704- digest_method = ds .DigestMethod (algorithm = ds . DIGEST_SHA1 )
1714+ digest_method = ds .DigestMethod (algorithm = digest_alg )
17051715
17061716 reference = ds .Reference (uri = "#%s" % ident , digest_value = ds .DigestValue (),
17071717 transforms = transforms , digest_method = digest_method )
0 commit comments