2013-11-27 07:53:57 -06:00
|
|
|
#!/usr/bin/python2 -E
|
2012-07-11 14:51:01 -05:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
2013-10-16 03:40:31 -05:00
|
|
|
# Jan Cholasta <jcholast@redhat.com>
|
2012-07-11 14:51:01 -05:00
|
|
|
#
|
2013-10-16 03:40:31 -05:00
|
|
|
# Copyright (C) 2013 Red Hat
|
2012-07-11 14:51:01 -05:00
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import sys
|
2015-03-16 10:43:10 -05:00
|
|
|
import os
|
2012-07-11 14:51:01 -05:00
|
|
|
import syslog
|
2014-07-18 04:01:13 -05:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2014-01-23 08:33:26 -06:00
|
|
|
import traceback
|
2013-10-16 03:40:31 -05:00
|
|
|
|
2014-07-18 04:01:13 -05:00
|
|
|
from ipapython import ipautil
|
2012-07-11 14:51:01 -05:00
|
|
|
from ipalib import api
|
2015-08-27 00:37:24 -05:00
|
|
|
from ipaserver.install import certs, cainstance, krainstance
|
2014-05-29 03:37:18 -05:00
|
|
|
from ipaplatform import services
|
2014-07-18 04:01:13 -05:00
|
|
|
from ipaplatform.paths import paths
|
2013-10-16 03:40:31 -05:00
|
|
|
|
2012-07-11 14:51:01 -05:00
|
|
|
|
2015-01-08 03:06:46 -06:00
|
|
|
def _main():
|
|
|
|
nickname = 'ipaCert'
|
|
|
|
|
2016-06-16 23:18:05 -05:00
|
|
|
api.bootstrap(in_server=True, context='restart')
|
2014-01-23 08:33:26 -06:00
|
|
|
api.finalize()
|
2012-07-11 14:51:01 -05:00
|
|
|
|
2014-07-18 04:01:13 -05:00
|
|
|
tmpdir = tempfile.mkdtemp(prefix="tmp-")
|
|
|
|
try:
|
|
|
|
principal = str('host/%s@%s' % (api.env.host, api.env.realm))
|
2015-03-16 10:43:10 -05:00
|
|
|
ccache_filename = os.path.join(tmpdir, 'ccache')
|
|
|
|
ipautil.kinit_keytab(principal, paths.KRB5_KEYTAB,
|
|
|
|
ccache_filename)
|
|
|
|
os.environ['KRB5CCNAME'] = ccache_filename
|
2014-07-18 04:01:13 -05:00
|
|
|
|
|
|
|
ca = cainstance.CAInstance(host_name=api.env.host, ldapi=False)
|
|
|
|
if ca.is_renewal_master():
|
|
|
|
# Fetch the new certificate
|
|
|
|
db = certs.CertDB(api.env.realm)
|
|
|
|
dercert = db.get_cert_from_db(nickname, pem=False)
|
|
|
|
if not dercert:
|
|
|
|
syslog.syslog(
|
|
|
|
syslog.LOG_ERR, "No certificate %s found." % nickname)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Load it into dogtag
|
|
|
|
cainstance.update_people_entry(dercert)
|
2015-08-27 00:37:24 -05:00
|
|
|
|
2015-09-16 02:05:20 -05:00
|
|
|
if api.Command.kra_is_enabled()['result']:
|
2015-09-21 01:32:04 -05:00
|
|
|
krainstance.export_kra_agent_pem()
|
2014-07-18 04:01:13 -05:00
|
|
|
finally:
|
|
|
|
shutil.rmtree(tmpdir)
|
2012-10-23 13:07:13 -05:00
|
|
|
|
2014-01-23 08:33:26 -06:00
|
|
|
# Now restart Apache so the new certificate is available
|
2013-10-16 03:40:31 -05:00
|
|
|
syslog.syslog(syslog.LOG_NOTICE, "Restarting httpd")
|
2014-01-23 08:33:26 -06:00
|
|
|
try:
|
2014-05-29 03:37:18 -05:00
|
|
|
services.knownservices.httpd.restart()
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-10-16 03:40:31 -05:00
|
|
|
syslog.syslog(syslog.LOG_ERR, "Cannot restart httpd: %s" % e)
|
|
|
|
else:
|
|
|
|
syslog.syslog(syslog.LOG_NOTICE, "Restarted httpd")
|
2012-07-11 14:51:01 -05:00
|
|
|
|
2015-01-08 03:06:46 -06:00
|
|
|
|
|
|
|
def main():
|
2015-11-09 03:53:02 -06:00
|
|
|
try:
|
2015-01-08 03:06:46 -06:00
|
|
|
_main()
|
2015-11-09 03:53:02 -06:00
|
|
|
finally:
|
|
|
|
# lock acquired in renew_ra_cert_pre
|
|
|
|
certs.renewal_lock.release('renew_ra_cert')
|
2015-01-08 03:06:46 -06:00
|
|
|
|
|
|
|
|
2012-07-11 14:51:01 -05:00
|
|
|
try:
|
2014-01-23 08:33:26 -06:00
|
|
|
main()
|
|
|
|
except Exception:
|
|
|
|
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
|