@@ -191,43 +191,45 @@ def do_contact_person_info(lava):
191
191
return cps
192
192
193
193
194
- def do_key_descriptor (cert , use = "both" ):
195
- if use == "both" :
196
- return [
197
- md .KeyDescriptor (
198
- key_info = ds .KeyInfo (
199
- x509_data = ds .X509Data (
200
- x509_certificate = ds .X509Certificate (text = cert )
201
- )
202
- ),
203
- use = "encryption"
204
- ),
205
- md .KeyDescriptor (
206
- key_info = ds .KeyInfo (
207
- x509_data = ds .X509Data (
208
- x509_certificate = ds .X509Certificate (text = cert )
209
- )
210
- ),
211
- use = "signing"
194
+ def do_key_descriptor (cert = None , enc_cert = None , use = "both" ):
195
+ kd_list = []
196
+ if use in ["signing" , "both" ] and cert is not None :
197
+ if not isinstance (cert , list ):
198
+ cert = [cert ]
199
+ for _cert in cert :
200
+ kd_list .append (
201
+ md .KeyDescriptor (
202
+ key_info = ds .KeyInfo (
203
+ x509_data = ds .X509Data (
204
+ x509_certificate = ds .X509Certificate (text = _cert )
205
+ )
206
+ ),
207
+ use = "signing"
208
+ )
212
209
)
213
- ]
214
- elif use in ["signing" , "encryption" ]:
215
- return md .KeyDescriptor (
216
- key_info = ds .KeyInfo (
217
- x509_data = ds .X509Data (
218
- x509_certificate = ds .X509Certificate (text = cert )
210
+ if use in ["both" , "encryption" ] and enc_cert is not None :
211
+ if not isinstance (enc_cert , list ):
212
+ enc_cert = [enc_cert ]
213
+ for _enc_cert in enc_cert :
214
+ kd_list .append (
215
+ md .KeyDescriptor (
216
+ key_info = ds .KeyInfo (
217
+ x509_data = ds .X509Data (
218
+ x509_certificate = ds .X509Certificate (text = _enc_cert )
219
+ )
220
+ ),
221
+ use = "encryption"
219
222
)
220
- ),
221
- use = use
222
- )
223
- else :
223
+ )
224
+ if len (kd_list ) == 0 and cert is not None :
224
225
return md .KeyDescriptor (
225
226
key_info = ds .KeyInfo (
226
227
x509_data = ds .X509Data (
227
228
x509_certificate = ds .X509Certificate (text = cert )
228
229
)
229
230
)
230
231
)
232
+ return kd_list
231
233
232
234
233
235
def do_requested_attribute (attributes , acs , is_required = "false" ):
@@ -502,7 +504,7 @@ def do_attribute_consuming_service(conf, spsso):
502
504
spsso .attribute_consuming_service = [ac_serv ]
503
505
504
506
505
- def do_spsso_descriptor (conf , cert = None ):
507
+ def do_spsso_descriptor (conf , cert = None , enc_cert = None ):
506
508
spsso = md .SPSSODescriptor ()
507
509
spsso .protocol_support_enumeration = samlp .NAMESPACE
508
510
@@ -537,9 +539,9 @@ def do_spsso_descriptor(conf, cert=None):
537
539
spsso .extensions = md .Extensions ()
538
540
spsso .extensions .add_extension_element (do_uiinfo (ui_info ))
539
541
540
- if cert :
541
- encryption_type = conf .encryption_type
542
- spsso .key_descriptor = do_key_descriptor (cert , encryption_type )
542
+ if cert or enc_cert :
543
+ metadata_key_usage = conf .metadata_key_usage
544
+ spsso .key_descriptor = do_key_descriptor (cert = cert , enc_cert = enc_cert , use = metadata_key_usage )
543
545
544
546
for key in ["want_assertions_signed" , "authn_requests_signed" ]:
545
547
try :
@@ -557,7 +559,7 @@ def do_spsso_descriptor(conf, cert=None):
557
559
return spsso
558
560
559
561
560
- def do_idpsso_descriptor (conf , cert = None ):
562
+ def do_idpsso_descriptor (conf , cert = None , enc_cert = None ):
561
563
idpsso = md .IDPSSODescriptor ()
562
564
idpsso .protocol_support_enumeration = samlp .NAMESPACE
563
565
@@ -586,8 +588,8 @@ def do_idpsso_descriptor(conf, cert=None):
586
588
idpsso .extensions = md .Extensions ()
587
589
idpsso .extensions .add_extension_element (do_uiinfo (ui_info ))
588
590
589
- if cert :
590
- idpsso .key_descriptor = do_key_descriptor (cert )
591
+ if cert or enc_cert :
592
+ idpsso .key_descriptor = do_key_descriptor (cert , enc_cert , use = conf . metadata_key_usage )
591
593
592
594
for key in ["want_authn_requests_signed" ]:
593
595
#"want_authn_requests_only_with_valid_cert"]:
@@ -603,7 +605,7 @@ def do_idpsso_descriptor(conf, cert=None):
603
605
return idpsso
604
606
605
607
606
- def do_aa_descriptor (conf , cert ):
608
+ def do_aa_descriptor (conf , cert = None , enc_cert = None ):
607
609
aad = md .AttributeAuthorityDescriptor ()
608
610
aad .protocol_support_enumeration = samlp .NAMESPACE
609
611
@@ -616,8 +618,8 @@ def do_aa_descriptor(conf, cert):
616
618
617
619
_do_nameid_format (aad , conf , "aa" )
618
620
619
- if cert :
620
- aad .key_descriptor = do_key_descriptor (cert )
621
+ if cert or enc_cert :
622
+ aad .key_descriptor = do_key_descriptor (cert , enc_cert , use = conf . metadata_key_usage )
621
623
622
624
attributes = conf .getattr ("attribute" , "aa" )
623
625
if attributes :
@@ -632,7 +634,7 @@ def do_aa_descriptor(conf, cert):
632
634
return aad
633
635
634
636
635
- def do_aq_descriptor (conf , cert ):
637
+ def do_aq_descriptor (conf , cert = None , enc_cert = None ):
636
638
aqs = md .AuthnAuthorityDescriptor ()
637
639
aqs .protocol_support_enumeration = samlp .NAMESPACE
638
640
@@ -645,13 +647,13 @@ def do_aq_descriptor(conf, cert):
645
647
646
648
_do_nameid_format (aqs , conf , "aq" )
647
649
648
- if cert :
649
- aqs .key_descriptor = do_key_descriptor (cert )
650
+ if cert or enc_cert :
651
+ aqs .key_descriptor = do_key_descriptor (cert , enc_cert , use = conf . metadata_key_usage )
650
652
651
653
return aqs
652
654
653
655
654
- def do_pdp_descriptor (conf , cert ):
656
+ def do_pdp_descriptor (conf , cert = None , enc_cert = None ):
655
657
""" Create a Policy Decision Point descriptor """
656
658
pdp = md .PDPDescriptor ()
657
659
@@ -667,13 +669,24 @@ def do_pdp_descriptor(conf, cert):
667
669
_do_nameid_format (pdp , conf , "pdp" )
668
670
669
671
if cert :
670
- pdp .key_descriptor = do_key_descriptor (cert )
672
+ pdp .key_descriptor = do_key_descriptor (cert , enc_cert , use = conf . metadata_key_usage )
671
673
672
674
return pdp
673
675
674
676
675
677
def entity_descriptor (confd ):
676
- mycert = "" .join (open (confd .cert_file ).readlines ()[1 :- 1 ])
678
+ mycert = None
679
+ enc_cert = None
680
+ if confd .cert_file is not None :
681
+ mycert = []
682
+ mycert .append ("" .join (open (confd .cert_file ).readlines ()[1 :- 1 ]))
683
+ if confd .additional_cert_files is not None :
684
+ for _cert_file in confd .additional_cert_files :
685
+ mycert .append ("" .join (open (_cert_file ).readlines ()[1 :- 1 ]))
686
+ if confd .encryption_keypairs is not None :
687
+ enc_cert = []
688
+ for _encryption in confd .encryption_keypairs :
689
+ enc_cert .append ("" .join (open (_encryption ["cert_file" ]).readlines ()[1 :- 1 ]))
677
690
678
691
entd = md .EntityDescriptor ()
679
692
entd .entity_id = confd .entityid
@@ -701,19 +714,19 @@ def entity_descriptor(confd):
701
714
702
715
if "sp" in serves :
703
716
confd .context = "sp"
704
- entd .spsso_descriptor = do_spsso_descriptor (confd , mycert )
717
+ entd .spsso_descriptor = do_spsso_descriptor (confd , mycert , enc_cert )
705
718
if "idp" in serves :
706
719
confd .context = "idp"
707
- entd .idpsso_descriptor = do_idpsso_descriptor (confd , mycert )
720
+ entd .idpsso_descriptor = do_idpsso_descriptor (confd , mycert , enc_cert )
708
721
if "aa" in serves :
709
722
confd .context = "aa"
710
- entd .attribute_authority_descriptor = do_aa_descriptor (confd , mycert )
723
+ entd .attribute_authority_descriptor = do_aa_descriptor (confd , mycert , enc_cert )
711
724
if "pdp" in serves :
712
725
confd .context = "pdp"
713
- entd .pdp_descriptor = do_pdp_descriptor (confd , mycert )
726
+ entd .pdp_descriptor = do_pdp_descriptor (confd , mycert , enc_cert )
714
727
if "aq" in serves :
715
728
confd .context = "aq"
716
- entd .authn_authority_descriptor = do_aq_descriptor (confd , mycert )
729
+ entd .authn_authority_descriptor = do_aq_descriptor (confd , mycert , enc_cert )
717
730
718
731
return entd
719
732
0 commit comments