|
11 | 11 | from saml2.argtree import add_path
|
12 | 12 | from saml2.cert import OpenSSLWrapper
|
13 | 13 | from saml2.xmldsig import sig_default
|
14 |
| -from saml2.xmldsig import SIG_RSA_SHA256 |
| 14 | +from saml2.xmldsig import SIG_RSA_SHA256, SIG_RSA_SHA1 |
15 | 15 | from saml2 import BINDING_HTTP_POST
|
16 | 16 | from saml2 import BINDING_HTTP_REDIRECT
|
17 | 17 | from saml2 import config
|
|
29 | 29 | from saml2.authn_context import INTERNETPROTOCOLPASSWORD
|
30 | 30 | from saml2.client import Saml2Client
|
31 | 31 | from saml2.pack import parse_soap_enveloped_saml
|
32 |
| -from saml2.response import LogoutResponse, StatusInvalidNameidPolicy, StatusError |
| 32 | +from saml2.response import LogoutResponse, StatusInvalidNameidPolicy, StatusError, \ |
| 33 | + IncorrectlySigned |
33 | 34 | from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion, Advice
|
34 | 35 | from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
35 | 36 | from saml2.saml import NameID
|
@@ -172,6 +173,9 @@ def setup_class(self):
|
172 | 173 | conf.load_file("server_conf")
|
173 | 174 | self.client = Saml2Client(conf)
|
174 | 175 |
|
| 176 | + def setup_method(self): |
| 177 | + self.server.config.setattr("idp", "want_authn_requests_signed", None) |
| 178 | + |
175 | 179 | def teardown_class(self):
|
176 | 180 | self.server.close()
|
177 | 181 |
|
@@ -1524,6 +1528,90 @@ def test_signed_redirect(self):
|
1524 | 1528 | qs["SAMLRequest"][0], BINDING_HTTP_REDIRECT
|
1525 | 1529 | )
|
1526 | 1530 |
|
| 1531 | + def test_signed_redirect_passes_if_needs_signed_requests(self): |
| 1532 | + # Revert configuration change to disallow unsinged responses |
| 1533 | + self.client.want_response_signed = True |
| 1534 | + self.server.config.setattr("idp", "want_authn_requests_signed", True) |
| 1535 | + |
| 1536 | + reqid, req = self.client.create_authn_request( |
| 1537 | + "http://localhost:8088/sso", message_id="id1" |
| 1538 | + ) |
| 1539 | + |
| 1540 | + info = self.client.apply_binding( |
| 1541 | + BINDING_HTTP_REDIRECT, |
| 1542 | + str(req), |
| 1543 | + destination="", |
| 1544 | + relay_state="relay2", |
| 1545 | + sign=True, |
| 1546 | + sigalg=SIG_RSA_SHA256, |
| 1547 | + ) |
| 1548 | + loc = info["headers"][0][1] |
| 1549 | + qs = list_values2simpletons(parse.parse_qs(loc[1:])) |
| 1550 | + |
| 1551 | + res = self.server.parse_authn_request( |
| 1552 | + qs["SAMLRequest"], |
| 1553 | + BINDING_HTTP_REDIRECT, |
| 1554 | + relay_state=qs["RelayState"], |
| 1555 | + sigalg=qs["SigAlg"], |
| 1556 | + signature=qs["Signature"] |
| 1557 | + ) |
| 1558 | + assert res.message.destination == "http://localhost:8088/sso" |
| 1559 | + assert res.message.id == "id1" |
| 1560 | + |
| 1561 | + def test_signed_redirect_fail_if_needs_signed_request_but_received_unsigned(self): |
| 1562 | + # Revert configuration change to disallow unsinged responses |
| 1563 | + self.client.want_response_signed = True |
| 1564 | + self.server.config.setattr("idp", "want_authn_requests_signed", True) |
| 1565 | + |
| 1566 | + reqid, req = self.client.create_authn_request( |
| 1567 | + "http://localhost:8088/sso", message_id="id1" |
| 1568 | + ) |
| 1569 | + |
| 1570 | + info = self.client.apply_binding( |
| 1571 | + BINDING_HTTP_REDIRECT, |
| 1572 | + str(req), |
| 1573 | + destination="", |
| 1574 | + relay_state="relay2", |
| 1575 | + sign=True, |
| 1576 | + sigalg=SIG_RSA_SHA256, |
| 1577 | + ) |
| 1578 | + loc = info["headers"][0][1] |
| 1579 | + qs = list_values2simpletons(parse.parse_qs(loc[1:])) |
| 1580 | + |
| 1581 | + with raises(IncorrectlySigned): |
| 1582 | + self.server.parse_authn_request( |
| 1583 | + qs["SAMLRequest"], BINDING_HTTP_REDIRECT |
| 1584 | + ) |
| 1585 | + |
| 1586 | + def test_signed_redirect_fail_if_needs_signed_request_but_sigalg_not_matches(self): |
| 1587 | + # Revert configuration change to disallow unsinged responses |
| 1588 | + self.client.want_response_signed = True |
| 1589 | + self.server.config.setattr("idp", "want_authn_requests_signed", True) |
| 1590 | + |
| 1591 | + reqid, req = self.client.create_authn_request( |
| 1592 | + "http://localhost:8088/sso", message_id="id1" |
| 1593 | + ) |
| 1594 | + |
| 1595 | + info = self.client.apply_binding( |
| 1596 | + BINDING_HTTP_REDIRECT, |
| 1597 | + str(req), |
| 1598 | + destination="", |
| 1599 | + relay_state="relay2", |
| 1600 | + sign=True, |
| 1601 | + sigalg=SIG_RSA_SHA256, |
| 1602 | + ) |
| 1603 | + loc = info["headers"][0][1] |
| 1604 | + qs = list_values2simpletons(parse.parse_qs(loc[1:])) |
| 1605 | + |
| 1606 | + with raises(IncorrectlySigned): |
| 1607 | + self.server.parse_authn_request( |
| 1608 | + qs["SAMLRequest"], |
| 1609 | + BINDING_HTTP_REDIRECT, |
| 1610 | + relay_state=qs["RelayState"], |
| 1611 | + sigalg=SIG_RSA_SHA1, |
| 1612 | + signature=qs["Signature"] |
| 1613 | + ) |
| 1614 | + |
1527 | 1615 | def test_do_logout_signed_redirect(self):
|
1528 | 1616 | conf = config.SPConfig()
|
1529 | 1617 | conf.load_file("sp_slo_redirect_conf")
|
|
0 commit comments