Skip to content

Commit

Permalink
Update ServerConfig.get_sslcert()
Browse files Browse the repository at this point in the history
For consistency, the ServerConfig.get_sslcert() has been
modified to return None if the SSL cert does not exist.
All callers have been modified to check the return value.
  • Loading branch information
edewata committed Nov 10, 2023
1 parent 712dbb9 commit d542203
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 15 additions & 1 deletion base/server/python/pki/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ def export_ca_cert(self):

sslcert = server_config.get_sslcert(sslhost)

if sslcert is None:
raise Exception('Missing SSL certificate')

keystore_type = sslcert.get('certificateKeystoreType')
keystore_provider = sslcert.get('certificateKeystoreProvider')

Expand Down Expand Up @@ -1336,6 +1339,9 @@ def get_sslserver_cert_nickname(self):

sslcert = server_config.get_sslcert(sslhost)

if sslcert is None:
raise Exception('Missing SSL certificate')

return sslcert.get('certificateKeyAlias')

def set_sslserver_cert_nickname(self, nickname, token=None):
Expand All @@ -1359,6 +1365,10 @@ def set_sslserver_cert_nickname(self, nickname, token=None):
raise Exception('Missing SSL host')

sslcert = server_config.get_sslcert(sslhost)

if sslcert is None:
raise Exception('Missing SSL certificate')

sslcert.set('certificateKeyAlias', fullname)
server_config.save()

Expand Down Expand Up @@ -1905,7 +1915,7 @@ def get_sslcert(self, sslhost, certType='UNDEFINED'):
if t == certType:
return sslcert

raise KeyError('SSL certificate not found: %s' % certType)
return None

def create_sslcert(self, sslhost, certType='UNDEFINED'):
'''
Expand All @@ -1923,6 +1933,10 @@ def create_sslcert(self, sslhost, certType='UNDEFINED'):
def remove_sslcert(self, sslhost, certType):

sslcert = self.get_sslcert(sslhost, certType)

if sslcert is None:
raise Exception('SSL certificate not found: %s' % certType)

sslhost.remove(sslcert)

def get_realm(self, className):
Expand Down
7 changes: 3 additions & 4 deletions base/server/python/pki/server/cli/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,11 +1274,10 @@ def execute(self, argv):
if sslhost is None:
raise Exception('SSL host not found: %s' % hostname)

try:
server_config.get_sslcert(sslhost, certType)
sslcert = server_config.get_sslcert(sslhost, certType)

if sslcert is not None:
raise Exception('SSL certificate already exists: %s' % certType)
except KeyError:
pass

sslcert = server_config.create_sslcert(sslhost, certType)

Expand Down

0 comments on commit d542203

Please sign in to comment.