Debian Codegraph @

src/ipahealthcheck/dogtag/ca.py

raw symbols SCIP
1 #
2 # Copyright (C) 2019 FreeIPA Contributors see COPYING for license
3 #
4
5 import loggingscip-python python python-stdlib 3.11 logging/__init__:
6
7 from ipahealthcheck.dogtag.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.dogtag.plugin`/__init__: import DogtagPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/DogtagPlugin#, registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/registry.
8 from ipahealthcheck.core.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.plugin`/__init__: import Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#
9 from ipahealthcheck.core.pluginscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.plugin`/__init__: import durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration().
10 from ipahealthcheck.corescip-python python ipahealthcheck 0.16 `ipahealthcheck.core`/__init__: import constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:
11
12 from ipalibscip-python python ipahealthcheck 0.16 ipalib/__init__: import api, errors, x509
13 from ipaplatform.pathsscip-python python ipahealthcheck 0.16 `ipaplatform.paths`/__init__: import paths
14 from ipaserver.installscip-python python ipahealthcheck 0.16 `ipaserver.install`/__init__: import certs
15 from ipaserver.installscip-python python ipahealthcheck 0.16 `ipaserver.install`/__init__: import krainstance
16 from ipapython.directivesetterscip-python python ipahealthcheck 0.16 `ipapython.directivesetter`/__init__: import get_directive
17 from cryptography.hazmat.primitives.serializationscip-python python ipahealthcheck 0.16 `cryptography.hazmat.primitives.serialization`/__init__: import Encoding
18
19 loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/logger. = loggingscip-python python python-stdlib 3.11 logging/__init__:.getLoggerscip-python python python-stdlib 3.11 logging/getLogger().()
20
21
22 @registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/registry.
23 class DogtagCertsConfigCheckscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#(DogtagPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/DogtagPlugin#):
24 """
25 Compare the cert blob in the NSS database to that stored in CS.cfg
26 """
27 @durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration().
28 def checkscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(self)):
29 if not selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(self).cascip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/DogtagPlugin#ca..is_configured():
30 loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().("No CA configured, skipping dogtag config check")
31 return
32
33 kra = krainstance.KRAInstance(api.env.realm)
34
35 blobs = {'auditSigningCert cert-pki-ca': 'ca.audit_signing.cert',
36 'ocspSigningCert cert-pki-ca': 'ca.ocsp_signing.cert',
37 'caSigningCert cert-pki-ca': 'ca.signing.cert',
38 'subsystemCert cert-pki-ca': 'ca.subsystem.cert',
39 'Server-Cert cert-pki-ca': 'ca.sslserver.cert'}
40
41 # Nicknames to skip because their certs are not in CS.cfg
42 skip = []
43
44 if kra.is_installed():
45 kra_blobs = {
46 'transportCert cert-pki-kra':
47 'ca.connector.KRA.transportCert',
48 }
49 blobs.updatescip-python python python-stdlib 3.11 typing/MutableMapping#update().(kra_blobs)
50 skip.appendscip-python python python-stdlib 3.11 builtins/list#append().('storageCert cert-pki-kra')
51 skip.appendscip-python python python-stdlib 3.11 builtins/list#append().('auditSigningCert cert-pki-kra')
52
53 db = certs.CertDB(api.env.realm, paths.PKI_TOMCAT_ALIAS_DIR)
54 for nickname, _trust_flags in db.list_certs():
55 if nickname in skip:
56 loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().('Skipping nickname %s because it isn\'t in '
57 'the configuration file')
58 continue
59 try:
60 val = get_directive(paths.CA_CS_CFG_PATH,
61 blobs[nickname], '=')
62 except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#:
63 loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().("%s not found, assuming 3rd party", nickname)
64 continue
65 if val is None:
66 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
67 key=nickname,
68 configfile=paths.CA_CS_CFG_PATH,
69 msg='Certificate %s not found in %s' %
70 (blobs[nickname], paths.CA_CS_CFG_PATH))
71 continue
72 cert = db.get_cert_from_db(nickname)
73 pem = cert.public_bytes(Encoding.PEM).decode()
74 pem = pem.replace('\n', '')
75 pem = pem.replace('-----BEGIN CERTIFICATE-----', '')
76 pem = pem.replace('-----END CERTIFICATE-----', '')
77
78 if pem.strip() != val:
79 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
80 key=nickname,
81 directive=blobs[nickname],
82 configfile=paths.CA_CS_CFG_PATH,
83 msg='Certificate \'%s\' does not match the value '
84 'of %s in %s' %
85 (nickname, blobs[nickname], paths.CA_CS_CFG_PATH))
86 else:
87 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConfigCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS.,
88 key=nickname,
89 configfile=paths.CA_CS_CFG_PATH)
90
91
92 @registryscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/registry.
93 class DogtagCertsConnectivityCheckscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#(DogtagPluginscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/DogtagPlugin#):
94 """
95 Test basic connectivity by using cert-show to fetch a cert
96
97 The RA agent certificate is used because if a CA is configured we
98 know this certificate should exist. Use its serial number to do
99 the lookup.
100 """
101 requiresscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#requires. = ('dirsrv',)
102
103 @durationscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/duration().
104 def checkscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self)):
105 if not selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self).cascip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.plugin`/DogtagPlugin#ca..is_configured():
106 loggerscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/logger..debugscip-python python python-stdlib 3.11 logging/Logger#debug().('CA is not configured, skipping connectivity check')
107 return
108
109 try:
110 cert = x509.load_certificate_from_file(paths.RA_AGENT_PEM)
111 except Exceptionscip-python python python-stdlib 3.11 builtins/Exception# as e:
112 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
113 key='ipa_ra_crt_file_missing',
114 path=paths.RA_AGENT_PEM,
115 error=strscip-python python python-stdlib 3.11 builtins/str#(e),
116 msg='The IPA RA cert file {path} could not be '
117 'opened: {error}')
118 return
119
120 # We used to use serial #1 but with RSNv3 it can be anything.
121 try:
122 api.Command.cert_show(cert.serial_number, all=True)
123 except errors.CertificateOperationError as e:
124 if 'not found' in strscip-python python python-stdlib 3.11 builtins/str#(e):
125 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
126 key='cert_show_ra',
127 error=strscip-python python python-stdlib 3.11 builtins/str#(e),
128 serial=strscip-python python python-stdlib 3.11 builtins/str#(cert.serial_number),
129 msg='Serial number not found: {error}')
130 else:
131 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
132 key='cert_show_ra',
133 error=strscip-python python python-stdlib 3.11 builtins/str#(e),
134 serial=strscip-python python python-stdlib 3.11 builtins/str#(cert.serial_number),
135 msg='Request for certificate failed: {error}')
136 except Exceptionscip-python python python-stdlib 3.11 builtins/Exception# as e:
137 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.ERRORscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/ERROR.,
138 key='cert_show_ra',
139 error=strscip-python python python-stdlib 3.11 builtins/str#(e),
140 serial=strscip-python python python-stdlib 3.11 builtins/str#(cert.serial_number),
141 msg='Request for certificate failed: {error}')
142 else:
143 yield Resultscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.plugin`/Result#(selfscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.dogtag.ca`/DogtagCertsConnectivityCheck#check().(self), constantsscip-python python ipahealthcheck 0.16 `ipahealthcheck.core.constants`/__init__:.SUCCESSscip-python python ipahealthcheck 0.16 `src.ipahealthcheck.core.constants`/SUCCESS.)