Skip to content

Commit ed1bb33

Browse files
author
Roland Hedberg
committedJun 27, 2015
Improve support for SigAlg usage in HTTP redirect.
1 parent b7f618b commit ed1bb33

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed
 

‎example/sp-wsgi/sp.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def _pick_idp(self, came_from):
544544
logger.info("Chosen IdP: '%s'" % idp_entity_id)
545545
return 0, idp_entity_id
546546

547-
def redirect_to_auth(self, _cli, entity_id, came_from):
547+
def redirect_to_auth(self, _cli, entity_id, came_from, sigalg=""):
548548
try:
549549
# Picks a binding to use for sending the Request to the IDP
550550
_binding, destination = _cli.pick_binding(
@@ -573,11 +573,13 @@ def redirect_to_auth(self, _cli, entity_id, came_from):
573573
element_to_extension_element(spcertenc)])
574574

575575
req_id, req = _cli.create_authn_request(destination,
576-
binding=return_binding, extensions=extensions)
576+
binding=return_binding,
577+
extensions=extensions)
577578
_rstate = rndstr()
578579
self.cache.relay_state[_rstate] = came_from
579580
ht_args = _cli.apply_binding(_binding, "%s" % req, destination,
580-
relay_state=_rstate)
581+
relay_state=_rstate,
582+
sigalg=sigalg)
581583
_sid = req_id
582584

583585
if cert is not None:

‎setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def run_tests(self):
6666
"Development Status :: 4 - Beta",
6767
"License :: OSI Approved :: Apache Software License",
6868
"Topic :: Software Development :: Libraries :: Python Modules",
69-
"Programming Language :: Python :: 2.7"],
69+
"Programming Language :: Python :: 2.7",
70+
"Programming Language :: Python :: 3.4"
71+
],
7072

7173
scripts=["tools/parse_xsd2.py", "tools/make_metadata.py",
7274
"tools/mdexport.py", "tools/merge_metadata.py"],

‎src/saml2/client.py

+28-26
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
from saml2.time_util import not_on_or_after
2525
from saml2.saml import AssertionIDRef
2626
from saml2.client_base import Base
27+
from saml2.client_base import SignOnError
2728
from saml2.client_base import LogoutError
2829
from saml2.client_base import NoServiceDefined
2930
from saml2.mdstore import destinations
3031

3132
try:
32-
from urlparse import parse_qs
33+
from urllib.parse import parse_qs
3334
except ImportError:
34-
# Compatibility with Python <= 2.5
35-
from cgi import parse_qs
35+
from urlparse import parse_qs
3636

3737
import logging
3838

@@ -42,13 +42,11 @@
4242
class Saml2Client(Base):
4343
""" The basic pySAML2 service provider class """
4444

45-
def prepare_for_authenticate(self, entityid=None, relay_state="",
46-
binding=saml2.BINDING_HTTP_REDIRECT, vorg="",
47-
nameid_format=None,
48-
scoping=None, consent=None, extensions=None,
49-
sign=None,
50-
response_binding=saml2.BINDING_HTTP_POST,
51-
**kwargs):
45+
def prepare_for_authenticate(
46+
self, entityid=None, relay_state="",
47+
binding=saml2.BINDING_HTTP_REDIRECT, vorg="", nameid_format=None,
48+
scoping=None, consent=None, extensions=None, sign=None,
49+
response_binding=saml2.BINDING_HTTP_POST, **kwargs):
5250
""" Makes all necessary preparations for an authentication request.
5351
5452
:param entityid: The entity ID of the IdP to send the request to
@@ -82,14 +80,12 @@ def prepare_for_authenticate(self, entityid=None, relay_state="",
8280

8381
return reqid, info
8482

85-
def prepare_for_negotiated_authenticate(self, entityid=None, relay_state="",
86-
binding=None, vorg="",
87-
nameid_format=None,
88-
scoping=None, consent=None, extensions=None,
89-
sign=None,
90-
response_binding=saml2.BINDING_HTTP_POST,
91-
**kwargs):
92-
""" Makes all necessary preparations for an authentication request that negotiates
83+
def prepare_for_negotiated_authenticate(
84+
self, entityid=None, relay_state="", binding=None, vorg="",
85+
nameid_format=None, scoping=None, consent=None, extensions=None,
86+
sign=None, response_binding=saml2.BINDING_HTTP_POST, **kwargs):
87+
""" Makes all necessary preparations for an authentication request
88+
that negotiates
9389
which binding to use for authentication.
9490
9591
:param entityid: The entity ID of the IdP to send the request to
@@ -117,20 +113,25 @@ def prepare_for_negotiated_authenticate(self, entityid=None, relay_state="",
117113

118114
reqid, request = self.create_authn_request(
119115
destination, vorg, scoping, response_binding, nameid_format,
120-
consent=consent,
121-
extensions=extensions, sign=sign,
116+
consent=consent, extensions=extensions, sign=sign,
122117
**kwargs)
123118

124119
_req_str = str(request)
125120

126121
logger.info("AuthNReq: %s" % _req_str)
127122

123+
try:
124+
sigalg = kwargs["sigalg"]
125+
except KeyError:
126+
sigalg = ""
127+
128128
http_info = self.apply_binding(binding, _req_str, destination,
129-
relay_state)
129+
relay_state, sigalg=sigalg)
130130

131131
return reqid, binding, http_info
132132
else:
133-
raise SignOnError("No supported bindings available for authentication")
133+
raise SignOnError(
134+
"No supported bindings available for authentication")
134135

135136
def global_logout(self, name_id, reason="", expire=None, sign=None):
136137
""" More or less a layer of indirection :-/
@@ -206,7 +207,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
206207
destination, entity_id, name_id=name_id, reason=reason,
207208
expire=expire)
208209

