-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove CSR from CS.cfg and store them in certs folder
CSR are created and stored in `<instance_config>/certs` folder as `<certs_id>.csr` files. Fix #2111
- Loading branch information
Showing
7 changed files
with
141 additions
and
46 deletions.
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
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
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
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
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
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,52 @@ | ||
# Authors: | ||
# Marco Fargetta <[email protected]> | ||
# | ||
# Copyright Red Hat, Inc. | ||
# | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
import logging | ||
import os | ||
|
||
import pki | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RemoveCertCSRfromConfig(pki.server.upgrade.PKIServerUpgradeScriptlet): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.message = 'Removes certs data and CSR from CS.cfg' | ||
|
||
def upgrade_subsystem(self, instance, subsystem): | ||
|
||
self.backup(subsystem.cs_conf) | ||
certs_path = os.path.join(instance.conf_dir, 'certs') | ||
if not os.path.isdir(certs_path): | ||
os.mkdir(certs_path) | ||
|
||
logger.info('Removing certs data') | ||
if subsystem.name == 'ca': | ||
self.clean_cert_csr('signing', subsystem, certs_path) | ||
self.clean_cert_csr('ocsp_signing', subsystem, certs_path) | ||
if subsystem.name == 'kra': | ||
self.clean_cert_csr('storage', subsystem, certs_path) | ||
self.clean_cert_csr('transport', subsystem, certs_path) | ||
if subsystem.name == 'ocsp': | ||
self.clean_cert_csr('signing', subsystem, certs_path) | ||
|
||
self.clean_cert_csr('sslserver', subsystem, certs_path) | ||
self.clean_cert_csr('subsystem', subsystem, certs_path) | ||
self.clean_cert_csr('audit_signing', subsystem, certs_path) | ||
|
||
subsystem.save() | ||
|
||
def clean_cert_csr(self, tag, subsystem, dest_path): | ||
subsystem.config.pop('%s.%s.cert' % (subsystem.name, tag), None) | ||
cert_req = subsystem.config.pop('%s.%s.certreq' % (subsystem.name, tag), None) | ||
nickname = subsystem.config.get('%s.%s.nickname' % (subsystem.name, tag)) | ||
if cert_req: | ||
csr_data = pki.nssdb.convert_csr(cert_req, 'base64', 'pem') | ||
with open(os.path.join(dest_path, nickname + '.csr'), 'w', encoding='utf-8') as f: | ||
f.write(csr_data) |
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