Skip to content

Commit 6c604e3

Browse files
author
Roland Hedberg
committed
Merge pull request #223 from HaToHo/master
Added comments.
2 parents 3e6b4c9 + b96b5f9 commit 6c604e3

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

src/saml2/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ def get_xml_string_with_self_contained_assertion_within_advice_encrypted_asserti
603603
return ElementTree.tostring(tree, encoding="UTF-8")
604604

605605
def get_xml_string_with_self_contained_assertion_within_encrypted_assertion(self, assertion_tag):
606+
""" Makes a encrypted assertion only containing self contained namespaces.
607+
608+
:param assertion_tag: Tag for the assertion to be transformed.
609+
:return: A new samlp.Resonse in string representation.
610+
"""
606611
prefix_map = self.get_prefix_map([self.encrypted_assertion._to_element_tree().find(assertion_tag)])
607612

608613
tree = self._to_element_tree()

src/saml2/entity.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,26 @@ def _add_info(self, msg, **kwargs):
504504
msg.extension_elements = extensions
505505

506506
def has_encrypt_cert_in_metadata(self, sp_entity_id):
507+
""" Verifies if the metadata contains encryption certificates.
508+
509+
:param sp_entity_id: Entity ID for the calling service provider.
510+
:return: True if encrypt cert exists in metadata, otherwise False.
511+
"""
507512
if sp_entity_id is not None:
508513
_certs = self.metadata.certs(sp_entity_id, "any", "encryption")
509514
if len(_certs) > 0:
510515
return True
511516
return False
512517