209-
#to_sign = []
210+
# to_sign = []
210211
if binding.startswith("http://"):
211212
sign = True
212213

@@ -230,7 +231,8 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
230231
not_done.remove(entity_id)
231232
response = response.text
232233
logger.info("Response: %s" % response)
233-
res = self.parse_logout_request_response(response, binding)
234+
res = self.parse_logout_request_response(response,
235+
binding)
234236
responses[entity_id] = res
235237
else:
236238
logger.info("NOT OK response from %s" % destination)
@@ -324,15 +326,15 @@ def _use_soap(self, destination, query_type, **kwargs):
324326
raise HTTPError("%d:%s" % (response.status_code, response.error))
325327

326328
if response:
327-
#not_done.remove(entity_id)
329+
# not_done.remove(entity_id)
328330
logger.info("OK response from %s" % destination)
329331
return response
330332
else:
331333
logger.info("NOT OK response from %s" % destination)
332334

333335
return None
334336

335-
#noinspection PyUnusedLocal
337+
# noinspection PyUnusedLocal
336338
def do_authz_decision_query(self, entity_id, action,
337339
subject_id, nameid_format,
338340
evidence=None, resource=None,

‎src/saml2/httpbase.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from six.moves import http_cookiejar
44
import copy
55
import re
6-
import urllib
76
from six.moves.urllib.parse import urlparse
87
from six.moves.urllib.parse import urlencode
98
import requests
@@ -311,7 +310,8 @@ def use_http_uri(message, typ, destination="", relay_state=""):
311310

312311
return info
313312

314-
def use_soap(self, request, destination="", soap_headers=None, sign=False):
313+
def use_soap(self, request, destination="", soap_headers=None, sign=False,
314+
**kwargs):
315315
"""
316316
Construct the necessary information for using SOAP+POST
317317

‎src/saml2/pack.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
def http_form_post_message(message, location, relay_state="",
48-
typ="SAMLRequest"):
48+
typ="SAMLRequest", **kwargs):
4949
"""The HTTP POST binding defines a mechanism by which SAML protocol
5050
messages may be transmitted within the base64-encoded content of a
5151
HTML form control.
@@ -80,7 +80,7 @@ def http_form_post_message(message, location, relay_state="",
8080

8181

8282
def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
83-
sigalg=None, key=None):
83+
sigalg=None, key=None, **kwargs):
8484
"""The HTTP Redirect binding defines a mechanism by which SAML protocol
8585
messages can be transmitted within URL parameters.
8686
Messages are encoded for use with this binding using a URL encoding
@@ -256,5 +256,6 @@ def packager(identifier):
256256
raise Exception("Unknown binding type: %s" % identifier)
257257

258258

259-
def factory(binding, message, location, relay_state="", typ="SAMLRequest"):
260-
return PACKING[binding](message, location, relay_state, typ)
259+
def factory(binding, message, location, relay_state="", typ="SAMLRequest",
260+
**kwargs):
261+
return PACKING[binding](message, location, relay_state, typ, **kwargs)

0 commit comments

Comments
 (0)
Please sign in to comment.