Skip to content

Commit 6f5d492

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. Updates #1566 I've been able to successfully connect from my iPad Pro now to my code-server instance with a self signed certificate! Next commit will be docs.
1 parent b6c1acc commit 6f5d492

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
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

+20-4
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,9 +64,25 @@ 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) => {
68-
return error ? reject(error) : resolve(result)
69-
})
67+
pem.createCertificate(
68+
{
69+
selfSigned: true,
70+
config: `
71+
[req]
72+
req_extensions = v3_req
73+
74+
[ v3_req ]
75+
extendedKeyUsage = serverAuth
76+
subjectAltName = @alt_names
77+
78+
[alt_names]
79+
DNS.1 = localhost
80+
`,
81+
},
82+
(error, result) => {
83+
return error ? reject(error) : resolve(result)
84+
},
85+
)
7086
})
7187
await fs.mkdirp(tmpdir)
7288
await Promise.all([fs.writeFile(certPath, certs.certificate), fs.writeFile(certKeyPath, certs.serviceKey)])

0 commit comments

Comments
 (0)