Skip to content

Commit 1ac761f

Browse files
committed
handle certs
1 parent 79a6364 commit 1ac761f

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

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

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { ToolkitError } from '../../errors'
7-
import { Logger } from '../../logger/logger'
7+
import { Logger, getLogger } from '../../logger/logger'
88
import { ChildProcess } from '../../utilities/processUtils'
99
import { waitUntil } from '../../utilities/timeoutUtils'
1010
import { isDebugInstance } from '../../vscode/env'
@@ -83,57 +83,65 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
8383
}
8484

8585
/**
86-
* Gets proxy settings from VS Code configuration
86+
* Gets proxy settings and certificates from VS Code
8787
*/
88-
export function getVSCodeProxySettings(): { proxyUrl?: string; proxyBypassRules?: string; certificatePath?: string } {
88+
export function getVSCodeSettings(): { proxyUrl?: string; certificatePath?: string } {
89+
const result: { proxyUrl?: string; certificatePath?: string } = {}
90+
const logger = getLogger('amazonqLsp')
91+
8992
try {
90-
const result: { proxyUrl?: string; proxyBypassRules?: string; certificatePath?: string } = {}
93+
// Check if user already has NODE_EXTRA_CA_CERTS set
94+
const userCerts = process.env.NODE_EXTRA_CA_CERTS
95+
if (userCerts) {
96+
logger.info(`User already has NODE_EXTRA_CA_CERTS set: ${userCerts}`)
97+
return result
98+
}
9199

92100
// Get proxy settings from VS Code configuration
93101
const httpConfig = vscode.workspace.getConfiguration('http')
94102
const proxy = httpConfig.get<string>('proxy')
95-
96103
if (proxy) {
97104
result.proxyUrl = proxy
105+
logger.info(`Using proxy from VS Code settings: ${proxy}`)
98106
}
99107

100-
// Try to get system certificates
101108
try {
102109
// @ts-ignore - This is a valid access pattern in VSCode extensions
103110
const electron = require('electron')
104111
if (electron?.net?.getCACertificates) {
105112
const certs = electron.net.getCACertificates()
106113
if (certs && certs.length > 0) {
107-
// Create a temporary file with the certificates
108-
const os = require('os')
114+
logger.info(`Found ${certs.length} certificates in VS Code's trust store`)
115+
116+
// Create a temporary file with certificates
109117
const fs = require('fs')
118+
const os = require('os')
110119
const path = require('path')
111120

121+
const tempDir = path.join(os.tmpdir(), 'aws-toolkit-vscode')
122+
if (!fs.existsSync(tempDir)) {
123+
fs.mkdirSync(tempDir, { recursive: true })
124+
}
125+
126+
const certPath = path.join(tempDir, 'vscode-ca-certs.pem')
112127
const certContent = certs
128+
.filter((cert: any) => cert.pemEncoded)
113129
.map((cert: any) => cert.pemEncoded)
114-
.filter(Boolean)
115-
.join('\\n')
116-
117-
if (certContent) {
118-
const tempDir = path.join(os.tmpdir(), 'aws-toolkit-vscode')
119-
if (!fs.existsSync(tempDir)) {
120-
fs.mkdirSync(tempDir, { recursive: true })
121-
}
122-
123-
const certPath = path.join(tempDir, 'vscode-ca-certs.pem')
124-
fs.writeFileSync(certPath, certContent)
125-
result.certificatePath = certPath
126-
}
130+
.join('\n')
131+
132+
fs.writeFileSync(certPath, certContent)
133+
result.certificatePath = certPath
134+
logger.info(`Created certificate file at: ${certPath}`)
127135
}
128136
}
129137
} catch (err) {
130-
// Silently fail if we can't access certificates
138+
logger.error(`Failed to extract certificates: ${err}`)
131139
}
132140

133141
return result
134142
} catch (err) {
135-
// Silently fail if we can't access VS Code configuration
136-
return {}
143+
logger.error(`Failed to get VS Code settings: ${err}`)
144+
return result
137145
}
138146
}
139147

@@ -165,25 +173,22 @@ export function createServerOptions({
165173
Object.assign(processEnv, env)
166174
}
167175

168-
// Get proxy settings from VS Code
169-
const proxySettings = getVSCodeProxySettings()
176+
// Get settings from VS Code
177+
const settings = getVSCodeSettings()
178+
const logger = getLogger('amazonqLsp')
170179

171180
// Add proxy settings to the Node.js process
172-
if (proxySettings.proxyUrl) {
173-
processEnv.HTTPS_PROXY = proxySettings.proxyUrl
174-
processEnv.HTTP_PROXY = proxySettings.proxyUrl
175-
processEnv.https_proxy = proxySettings.proxyUrl
176-
processEnv.http_proxy = proxySettings.proxyUrl
181+
if (settings.proxyUrl) {
182+
processEnv.HTTPS_PROXY = settings.proxyUrl
183+
processEnv.HTTP_PROXY = settings.proxyUrl
184+
processEnv.https_proxy = settings.proxyUrl
185+
processEnv.http_proxy = settings.proxyUrl
177186
}
178187

179188
// Add certificate path if available
180-
if (proxySettings.certificatePath) {
181-
processEnv.NODE_EXTRA_CA_CERTS = proxySettings.certificatePath
182-
}
183-
184-
// Enable Node.js to use system CA certificates as a fallback
185-
if (!processEnv.NODE_EXTRA_CA_CERTS) {
186-
processEnv.NODE_TLS_USE_SYSTEM_CA_STORE = '1'
189+
if (settings.certificatePath) {
190+
processEnv.NODE_EXTRA_CA_CERTS = settings.certificatePath
191+
logger.info(`Using certificate file: ${settings.certificatePath}`)
187192
}
188193

189194
// Get SSL verification settings
@@ -193,6 +198,7 @@ export function createServerOptions({
193198
// Handle SSL certificate verification
194199
if (!strictSSL) {
195200
processEnv.NODE_TLS_REJECT_UNAUTHORIZED = '0'
201+
logger.info('SSL verification disabled via VS Code settings')
196202
}
197203

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

0 commit comments

Comments
 (0)