@@ -194,6 +194,24 @@ def set_cert_path(self, path):
194
194
"""
195
195
self ._paths ['cert' ] = path
196
196
197
+ def set_sp_cert_filename (self , filename ):
198
+ """
199
+ Set the filename of the SP certificate
200
+ """
201
+ self ._sp ['cert_filename' ] = filename
202
+
203
+ def set_sp_key_filename (self , filename ):
204
+ """
205
+ Set the filename of the SP key
206
+ """
207
+ self ._sp ['key_filename' ] = filename
208
+
209
+ def set_idp_cert_filename (self , filename ):
210
+ """
211
+ Set the filename of the idp certificate
212
+ """
213
+ self ._idp ['cert_filename' ] = filename
214
+
197
215
def get_lib_path (self ):
198
216
"""
199
217
Returns lib path
@@ -214,26 +232,27 @@ def get_schemas_path(self):
214
232
215
233
def _load_settings_from_dict (self , settings ):
216
234
"""
217
- Loads settings info from a settings Dict
235
+ Loads settings info from a settings Dict, adds default values and validates the settings
218
236
219
237
:param settings: SAML Toolkit Settings
220
238
:type settings: dict
221
239
222
240
:returns: True if the settings info is valid
223
241
:rtype: boolean
224
242
"""
243
+ self ._sp = settings .get ('sp' , {})
244
+ self ._idp = settings .get ('idp' , {})
245
+ self ._strict = settings .get ('strict' , True )
246
+ self ._debug = settings .get ('debug' , False )
247
+ self ._security = settings .get ('security' , {})
248
+ self ._contacts = settings .get ('contactPerson' , {})
249
+ self ._organization = settings .get ('organization' , {})
250
+ self ._add_default_values ()
251
+
252
+ self ._errors = []
225
253
errors = self .check_settings (settings )
254
+
226
255
if len (errors ) == 0 :
227
- self ._errors = []
228
- self ._sp = settings ['sp' ]
229
- self ._idp = settings .get ('idp' , {})
230
- self ._strict = settings .get ('strict' , True )
231
- self ._debug = settings .get ('debug' , False )
232
- self ._security = settings .get ('security' , {})
233
- self ._contacts = settings .get ('contactPerson' , {})
234
- self ._organization = settings .get ('organization' , {})
235
-
236
- self ._add_default_values ()
237
256
return True
238
257
239
258
self ._errors = errors
@@ -328,6 +347,11 @@ def _add_default_values(self):
328
347
self ._sp .setdefault ('x509cert' , '' )
329
348
self ._sp .setdefault ('privateKey' , '' )
330
349
350
+ # Set the default filenames for the certificates and keys
351
+ self ._idp .setdefault ('cert_filename' , 'idp.crt' )
352
+ self ._sp .setdefault ('cert_filename' , 'sp.crt' )
353
+ self ._sp .setdefault ('key_filename' , 'sp.key' )
354
+
331
355
self ._security .setdefault ('requestedAuthnContext' , True )
332
356
self ._security .setdefault ('requestedAuthnContextComparison' , 'exact' )
333
357
self ._security .setdefault ('failOnAuthnContextMismatch' , False )
@@ -389,7 +413,7 @@ def check_idp_settings(self, settings):
389
413
if 'security' in settings :
390
414
security = settings ['security' ]
391
415
392
- exists_x509 = bool (idp . get ( 'x509cert' ))
416
+ exists_x509 = bool (self . get_idp_cert ( ))
393
417
exists_fingerprint = bool (idp .get ('certFingerprint' ))
394
418
395
419
exists_multix509sign = 'x509certMulti' in idp and \
@@ -566,7 +590,7 @@ def get_sp_key(self):
566
590
:rtype: string or None
567
591
"""
568
592
key = self ._sp .get ('privateKey' )
569
- key_file_name = self ._paths ['cert' ] + 'sp.key'
593
+ key_file_name = self ._paths ['cert' ] + self . _sp [ 'key_filename' ]
570
594
571
595
if not key and exists (key_file_name ):
572
596
with open (key_file_name ) as f :
@@ -581,7 +605,7 @@ def get_sp_cert(self):
581
605
:rtype: string or None
582
606
"""
583
607
cert = self ._sp .get ('x509cert' )
584
- cert_file_name = self ._paths ['cert' ] + 'sp.crt'
608
+ cert_file_name = self ._paths ['cert' ] + self . _sp [ 'cert_filename' ]
585
609
586
610
if not cert and exists (cert_file_name ):
587
611
with open (cert_file_name ) as f :
@@ -612,7 +636,7 @@ def get_idp_cert(self):
612
636
:rtype: string
613
637
"""
614
638
cert = self ._idp .get ('x509cert' )
615
- cert_file_name = self .get_cert_path () + 'idp.crt'
639
+ cert_file_name = self .get_cert_path () + self . _idp [ 'cert_filename' ]
616
640
if not cert and exists (cert_file_name ):
617
641
with open (cert_file_name ) as f :
618
642
cert = f .read ()
0 commit comments