Skip to content

Commit 7f6f2bb

Browse files
committed
src/node/util.ts: Make certificate generation "modern"
Now we add a subject alt name, set extendedKeyUsage and use the correct certificate extension. The above allow it to be properly trusted by iOS. See https://support.apple.com/en-us/HT210176 *.cert isn't a real extension for certificates, *.crt is correct for it to be recognized by e.g. keychain or when importing as a profile into iOS.
1 parent 745bd4a commit 7f6f2bb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

doc/FAQ.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pass in an existing certificate by providing the path to `--cert` and the path t
145145
the key with `--cert-key`.
146146

147147
The self signed certificate will be generated into
148-
`~/.local/share/code-server/self-signed.cert`.
148+
`~/.local/share/code-server/self-signed.crt`.
149149

150150
If `code-server` has been passed a certificate it will also respond to HTTPS
151151
requests and will redirect all HTTP requests to HTTPS.

src/node/util.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function humanPath(p?: string): string {
5555
}
5656

5757
export const generateCertificate = async (): Promise<{ cert: string; certKey: string }> => {
58-
const certPath = path.join(paths.data, "self-signed.cert")
58+
const certPath = path.join(paths.data, "self-signed.crt")
5959
const certKeyPath = path.join(paths.data, "self-signed.key")
6060

6161
const checks = await Promise.all([fs.pathExists(certPath), fs.pathExists(certKeyPath)])
@@ -64,7 +64,17 @@ export const generateCertificate = async (): Promise<{ cert: string; certKey: st
6464
// generate certificates.
6565
const pem = require("pem") as typeof import("pem")
6666
const certs = await new Promise<import("pem").CertificateCreationResult>((resolve, reject): void => {
67-
pem.createCertificate({ selfSigned: true }, (error, result) => {
67+
pem.createCertificate({ selfSigned: true, config: `
68+
[req]
69+
req_extensions = v3_req
70+
71+
[ v3_req ]
72+
extendedKeyUsage = serverAuth
73+
subjectAltName = @alt_names
74+
75+
[alt_names]
76+
DNS.1 = localhost
77+
`}, (error, result) => {
6878
return error ? reject(error) : resolve(result)
6979
})
7080
})

0 commit comments

Comments
 (0)