upgrade: remove ipaCert and key from /etc/httpd/alias

With ipa 4.5+, the RA cert is stored in files in
/var/lib/ipa/ra-agent.{key|pem}. The upgrade code handles
the move from /etc/httpd/alias to the files but does not remove
the private key from /etc/httpd/alias.

The fix calls certutil -F -n ipaCert to remove cert and key,
instead of -D -n ipaCert which removes only the cert.

Fixes: https://pagure.io/freeipa/issue/7329
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
Florence Blanc-Renaud authored and Alexander Bokovoy committed 2019-07-15 17:08:21 +03:00
1 parent 843f57abe4
commit ef39e1b02a
3 files changed
+102 -1

No files matched your search

+26
View File
@@ -892,6 +892,32 @@ class NSSDatabase:
def delete_cert(self, nick):
self.run_certutil(["-D", "-n", nick])
def delete_key_only(self, nick):
"""Delete the key with provided nick
This commands removes the key but leaves the cert in the DB.
"""
keys = self.list_keys()
# keys is a list of tuple(slot, algo, keyid, nickname)
for (_slot, _algo, keyid, nickname) in keys:
if nickname == nick:
# Key is present in the DB, delete the key
self.run_certutil(["-F", "-k", keyid])
break
def delete_key_and_cert(self, nick):
"""Delete a cert and its key from the DB"""
try:
self.run_certutil(["-F", "-n", nick])
except ipautil.CalledProcessError:
# Using -F -k instead of -F -n because the latter fails if
# the DB contains only the key
self.delete_key_only(nick)
# Check that cert was deleted
for (certname, _flags) in self.list_certs():
if certname == nick:
self.delete_cert(nick)
def verify_server_cert_validity(self, nickname, hostname):
"""Verify a certificate is valid for a SSL server with given hostname