2015-06-08 00:23:56 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
|
|
|
#
|
|
|
|
|
2016-11-09 05:44:22 -06:00
|
|
|
"""
|
|
|
|
CA installer module
|
|
|
|
"""
|
|
|
|
|
2018-04-05 02:21:16 -05:00
|
|
|
from __future__ import print_function, absolute_import
|
2015-08-12 06:44:11 -05:00
|
|
|
|
2016-11-09 05:44:22 -06:00
|
|
|
import enum
|
2017-05-24 09:35:07 -05:00
|
|
|
import logging
|
2016-10-24 07:33:19 -05:00
|
|
|
import os.path
|
|
|
|
|
2016-11-09 05:44:22 -06:00
|
|
|
import six
|
|
|
|
|
2016-11-16 04:49:36 -06:00
|
|
|
from ipalib.constants import IPA_CA_CN
|
2016-11-23 08:40:21 -06:00
|
|
|
from ipalib.install import certstore
|
2016-11-09 05:44:22 -06:00
|
|
|
from ipalib.install.service import enroll_only, master_install_only, replica_install_only
|
2016-11-30 00:26:15 -06:00
|
|
|
from ipaserver.install import sysupgrade
|
2016-11-09 05:44:22 -06:00
|
|
|
from ipapython.install import typing
|
2017-03-08 02:03:13 -06:00
|
|
|
from ipapython.install.core import group, knob, extend_knob
|
2018-04-26 05:06:36 -05:00
|
|
|
from ipaserver.install import cainstance, bindinstance, dsinstance
|
2015-11-09 11:28:47 -06:00
|
|
|
from ipapython import ipautil, certdb
|
2018-11-29 07:49:43 -06:00
|
|
|
from ipapython import ipaldap
|
2016-06-17 06:14:49 -05:00
|
|
|
from ipapython.admintool import ScriptError
|
2015-06-08 00:23:56 -05:00
|
|
|
from ipaplatform import services
|
|
|
|
from ipaplatform.paths import paths
|
|
|
|
from ipaserver.install import installutils, certs
|
|
|
|
from ipaserver.install.replication import replica_conn_check
|
2019-07-11 00:17:04 -05:00
|
|
|
from ipalib import api, errors, x509
|
2015-06-08 00:23:56 -05:00
|
|
|
from ipapython.dn import DN
|
|
|
|
|
2019-03-06 14:12:49 -06:00
|
|
|
from . import conncheck, dogtag, cainstance
|
2016-11-09 05:44:22 -06:00
|
|
|
|
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2016-11-16 04:49:36 -06:00
|
|
|
VALID_SUBJECT_BASE_ATTRS = {
|
|
|
|
'st', 'o', 'ou', 'dnqualifier', 'c', 'serialnumber', 'l', 'title', 'sn',
|
|
|
|
'givenname', 'initials', 'generationqualifier', 'dc', 'mail', 'uid',
|
|
|
|
'postaladdress', 'postalcode', 'postofficebox', 'houseidentifier', 'e',
|
|
|
|
'street', 'pseudonym', 'incorporationlocality', 'incorporationstate',
|
|
|
|
'incorporationcountry', 'businesscategory',
|
|
|
|
}
|
|
|
|
VALID_SUBJECT_ATTRS = {'cn'} | VALID_SUBJECT_BASE_ATTRS
|
2016-11-09 05:44:22 -06:00
|
|
|
|
2017-05-24 09:35:07 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-03-17 12:40:04 -05:00
|
|
|
external_cert_file = None
|
|
|
|
external_ca_file = None
|
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-11-16 04:49:36 -06:00
|
|
|
def subject_validator(valid_attrs, value):
|
2017-08-18 03:25:51 -05:00
|
|
|
if not isinstance(value, unicode):
|
|
|
|
v = unicode(value, 'utf-8')
|
|
|
|
else:
|
|
|
|
v = value
|
2016-11-16 04:49:36 -06:00
|
|
|
if any(ord(c) < 0x20 for c in v):
|
|
|
|
raise ValueError("must not contain control characters")
|
|
|
|
if '&' in v:
|
|
|
|
raise ValueError("must not contain an ampersand (\"&\")")
|
|
|
|
try:
|
|
|
|
dn = DN(v)
|
|
|
|
for rdn in dn:
|
|
|
|
if rdn.attr.lower() not in valid_attrs:
|
|
|
|
raise ValueError("invalid attribute: \"%s\"" % rdn.attr)
|
|
|
|
except ValueError as e:
|
|
|
|
raise ValueError("invalid DN: %s" % e)
|
|
|
|
|
|
|
|
|
|
|
|
def lookup_ca_subject(api, subject_base):
|
|
|
|
dn = DN(('cn', IPA_CA_CN), api.env.container_ca, api.env.basedn)
|
|
|
|
try:
|
|
|
|
# we do not use api.Command.ca_show because it attempts to
|
|
|
|
# talk to the CA (to read certificate / chain), but the RA
|
|
|
|
# backend may be unavailable (ipa-replica-install) or unusable
|
|
|
|
# due to RA Agent cert not yet created (ipa-ca-install).
|
|
|
|
ca_subject = api.Backend.ldap2.get_entry(dn)['ipacasubjectdn'][0]
|
|
|
|
except errors.NotFound:
|
|
|
|
# if the entry doesn't exist, we are dealing with a pre-v4.4
|
|
|
|
# installation, where the default CA subject was always based
|
|
|
|
# on the subject_base.
|
|
|
|
#
|
|
|
|
# installutils.default_ca_subject_dn is NOT used here in
|
|
|
|
# case the default changes in the future.
|
|
|
|
ca_subject = DN(('CN', 'Certificate Authority'), subject_base)
|
2018-09-26 05:39:56 -05:00
|
|
|
return str(ca_subject)
|
2016-11-16 04:49:36 -06:00
|
|
|
|
|
|
|
|
2016-11-11 02:54:01 -06:00
|
|
|
def set_subject_base_in_config(subject_base):
|
|
|
|
entry_attrs = api.Backend.ldap2.get_ipa_config()
|
|
|
|
entry_attrs['ipacertificatesubjectbase'] = [str(subject_base)]
|
|
|
|
try:
|
|
|
|
api.Backend.ldap2.update_entry(entry_attrs)
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2017-11-28 01:55:59 -06:00
|
|
|
def print_ca_configuration(options):
|
|
|
|
"""Print info about how the CA will be configured.
|
|
|
|
|
|
|
|
Does not print trailing empty line.
|
|
|
|
|
|
|
|
"""
|
|
|
|
print("The CA will be configured with:")
|
|
|
|
print("Subject DN: {}".format(options.ca_subject))
|
|
|
|
print("Subject base: {}".format(options.subject_base))
|
2018-05-01 21:07:02 -05:00
|
|
|
if options.external_ca:
|
|
|
|
chaining = "externally signed (two-step installation)"
|
|
|
|
elif options.external_cert_files:
|
|
|
|
chaining = "externally signed"
|
|
|
|
else:
|
|
|
|
chaining = "self-signed"
|
|
|
|
print("Chaining: {}".format(chaining))
|
2017-11-28 01:55:59 -06:00
|
|
|
|
|
|
|
|
2019-03-06 14:12:49 -06:00
|
|
|
def uninstall_check(options):
|
|
|
|
"""Check if the host is CRL generation master"""
|
|
|
|
# Skip the checks if the host is not a CA instance
|
|
|
|
ca = cainstance.CAInstance(api.env.realm)
|
|
|
|
if not (api.Command.ca_is_enabled()['result'] and
|
|
|
|
cainstance.is_ca_installed_locally()):
|
|
|
|
return
|
|
|
|
|
|
|
|
# skip the checks if the host is the last master
|
|
|
|
ipa_config = api.Command.config_show()['result']
|
2019-03-26 14:09:27 -05:00
|
|
|
ipa_masters = ipa_config.get('ipa_master_server', [])
|
2019-03-06 14:12:49 -06:00
|
|
|
if len(ipa_masters) <= 1:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
crlgen_enabled = ca.is_crlgen_enabled()
|
|
|
|
except cainstance.InconsistentCRLGenConfigException:
|
|
|
|
# If config is inconsistent, let's be safe and act as if
|
|
|
|
# crl gen was enabled
|
|
|
|
crlgen_enabled = True
|
|
|
|
|
|
|
|
if crlgen_enabled:
|
|
|
|
print("Deleting this server will leave your installation "
|
|
|
|
"without a CRL generation master.")
|
|
|
|
if (options.unattended and not options.ignore_last_of_role) or \
|
|
|
|
not (options.unattended or ipautil.user_input(
|
|
|
|
"Are you sure you want to continue with the uninstall "
|
|
|
|
"procedure?", False)):
|
|
|
|
raise ScriptError("Aborting uninstall operation.")
|
|
|
|
|
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
def install_check(standalone, replica_config, options):
|
|
|
|
global external_cert_file
|
|
|
|
global external_ca_file
|
|
|
|
|
|
|
|
realm_name = options.realm_name
|
|
|
|
host_name = options.host_name
|
2016-11-16 04:49:36 -06:00
|
|
|
|
|
|
|
if replica_config is None:
|
|
|
|
options._subject_base = options.subject_base
|
|
|
|
options._ca_subject = options.ca_subject
|
|
|
|
else:
|
|
|
|
# during replica install, this gets invoked before local DS is
|
|
|
|
# available, so use the remote api.
|
|
|
|
_api = api if standalone else options._remote_api
|
|
|
|
|
|
|
|
# for replica-install the knobs cannot be written, hence leading '_'
|
2018-09-26 05:39:56 -05:00
|
|
|
options._subject_base = str(replica_config.subject_base)
|
2016-11-16 04:49:36 -06:00
|
|
|
options._ca_subject = lookup_ca_subject(_api, options._subject_base)
|
|
|
|
|
|
|
|
if replica_config is not None and not replica_config.setup_ca:
|
|
|
|
return
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
if replica_config is not None:
|
|
|
|
if standalone and api.env.ra_plugin == 'selfsign':
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError('A selfsign CA can not be added')
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
if standalone and not options.skip_conncheck:
|
2015-08-07 14:14:58 -05:00
|
|
|
principal = options.principal
|
2015-06-08 00:23:56 -05:00
|
|
|
replica_conn_check(
|
2016-10-24 06:09:11 -05:00
|
|
|
replica_config.ca_host_name, host_name, realm_name, True,
|
2015-08-07 14:14:58 -05:00
|
|
|
replica_config.ca_ds_port, options.admin_password,
|
2015-12-09 01:18:21 -06:00
|
|
|
principal=principal, ca_cert_file=options.ca_cert_file)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-24 07:33:19 -05:00
|
|
|
if options.skip_schema_check:
|
2017-05-24 09:35:07 -05:00
|
|
|
logger.info("Skipping CA DS schema check")
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2015-07-15 07:15:49 -05:00
|
|
|
if standalone:
|
2015-10-23 10:21:01 -05:00
|
|
|
if api.Command.ca_is_enabled()['result']:
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
2015-07-15 07:15:49 -05:00
|
|
|
"One or more CA masters are already present in IPA realm "
|
|
|
|
"'%s'.\nIf you wish to replicate CA to this host, please "
|
|
|
|
"re-run 'ipa-ca-install'\nwith a replica file generated on "
|
|
|
|
"an existing CA master as argument." % realm_name
|
|
|
|
)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2015-06-08 03:32:58 -05:00
|
|
|
if options.external_cert_files:
|
2015-06-08 00:23:56 -05:00
|
|
|
if not cainstance.is_step_one_done():
|
|
|
|
# This can happen if someone passes external_ca_file without
|
|
|
|
# already having done the first stage of the CA install.
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
|
|
|
"CA is not installed yet. To install with an external CA "
|
2015-06-08 00:23:56 -05:00
|
|
|
"is a two-stage process.\nFirst run the installer with "
|
|
|
|
"--external-ca.")
|
|
|
|
|
|
|
|
external_cert_file, external_ca_file = installutils.load_external_cert(
|
2016-11-16 04:49:36 -06:00
|
|
|
options.external_cert_files, options._ca_subject)
|
2015-06-08 03:32:58 -05:00
|
|
|
elif options.external_ca:
|
|
|
|
if cainstance.is_step_one_done():
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
|
|
|
"CA is already installed.\nRun the installer with "
|
|
|
|
"--external-cert-file.")
|
2017-10-20 04:10:20 -05:00
|
|
|
if os.path.isfile(paths.ROOT_IPA_CSR):
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
|
|
|
"CA CSR file %s already exists.\nIn order to continue "
|
|
|
|
"remove the file and run the installer again." %
|
|
|
|
paths.ROOT_IPA_CSR)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2017-05-24 02:59:46 -05:00
|
|
|
if not options.external_ca_type:
|
2019-07-11 00:17:04 -05:00
|
|
|
options.external_ca_type = x509.ExternalCAType.GENERIC.value
|
2017-05-24 02:59:46 -05:00
|
|
|
|
|
|
|
if options.external_ca_profile is not None:
|
|
|
|
# check that profile is valid for the external ca type
|
|
|
|
if options.external_ca_type \
|
|
|
|
not in options.external_ca_profile.valid_for:
|
|
|
|
raise ScriptError(
|
|
|
|
"External CA profile specification '{}' "
|
|
|
|
"cannot be used with external CA type '{}'."
|
|
|
|
.format(
|
|
|
|
options.external_ca_profile.unparsed_input,
|
|
|
|
options.external_ca_type)
|
|
|
|
)
|
|
|
|
|
2015-06-08 03:32:58 -05:00
|
|
|
if not options.external_cert_files:
|
2018-03-28 05:05:34 -05:00
|
|
|
if not cainstance.check_ports():
|
|
|
|
print(
|
|
|
|
"IPA requires ports 8080 and 8443 for PKI, but one or more "
|
|
|
|
"are currently in use."
|
|
|
|
)
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError("Aborting installation")
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
if standalone:
|
|
|
|
dirname = dsinstance.config_dirname(
|
2018-11-29 07:49:43 -06:00
|
|
|
ipaldap.realm_to_serverid(realm_name))
|
2017-01-13 02:08:42 -06:00
|
|
|
cadb = certs.CertDB(realm_name, nssdir=paths.PKI_TOMCAT_ALIAS_DIR,
|
|
|
|
subject_base=options._subject_base)
|
2016-11-16 04:49:36 -06:00
|
|
|
dsdb = certs.CertDB(
|
|
|
|
realm_name, nssdir=dirname, subject_base=options._subject_base)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2018-01-16 02:40:33 -06:00
|
|
|
# Check that we can add our CA cert to DS and PKI NSS databases
|
2015-06-08 00:23:56 -05:00
|
|
|
for db in (cadb, dsdb):
|
2017-04-11 03:21:15 -05:00
|
|
|
if not db.exists():
|
|
|
|
continue
|
2016-10-04 09:54:44 -05:00
|
|
|
for nickname, _trust_flags in db.list_certs():
|
2017-01-13 02:08:42 -06:00
|
|
|
if nickname == certdb.get_ca_nickname(realm_name):
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
|
|
|
"Certificate with nickname %s is present in %s, "
|
|
|
|
"cannot continue." % (nickname, db.secdir))
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
cert = db.get_cert_from_db(nickname)
|
|
|
|
if not cert:
|
|
|
|
continue
|
2017-07-27 05:05:19 -05:00
|
|
|
subject = DN(cert.subject)
|
2017-01-13 02:08:42 -06:00
|
|
|
if subject == DN(options._ca_subject):
|
2016-06-17 06:14:49 -05:00
|
|
|
raise ScriptError(
|
|
|
|
"Certificate with subject %s is present in %s, "
|
|
|
|
"cannot continue." % (subject, db.secdir))
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
|
2018-04-26 05:06:36 -05:00
|
|
|
def install(standalone, replica_config, options, custodia):
|
|
|
|
install_step_0(standalone, replica_config, options, custodia=custodia)
|
|
|
|
install_step_1(standalone, replica_config, options, custodia=custodia)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
|
2018-04-26 05:06:36 -05:00
|
|
|
def install_step_0(standalone, replica_config, options, custodia):
|
2015-06-08 00:23:56 -05:00
|
|
|
realm_name = options.realm_name
|
|
|
|
dm_password = options.dm_password
|
|
|
|
host_name = options.host_name
|
2016-11-16 04:49:36 -06:00
|
|
|
ca_subject = options._ca_subject
|
|
|
|
subject_base = options._subject_base
|
2017-05-24 02:59:46 -05:00
|
|
|
external_ca_profile = None
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-24 07:33:19 -05:00
|
|
|
if replica_config is None:
|
|
|
|
ca_signing_algorithm = options.ca_signing_algorithm
|
|
|
|
if options.external_ca:
|
|
|
|
ca_type = options.external_ca_type
|
2017-05-24 02:59:46 -05:00
|
|
|
external_ca_profile = options.external_ca_profile
|
2016-10-24 07:33:19 -05:00
|
|
|
csr_file = paths.ROOT_IPA_CSR
|
|
|
|
else:
|
|
|
|
ca_type = None
|
|
|
|
csr_file = None
|
|
|
|
if options.external_cert_files:
|
|
|
|
cert_file = external_cert_file.name
|
|
|
|
cert_chain_file = external_ca_file.name
|
|
|
|
else:
|
|
|
|
cert_file = None
|
|
|
|
cert_chain_file = None
|
|
|
|
|
|
|
|
pkcs12_info = None
|
|
|
|
master_host = None
|
|
|
|
master_replication_port = None
|
|
|
|
ra_p12 = None
|
2016-10-26 07:28:21 -05:00
|
|
|
ra_only = False
|
2016-10-24 07:33:19 -05:00
|
|
|
promote = False
|
2015-06-08 00:23:56 -05:00
|
|
|
else:
|
2016-10-24 07:33:19 -05:00
|
|
|
cafile = os.path.join(replica_config.dir, 'cacert.p12')
|
2018-09-10 07:30:44 -05:00
|
|
|
custodia.get_ca_keys(
|
|
|
|
cafile,
|
|
|
|
replica_config.dirman_password)
|
2016-10-24 07:33:19 -05:00
|
|
|
|
|
|
|
ca_signing_algorithm = None
|
|
|
|
ca_type = None
|
|
|
|
csr_file = None
|
|
|
|
cert_file = None
|
|
|
|
cert_chain_file = None
|
|
|
|
|
|
|
|
pkcs12_info = (cafile,)
|
|
|
|
master_host = replica_config.ca_host_name
|
|
|
|
master_replication_port = replica_config.ca_ds_port
|
|
|
|
ra_p12 = os.path.join(replica_config.dir, 'ra.p12')
|
2016-10-26 07:28:21 -05:00
|
|
|
ra_only = not replica_config.setup_ca
|
2018-09-10 07:30:44 -05:00
|
|
|
promote = True
|
2016-10-24 07:33:19 -05:00
|
|
|
|
2016-11-30 00:26:15 -06:00
|
|
|
# if upgrading from CA-less to CA-ful, need to rewrite
|
2016-11-16 04:49:36 -06:00
|
|
|
# certmap.conf and subject_base configuration
|
2016-11-30 00:26:15 -06:00
|
|
|
#
|
|
|
|
set_subject_base_in_config(subject_base)
|
|
|
|
sysupgrade.set_upgrade_state(
|
|
|
|
'certmap.conf', 'subject_base', str(subject_base))
|
2016-11-16 04:49:36 -06:00
|
|
|
dsinstance.write_certmap_conf(realm_name, ca_subject)
|
2016-11-30 00:26:15 -06:00
|
|
|
|
2018-11-30 13:54:35 -06:00
|
|
|
# use secure ldaps when installing a replica or upgrading to CA-ful
|
|
|
|
# In both cases, 389-DS is already configured to have a trusted cert.
|
|
|
|
use_ldaps = standalone or replica_config is not None
|
|
|
|
|
2018-04-26 05:06:36 -05:00
|
|
|
ca = cainstance.CAInstance(
|
|
|
|
realm=realm_name, host_name=host_name, custodia=custodia
|
|
|
|
)
|
2018-09-03 05:45:30 -05:00
|
|
|
ca.configure_instance(
|
|
|
|
host_name, dm_password, dm_password,
|
|
|
|
subject_base=subject_base,
|
|
|
|
ca_subject=ca_subject,
|
|
|
|
ca_signing_algorithm=ca_signing_algorithm,
|
|
|
|
ca_type=ca_type,
|
|
|
|
external_ca_profile=external_ca_profile,
|
|
|
|
csr_file=csr_file,
|
|
|
|
cert_file=cert_file,
|
|
|
|
cert_chain_file=cert_chain_file,
|
|
|
|
pkcs12_info=pkcs12_info,
|
|
|
|
master_host=master_host,
|
|
|
|
master_replication_port=master_replication_port,
|
|
|
|
ra_p12=ra_p12,
|
|
|
|
ra_only=ra_only,
|
|
|
|
promote=promote,
|
|
|
|
use_ldaps=use_ldaps,
|
|
|
|
pki_config_override=options.pki_config_override,
|
|
|
|
)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
|
2018-04-26 05:06:36 -05:00
|
|
|
def install_step_1(standalone, replica_config, options, custodia):
|
2016-10-26 07:28:21 -05:00
|
|
|
if replica_config is not None and not replica_config.setup_ca:
|
|
|
|
return
|
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
realm_name = options.realm_name
|
|
|
|
host_name = options.host_name
|
2016-11-16 04:49:36 -06:00
|
|
|
subject_base = options._subject_base
|
2015-06-08 00:23:56 -05:00
|
|
|
basedn = ipautil.realm_to_suffix(realm_name)
|
|
|
|
|
2018-04-26 05:06:36 -05:00
|
|
|
ca = cainstance.CAInstance(
|
|
|
|
realm=realm_name, host_name=host_name, custodia=custodia
|
|
|
|
)
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-24 07:33:19 -05:00
|
|
|
ca.stop('pki-tomcat')
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
# This is done within stopped_service context, which restarts CA
|
2017-11-08 12:21:22 -06:00
|
|
|
ca.enable_client_auth_to_db()
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-05-31 17:07:33 -05:00
|
|
|
# Lightweight CA key retrieval is configured in step 1 instead
|
|
|
|
# of CAInstance.configure_instance (which is invoked from step
|
|
|
|
# 0) because kadmin_addprinc fails until krb5.conf is installed
|
|
|
|
# by krb.create_instance.
|
|
|
|
#
|
|
|
|
ca.setup_lightweight_ca_key_retrieval()
|
|
|
|
|
2018-11-29 07:49:43 -06:00
|
|
|
serverid = ipaldap.realm_to_serverid(realm_name)
|
2016-10-24 07:33:19 -05:00
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
if standalone and replica_config is None:
|
|
|
|
dirname = dsinstance.config_dirname(serverid)
|
|
|
|
|
|
|
|
# Store the new IPA CA cert chain in DS NSS database and LDAP
|
2017-01-13 02:08:42 -06:00
|
|
|
cadb = certs.CertDB(
|
|
|
|
realm_name, nssdir=paths.PKI_TOMCAT_ALIAS_DIR,
|
|
|
|
subject_base=subject_base)
|
|
|
|
dsdb = certs.CertDB(
|
|
|
|
realm_name, nssdir=dirname, subject_base=subject_base)
|
2017-06-16 03:18:07 -05:00
|
|
|
cacert = cadb.get_cert_from_db('caSigningCert cert-pki-ca')
|
2017-01-13 02:08:42 -06:00
|
|
|
nickname = certdb.get_ca_nickname(realm_name)
|
2017-04-27 02:33:25 -05:00
|
|
|
trust_flags = certdb.IPA_CA_TRUST_FLAGS
|
2017-01-13 02:08:42 -06:00
|
|
|
dsdb.add_cert(cacert, nickname, trust_flags)
|
2015-06-08 00:23:56 -05:00
|
|
|
certstore.put_ca_cert_nss(api.Backend.ldap2, api.env.basedn,
|
2017-01-13 02:08:42 -06:00
|
|
|
cacert, nickname, trust_flags,
|
2015-06-08 00:23:56 -05:00
|
|
|
config_ipa=True, config_compat=True)
|
|
|
|
|
|
|
|
# Store DS CA cert in Dogtag NSS database
|
|
|
|
trust_flags = dict(reversed(dsdb.list_certs()))
|
|
|
|
server_certs = dsdb.find_server_certs()
|
|
|
|
trust_chain = dsdb.find_root_cert(server_certs[0][0])[:-1]
|
|
|
|
nickname = trust_chain[-1]
|
|
|
|
cert = dsdb.get_cert_from_db(nickname)
|
2017-01-13 02:08:42 -06:00
|
|
|
cadb.add_cert(cert, nickname, trust_flags[nickname])
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-24 07:33:19 -05:00
|
|
|
installutils.restart_dirsrv()
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-24 07:33:19 -05:00
|
|
|
ca.start('pki-tomcat')
|
2015-06-08 00:23:56 -05:00
|
|
|
|
2016-10-27 06:12:02 -05:00
|
|
|
if standalone or replica_config is not None:
|
|
|
|
# We need to restart apache as we drop a new config file in there
|
|
|
|
services.knownservices.httpd.restart(capture_output=True)
|
2016-10-24 07:33:19 -05:00
|
|
|
|
|
|
|
if standalone:
|
2015-06-08 00:23:56 -05:00
|
|
|
# Install CA DNS records
|
2016-11-11 05:45:11 -06:00
|
|
|
if bindinstance.dns_container_exists(basedn):
|
2016-10-06 10:35:04 -05:00
|
|
|
bind = bindinstance.BindInstance()
|
2016-06-12 11:05:48 -05:00
|
|
|
bind.update_system_records()
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
|
2015-11-09 11:28:47 -06:00
|
|
|
def uninstall():
|
2017-02-14 09:54:43 -06:00
|
|
|
ca_instance = cainstance.CAInstance(api.env.realm)
|
2021-02-10 14:49:12 -06:00
|
|
|
ca_instance.stop_tracking_certificates()
|
2019-06-11 10:05:29 -05:00
|
|
|
ipautil.remove_file(paths.RA_AGENT_PEM)
|
|
|
|
ipautil.remove_file(paths.RA_AGENT_KEY)
|
2015-06-08 00:23:56 -05:00
|
|
|
if ca_instance.is_configured():
|
|
|
|
ca_instance.uninstall()
|
2016-11-09 05:44:22 -06:00
|
|
|
|
|
|
|
|
|
|
|
class CASigningAlgorithm(enum.Enum):
|
|
|
|
SHA1_WITH_RSA = 'SHA1withRSA'
|
|
|
|
SHA_256_WITH_RSA = 'SHA256withRSA'
|
2021-06-30 12:15:45 -05:00
|
|
|
SHA_384_WITH_RSA = 'SHA384withRSA'
|
2016-11-09 05:44:22 -06:00
|
|
|
SHA_512_WITH_RSA = 'SHA512withRSA'
|
|
|
|
|
|
|
|
|
2017-03-08 02:03:13 -06:00
|
|
|
@group
|
2016-11-09 05:44:22 -06:00
|
|
|
class CAInstallInterface(dogtag.DogtagInstallInterface,
|
|
|
|
conncheck.ConnCheckInterface):
|
|
|
|
"""
|
|
|
|
Interface of the CA installer
|
|
|
|
|
|
|
|
Knobs defined here will be available in:
|
|
|
|
* ipa-server-install
|
|
|
|
* ipa-replica-prepare
|
|
|
|
* ipa-replica-install
|
|
|
|
* ipa-ca-install
|
|
|
|
"""
|
2017-03-08 02:03:13 -06:00
|
|
|
description = "Certificate system"
|
2016-11-09 05:44:22 -06:00
|
|
|
|
2017-03-08 02:03:13 -06:00
|
|
|
principal = conncheck.ConnCheckInterface.principal
|
|
|
|
principal = extend_knob(
|
|
|
|
principal,
|
2016-11-09 05:44:22 -06:00
|
|
|
description="User allowed to manage replicas",
|
2017-03-08 02:03:13 -06:00
|
|
|
cli_names=list(principal.cli_names) + ['-P'],
|
2016-11-09 05:44:22 -06:00
|
|
|
)
|
|
|
|
principal = enroll_only(principal)
|
|
|
|
principal = replica_install_only(principal)
|
|
|
|
|
2017-03-08 02:03:13 -06:00
|
|
|
admin_password = conncheck.ConnCheckInterface.admin_password
|
|
|
|
admin_password = extend_knob(
|
|
|
|
admin_password,
|
2016-11-09 05:44:22 -06:00
|
|
|
description="Admin user Kerberos password used for connection check",
|
2017-03-08 02:03:13 -06:00
|
|
|
cli_names=list(admin_password.cli_names) + ['-w'],
|
2016-11-09 05:44:22 -06:00
|
|
|
)
|
|
|
|
admin_password = enroll_only(admin_password)
|
|
|
|
|
|
|
|
external_ca = knob(
|
|
|
|
None,
|
|
|
|
description=("Generate a CSR for the IPA CA certificate to be signed "
|
|
|
|
"by an external CA"),
|
|
|
|
)
|
|
|
|
external_ca = master_install_only(external_ca)
|
|
|
|
|
|
|
|
external_ca_type = knob(
|
2019-07-11 00:17:04 -05:00
|
|
|
x509.ExternalCAType, None, description="Type of the external CA")
|
2016-11-09 05:44:22 -06:00
|
|
|
external_ca_type = master_install_only(external_ca_type)
|
|
|
|
|
2017-05-24 02:59:46 -05:00
|
|
|
external_ca_profile = knob(
|
2019-07-11 00:17:04 -05:00
|
|
|
type=x509.ExternalCAProfile,
|
2017-05-24 02:59:46 -05:00
|
|
|
default=None,
|
|
|
|
description=(
|
|
|
|
"Specify the certificate profile/template to use at the "
|
|
|
|
"external CA"),
|
|
|
|
)
|
|
|
|
external_ca_profile = master_install_only(external_ca_profile)
|
|
|
|
|
2016-11-09 05:44:22 -06:00
|
|
|
external_cert_files = knob(
|
|
|
|
typing.List[str], None,
|
|
|
|
description=("File containing the IPA CA certificate and the external "
|
|
|
|
"CA certificate chain"),
|
|
|
|
cli_names='--external-cert-file',
|
|
|
|
cli_deprecated_names=['--external_cert_file', '--external_ca_file'],
|
|
|
|
cli_metavar='FILE',
|
|
|
|
)
|
|
|
|
external_cert_files = master_install_only(external_cert_files)
|
|
|
|
|
|
|
|
@external_cert_files.validator
|
|
|
|
def external_cert_files(self, value):
|
|
|
|
if any(not os.path.isabs(path) for path in value):
|
|
|
|
raise ValueError("must use an absolute path")
|
|
|
|
|
2016-11-16 03:59:58 -06:00
|
|
|
subject_base = knob(
|
2016-11-09 05:44:22 -06:00
|
|
|
str, None,
|
2016-11-16 17:26:02 -06:00
|
|
|
description=(
|
|
|
|
"The certificate subject base (default O=<realm-name>). "
|
|
|
|
"RDNs are in LDAP order (most specific RDN first)."
|
|
|
|
),
|
2016-11-16 03:59:58 -06:00
|
|
|
cli_deprecated_names=['--subject'],
|
2016-11-09 05:44:22 -06:00
|
|
|
)
|
2016-11-16 03:59:58 -06:00
|
|
|
subject_base = master_install_only(subject_base)
|
2016-11-09 05:44:22 -06:00
|
|
|
|
2016-11-16 03:59:58 -06:00
|
|
|
@subject_base.validator
|
|
|
|
def subject_base(self, value):
|
2016-11-16 04:49:36 -06:00
|
|
|
subject_validator(VALID_SUBJECT_BASE_ATTRS, value)
|
|
|
|
|
|
|
|
ca_subject = knob(
|
|
|
|
str, None,
|
|
|
|
description=(
|
|
|
|
"The CA certificate subject DN "
|
2016-11-16 17:26:02 -06:00
|
|
|
"(default CN=Certificate Authority,O=<realm-name>). "
|
|
|
|
"RDNs are in LDAP order (most specific RDN first)."
|
2016-11-16 04:49:36 -06:00
|
|
|
),
|
|
|
|
)
|
|
|
|
ca_subject = master_install_only(ca_subject)
|
|
|
|
|
|
|
|
@ca_subject.validator
|
|
|
|
def ca_subject(self, value):
|
|
|
|
subject_validator(VALID_SUBJECT_ATTRS, value)
|
2016-11-09 05:44:22 -06:00
|
|
|
|
|
|
|
ca_signing_algorithm = knob(
|
|
|
|
CASigningAlgorithm, None,
|
|
|
|
description="Signing algorithm of the IPA CA certificate",
|
|
|
|
)
|
|
|
|
ca_signing_algorithm = master_install_only(ca_signing_algorithm)
|
|
|
|
|
|
|
|
skip_schema_check = knob(
|
|
|
|
None,
|
|
|
|
description="skip check for updated CA DS schema on the remote master",
|
|
|
|
)
|
|
|
|
skip_schema_check = enroll_only(skip_schema_check)
|
|
|
|
skip_schema_check = replica_install_only(skip_schema_check)
|