mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipa-custodia: use Dogtag's alias/pwdfile.txt
/etc/pki/pki-tomcat/password.conf contains additional passwords like replicadb. ipa-custodia does not need these passwords. /etc/pki/pki-tomcat/alias/pwdfile.txt holds the passphrase for Tomcat's NSSDB. The file also simplifies implementation because it removes another temporary file. pwdfile.txt is created by CAInstance.create_certstore_passwdfile() Related: https://pagure.io/freeipa/issue/6888 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Simo Sorce <ssorce@redhat.com>
This commit is contained in:
@@ -93,6 +93,7 @@ class BasePathNamespace(object):
|
|||||||
NSS_DB_DIR = "/etc/pki/nssdb"
|
NSS_DB_DIR = "/etc/pki/nssdb"
|
||||||
PKI_TOMCAT = "/etc/pki/pki-tomcat"
|
PKI_TOMCAT = "/etc/pki/pki-tomcat"
|
||||||
PKI_TOMCAT_ALIAS_DIR = "/etc/pki/pki-tomcat/alias"
|
PKI_TOMCAT_ALIAS_DIR = "/etc/pki/pki-tomcat/alias"
|
||||||
|
PKI_TOMCAT_ALIAS_PWDFILE_TXT = "/etc/pki/pki-tomcat/alias/pwdfile.txt"
|
||||||
PKI_TOMCAT_PASSWORD_CONF = "/etc/pki/pki-tomcat/password.conf"
|
PKI_TOMCAT_PASSWORD_CONF = "/etc/pki/pki-tomcat/password.conf"
|
||||||
ETC_REDHAT_RELEASE = "/etc/redhat-release"
|
ETC_REDHAT_RELEASE = "/etc/redhat-release"
|
||||||
RESOLV_CONF = "/etc/resolv.conf"
|
RESOLV_CONF = "/etc/resolv.conf"
|
||||||
|
|||||||
@@ -34,17 +34,6 @@ def log_error(error):
|
|||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def PKI_TOMCAT_password_callback():
|
|
||||||
password = None
|
|
||||||
with open(paths.PKI_TOMCAT_PASSWORD_CONF) as f:
|
|
||||||
for line in f.readlines():
|
|
||||||
key, value = line.strip().split('=')
|
|
||||||
if key == 'internal':
|
|
||||||
password = value
|
|
||||||
break
|
|
||||||
return password
|
|
||||||
|
|
||||||
|
|
||||||
class NSSWrappedCertDB(DBMAPHandler):
|
class NSSWrappedCertDB(DBMAPHandler):
|
||||||
'''
|
'''
|
||||||
Store that extracts private keys from an NSSDB, wrapped with the
|
Store that extracts private keys from an NSSDB, wrapped with the
|
||||||
@@ -55,27 +44,23 @@ class NSSWrappedCertDB(DBMAPHandler):
|
|||||||
if 'path' not in dbmap:
|
if 'path' not in dbmap:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Configuration does not provide NSSDB path')
|
'Configuration does not provide NSSDB path')
|
||||||
if 'pwcallback' not in dbmap:
|
if 'pwdfile' not in dbmap:
|
||||||
raise ValueError(
|
raise ValueError('Configuration does not provide password file')
|
||||||
'Configuration does not provide Password Calback')
|
|
||||||
if 'wrap_nick' not in dbmap:
|
if 'wrap_nick' not in dbmap:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Configuration does not provide nickname of wrapping key')
|
'Configuration does not provide nickname of wrapping key')
|
||||||
self.nssdb_path = dbmap['path']
|
self.nssdb_path = dbmap['path']
|
||||||
self.nssdb_password = dbmap['pwcallback']()
|
self.nssdb_pwdfile = dbmap['pwdfile']
|
||||||
self.wrap_nick = dbmap['wrap_nick']
|
self.wrap_nick = dbmap['wrap_nick']
|
||||||
self.target_nick = nickname
|
self.target_nick = nickname
|
||||||
|
|
||||||
def export_key(self):
|
def export_key(self):
|
||||||
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
||||||
try:
|
try:
|
||||||
nsspwfile = os.path.join(tdir, 'nsspwfile')
|
|
||||||
with open(nsspwfile, 'w+') as f:
|
|
||||||
f.write(self.nssdb_password)
|
|
||||||
wrapped_key_file = os.path.join(tdir, 'wrapped_key')
|
wrapped_key_file = os.path.join(tdir, 'wrapped_key')
|
||||||
certificate_file = os.path.join(tdir, 'certificate')
|
certificate_file = os.path.join(tdir, 'certificate')
|
||||||
ipautil.run([
|
ipautil.run([
|
||||||
paths.PKI, '-d', self.nssdb_path, '-C', nsspwfile,
|
paths.PKI, '-d', self.nssdb_path, '-C', self.nssdb_pwdfile,
|
||||||
'ca-authority-key-export',
|
'ca-authority-key-export',
|
||||||
'--wrap-nickname', self.wrap_nick,
|
'--wrap-nickname', self.wrap_nick,
|
||||||
'--target-nickname', self.target_nick,
|
'--target-nickname', self.target_nick,
|
||||||
@@ -103,18 +88,15 @@ class NSSCertDB(DBMAPHandler):
|
|||||||
' expected "NSSDB"' % (dbmap['type'],))
|
' expected "NSSDB"' % (dbmap['type'],))
|
||||||
if 'path' not in dbmap:
|
if 'path' not in dbmap:
|
||||||
raise ValueError('Configuration does not provide NSSDB path')
|
raise ValueError('Configuration does not provide NSSDB path')
|
||||||
if 'pwcallback' not in dbmap:
|
if 'pwdfile' not in dbmap:
|
||||||
raise ValueError('Configuration does not provide Password Calback')
|
raise ValueError('Configuration does not provide password file')
|
||||||
self.nssdb_path = dbmap['path']
|
self.nssdb_path = dbmap['path']
|
||||||
|
self.nssdb_pwdfile = dbmap['pwdfile']
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
self.nssdb_password = dbmap['pwcallback']()
|
|
||||||
|
|
||||||
def export_key(self):
|
def export_key(self):
|
||||||
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
||||||
try:
|
try:
|
||||||
nsspwfile = os.path.join(tdir, 'nsspwfile')
|
|
||||||
with open(nsspwfile, 'w') as f:
|
|
||||||
f.write(self.nssdb_password)
|
|
||||||
pk12pwfile = os.path.join(tdir, 'pk12pwfile')
|
pk12pwfile = os.path.join(tdir, 'pk12pwfile')
|
||||||
password = ipautil.ipa_generate_password()
|
password = ipautil.ipa_generate_password()
|
||||||
with open(pk12pwfile, 'w') as f:
|
with open(pk12pwfile, 'w') as f:
|
||||||
@@ -124,7 +106,7 @@ class NSSCertDB(DBMAPHandler):
|
|||||||
"-d", self.nssdb_path,
|
"-d", self.nssdb_path,
|
||||||
"-o", pk12file,
|
"-o", pk12file,
|
||||||
"-n", self.nickname,
|
"-n", self.nickname,
|
||||||
"-k", nsspwfile,
|
"-k", self.nssdb_pwdfile,
|
||||||
"-w", pk12pwfile])
|
"-w", pk12pwfile])
|
||||||
with open(pk12file, 'rb') as f:
|
with open(pk12file, 'rb') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
@@ -137,9 +119,6 @@ class NSSCertDB(DBMAPHandler):
|
|||||||
v = json_decode(value)
|
v = json_decode(value)
|
||||||
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
tdir = tempfile.mkdtemp(dir=paths.TMP)
|
||||||
try:
|
try:
|
||||||
nsspwfile = os.path.join(tdir, 'nsspwfile')
|
|
||||||
with open(nsspwfile, 'w') as f:
|
|
||||||
f.write(self.nssdb_password)
|
|
||||||
pk12pwfile = os.path.join(tdir, 'pk12pwfile')
|
pk12pwfile = os.path.join(tdir, 'pk12pwfile')
|
||||||
with open(pk12pwfile, 'w') as f:
|
with open(pk12pwfile, 'w') as f:
|
||||||
f.write(v['export password'])
|
f.write(v['export password'])
|
||||||
@@ -150,7 +129,7 @@ class NSSCertDB(DBMAPHandler):
|
|||||||
"-d", self.nssdb_path,
|
"-d", self.nssdb_path,
|
||||||
"-i", pk12file,
|
"-i", pk12file,
|
||||||
"-n", self.nickname,
|
"-n", self.nickname,
|
||||||
"-k", nsspwfile,
|
"-k", self.nssdb_pwdfile,
|
||||||
"-w", pk12pwfile])
|
"-w", pk12pwfile])
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tdir)
|
shutil.rmtree(tdir)
|
||||||
@@ -254,12 +233,12 @@ NAME_DB_MAP = {
|
|||||||
'type': 'NSSDB',
|
'type': 'NSSDB',
|
||||||
'path': paths.PKI_TOMCAT_ALIAS_DIR,
|
'path': paths.PKI_TOMCAT_ALIAS_DIR,
|
||||||
'handler': NSSCertDB,
|
'handler': NSSCertDB,
|
||||||
'pwcallback': PKI_TOMCAT_password_callback,
|
'pwdfile': paths.PKI_TOMCAT_ALIAS_PWDFILE_TXT,
|
||||||
},
|
},
|
||||||
'ca_wrapped': {
|
'ca_wrapped': {
|
||||||
'handler': NSSWrappedCertDB,
|
'handler': NSSWrappedCertDB,
|
||||||
'path': paths.PKI_TOMCAT_ALIAS_DIR,
|
'path': paths.PKI_TOMCAT_ALIAS_DIR,
|
||||||
'pwcallback': PKI_TOMCAT_password_callback,
|
'pwdfile': paths.PKI_TOMCAT_ALIAS_PWDFILE_TXT,
|
||||||
'wrap_nick': 'caSigningCert cert-pki-ca',
|
'wrap_nick': 'caSigningCert cert-pki-ca',
|
||||||
},
|
},
|
||||||
'ra': {
|
'ra': {
|
||||||
|
|||||||
Reference in New Issue
Block a user