Skip to content

Commit 9916e83

Browse files
committed
util: Generate self signed certificate into data directory
Closes #1778
1 parent 860c99e commit 9916e83

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

doc/FAQ.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ For HTTPS, you can use a self signed certificate by passing in just `--cert` or
144144
pass in an existing certificate by providing the path to `--cert` and the path to
145145
the key with `--cert-key`.
146146

147+
The self signed certificate will be generated into
148+
`~/.local/share/code-server/self-signed.cert`.
149+
147150
If `code-server` has been passed a certificate it will also respond to HTTPS
148151
requests and will redirect all HTTP requests to HTTPS.
149152

src/node/util.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ export function humanPath(p?: string): string {
5555
}
5656

5757
export const generateCertificate = async (): Promise<{ cert: string; certKey: string }> => {
58-
const paths = {
59-
cert: path.join(tmpdir, "self-signed.cert"),
60-
certKey: path.join(tmpdir, "self-signed.key"),
61-
}
62-
const checks = await Promise.all([fs.pathExists(paths.cert), fs.pathExists(paths.certKey)])
58+
const certPath = path.join(paths.data, "self-signed.cert")
59+
const certKeyPath = path.join(paths.data, "self-signed.key")
60+
61+
const checks = await Promise.all([fs.pathExists(certPath), fs.pathExists(certKeyPath)])
6362
if (!checks[0] || !checks[1]) {
6463
// Require on demand so openssl isn't required if you aren't going to
6564
// generate certificates.
@@ -70,9 +69,12 @@ export const generateCertificate = async (): Promise<{ cert: string; certKey: st
7069
})
7170
})
7271
await fs.mkdirp(tmpdir)
73-
await Promise.all([fs.writeFile(paths.cert, certs.certificate), fs.writeFile(paths.certKey, certs.serviceKey)])
72+
await Promise.all([fs.writeFile(certPath, certs.certificate), fs.writeFile(certKeyPath, certs.serviceKey)])
73+
}
74+
return {
75+
cert: certPath,
76+
certKey: certKeyPath,
7477
}
75-
return paths
7678
}
7779

7880
export const generatePassword = async (length = 24): Promise<string> => {

0 commit comments

Comments
 (0)