42
42
43
43
from tempfile import NamedTemporaryFile
44
44
from 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
45
53
from xmlenc import EncryptionMethod
46
54
from xmlenc import EncryptedKey
47
55
from xmlenc import CipherData
48
56
from xmlenc import CipherValue
49
57
from xmlenc import EncryptedData
50
58
59
+ from Crypto .Hash import SHA
60
+ from Crypto .Hash import SHA224
51
61
from Crypto .Hash import SHA256
52
62
from Crypto .Hash import SHA384
53
63
from Crypto .Hash import SHA512
54
- from Crypto .Hash import SHA
55
64
56
65
logger = logging .getLogger (__name__ )
57
66
58
67
SIG = "{%s#}%s" % (ds .NAMESPACE , "Signature" )
59
68
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
-
65
69
RSA_1_5 = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
66
70
TRIPLE_DES_CBC = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
67
71
XMLTAG = "<?xml version='1.0'?>"
@@ -595,10 +599,11 @@ def verify(self, msg, sig, key):
595
599
596
600
597
601
SIGNER_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 ),
602
607
}
603
608
604
609
REQ_ORDER = ["SAMLRequest" , "RelayState" , "SigAlg" ]
@@ -619,7 +624,7 @@ def verify_redirect_signature(saml_msg, cert):
619
624
except KeyError :
620
625
raise Unsupported ("Signature algorithm: %s" % saml_msg ["SigAlg" ])
621
626
else :
622
- if saml_msg ["SigAlg" ][0 ] == RSA_SHA1 :
627
+ if saml_msg ["SigAlg" ][0 ] == SIG_RSA_SHA1 :
623
628
if "SAMLRequest" in saml_msg :
624
629
_order = REQ_ORDER
625
630
elif "SAMLResponse" in saml_msg :
@@ -1682,7 +1687,8 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None):
1682
1687
# ===========================================================================
1683
1688
1684
1689
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 ):
1686
1692
"""
1687
1693
If an assertion is to be signed the signature part has to be preset
1688
1694
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):
1695
1701
:return: A preset signature part
1696
1702
"""
1697
1703
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 )
1699
1709
canonicalization_method = ds .CanonicalizationMethod (
1700
1710
algorithm = ds .ALG_EXC_C14N )
1701
1711
trans0 = ds .Transform (algorithm = ds .TRANSFORM_ENVELOPED )
1702
1712
trans1 = ds .Transform (algorithm = ds .ALG_EXC_C14N )
1703
1713
transforms = ds .Transforms (transform = [trans0 , trans1 ])
1704
- digest_method = ds .DigestMethod (algorithm = ds . DIGEST_SHA1 )
1714
+ digest_method = ds .DigestMethod (algorithm = digest_alg )
1705
1715
1706
1716
reference = ds .Reference (uri = "#%s" % ident , digest_value = ds .DigestValue (),
1707
1717
transforms = transforms , digest_method = digest_method )
0 commit comments