@samitouri / QOSami-HFS / commits / b2dec390

warn about expired certificate

Massimo Melina committed Aug 23, 2023 at 18:28 UTC b2dec3900a31fbe2e02467c421c2f056612cd83c
2 files changed +14 -2
admin/src/OptionsPage.ts
+3 -1
@@ -99,7 +99,9 @@ export default function OptionsPage() {
99 },
100 httpsEnabled && { k: 'cert', comp: FileField, md: 4, label: "HTTPS certificate file",
101 helperText: wikiLink('HTTPS#certificate', "What is this?"),
102 - error: with_(status?.https.error, e => isCertError(e) && [e, ' - ', h(LinkBtn, { key: 'fix', onClick: makeCertAndSave }, "make one")]),
102 + error: with_(status?.https.error, e => isCertError(e) && (
103 + status.https.listening ? e
104 + : [e, ' - ', h(LinkBtn, { key: 'fix', onClick: makeCertAndSave }, "make one")] )),
105 },
106 httpsEnabled && { k: 'private_key', comp: FileField, md: 4, label: "HTTPS private key file",
107 ...with_(status?.https.error, e => isKeyError(e) ? { error: true, helperText: e } : null)
src/listen.ts
+11 -1
@@ -13,6 +13,7 @@ import { ADMIN_URI, argv, DEV } from './const'
13 import findProcess from 'find-process'
14 import { anyAccountCanLoginAdmin } from './adminApis'
15 import _ from 'lodash'
16 +import { X509Certificate } from 'crypto'
17
18 interface ServerExtra { name: string, error?: string, busy?: Promise<string> }
19 let httpSrv: undefined | http.Server & ServerExtra
@@ -63,9 +64,18 @@ const considerHttps = debounceAsync(async () => {
64 await wait(100)
65 httpsSrv = Object.assign(
66 https.createServer(port < 0 ? {} : { key: httpsOptions.private_key, cert: httpsOptions.cert }, app.callback()),
66 - { name: 'https', error: undefined }
67 + { name: 'https' }
68 )
69 if (port >= 0) {
70 + const cert = new X509Certificate(httpsOptions.cert)
71 + const cn = cert.subject.split('CN=')[1]?.split('\n')[0]
72 + if (cn)
73 + console.log("certificate loaded for", cn)
74 + const now = new Date()
75 + httpsSrv.error = new Date(cert.validFrom) > now ? "certificate not valid yet"
76 + : new Date(cert.validTo) < now ? "certificate expired"
77 + : undefined
78 +
79 const namesForOutput: any = { cert: 'certificate', private_key: 'private key' }
80 const missing = httpsNeeds.find(x => !x.get())?.key()
81 if (missing)