Skip to content

Commit deeb0b5

Browse files
committed
Check allowed signature and digest algo for the POST binding
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent e30702a commit deeb0b5

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/saml2/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from saml2 import BINDING_HTTP_POST
1515
from saml2 import BINDING_SOAP
1616

17-
import saml2.xmldsig as ds
17+
from saml2.xmldsig import DefaultSignature
1818

1919
from saml2.ident import decode, code
2020
from saml2.httpbase import HTTPError
@@ -264,7 +264,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
264264
if sign is None:
265265
sign = self.logout_requests_signed
266266

267-
def_sig = ds.DefaultSignature()
267+
def_sig = DefaultSignature()
268268
sign_alg = def_sig.get_sign_alg() if sign_alg is None else sign_alg
269269
digest_alg = (
270270
def_sig.get_digest_alg()

src/saml2/client_base.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
from saml2 import BINDING_HTTP_POST
5555
from saml2 import BINDING_PAOS
5656

57-
import saml2.xmldsig as ds
58-
57+
from saml2.xmldsig import SIG_ALLOWED_ALG
58+
from saml2.xmldsig import DIGEST_ALLOWED_ALG
59+
from saml2.xmldsig import DefaultSignature
5960

6061
logger = logging.getLogger(__name__)
6162

@@ -450,10 +451,19 @@ def create_authn_request(
450451
# XXX will be used to embed the signature to the xml doc - ie, POST binding
451452
# XXX always called by the SP, no need to check the context
452453
sign = self.authn_requests_signed if sign is None else sign
453-
def_sig = ds.DefaultSignature()
454+
def_sig = DefaultSignature()
454455
sign_alg = sign_alg or def_sig.get_sign_alg()
455456
digest_alg = digest_alg or def_sig.get_digest_alg()
456457

458+
if sign_alg not in [long_name for short_name, long_name in SIG_ALLOWED_ALG]:
459+
raise Exception(
460+
"Signature algo not in allowed list: {algo}".format(algo=sign_alg)
461+
)
462+
if digest_alg not in [long_name for short_name, long_name in DIGEST_ALLOWED_ALG]:
463+
raise Exception(
464+
"Digest algo not in allowed list: {algo}".format(algo=digest_alg)
465+
)
466+
457467
if (sign and self.sec.cert_handler.generate_cert()) or client_crt is not None:
458468
with self.lock:
459469
self.sec.cert_handler.update_cert(True, client_crt)

src/saml2/entity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
from saml2.pack import http_redirect_message
7575
from saml2.pack import http_form_post_message
7676

77-
import saml2.xmldsig as ds
77+
from saml2.xmldsig import DefaultSignature
7878

7979

8080
logger = logging.getLogger(__name__)
@@ -231,7 +231,7 @@ def apply_binding(
231231
else None
232232
)
233233
sign = sign_config if sign is None else sign
234-
def_sig = ds.DefaultSignature()
234+
def_sig = DefaultSignature()
235235
sigalg = sigalg or def_sig.get_sign_alg()
236236

237237
# unless if BINDING_HTTP_ARTIFACT

src/saml2/pack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ def http_redirect_message(
186186
args["RelayState"] = relay_state
187187

188188
if sign:
189-
# XXX check for allowed algo -- should do the same for POST binding
190189
# sigalgs, should be one defined in xmldsig
191190
if sigalg not in [long_name for short_name, long_name in SIG_ALLOWED_ALG]:
192191
raise Exception(

0 commit comments

Comments
 (0)