fix: the root CA is created by the server, an offline CA or a Simple CA service, chosen at setup; the shell can stay open in a tab of its own, the Docker page is offered only with Docker, and the test scripts are in bin/.
Release / release (push) Failing after 14m20s
Release / release (push) Failing after 14m20s
This commit is contained in:
1 parent
ff0c93ed73
commit
a649331aa2
49 files changed
+1597
-637
No files matched your search
@@ -4,10 +4,10 @@
|
||||
status shows the root, the issuing CAs and the warnings; list the certificates the server issued. issue signs a CSR,
|
||||
or makes a key and writes a PFX file whose password is read from the first line of standard input. ca csr prints the
|
||||
CSR of an issuing CA that waits for the offline root, with the openssl extensions to sign it with, and ca import takes
|
||||
the signed certificate. root export-key writes the root key encrypted with the passphrase read from standard input,
|
||||
root remove-key removes it from the server, root import-key puts it back, and root import-crl takes a root CRL signed
|
||||
offline. maintain signs the stale CRLs again; linux-manager-pki.service runs it daily. A change that needs
|
||||
linux-manager-setup restarts it without waiting.
|
||||
the signed certificate, and, named root, the certificate of the offline root. root import-crl takes a CRL of the
|
||||
offline root, and root setup-code exchanges a setup code of a Simple CA token, read from the first line of standard
|
||||
input, for the token. maintain signs the stale CRLs again, or fetches those of Simple CA; linux-manager-pki.service
|
||||
runs it daily. A change that needs linux-manager-setup restarts it without waiting.
|
||||
|
||||
The answer is text for people on standard output, and a failure is a message on standard error. With --json the answer
|
||||
is JSON on standard output, and a failure is {"error": ...} there too. The exit status says what failed: 2 the request
|
||||
@@ -21,11 +21,9 @@ commands and their options.
|
||||
linux-manager-ca [--json] revoke SERIAL [--reason REASON]
|
||||
linux-manager-ca [--json] maintain
|
||||
linux-manager-ca [--json] ca csr NAME
|
||||
linux-manager-ca [--json] ca import NAME FILE
|
||||
linux-manager-ca [--json] root export-key --out FILE (passphrase on stdin)
|
||||
linux-manager-ca [--json] root remove-key [--yes]
|
||||
linux-manager-ca [--json] root import-key FILE (passphrase on stdin, an empty line for none)
|
||||
linux-manager-ca [--json] ca import NAME|root FILE
|
||||
linux-manager-ca [--json] root import-crl FILE
|
||||
linux-manager-ca [--json] root setup-code (setup code on stdin)
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -64,11 +62,19 @@ def restart_setup():
|
||||
|
||||
def show_status(document):
|
||||
root = document['root']
|
||||
if root is None:
|
||||
print('Root CA: none; linux-manager-setup creates it once a platform is chosen')
|
||||
source = {'local': 'created by the server', 'offline': 'offline',
|
||||
'simple-ca': f'Simple CA {root["simple_ca_url"]}'}[root['source']]
|
||||
if root['state'] == 'pending':
|
||||
print(f'Root CA: {source}, waits for its certificate')
|
||||
else:
|
||||
print(f'Root CA: {root["subject"]}, expires {root["expires"]}, key {"on the server" if root["key"] else "offline"}'
|
||||
f', CRL until {root["crl_next_update"] or "none"}')
|
||||
print(f'Root CA: {root["subject"]}, {source}, expires {root["expires"]}, '
|
||||
f'CRL until {root["crl_next_update"] or "none"}')
|
||||
if root['upstream']:
|
||||
upstream = root['upstream']
|
||||
print(f'Simple CA issuing CA {upstream["name"]}: {upstream["subject"]}, expires {upstream["expires"]}, '
|
||||
f'CRL until {upstream["crl_next_update"] or "none"}')
|
||||
if root['source'] == 'simple-ca':
|
||||
print(f'Simple CA token: {"valid until " + root["token_expires"] if root["token_expires"] else "none"}')
|
||||
for authority in document['authorities']:
|
||||
line = f'Issuing CA {authority["name"]}: {authority["common_name"]}, {authority["state"]}'
|
||||
if authority['expires']:
|
||||
@@ -115,36 +121,26 @@ def run(options):
|
||||
return document, f'Certificate {document["serial"]} revoked' + \
|
||||
('; linux-manager-setup issues a new one.' if document['reissue'] else '.')
|
||||
if options.command == 'maintain':
|
||||
due = linuxmanager_pki.maintain(cfg)
|
||||
notices, due = linuxmanager_pki.maintain(cfg)
|
||||
if due:
|
||||
restart_setup()
|
||||
return {'renewal': due}, 'CRLs checked' + ('; linux-manager-setup renews the server certificates.' if due else '.')
|
||||
return {'renewal': due, 'notices': notices}, '\n'.join(
|
||||
['CRLs checked' + ('; linux-manager-setup renews the certificates.' if due else '.'),
|
||||
*(f'Warning: {notice}' for notice in notices)])
|
||||
if options.command == 'ca' and options.action == 'csr':
|
||||
document = linuxmanager_pki.csr(cfg, options.name)
|
||||
return document, document['csr'] + '\n' + document['extensions']
|
||||
if options.command == 'ca':
|
||||
document = linuxmanager_pki.import_ca(cfg, options.name, pathlib.Path(options.file).read_text(encoding='ascii'))
|
||||
restart_setup()
|
||||
return document, f'Issuing CA {options.name} has its certificate, which expires {document["expires"]}.'
|
||||
if options.action == 'export-key':
|
||||
data = linuxmanager_pki.export_root_key(secret())
|
||||
out = pathlib.Path(options.out)
|
||||
with open(out, 'xb') as handle:
|
||||
handle.write(data)
|
||||
return {'exported': str(out)}, f'Root key written to {out}, encrypted.'
|
||||
if options.action == 'remove-key':
|
||||
if not options.yes:
|
||||
print('Remove the root key from the server? Keep an exported copy first. Type yes: ', end='',
|
||||
file=sys.stderr, flush=True)
|
||||
if secret().strip() != 'yes':
|
||||
return {'removed': False}, 'Nothing removed.'
|
||||
linuxmanager_pki.remove_root_key()
|
||||
return {'removed': True}, 'Root key removed; new issuing CAs now wait for an offline signature.'
|
||||
if options.action == 'import-key':
|
||||
linuxmanager_pki.import_root_key(pathlib.Path(options.file).read_bytes(), secret() or None)
|
||||
what = 'The root' if options.name == 'root' else f'Issuing CA {options.name}'
|
||||
return document, f'{what} has its certificate, which expires {document["expires"]}.'
|
||||
if options.action == 'setup-code':
|
||||
document = linuxmanager_pki.exchange_code(cfg, secret())
|
||||
restart_setup()
|
||||
return {'imported': True}, 'Root key back on the server.'
|
||||
document = linuxmanager_pki.import_root_crl(pathlib.Path(options.file).read_bytes())
|
||||
return document, (f'Simple CA token of issuing CA {document["upstream"]} taken'
|
||||
+ (f', valid until {document["expires"]}.' if document['expires'] else '.'))
|
||||
document = linuxmanager_pki.import_root_crl(cfg, pathlib.Path(options.file).read_bytes())
|
||||
return document, f'Root CRL taken, valid until {document["next_update"]}.'
|
||||
|
||||
|
||||
@@ -165,21 +161,17 @@ def main(argv):
|
||||
revoker = commands.add_parser('revoke', help='revoke a certificate the server issued')
|
||||
revoker.add_argument('serial', help='the serial number, hexadecimal')
|
||||
revoker.add_argument('--reason', choices=linuxmanager_pki.REASONS, help='the reason, unspecified by default')
|
||||
commands.add_parser('maintain', help='sign the stale CRLs again')
|
||||
authority = commands.add_parser('ca', help='an issuing CA that waits for the offline root')
|
||||
commands.add_parser('maintain', help='sign the stale CRLs again, or fetch those of Simple CA')
|
||||
authority = commands.add_parser('ca', help='an issuing CA, or the root, that waits for the offline root')
|
||||
actions = authority.add_subparsers(dest='action', required=True, parser_class=Parser)
|
||||
actions.add_parser('csr', help='print its CSR and the openssl extensions').add_argument('name')
|
||||
importer = actions.add_parser('import', help='take its certificate signed by the root')
|
||||
importer.add_argument('name')
|
||||
importer = actions.add_parser('import', help='take its certificate signed by the root, or the root certificate')
|
||||
importer.add_argument('name', help='the issuing CA, or root')
|
||||
importer.add_argument('file')
|
||||
root = commands.add_parser('root', help='the root CA')
|
||||
root_actions = root.add_subparsers(dest='action', required=True, parser_class=Parser)
|
||||
exporter = root_actions.add_parser('export-key', help='write the root key encrypted with the passphrase from stdin')
|
||||
exporter.add_argument('--out', required=True, help='the file to write')
|
||||
remover = root_actions.add_parser('remove-key', help='remove the root key from the server')
|
||||
remover.add_argument('--yes', action='store_true', help='do not ask')
|
||||
root_actions.add_parser('import-key', help='put the root key back').add_argument('file')
|
||||
root_actions.add_parser('import-crl', help='take a root CRL signed offline').add_argument('file')
|
||||
root_actions.add_parser('import-crl', help='take a CRL of the offline root').add_argument('file')
|
||||
root_actions.add_parser('setup-code', help='exchange a Simple CA setup code from stdin for the token')
|
||||
options = parser.parse_args(argv)
|
||||
os.umask(0o077)
|
||||
|
||||
|
||||
Reference in new issue
Block a user