MCPcopy Create free account
hub / github.com/devcontainers/cli / secureContextWithExtraCerts

Function secureContextWithExtraCerts

src/spec-utils/httpRequest.ts:130–161  ·  view source on GitHub ↗
(output: Log, options?: tls.SecureContextOptions)

Source from the content-addressed store, hash-verified

128let _secureContextWithExtraCerts: Promise<tls.SecureContext | undefined> | undefined;
129
130async function secureContextWithExtraCerts(output: Log, options?: tls.SecureContextOptions) {
131 // Work around https://github.com/electron/electron/issues/10257.
132
133 if (_secureContextWithExtraCerts) {
134 return _secureContextWithExtraCerts;
135 }
136
137 return _secureContextWithExtraCerts = (async () => {
138 if (!process.versions.electron || !process.env.NODE_EXTRA_CA_CERTS) {
139 return undefined;
140 }
141
142 try {
143 const content = await readLocalFile(process.env.NODE_EXTRA_CA_CERTS, { encoding: 'utf8' });
144 const certs = (content.split(/(?=-----BEGIN CERTIFICATE-----)/g)
145 .filter(pem => !!pem.length));
146 output.write(`Loading ${certs.length} extra certificates from ${process.env.NODE_EXTRA_CA_CERTS}.`);
147 if (!certs.length) {
148 return undefined;
149 }
150
151 const secureContext = tls.createSecureContext(options);
152 for (const cert of certs) {
153 secureContext.context.addCACert(cert);
154 }
155 return secureContext;
156 } catch (err) {
157 output.write(`Error loading extra certificates from ${process.env.NODE_EXTRA_CA_CERTS}: ${err.message}`, LogLevel.Error);
158 return undefined;
159 }
160 })();
161}

Callers 3

requestFunction · 0.85
headRequestFunction · 0.85
requestResolveHeadersFunction · 0.85

Calls 1

writeMethod · 0.65

Tested by

no test coverage detected