Skip to content

Commit b6c1acc

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

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

doc/FAQ.md

+3
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/entry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const main = async (args: Args, configArgs: Args): Promise<void> => {
209209
logger.info(
210210
args.cert && args.cert.value
211211
? ` - Using provided certificate and key for HTTPS`
212-
: ` - Using generated certificate and key for HTTPS`,
212+
: ` - Using generated certificate and key for HTTPS: ${humanPath(options.cert)}`,
213213
)
214214
} else {
215215
logger.info(" - Not serving HTTPS")

src/node/util.ts

+9-7
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)