feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s

This commit is contained in:
slawek committed 2026-11-14 12:52:44 +01:00
1 parent 6d90441bee
commit 8efe21bfa6
129 files changed
+17381 -104

No files matched your search

+754
View File
@@ -0,0 +1,754 @@
import Add from '@mui/icons-material/Add'
import Block from '@mui/icons-material/Block'
import Delete from '@mui/icons-material/Delete'
import Download from '@mui/icons-material/Download'
import Edit from '@mui/icons-material/Edit'
import Refresh from '@mui/icons-material/Refresh'
import Settings from '@mui/icons-material/Settings'
import UploadFile from '@mui/icons-material/UploadFile'
import WarningAmber from '@mui/icons-material/WarningAmber'
import {
Alert, Box, Button, Chip, IconButton, MenuItem, Stack, Tab, Table, TableBody, TableCell, TableHead, TableRow, Tabs, TextField,
Tooltip, Typography,
} from '@mui/material'
import { useCallback, useEffect, useState } from 'react'
import { when } from './BackupSummary.tsx'
import CertificateDialog from './CertificateDialog.tsx'
import ConfirmDialog, { type ConfirmDialogProps } from './ConfirmDialog.tsx'
import ImportDialog from './ImportDialog.tsx'
import IssuingCaDialog from './IssuingCaDialog.tsx'
import TemplateDialog from './TemplateDialog.tsx'
import Toolbar from './Toolbar.tsx'
import EkuDialog from './EkuDialog.tsx'
import PkiSettingsDialog, { PUBLISH_LABELS } from './PkiSettingsDialog.tsx'
import { Pairs, Section } from './RouterPanel.tsx'
import {
ApiError, BUNDLE_SHAPE, CA_IMPORTED_SHAPE, CRL_IMPORTED_SHAPE, CSR_SHAPE, ISSUED_SHAPE, PFX_SHAPE, PKI_SETTINGS_SHAPE, PKI_SHAPE, REVOKED_SHAPE,
BUILTIN_TEMPLATES, REVOKE_REASONS, request, type Pki, type PkiCertificate, type PkiIssuingCa, type PkiTemplate,
} from './api.ts'
import { saveFile } from './saveFile.ts'
/** The tabs of the page: the root and the general information, the templates, the extended key usages, the two
* built-in issuing CAs, the general-purpose ones. */
type View = 'root' | 'templates' | 'usages' | 'p2s' | 's2s' | 'issuing'
/** The built-in CAs, whose certificates the Issuing CAs tab leaves out. */
const BUILTIN_CAS = ['root', 'p2s', 's2s']
/** The note shown after a change, which the router applies when vpn-router-setup has run again. */
const APPLIED = 'The router applies the change in the background.'
/** The colour of each state of an issuing CA and of a certificate. */
const STATE_COLORS: Record<string, 'success' | 'warning' | 'error' | 'default'> = {
active: 'success',
valid: 'success',
pending: 'warning',
missing: 'error',
expired: 'default',
revoked: 'error',
}
/** The labels of the revocation reasons. */
const REASON_LABELS: Record<string, string> = {
unspecified: 'Unspecified',
key_compromise: 'Key compromise',
affiliation_changed: 'Affiliation changed',
superseded: 'Superseded',
cessation_of_operation: 'Cessation of operation',
privilege_withdrawn: 'Privilege withdrawn',
}
/**
* The router's PKI in tabs: Root, the root CA with the general settings and the certificates of the issuing CAs;
* Templates, the certificate templates, which are added, changed, removed and reset there; Extended key usages, the
* built-in ones and the custom ones, which are added, changed and removed there; P2S Issuing CA and S2S
* Issuing CA, each built-in CA with the certificates it issued; Issuing CAs, the general-purpose CAs, which are added,
* changed and removed there, with their certificates, filtered by CA. The warnings, Issue and Settings
* are above the tabs. Settings edits the pki section, Issue issues a certificate from a CSR or into a PFX file, a
* certificate of another system or of the router is revoked, an issuing CA waiting for the offline root gives its CSR
* and takes its signed certificate, and the root takes a CRL signed offline. The root key is managed on the router
* with vpn-router-ca only.
*/
export default function CertificatesPanel() {
const [pki, setPki] = useState<Pki | null>(null)
const [error, setError] = useState<string | null>(null)
const [unavailable, setUnavailable] = useState(false)
const [note, setNote] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [editing, setEditing] = useState(false)
const [authority, setAuthority] = useState<{ name?: string } | null>(null)
const [template, setTemplate] = useState<{ name?: string } | null>(null)
const [usage, setUsage] = useState<{ name?: string } | null>(null)
const [issuing, setIssuing] = useState(false)
const [importing, setImporting] = useState<string | null>(null)
const [uploading, setUploading] = useState(false)
const [confirm, setConfirm] = useState<ConfirmDialogProps | null>(null)
const [filter, setFilter] = useState('')
const [view, setView] = useState<View>('root')
const refresh = useCallback(async () => {
setBusy(true)
try {
setPki(await request<Pki>('GET', '/ca', PKI_SHAPE))
setError(null)
setUnavailable(false)
} catch (caught) {
const failure = caught as ApiError
setPki(null)
setUnavailable(failure.status === 404)
setError(failure.message)
} finally {
setBusy(false)
}
}, [])
useEffect(() => {
void refresh()
}, [refresh])
/** Saves the certificates a client trusts the CA with: the root alone, or an issuing CA followed by the root. */
async function downloadBundle(name: string) {
try {
const { pem } = await request<{ name: string; pem: string }>('GET', `/ca/bundle/${name}`, BUNDLE_SHAPE)
saveFile(name === 'root' ? 'root-ca.pem' : `${name}-ca-bundle.pem`, pem, 'application/x-pem-file')
setError(null)
} catch (caught) {
setError((caught as Error).message)
}
}
async function downloadCsr(name: string) {
try {
const { csr, extensions } = await request<{ csr: string; extensions: string }>('GET', `/ca/issuing/${name}/csr`, CSR_SHAPE)
saveFile(`${name}.csr`, csr, 'application/pkcs10')
saveFile(`${name}-extensions.cnf`, extensions, 'text/plain')
setError(null)
} catch (caught) {
setError((caught as Error).message)
}
}
/** Writes the general-purpose issuing CAs: the current ones with name set to values, or without it when values is null. */
async function saveAuthority(name: string, values: PkiIssuingCa | null) {
const { [name]: _current, ...others } = pki?.settings.issuing_cas ?? {}
await request('PUT', '/ca', PKI_SETTINGS_SHAPE, { issuing_cas: values === null ? others : { ...others, [name]: values } })
setNote(APPLIED)
await refresh()
}
/** Writes the templates of pki.templates: the current ones with name set to values, or without it when values is
* null, which removes a template of the router's own or brings a built-in one back to its defaults. */
async function saveTemplate(name: string, values: PkiTemplate | null) {
const { [name]: _current, ...others } = pki?.settings.templates ?? {}
await request('PUT', '/ca', PKI_SETTINGS_SHAPE, { templates: values === null ? others : { ...others, [name]: values } })
setNote(APPLIED)
await refresh()
}
/** Writes the custom extended key usages: the current ones with name set to oid, or without it when oid is null. */
async function saveUsage(name: string, oid: string | null) {
const { [name]: _current, ...others } = pki?.settings.extended_key_usages ?? {}
await request('PUT', '/ca', PKI_SETTINGS_SHAPE, { extended_key_usages: oid === null ? others : { ...others, [name]: oid } })
setNote(APPLIED)
await refresh()
}
function removeUsage(name: string) {
setConfirm({
title: 'Remove extended key usage',
message: `Remove extended key usage ${name}? The router refuses while a template gives it; certificates issued with it keep it.`,
confirmLabel: 'Remove',
destructive: true,
onCancel: () => setConfirm(null),
onConfirm: () => {
setConfirm(null)
setBusy(true)
saveUsage(name, null)
.then(() => setError(null))
.catch((caught: Error) => setError(caught.message))
.finally(() => setBusy(false))
},
})
}
function removeTemplate(name: string, builtin: boolean) {
setConfirm({
title: builtin ? 'Reset template' : 'Remove template',
message: builtin
? `Bring template ${name} back to its built-in options? The certificates issued afterwards follow them.`
: `Remove template ${name}? The router refuses while an issuing CA issues it; certificates issued with it stay valid.`,
confirmLabel: builtin ? 'Reset' : 'Remove',
destructive: !builtin,
onCancel: () => setConfirm(null),
onConfirm: () => {
setConfirm(null)
setBusy(true)
saveTemplate(name, null)
.then(() => setError(null))
.catch((caught: Error) => setError(caught.message))
.finally(() => setBusy(false))
},
})
}
function removeAuthority(name: string) {
setConfirm({
title: 'Remove issuing CA',
message: `Remove issuing CA ${name}? The router retires it and revokes its certificate on the root CRL; with the root offline, the root CRL is signed offline. Its certificates stay valid until they expire or are revoked.`,
confirmLabel: 'Remove',
destructive: true,
onCancel: () => setConfirm(null),
onConfirm: () => {
setConfirm(null)
setBusy(true)
saveAuthority(name, null)
.then(() => setError(null))
.catch((caught: Error) => setError(caught.message))
.finally(() => setBusy(false))
},
})
}
function revoke(certificate: PkiCertificate) {
let reason: string = REVOKE_REASONS[0]
setConfirm({
title: 'Revoke certificate',
message: `Revoke certificate ${certificate.serial} of ${certificate.subject}? The CRL of ${certificate.ca} lists it at once.${certificate.kind === 'router' ? ' The router issues itself a new one.' : ''}`,
confirmLabel: 'Revoke',
destructive: true,
children: (
<TextField
select
fullWidth
label="Reason"
defaultValue={reason}
sx={{ mt: 2 }}
onChange={(event) => {
reason = event.target.value
}}
>
{REVOKE_REASONS.map((item) => <MenuItem key={item} value={item}>{REASON_LABELS[item]}</MenuItem>)}
</TextField>
),
onCancel: () => setConfirm(null),
onConfirm: () => {
setConfirm(null)
setBusy(true)
request<{ reissue: boolean }>('POST', `/ca/certificates/${certificate.serial}/revoke`, REVOKED_SHAPE, { reason })
.then((revoked) => {
setError(null)
setNote(revoked.reissue ? APPLIED : null)
})
.catch((caught: Error) => setError(caught.message))
.finally(() => void refresh())
},
})
}
const root = pki?.status.root
const general = pki?.status.authorities.filter((authority) => !authority.builtin) ?? []
const generalNames = [...new Set([...general.map((authority) => authority.name),
...(pki?.certificates ?? []).map((certificate) => certificate.ca).filter((name) => !BUILTIN_CAS.includes(name))])]
const generalCertificates = (pki?.certificates ?? [])
.filter((certificate) => !BUILTIN_CAS.includes(certificate.ca) && (filter === '' || certificate.ca === filter))
/** The actions of an issuing CA waiting for the offline root: download its CSR and import its signed certificate. */
const pendingActions = (name: string) => (
<>
<Tooltip title="Download the CSR and the openssl extensions to sign it with">
<span>
<IconButton size="small" disabled={busy} onClick={() => void downloadCsr(name)}><Download fontSize="small" /></IconButton>
</span>
</Tooltip>
<Tooltip title="Import the certificate signed by the root">
<span>
<IconButton size="small" disabled={busy} onClick={() => setImporting(name)}><UploadFile fontSize="small" /></IconButton>
</span>
</Tooltip>
</>
)
/** The active issuing CA a certificate the root issued belongs to, matched by its subject and expiry. */
const authorityOf = (certificate: PkiCertificate) => certificate.kind === 'ca' && certificate.state === 'valid'
? pki?.status.authorities.find((item) => item.state === 'active' && item.subject === certificate.subject && item.expires === certificate.expires)
: undefined
/** A table of certificates with their state and, for one of another system or of the router, Revoke; for an active
* issuing CA, the download of its CA bundle. */
const certificateTable = (list: PkiCertificate[]) => (
<Box sx={{ overflowX: 'auto' }}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Serial</TableCell>
<TableCell>CA</TableCell>
<TableCell>Kind</TableCell>
<TableCell>Template</TableCell>
<TableCell>Subject</TableCell>
<TableCell>Alternative names</TableCell>
<TableCell>Expires</TableCell>
<TableCell>State</TableCell>
<TableCell align="right">Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{list.length === 0 && (
<TableRow>
<TableCell colSpan={9} sx={{ color: 'text.secondary' }}>None.</TableCell>
</TableRow>
)}
{list.map((certificate) => (
<TableRow key={certificate.serial} hover>
<TableCell sx={{ fontFamily: 'monospace', whiteSpace: 'nowrap' }}>{certificate.serial}</TableCell>
<TableCell sx={{ whiteSpace: 'nowrap' }}>{certificate.ca}</TableCell>
<TableCell sx={{ whiteSpace: 'nowrap' }}>{certificate.kind}</TableCell>
<TableCell sx={{ whiteSpace: 'nowrap' }}>{certificate.template ?? '-'}</TableCell>
<TableCell>{certificate.subject}</TableCell>
<TableCell>{certificate.sans.join(', ') || '-'}</TableCell>
<TableCell sx={{ whiteSpace: 'nowrap' }}>{when(certificate.expires)}</TableCell>
<TableCell>
<Tooltip title={certificate.revoked ? `${when(certificate.revoked)}, ${REASON_LABELS[certificate.reason ?? ''] ?? certificate.reason ?? ''}` : ''}>
<Chip size="small" label={certificate.state} color={STATE_COLORS[certificate.state] ?? 'default'} />
</Tooltip>
</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
{authorityOf(certificate) && (
<Tooltip title="Download the CA bundle: the issuing CA and the root">
<span>
<IconButton size="small" disabled={busy} onClick={() => void downloadBundle(authorityOf(certificate)!.name)}>
<Download fontSize="small" />
</IconButton>
</span>
</Tooltip>
)}
{(certificate.kind === 'external' || certificate.kind === 'router') && certificate.state === 'valid' && (
<Tooltip title="Revoke">
<span>
<IconButton size="small" color="error" disabled={busy} onClick={() => revoke(certificate)}><Block fontSize="small" /></IconButton>
</span>
</Tooltip>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
)
/** A tab of a built-in issuing CA: its details, the actions while it waits for the offline root, its certificates. */
const builtinTab = (name: 'p2s' | 's2s', title: string) => {
const authority = pki?.status.authorities.find((item) => item.name === name)
return (
<Box sx={{ display: 'grid', gap: 2 }}>
<Section title={title}>
{authority ? (
<>
<Pairs
rows={[
['Common name', authority.subject ?? authority.common_name],
['State', <Chip size="small" label={authority.state} color={STATE_COLORS[authority.state] ?? 'default'} />],
['Expires', when(authority.expires)],
['CRL valid until', when(authority.crl_next_update)],
['Templates', authority.templates.join(', ')],
]}
/>
{authority.state === 'pending' && (
<Stack direction="row" sx={{ mt: 1, alignItems: 'center', justifyContent: 'flex-end', gap: 1 }}>
<Typography variant="body2" color="text.secondary">Waits for its certificate signed by the root:</Typography>
{pendingActions(name)}
</Stack>
)}
{authority.state === 'active' && (
<Stack direction="row" sx={{ mt: 1, justifyContent: 'flex-end' }}>
<Button size="small" variant="outlined" startIcon={<Download />} disabled={busy} onClick={() => void downloadBundle(name)}>
Download CA bundle
</Button>
</Stack>
)}
</>
) : <Typography variant="body2" color="text.secondary">None yet; the router creates it once a platform is chosen.</Typography>}
</Section>
<Section title="Certificates issued">{certificateTable((pki?.certificates ?? []).filter((certificate) => certificate.ca === name))}</Section>
</Box>
)
}
return (
<Box component="section">
<Toolbar description="The root CA and the issuing CAs for P2S, site-to-site and general use.">
<Button variant="contained" startIcon={<Add />} disabled={busy || pki === null} onClick={() => setIssuing(true)}>
Issue
</Button>
<Button variant="outlined" startIcon={<Settings />} disabled={busy || pki === null} onClick={() => setEditing(true)}>
Settings
</Button>
<Button variant="outlined" startIcon={<Refresh />} disabled={busy} onClick={() => void refresh()}>
Refresh
</Button>
</Toolbar>
{error && <Alert severity={unavailable ? 'info' : 'error'} sx={{ mb: 2, whiteSpace: 'pre-line' }}>{error}</Alert>}
{note && <Alert severity="info" sx={{ mb: 2 }} onClose={() => setNote(null)}>{note}</Alert>}
{pki?.status.warnings.map((warning) => <Alert key={warning} severity="warning" sx={{ mb: 2 }}>{warning}</Alert>)}
{pki && (
<Tabs value={view} onChange={(_event, next: View) => setView(next)} sx={{ mb: 2, borderBottom: 1, borderColor: 'divider' }}>
<Tab value="root" label="Root" />
<Tab value="templates" label="Templates" />
<Tab value="usages" label="Extended key usages" />
<Tab value="p2s" label="P2S Issuing CA" />
<Tab value="s2s" label="S2S Issuing CA" />
<Tab value="issuing" label="Issuing CAs" />
</Tabs>
)}
{pki && view === 'root' && (
<Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' } }}>
<Section title="Root CA">
{root ? (
<>
<Pairs
rows={[
['Subject', root.subject],
['Expires', when(root.expires)],
['Key', root.key ? (
<Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.5 }}>
on the router
<Tooltip title="Keeping the root key off the router is recommended: vpn-router-ca root export-key, then vpn-router-ca root remove-key.">
<WarningAmber fontSize="small" color="warning" aria-label="The root key is on the router" />
</Tooltip>
</Box>
) : 'offline'],
['CRL valid until', when(root.crl_next_update)],
['CRL', root.crl_source === 'uploaded' ? 'uploaded' : root.crl_source === 'signed' ? 'signed by the router' : '-'],
]}
/>
<Stack direction="row" sx={{ mt: 1, justifyContent: 'flex-end', gap: 1 }}>
<Button size="small" variant="outlined" startIcon={<Download />} disabled={busy} onClick={() => void downloadBundle('root')}>
Download root CA
</Button>
<Button size="small" variant="outlined" startIcon={<UploadFile />} disabled={busy} onClick={() => setUploading(true)}>
Upload CRL
</Button>
</Stack>
</>
) : <Typography variant="body2" color="text.secondary">None yet; the router creates it once a platform is chosen.</Typography>}
</Section>
<Section title="General">
<Pairs
rows={[
['Published at', pki.settings.publish.map((item) => PUBLISH_LABELS[item] ?? item).join('; ') || 'nowhere'],
['CA key', pki.settings.key],
['Lifetimes', `root ${pki.settings.root_days} days, issuing CAs ${pki.settings.ca_days} days`],
['CRLs', `issuing CAs ${pki.settings.crl_days} days, root ${pki.settings.root_crl_days} days`],
]}
/>
</Section>
<Section title="Issuing CA certificates" wide>
{certificateTable(pki.certificates.filter((certificate) => certificate.ca === 'root'))}
{pki.status.retired.length > 0 && (
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
{`Retired: ${pki.status.retired.map((retired) => `${retired.name} (${when(retired.retired)})`).join(', ')}`}
</Typography>
)}
</Section>
</Box>
)}
{pki && view === 'templates' && (
<Box sx={{ display: 'grid', gap: 2 }}>
<Section title="Certificate templates">
<Stack direction="row" sx={{ mb: 1, justifyContent: 'flex-end' }}>
<Button size="small" variant="outlined" startIcon={<Add />} disabled={busy} onClick={() => setTemplate({})}>
Add template
</Button>
</Stack>
<Box sx={{ overflowX: 'auto' }}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Key</TableCell>
<TableCell>Days</TableCell>
<TableCell>Subject</TableCell>
<TableCell>Key usage</TableCell>
<TableCell>Extended key usage</TableCell>
<TableCell>Alternative names</TableCell>
<TableCell>Policies</TableCell>
<TableCell>Issued by</TableCell>
<TableCell align="right">Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{Object.entries(pki.templates).map(([name, values]) => {
const builtin = (BUILTIN_TEMPLATES as readonly string[]).includes(name)
const changed = pki.settings.templates[name] !== undefined
return (
<TableRow key={name} hover>
<TableCell>
{name}
{builtin && <Chip size="small" variant="outlined" label={changed ? 'built in, changed' : 'built in'} sx={{ ml: 1 }} />}
</TableCell>
<TableCell>{values.key}</TableCell>
<TableCell>{values.days}</TableCell>
<TableCell>{values.subject}</TableCell>
<TableCell>{values.key_usage.join(', ')}</TableCell>
<TableCell>{values.extended_key_usage.join(', ') || '-'}</TableCell>
<TableCell>{values.sans.join(', ') || '-'}</TableCell>
<TableCell>{values.policies.join(', ') || '-'}</TableCell>
<TableCell>
{pki.status.authorities.filter((item) => item.templates.includes(name)).map((item) => item.name).join(', ') || '-'}
</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
<Tooltip title="Edit">
<span>
<IconButton size="small" disabled={busy} onClick={() => setTemplate({ name })}><Edit fontSize="small" /></IconButton>
</span>
</Tooltip>
{(!builtin || changed) && (
<Tooltip title={builtin ? 'Reset to the built-in options' : 'Remove'}>
<span>
<IconButton size="small" color={builtin ? 'default' : 'error'} disabled={busy} onClick={() => removeTemplate(name, builtin)}>
{builtin ? <Refresh fontSize="small" /> : <Delete fontSize="small" />}
</IconButton>
</span>
</Tooltip>
)}
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</Box>
</Section>
</Box>
)}
{pki && view === 'usages' && (
<Box sx={{ display: 'grid', gap: 2 }}>
<Section title="Extended key usages">
<Stack direction="row" sx={{ mb: 1, justifyContent: 'flex-end' }}>
<Button size="small" variant="outlined" startIcon={<Add />} disabled={busy} onClick={() => setUsage({})}>
Add extended key usage
</Button>
</Stack>
<Box sx={{ overflowX: 'auto' }}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>OID</TableCell>
<TableCell>Given by</TableCell>
<TableCell align="right">Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{Object.entries(pki.extended_key_usages).map(([name, usage]) => (
<TableRow key={name} hover>
<TableCell>
{name}
{usage.builtin && <Chip size="small" variant="outlined" label="built in" sx={{ ml: 1 }} />}
</TableCell>
<TableCell sx={{ fontFamily: 'monospace' }}>{usage.oid}</TableCell>
<TableCell>
{Object.entries(pki.templates).filter(([, values]) => values.extended_key_usage.includes(name)).map(([template]) => template).join(', ') || '-'}
</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
{!usage.builtin && (
<>
<Tooltip title="Edit">
<span>
<IconButton size="small" disabled={busy} onClick={() => setUsage({ name })}><Edit fontSize="small" /></IconButton>
</span>
</Tooltip>
<Tooltip title="Remove">
<span>
<IconButton size="small" color="error" disabled={busy} onClick={() => removeUsage(name)}><Delete fontSize="small" /></IconButton>
</span>
</Tooltip>
</>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
</Section>
</Box>
)}
{pki && view === 'p2s' && builtinTab('p2s', 'P2S Issuing CA: the VPN server certificate and the users\' certificates')}
{pki && view === 's2s' && builtinTab('s2s', 'S2S Issuing CA: the site-to-site certificates of the router and its peers')}
{pki && view === 'issuing' && (
<Box sx={{ display: 'grid', gap: 2 }}>
<Section title="General-purpose issuing CAs">
<Stack direction="row" sx={{ mb: 1, justifyContent: 'flex-end' }}>
<Button size="small" variant="outlined" startIcon={<Add />} disabled={busy} onClick={() => setAuthority({})}>
Add issuing CA
</Button>
</Stack>
<Box sx={{ overflowX: 'auto' }}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Common name</TableCell>
<TableCell>State</TableCell>
<TableCell>Expires</TableCell>
<TableCell>CRL valid until</TableCell>
<TableCell>Templates</TableCell>
<TableCell>ACME</TableCell>
<TableCell align="right">Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{general.length === 0 && (
<TableRow>
<TableCell colSpan={8} sx={{ color: 'text.secondary' }}>None.</TableCell>
</TableRow>
)}
{general.map((authority) => (
<TableRow key={authority.name} hover>
<TableCell>{authority.name}</TableCell>
<TableCell>{authority.subject ?? authority.common_name}</TableCell>
<TableCell><Chip size="small" label={authority.state} color={STATE_COLORS[authority.state] ?? 'default'} /></TableCell>
<TableCell>{when(authority.expires)}</TableCell>
<TableCell>{when(authority.crl_next_update)}</TableCell>
<TableCell>{authority.templates.join(', ')}</TableCell>
<TableCell sx={{ wordBreak: 'break-all' }}>{authority.acme_url ?? (authority.acme ? 'waits for the certificate' : '-')}</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
{authority.state === 'pending' && pendingActions(authority.name)}
{authority.state === 'active' && (
<Tooltip title="Download the CA bundle: the issuing CA and the root">
<span>
<IconButton size="small" disabled={busy} onClick={() => void downloadBundle(authority.name)}><Download fontSize="small" /></IconButton>
</span>
</Tooltip>
)}
<Tooltip title="Edit">
<span>
<IconButton size="small" disabled={busy} onClick={() => setAuthority({ name: authority.name })}><Edit fontSize="small" /></IconButton>
</span>
</Tooltip>
<Tooltip title="Remove">
<span>
<IconButton size="small" color="error" disabled={busy} onClick={() => removeAuthority(authority.name)}><Delete fontSize="small" /></IconButton>
</span>
</Tooltip>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
</Section>
<Section title="Certificates issued">
<TextField select size="small" label="Issuing CA" value={filter} sx={{ mb: 1, minWidth: 200 }} onChange={(event) => setFilter(event.target.value)}>
<MenuItem value="">All</MenuItem>
{generalNames.map((name) => <MenuItem key={name} value={name}>{name}</MenuItem>)}
</TextField>
{certificateTable(generalCertificates)}
</Section>
</Box>
)}
{editing && pki && (
<PkiSettingsDialog
pki={pki}
onCancel={() => setEditing(false)}
onSave={async (settings) => {
await request('PUT', '/ca', PKI_SETTINGS_SHAPE, settings)
setEditing(false)
setNote(APPLIED)
await refresh()
}}
/>
)}
{usage && pki && (
<EkuDialog
pki={pki}
name={usage.name}
onCancel={() => setUsage(null)}
onSave={async (name, oid) => {
await saveUsage(name, oid)
setUsage(null)
}}
/>
)}
{template && pki && (
<TemplateDialog
pki={pki}
name={template.name}
onCancel={() => setTemplate(null)}
onSave={async (name, values) => {
await saveTemplate(name, values)
setTemplate(null)
}}
/>
)}
{authority && pki && (
<IssuingCaDialog
pki={pki}
name={authority.name}
onCancel={() => setAuthority(null)}
onSave={async (name, values) => {
await saveAuthority(name, values)
setAuthority(null)
}}
/>
)}
{issuing && pki && (
<CertificateDialog
pki={pki}
onCancel={() => setIssuing(false)}
onSave={async (issue) => {
if ('csr' in issue) {
const issued = await request<{ serial: string; certificate: string; chain: string }>('POST', '/ca/certificates', ISSUED_SHAPE, issue)
saveFile(`${issued.serial}.pem`, issued.certificate + issued.chain, 'application/x-pem-file')
} else {
const issued = await request<{ serial: string; pfx: string }>('POST', '/ca/certificates', PFX_SHAPE, issue)
saveFile(`${issue.subject}.pfx`, Uint8Array.from(atob(issued.pfx), (character) => character.charCodeAt(0)), 'application/x-pkcs12')
}
setIssuing(false)
await refresh()
}}
/>
)}
{importing && (
<ImportDialog
title={`Import the certificate of ${importing}`}
message="The certificate of the issuing CA, signed by the root CA for the key of its CSR."
label="Certificate"
begin="-----BEGIN CERTIFICATE-----"
onCancel={() => setImporting(null)}
onSave={async (certificate) => {
await request('PUT', `/ca/issuing/${importing}/certificate`, CA_IMPORTED_SHAPE, { certificate })
setImporting(null)
setNote(APPLIED)
await refresh()
}}
/>
)}
{uploading && (
<ImportDialog
title="Upload the root CRL"
message="A CRL of the root CA signed offline, not older than the current one."
label="CRL"
begin="-----BEGIN X509 CRL-----"
onCancel={() => setUploading(false)}
onSave={async (crl) => {
await request('PUT', '/ca/root/crl', CRL_IMPORTED_SHAPE, { crl })
setUploading(false)
await refresh()
}}
/>
)}
{confirm && <ConfirmDialog {...confirm} />}
</Box>
)
}