Skip to content

Commit 5886581

Browse files
committed
undo removeal of imports of xmldsig.SIG_RSA_SHA..
1 parent d770edd commit 5886581

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/saml2/sigver.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,30 @@
5555

5656
from tempfile import NamedTemporaryFile
5757
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
5866
from xmlenc import EncryptionMethod
5967
from xmlenc import EncryptedKey
6068
from xmlenc import CipherData
6169
from xmlenc import CipherValue
6270
from xmlenc import EncryptedData
6371

72+
from Crypto.Hash import SHA
73+
from Crypto.Hash import SHA224
6474
from Crypto.Hash import SHA256
6575
from Crypto.Hash import SHA384
6676
from Crypto.Hash import SHA512
67-
from Crypto.Hash import SHA
6877

6978
logger = logging.getLogger(__name__)
7079

7180
SIG = "{%s#}%s" % (ds.NAMESPACE, "Signature")
7281

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-
7882
RSA_1_5 = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
7983
TRIPLE_DES_CBC = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
8084
XMLTAG = "<?xml version='1.0'?>"
@@ -603,10 +607,11 @@ def verify(self, msg, sig, key):
603607

604608

605609
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),
610615
}
611616

612617
REQ_ORDER = ["SAMLRequest", "RelayState", "SigAlg"]
@@ -627,7 +632,7 @@ def verify_redirect_signature(saml_msg, cert):
627632
except KeyError:
628633
raise Unsupported("Signature algorithm: %s" % saml_msg["SigAlg"])
629634
else:
630-
if saml_msg["SigAlg"][0] == RSA_SHA1:
635+
if saml_msg["SigAlg"][0] == SIG_RSA_SHA1:
631636
if "SAMLRequest" in saml_msg:
632637
_order = REQ_ORDER
633638
elif "SAMLResponse" in saml_msg:
@@ -1679,7 +1684,8 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None):
16791684
# ===========================================================================
16801685

16811686

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):
16831689
"""
16841690
If an assertion is to be signed the signature part has to be preset
16851691
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):
16921698
:return: A preset signature part
16931699
"""
16941700

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)
16961706
canonicalization_method = ds.CanonicalizationMethod(
16971707
algorithm=ds.ALG_EXC_C14N)
16981708
trans0 = ds.Transform(algorithm=ds.TRANSFORM_ENVELOPED)
16991709
trans1 = ds.Transform(algorithm=ds.ALG_EXC_C14N)
17001710
transforms = ds.Transforms(transform=[trans0, trans1])
1701-
digest_method = ds.DigestMethod(algorithm=ds.DIGEST_SHA1)
1711+
digest_method = ds.DigestMethod(algorithm=digest_alg)
17021712

17031713
reference = ds.Reference(uri="#%s" % ident, digest_value=ds.DigestValue(),
17041714
transforms=transforms, digest_method=digest_method)

0 commit comments

Comments
 (0)