@@ -323,7 +323,7 @@ def _authn_response(self, in_response_to, consumer_url,
323
323
status = None , authn = None , issuer = None , policy = None ,
324
324
sign_assertion = False , sign_response = False ,
325
325
best_effort = False , encrypt_assertion = False ,
326
- encrypt_cert = None , authn_statement = None ,
326
+ encrypt_cert_advice = None , encrypt_cert_assertion = None , authn_statement = None ,
327
327
encrypt_assertion_self_contained = False , encrypted_advice_attributes = False ):
328
328
""" Create a response. A layer of indirection.
329
329
@@ -375,16 +375,17 @@ def _authn_response(self, in_response_to, consumer_url,
375
375
sign_response )
376
376
377
377
to_sign = []
378
- #if sign_assertion is not None and sign_assertion:
379
- # if assertion.advice and assertion.advice.assertion:
380
- # for tmp_assertion in assertion.advice.assertion:
381
- # tmp_assertion.signature = pre_signature_part(tmp_assertion.id, self.sec.my_cert, 1)
382
- # to_sign.append((class_name(tmp_assertion), tmp_assertion.id))
383
- # assertion.signature = pre_signature_part(assertion.id,
384
- # self.sec.my_cert, 1)
385
- # Just the assertion or the response and the assertion ?
386
- # to_sign.append((class_name(assertion), assertion.id))
378
+ if not encrypt_assertion :
379
+ if sign_assertion :
380
+ assertion .signature = pre_signature_part (assertion .id , self .sec .my_cert , 1 )
381
+ to_sign .append ((class_name (assertion ), assertion .id ))
387
382
383
+ if not encrypted_advice_attributes :
384
+ if sign_assertion :
385
+ if assertion .advice and assertion .advice .assertion :
386
+ for tmp_assertion in assertion .advice .assertion :
387
+ tmp_assertion .signature = pre_signature_part (tmp_assertion .id , self .sec .my_cert , 1 )
388
+ to_sign .append ((class_name (tmp_assertion ), tmp_assertion .id ))
388
389
389
390
# Store which assertion that has been sent to which SP about which
390
391
# subject.
@@ -400,7 +401,8 @@ def _authn_response(self, in_response_to, consumer_url,
400
401
401
402
return self ._response (in_response_to , consumer_url , status , issuer ,
402
403
sign_response , to_sign ,sp_entity_id = sp_entity_id , encrypt_assertion = encrypt_assertion ,
403
- encrypt_cert = encrypt_cert ,
404
+ encrypt_cert_advice = encrypt_cert_advice ,
405
+ encrypt_cert_assertion = encrypt_cert_assertion ,
404
406
encrypt_assertion_self_contained = encrypt_assertion_self_contained ,
405
407
encrypted_advice_attributes = encrypted_advice_attributes ,sign_assertion = sign_assertion ,
406
408
** args )
@@ -477,8 +479,8 @@ def create_authn_response(self, identity, in_response_to, destination,
477
479
sp_entity_id , name_id_policy = None , userid = None ,
478
480
name_id = None , authn = None , issuer = None ,
479
481
sign_response = None , sign_assertion = None ,
480
- encrypt_cert = None , encrypt_assertion = None ,
481
- encrypt_assertion_self_contained = False ,
482
+ encrypt_cert_advice = None , encrypt_cert_assertion = None , encrypt_assertion = None ,
483
+ encrypt_assertion_self_contained = True ,
482
484
encrypted_advice_attributes = False ,
483
485
** kwargs ):
484
486
""" Constructs an AuthenticationResponse
@@ -523,17 +525,35 @@ def create_authn_response(self, identity, in_response_to, destination,
523
525
if encrypt_assertion is None :
524
526
encrypt_assertion = False
525
527
528
+
529
+ if encrypt_assertion_self_contained is None :
530
+ encrypt_assertion_self_contained = self .config .getattr ("encrypt_assertion_self_contained" , "idp" )
531
+ if encrypt_assertion_self_contained is None :
532
+ encrypt_assertion_self_contained = True
533
+
534
+ if encrypted_advice_attributes is None :
535
+ encrypted_advice_attributes = self .config .getattr ("encrypted_advice_attributes" , "idp" )
536
+ if encrypted_advice_attributes is None :
537
+ encrypted_advice_attributes = False
538
+
539
+ if encrypted_advice_attributes :
540
+ verify_encrypt_cert = self .config .getattr ("verify_encrypt_cert_advice" , "idp" )
541
+ if verify_encrypt_cert is not None :
542
+ if encrypt_cert_advice is None :
543
+ raise CertificateError ("No SPCertEncType certificate for encryption contained in authentication "
544
+ "request." )
545
+ if not verify_encrypt_cert (encrypt_cert_advice ):
546
+ raise CertificateError ("Invalid certificate for encryption!" )
547
+
548
+
526
549
if encrypt_assertion :
527
- if encrypt_cert is not None :
528
- verify_encrypt_cert = self .config .getattr ("verify_encrypt_cert" , "idp" )
529
- if verify_encrypt_cert is not None :
530
- if not verify_encrypt_cert (encrypt_cert ):
531
- raise CertificateError ("Invalid certificate for encryption!" )
532
- else :
533
- raise CertificateError ("No SPCertEncType certificate for encryption contained in authentication "
534
- "request." )
535
- else :
536
- encrypt_assertion = False
550
+ verify_encrypt_cert = self .config .getattr ("verify_encrypt_cert_assertion" , "idp" )
551
+ if verify_encrypt_cert is not None :
552
+ if encrypt_cert_assertion is None :
553
+ raise CertificateError ("No SPCertEncType certificate for encryption contained in authentication "
554
+ "request." )
555
+ if not verify_encrypt_cert (encrypt_cert_assertion ):
556
+ raise CertificateError ("Invalid certificate for encryption!" )
537
557
538
558
if not name_id :
539
559
try :
@@ -593,7 +613,8 @@ def create_authn_response(self, identity, in_response_to, destination,
593
613
encrypt_assertion = encrypt_assertion ,
594
614
encrypt_assertion_self_contained = encrypt_assertion_self_contained ,
595
615
encrypted_advice_attributes = encrypted_advice_attributes ,
596
- encrypt_cert = encrypt_cert )
616
+ encrypt_cert_advice = encrypt_cert_advice ,
617
+ encrypt_cert_assertion = encrypt_cert_assertion )
597
618
return self ._authn_response (in_response_to , # in_response_to
598
619
destination , # consumer_url
599
620
sp_entity_id , # sp_entity_id
@@ -608,7 +629,8 @@ def create_authn_response(self, identity, in_response_to, destination,
608
629
encrypt_assertion = encrypt_assertion ,
609
630
encrypt_assertion_self_contained = encrypt_assertion_self_contained ,
610
631
encrypted_advice_attributes = encrypted_advice_attributes ,
611
- encrypt_cert = encrypt_cert )
632
+ encrypt_cert_advice = encrypt_cert_advice ,
633
+ encrypt_cert_assertion = encrypt_cert_assertion )
612
634
613
635
except MissingValue as exc :
614
636
return self .create_error_response (in_response_to , destination ,
0 commit comments