Skip to content

Commit 9210fff

Browse files
committed
use node's built-in CA cert support
1 parent cc3d03a commit 9210fff

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

packages/core/src/shared/lsp/utils/platform.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,14 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
8282
}
8383

8484
/**
85-
* Gets Electron settings from VS Code
85+
* Gets proxy settings from VS Code's Electron instance
8686
*/
87-
export function getElectronSettings(): { caCerts?: string; proxyRules?: string; proxyBypassRules?: string } {
87+
export function getElectronProxySettings(): { proxyRules?: string; proxyBypassRules?: string } {
8888
try {
8989
// Access Electron's modules through VSCode's API
9090
// @ts-ignore - This is a valid access pattern in VSCode extensions
9191
const electron = require('electron')
92-
const result: { caCerts?: string; proxyRules?: string; proxyBypassRules?: string } = {}
93-
94-
// Get certificates
95-
if (electron?.net?.getCACertificates) {
96-
const certs = electron.net.getCACertificates()
97-
if (certs && certs.length > 0) {
98-
// Convert the certificates to PEM format
99-
result.caCerts = certs
100-
.map((cert: any) => cert.pemEncoded)
101-
.filter(Boolean)
102-
.join('\n')
103-
}
104-
}
92+
const result: { proxyRules?: string; proxyBypassRules?: string } = {}
10593

10694
// Get proxy settings from Electron
10795
if (electron?.session?.defaultSession?.getProxyRules) {
@@ -147,23 +135,27 @@ export function createServerOptions({
147135
Object.assign(processEnv, env)
148136
}
149137

150-
// Get Electron settings (certificates and proxy)
151-
const electronSettings = getElectronSettings()
138+
// Get proxy settings from Electron
139+
const proxySettings = getElectronProxySettings()
140+
141+
// Enable Node.js to use system CA certificates
142+
processEnv.NODE_TLS_USE_SYSTEM_CA_STORE = '1'
152143

153-
// Add system CA certificates to the Node process if not already set
154-
if (!processEnv.NODE_EXTRA_CA_CERTS && electronSettings.caCerts) {
155-
processEnv.NODE_EXTRA_CA_CERTS = electronSettings.caCerts
144+
// Also set NODE_OPTIONS to ensure system CA certificates are used
145+
const nodeOptions = processEnv.NODE_OPTIONS || ''
146+
if (!nodeOptions.includes('--use-openssl-ca')) {
147+
processEnv.NODE_OPTIONS = `${nodeOptions} --use-openssl-ca`.trim()
156148
}
157149

158-
// Add Electron proxy settings to the Node process
159-
if (electronSettings.proxyRules && !processEnv.HTTP_PROXY) {
160-
processEnv.HTTP_PROXY = electronSettings.proxyRules
161-
processEnv.HTTPS_PROXY = electronSettings.proxyRules
150+
// Add Electron proxy settings to the Node.js process
151+
if (proxySettings.proxyRules && !processEnv.HTTP_PROXY) {
152+
processEnv.HTTP_PROXY = proxySettings.proxyRules
153+
processEnv.HTTPS_PROXY = proxySettings.proxyRules
162154
}
163155

164156
// Add proxy bypass rules if available
165-
if (electronSettings.proxyBypassRules) {
166-
processEnv.NO_PROXY = electronSettings.proxyBypassRules
157+
if (proxySettings.proxyBypassRules) {
158+
processEnv.NO_PROXY = proxySettings.proxyBypassRules
167159
}
168160

169161
const lspProcess = new ChildProcess(bin, args, {

0 commit comments

Comments
 (0)