55
55
56
56
from tempfile import NamedTemporaryFile
57
57
from subprocess import Popen , PIPE
58
+
59
+ from xmldsig import digest_default
60
+ from xmldsig import sig_default
61
+ from xmldsig import SIG_RSA_SHA1
62
+ from xmldsig import SIG_RSA_SHA224
63
+ from xmldsig import SIG_RSA_SHA256
64
+ from xmldsig import SIG_RSA_SHA384
65
+ from xmldsig import SIG_RSA_SHA512
58
66
from xmlenc import EncryptionMethod
59
67
from xmlenc import EncryptedKey
60
68
from xmlenc import CipherData
61
69
from xmlenc import CipherValue
62
70
from xmlenc import EncryptedData
63
71
72
+ from Crypto .Hash import SHA
73
+ from Crypto .Hash import SHA224
64
74
from Crypto .Hash import SHA256
65
75
from Crypto .Hash import SHA384
66
76
from Crypto .Hash import SHA512
67
- from Crypto .Hash import SHA
68
77
69
78
logger = logging .getLogger (__name__ )
70
79
71
80
SIG = "{%s#}%s" % (ds .NAMESPACE , "Signature" )
72
81
73
- RSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
74
- RSA_SHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
75
- RSA_SHA384 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
76
- RSA_SHA512 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
77
-
78
82
RSA_1_5 = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
79
83
TRIPLE_DES_CBC = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
80
84
XMLTAG = "<?xml version='1.0'?>"
@@ -603,10 +607,11 @@ def verify(self, msg, sig, key):
603
607
604
608
605
609
SIGNER_ALGS = {
606
- RSA_SHA1 : RSASigner (SHA ),
607
- RSA_SHA256 : RSASigner (SHA256 ),
608
- RSA_SHA384 : RSASigner (SHA384 ),
609
- RSA_SHA512 : RSASigner (SHA512 ),
610
+ SIG_RSA_SHA1 : RSASigner (SHA ),
611
+ SIG_RSA_SHA224 : RSASigner (SHA224 ),
612
+ SIG_RSA_SHA256 : RSASigner (SHA256 ),
613
+ SIG_RSA_SHA384 : RSASigner (SHA384 ),
614
+ SIG_RSA_SHA512 : RSASigner (SHA512 ),
610
615
}
611
616
612
617
REQ_ORDER = ["SAMLRequest" , "RelayState" , "SigAlg" ]
@@ -627,7 +632,7 @@ def verify_redirect_signature(saml_msg, cert):
627
632
except KeyError :
628
633
raise Unsupported ("Signature algorithm: %s" % saml_msg ["SigAlg" ])
629
634
else :
630
- if saml_msg ["SigAlg" ][0 ] == RSA_SHA1 :
635
+ if saml_msg ["SigAlg" ][0 ] == SIG_RSA_SHA1 :
631
636
if "SAMLRequest" in saml_msg :
632
637
_order = REQ_ORDER
633
638
elif "SAMLResponse" in saml_msg :
@@ -1679,7 +1684,8 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None):
1679
1684
# ===========================================================================
1680
1685
1681
1686
1682
- def pre_signature_part (ident , public_key = None , identifier = None ):
1687
+ def pre_signature_part (ident , public_key = None , identifier = None ,
1688
+ digest_alg = None , sign_alg = None ):
1683
1689
"""
1684
1690
If an assertion is to be signed the signature part has to be preset
1685
1691
with which algorithms to be used, this function returns such a
@@ -1692,13 +1698,17 @@ def pre_signature_part(ident, public_key=None, identifier=None):
1692
1698
:return: A preset signature part
1693
1699
"""
1694
1700
1695
- signature_method = ds .SignatureMethod (algorithm = ds .SIG_RSA_SHA1 )
1701
+ if not digest_alg :
1702
+ digest_alg = ds .digest_default
1703
+ if not sign_alg :
1704
+ sign_alg = ds .sig_default
1705
+ signature_method = ds .SignatureMethod (algorithm = sign_alg )
1696
1706
canonicalization_method = ds .CanonicalizationMethod (
1697
1707
algorithm = ds .ALG_EXC_C14N )
1698
1708
trans0 = ds .Transform (algorithm = ds .TRANSFORM_ENVELOPED )
1699
1709
trans1 = ds .Transform (algorithm = ds .ALG_EXC_C14N )
1700
1710
transforms = ds .Transforms (transform = [trans0 , trans1 ])
1701
- digest_method = ds .DigestMethod (algorithm = ds . DIGEST_SHA1 )
1711
+ digest_method = ds .DigestMethod (algorithm = digest_alg )
1702
1712
1703
1713
reference = ds .Reference (uri = "#%s" % ident , digest_value = ds .DigestValue (),
1704
1714
transforms = transforms , digest_method = digest_method )
0 commit comments