Skip to content

Commit 2878400

Browse files
committed
Formatting and restructure
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent ac59e8a commit 2878400

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

src/saml2/entity.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ def sign(
516516
# XXX DONE will actually use sign the POST-Binding
517517
# XXX DONE deepest level - needs to decide the sign value
518518
# XXX DONE calls self.sign must figure out sign
519-
# XXX ensure both SPs and IdPs go through this
520-
# XXX ensure this works for the POST-Binding
519+
# XXX DONE ensure both SPs and IdPs go through this
520+
# XXX DONE ensure this works for the POST-Binding
521521
def _message(
522522
self,
523523
request_cls,
@@ -673,6 +673,8 @@ def _encrypt_assertion(self, encrypt_cert, sp_entity_id, response, node_xpath=No
673673
return response
674674

675675
# XXX DONE calls self.sign must figure out sign
676+
# XXX calls signed_instance_factory - must have called pre_signature_part
677+
# XXX calls pre_signature_part - must figure out sign_alg/digest_alg
676678
def _response(
677679
self,
678680
in_response_to,
@@ -746,8 +748,8 @@ def _response(
746748

747749
sign = sign if sign is not None else self.should_sign
748750
if (
749-
not sign
750-
and to_sign
751+
to_sign
752+
and not sign
751753
and not encrypt_assertion
752754
):
753755
return signed_instance_factory(response, self.sec, to_sign)

src/saml2/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def setup_assertion(
414414
**kwargs)
415415
return assertion
416416

417+
# XXX calls pre_signature_part
417418
# XXX > _response
418419
def _authn_response(
419420
self,

src/saml2/sigver.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,20 @@ def signed_instance_factory(instance, seccont, elements_to_sign=None):
315315
:param elements_to_sign: Which parts if any that should be signed
316316
:return: A class instance if not signed otherwise a string
317317
"""
318-
if elements_to_sign:
319-
signed_xml = instance
320-
if not isinstance(instance, six.string_types):
321-
signed_xml = instance.to_string()
322-
for (node_name, nodeid) in elements_to_sign:
323-
signed_xml = seccont.sign_statement(
324-
signed_xml, node_name=node_name, node_id=nodeid)
325-
return signed_xml
326-
else:
318+
if not elements_to_sign:
327319
return instance
328320

321+
signed_xml = instance
322+
if not isinstance(instance, six.string_types):
323+
signed_xml = instance.to_string()
324+
325+
for (node_name, nodeid) in elements_to_sign:
326+
signed_xml = seccont.sign_statement(
327+
signed_xml, node_name=node_name, node_id=nodeid
328+
)
329+
330+
return signed_xml
331+
329332

330333
def make_temp(content, suffix="", decode=True, delete_tmpfiles=True):
331334
"""
@@ -1740,10 +1743,11 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None, sign_
17401743

17411744
if not item.signature:
17421745
item.signature = pre_signature_part(
1743-
sid,
1744-
self.cert_file,
1745-
sign_alg=sign_alg,
1746-
digest_alg=digest_alg)
1746+
ident=sid,
1747+
public_key=self.cert_file,
1748+
sign_alg=sign_alg,
1749+
digest_alg=digest_alg,
1750+
)
17471751

17481752
statement = self.sign_statement(
17491753
statement,
@@ -1757,7 +1761,13 @@ def multiple_signatures(self, statement, to_sign, key=None, key_file=None, sign_
17571761

17581762

17591763
# XXX FIXME calls DefaultSignature - remove to unveil chain of calls without proper args
1760-
def pre_signature_part(ident, public_key=None, identifier=None, digest_alg=None, sign_alg=None):
1764+
def pre_signature_part(
1765+
ident,
1766+
public_key=None,
1767+
identifier=None,
1768+
digest_alg=None,
1769+
sign_alg=None,
1770+
):
17611771
"""
17621772
If an assertion is to be signed the signature part has to be preset
17631773
with which algorithms to be used, this function returns such a
@@ -1770,10 +1780,12 @@ def pre_signature_part(ident, public_key=None, identifier=None, digest_alg=None,
17701780
:return: A preset signature part
17711781
"""
17721782

1783+
# XXX
17731784
if not digest_alg:
17741785
digest_alg = ds.DefaultSignature().get_digest_alg()
17751786
if not sign_alg:
17761787
sign_alg = ds.DefaultSignature().get_sign_alg()
1788+
17771789
signature_method = ds.SignatureMethod(algorithm=sign_alg)
17781790
canonicalization_method = ds.CanonicalizationMethod(
17791791
algorithm=ds.ALG_EXC_C14N)

0 commit comments

Comments
 (0)