513-
514518
def _encrypt_assertion(self, encrypt_cert, sp_entity_id, response, node_xpath=None):
519+
""" Encryption of assertions.
520+
521+
:param encrypt_cert: Certificate to be used for encryption.
522+
:param sp_entity_id: Entity ID for the calling service provider.
523+
:param response: A samlp.Response
524+
:param node_xpath: Unquie path to the element to be encrypted.
525+
:return: A new samlp.Resonse with the designated assertion encrypted.
526+
"""
515527
_certs = []
516528
cbxs = CryptoBackendXmlSec1(self.config.xmlsec_binary)
517529
if encrypt_cert:
@@ -558,6 +570,15 @@ def _response(self, in_response_to, consumer_url=None, status=None,
558570
:param issuer: The issuer of the response
559571
:param sign: Whether the response should be signed or not
560572
:param to_sign: If there are other parts to sign
573+
:param sp_entity_id: Entity ID for the calling service provider.
574+
:param encrypt_assertion: True if assertions should be encrypted.
575+
:param encrypt_assertion_self_contained: True if all encrypted assertions should have alla namespaces
576+
selfcontained.
577+
:param encrypted_advice_attributes: True if assertions in the advice element should be encrypted.
578+
:param encrypt_cert_advice: Certificate to be used for encryption of assertions in the advice element.
579+
:param encrypt_cert_assertion: Certificate to be used for encryption of assertions.
580+
:param sign_assertion: True if assertions should be signed.
581+
:param pefim: True if a response according to the PEFIM profile should be created.
561582
:param kwargs: Extra key word arguments
562583
:return: A Response instance
563584
"""

src/saml2/response.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,14 @@ def _assertion(self, assertion, verified=False):
799799
raise
800800

801801
def decrypt_assertions(self, encrypted_assertions, decr_txt, issuer=None, verified=False):
802+
""" Moves the decrypted assertion from the encrypted assertion to a list.
803+
804+
:param encrypted_assertions: A list of encrypted assertions.
805+
:param decr_txt: The string representation containing the decrypted data. Used when verifying signatures.
806+
:param issuer: The issuer of the response.
807+
:param verified: If True do not verify signatures, otherwise verify the signature if it exists.
808+
:return: A list of decrypted assertions.
809+
"""
802810
res = []
803811
for encrypted_assertion in encrypted_assertions:
804812
if encrypted_assertion.extension_elements:
@@ -815,11 +823,21 @@ def decrypt_assertions(self, encrypted_assertions, decr_txt, issuer=None, verifi
815823
return res
816824

817825
def find_encrypt_data_assertion(self, enc_assertions):
826+
""" Verifies if a list of encrypted assertions contains encrypted data.
827+
828+
:param enc_assertions: A list of encrypted assertions.
829+
:return: True encrypted data exists otherwise false.
830+
"""
818831
for _assertion in enc_assertions:
819832
if _assertion.encrypted_data is not None:
820833
return True
821834

822835
def find_encrypt_data_assertion_list(self, _assertions):
836+
""" Verifies if a list of assertions contains encrypted data in the advice element.
837+
838+
:param _assertions: A list of assertions.
839+
:return: True encrypted data exists otherwise false.
840+
"""
823841
for _assertion in _assertions:
824842
if _assertion.advice:
825843
if _assertion.advice.encrypted_assertion:
@@ -828,6 +846,11 @@ def find_encrypt_data_assertion_list(self, _assertions):
828846
return True
829847

830848
def find_encrypt_data(self, resp):
849+
""" Verifies if a saml response contains encrypted assertions with encrypted data.
850+
851+
:param resp: A saml response.
852+
:return: True encrypted data exists otherwise false.
853+
"""
831854
_has_encrypt_data = False
832855
if resp.encrypted_assertion:
833856
res = self.find_encrypt_data_assertion(resp.encrypted_assertion)
@@ -843,6 +866,11 @@ def find_encrypt_data(self, resp):
843866
return False
844867

845868
def parse_assertion(self, keys=None):
869+
""" Parse the assertions for a saml response.
870+
871+
:param keys: A string representing a RSA key or a list of strings containing RSA keys.
872+
:return: True if the assertions are parsed otherwise False.
873+
"""
846874
if self.context == "AuthnQuery":
847875
# can contain one or more assertions
848876
pass

src/saml2/server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,20 @@ def _authn_response(self, in_response_to, consumer_url,
337337
:param authn: A dictionary containing information about the
338338
authn context.
339339
:param issuer: The issuer of the response
340+
:param policy:
340341
:param sign_assertion: Whether the assertion should be signed or not
341342
:param sign_response: Whether the response should be signed or not
342343
:param best_effort: Even if not the SPs demands can be met send a
343344
response.
345+
:param encrypt_assertion: True if assertions should be encrypted.
346+
:param encrypt_assertion_self_contained: True if all encrypted assertions should have alla namespaces
347+
selfcontained.
348+
:param encrypted_advice_attributes: True if assertions in the advice element should be encrypted.
349+
:param encrypt_cert_advice: Certificate to be used for encryption of assertions in the advice element.
350+
:param encrypt_cert_assertion: Certificate to be used for encryption of assertions.
351+
:param authn_statement: Authentication statement.
352+
:param sign_assertion: True if assertions should be signed.
353+
:param pefim: True if a response according to the PEFIM profile should be created.
344354
:return: A response instance
345355
"""
346356

@@ -495,11 +505,20 @@ def create_authn_response(self, identity, in_response_to, destination,
495505
:param sp_entity_id: The entity identifier of the Service Provider
496506
:param name_id_policy: How the NameID should be constructed
497507
:param userid: The subject identifier
508+
:param name_id: The identifier of the subject.
498509
:param authn: Dictionary with information about the authentication
499510
context
500511
:param issuer: Issuer of the response
501512
:param sign_assertion: Whether the assertion should be signed or not.
502513
:param sign_response: Whether the response should be signed or not.
514+
:param encrypt_assertion: True if assertions should be encrypted.
515+
:param encrypt_assertion_self_contained: True if all encrypted assertions should have alla namespaces
516+
selfcontained.
517+
:param encrypted_advice_attributes: True if assertions in the advice element should be encrypted.
518+
:param encrypt_cert_advice: Certificate to be used for encryption of assertions in the advice element.
519+
:param encrypt_cert_assertion: Certificate to be used for encryption of assertions.
520+
:param sign_assertion: True if assertions should be signed.
521+
:param pefim: True if a response according to the PEFIM profile should be created.
503522
:return: A response instance
504523
"""
505524

0 commit comments

Comments
 (0)