-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce custom filenames for idp/sp cert/key #395
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,24 @@ def set_cert_path(self, path): | |
""" | ||
self._paths['cert'] = path | ||
|
||
def set_sp_cert_filename(self, filename): | ||
""" | ||
Set the filename of the SP certificate | ||
""" | ||
self._sp['cert_filename'] = filename | ||
|
||
def set_sp_key_filename(self, filename): | ||
""" | ||
Set the filename of the SP key | ||
""" | ||
self._sp['key_filename'] = filename | ||
|
||
def set_idp_cert_filename(self, filename): | ||
""" | ||
Set the filename of the idp certificate | ||
""" | ||
self._idp['cert_filename'] = filename | ||
|
||
def get_lib_path(self): | ||
""" | ||
Returns lib path | ||
|
@@ -214,26 +232,27 @@ def get_schemas_path(self): | |
|
||
def _load_settings_from_dict(self, settings): | ||
""" | ||
Loads settings info from a settings Dict | ||
Loads settings info from a settings Dict, adds default values and validates the settings | ||
|
||
:param settings: SAML Toolkit Settings | ||
:type settings: dict | ||
|
||
:returns: True if the settings info is valid | ||
:rtype: boolean | ||
""" | ||
self._sp = settings.get('sp', {}) | ||
self._idp = settings.get('idp', {}) | ||
self._strict = settings.get('strict', True) | ||
self._debug = settings.get('debug', False) | ||
self._security = settings.get('security', {}) | ||
self._contacts = settings.get('contactPerson', {}) | ||
self._organization = settings.get('organization', {}) | ||
self._add_default_values() | ||
|
||
self._errors = [] | ||
errors = self.check_settings(settings) | ||
|
||
if len(errors) == 0: | ||
self._errors = [] | ||
self._sp = settings['sp'] | ||
self._idp = settings.get('idp', {}) | ||
self._strict = settings.get('strict', True) | ||
self._debug = settings.get('debug', False) | ||
self._security = settings.get('security', {}) | ||
self._contacts = settings.get('contactPerson', {}) | ||
self._organization = settings.get('organization', {}) | ||
|
||
self._add_default_values() | ||
return True | ||
|
||
self._errors = errors | ||
|
@@ -328,6 +347,11 @@ def _add_default_values(self): | |
self._sp.setdefault('x509cert', '') | ||
self._sp.setdefault('privateKey', '') | ||
|
||
# Set the default filenames for the certificates and keys | ||
self._idp.setdefault('cert_filename', 'idp.crt') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better inject them in the _add_default_values method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is already part of the |
||
self._sp.setdefault('cert_filename', 'sp.crt') | ||
self._sp.setdefault('key_filename', 'sp.key') | ||
|
||
self._security.setdefault('requestedAuthnContext', True) | ||
self._security.setdefault('requestedAuthnContextComparison', 'exact') | ||
self._security.setdefault('failOnAuthnContextMismatch', False) | ||
|
@@ -389,7 +413,7 @@ def check_idp_settings(self, settings): | |
if 'security' in settings: | ||
security = settings['security'] | ||
|
||
exists_x509 = bool(idp.get('x509cert')) | ||
exists_x509 = bool(self.get_idp_cert()) | ||
exists_fingerprint = bool(idp.get('certFingerprint')) | ||
|
||
exists_multix509sign = 'x509certMulti' in idp and \ | ||
|
@@ -566,7 +590,7 @@ def get_sp_key(self): | |
:rtype: string or None | ||
""" | ||
key = self._sp.get('privateKey') | ||
key_file_name = self._paths['cert'] + 'sp.key' | ||
key_file_name = self._paths['cert'] + self._sp['key_filename'] | ||
|
||
if not key and exists(key_file_name): | ||
with open(key_file_name) as f: | ||
|
@@ -581,7 +605,7 @@ def get_sp_cert(self): | |
:rtype: string or None | ||
""" | ||
cert = self._sp.get('x509cert') | ||
cert_file_name = self._paths['cert'] + 'sp.crt' | ||
cert_file_name = self._paths['cert'] + self._sp['cert_filename'] | ||
|
||
if not cert and exists(cert_file_name): | ||
with open(cert_file_name) as f: | ||
|
@@ -612,7 +636,7 @@ def get_idp_cert(self): | |
:rtype: string | ||
""" | ||
cert = self._idp.get('x509cert') | ||
cert_file_name = self.get_cert_path() + 'idp.crt' | ||
cert_file_name = self.get_cert_path() + self._idp['cert_filename'] | ||
if not cert and exists(cert_file_name): | ||
with open(cert_file_name) as f: | ||
cert = f.read() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
----- Begin Certificate ----- | ||
MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhM | ||
CTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDg | ||
YDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqh | ||
kiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0w | ||
NzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyB | ||
Tb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBA | ||
MTD2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZ | ||
XR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqK | ||
xupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLC | ||
n7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtKTytHOge/OlJbo0 | ||
78dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVf | ||
p86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFD | ||
bStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJV | ||
hTyvLgFVK2QarQ4/67OZfHd7R+POBXhophSMv1ZOo | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order should not be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order doesn't matter to the functionality, as the '_load_settings_from_dict' method is only called during initialization. To make the code easier I use the
get_idp_cert()
method to check if the config option or file actually exists and has content. Using the old order we would require way more code as theget_idp_cert()
uses the data from the_idp
dict (and so does theget_sp_cert()
method)