(output: Log, options?: tls.SecureContextOptions)
| 128 | let _secureContextWithExtraCerts: Promise<tls.SecureContext | undefined> | undefined; |
| 129 | |
| 130 | async 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 | } |
no test coverage detected