feature: the VPN, the router, the name server and WebDAV are components switched on the System tab and installed on demand, Caddy from the Ubuntu archive is a dependency and serves every HTTP and HTTPS port, HTTPS is chosen at install, its certificate is of the Servers Issuing CA or self-signed by default, of ACME or of another CA, the issuing CAs are in one tab, a locked account is unlocked again, the name of a CA is fixed once the CA exists, and a run of setup is no longer cut short by a change.
Release / release (push) Failing after 8s
Release / release (push) Failing after 8s
This commit is contained in:
1 parent
a649331aa2
commit
a7bfabcb89
97 files changed
+4498
-1834
No files matched your search
@@ -1,33 +1,82 @@
|
||||
"""/https/settings: the settings of HTTPS, of which the API changes the CA of Caddy's certificates."""
|
||||
"""/https: the settings of HTTPS and the server's own HTTPS certificate."""
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
|
||||
import ldap
|
||||
|
||||
import linuxmanager
|
||||
import linuxmanager_pki
|
||||
|
||||
from .common import section_change
|
||||
from .common import PKI_STATUS, section_change
|
||||
|
||||
#: The settings of the https section PUT /https/settings changes.
|
||||
CHANGEABLE = ('acme_staging',)
|
||||
CHANGEABLE = ('acme_staging', 'certificate', 'self_signed_days', 'acme_provider', 'acme_url', 'acme_eab_key_id',
|
||||
'acme_eab_mac_key', 'zerossl_api_key')
|
||||
|
||||
#: The secrets of the https section, which the answers give as <name>_set instead.
|
||||
SECRETS = ('acme_eab_mac_key', 'zerossl_api_key')
|
||||
|
||||
#: The paths of /https.
|
||||
PATHS = ('/https/settings', '/https/csr', '/https/certificate', '/https/pfx')
|
||||
|
||||
|
||||
def https_settings(method, body):
|
||||
"""Answer a /https/settings request: the HTTP status and the JSON document.
|
||||
def shown(settings):
|
||||
"""The https section without its secrets, each replaced by whether it is set."""
|
||||
return {**{key: value for key, value in settings.items() if key not in SECRETS},
|
||||
**{f'{key}_set': bool(settings[key]) for key in SECRETS}}
|
||||
|
||||
GET /https/settings {"settings"}: the https section
|
||||
PUT /https/settings change acme_staging; the other settings of the section are changed on the server with
|
||||
linux-manager-config-edit, and a body naming one is 400
|
||||
|
||||
A change is applied by restarting linux-manager-setup without waiting for it.
|
||||
def https(method, path, body):
|
||||
"""Answer a /https request: the HTTP status and the JSON document.
|
||||
|
||||
GET /https/settings {"settings", "certificate"}: the https section, its secrets as <name>_set, and the
|
||||
server's HTTPS certificate (linuxmanager_pki.https_status)
|
||||
PUT /https/settings change any of CHANGEABLE; the other settings of the section are changed on the server
|
||||
with linux-manager-config-edit, and a body naming one is 400
|
||||
POST /https/csr make a key and a CSR for wan.local_fqdn: {"csr"}
|
||||
PUT /https/certificate take the certificate another CA signed for the CSR, PEM with its chain: {"certificate"}
|
||||
PUT /https/pfx take a PKCS#12 file of another CA's certificate: {"pfx" in base64, "password"}
|
||||
|
||||
A change is applied by a run of linux-manager-setup, without waiting for it.
|
||||
"""
|
||||
if body == 'invalid' or (body is not None and not isinstance(body, dict)):
|
||||
return 400, {'error': 'the body must be a JSON object'}
|
||||
if method in ('GET', 'HEAD'):
|
||||
try:
|
||||
return 200, {'settings': linuxmanager.load_config()['https']}
|
||||
except SystemExit as exc:
|
||||
return 500, {'error': str(exc.code)}
|
||||
if method != 'PUT':
|
||||
return 404, {'error': f'no route {method} /https/settings'}
|
||||
others = sorted(set(body or {}) - set(CHANGEABLE))
|
||||
if others:
|
||||
return 400, {'error': f'https.{", https.".join(others)}: changed on the server with linux-manager-config-edit only'}
|
||||
changed = section_change('https', body or {})
|
||||
return changed if isinstance(changed, tuple) else (200, {'settings': changed})
|
||||
body = body or {}
|
||||
try:
|
||||
cfg = linuxmanager.load_config()
|
||||
if path == '/https/settings' and method in ('GET', 'HEAD'):
|
||||
return 200, {'settings': shown(cfg['https']), 'certificate': linuxmanager_pki.https_status(cfg)}
|
||||
if path == '/https/settings' and method == 'PUT':
|
||||
others = sorted(set(body) - set(CHANGEABLE))
|
||||
if others:
|
||||
return 400, {'error': f'https.{", https.".join(others)}: changed on the server with '
|
||||
'linux-manager-config-edit only'}
|
||||
if 'certificate' in body and body['certificate'] not in linuxmanager.HTTPS_CERTIFICATES:
|
||||
return 400, {'error': f'https.certificate must be one of {", ".join(linuxmanager.HTTPS_CERTIFICATES)}'}
|
||||
changed = section_change('https', body)
|
||||
return changed if isinstance(changed, tuple) else (200, {'settings': shown(changed)})
|
||||
with linuxmanager_pki.locked():
|
||||
if (path, method) == ('/https/csr', 'POST'):
|
||||
return 200, linuxmanager_pki.https_csr(cfg)
|
||||
if (path, method) == ('/https/certificate', 'PUT'):
|
||||
document = linuxmanager_pki.import_https_certificate(cfg, body.get('certificate'))
|
||||
elif (path, method) == ('/https/pfx', 'PUT'):
|
||||
try:
|
||||
data = base64.b64decode(body.get('pfx') or '', validate=True)
|
||||
except (binascii.Error, TypeError):
|
||||
return 400, {'error': 'pfx must be a PKCS#12 file in base64'}
|
||||
password = body.get('password')
|
||||
if password is not None and not isinstance(password, str):
|
||||
return 400, {'error': 'password must be a string'}
|
||||
document = linuxmanager_pki.import_https_pfx(cfg, data, password)
|
||||
else:
|
||||
return 404, {'error': f'no route {method} {path}'}
|
||||
except linuxmanager_pki.Failure as failure:
|
||||
return PKI_STATUS.get(failure.status, 500), {'error': str(failure)}
|
||||
except ldap.LDAPError as exc:
|
||||
return 500, {'error': f'the directory, which holds the certificate, failed: {exc}'}
|
||||
except SystemExit as exc:
|
||||
return 500, {'error': str(exc.code)}
|
||||
linuxmanager.request_setup()
|
||||
return 200, document
|
||||
Reference in new issue
Block a user