| 36 | } |
| 37 | |
| 38 | get fixedCa(): string[] { |
| 39 | if (this._initialized) { |
| 40 | return this._fixedCa; |
| 41 | } |
| 42 | |
| 43 | const globalCerts: string[] = []; |
| 44 | if (Boolean(process.env.IS_BINARY)) { |
| 45 | if (Array.isArray(globalAgent.options.ca)) { |
| 46 | globalCerts.push( |
| 47 | ...globalAgent.options.ca.map((cert) => cert.toString()), |
| 48 | ); |
| 49 | } else if (typeof globalAgent.options.ca !== "undefined") { |
| 50 | globalCerts.push(globalAgent.options.ca.toString()); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | const extraCerts: string[] = []; |
| 55 | if (process.env.NODE_EXTRA_CA_CERTS) { |
| 56 | try { |
| 57 | const content = fs.readFileSync( |
| 58 | process.env.NODE_EXTRA_CA_CERTS, |
| 59 | "utf8", |
| 60 | ); |
| 61 | extraCerts.push(content); |
| 62 | } catch (error) { |
| 63 | if (process.env.VERBOSE_FETCH) { |
| 64 | console.error( |
| 65 | `Error reading NODE_EXTRA_CA_CERTS file: ${process.env.NODE_EXTRA_CA_CERTS}`, |
| 66 | error, |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | this._fixedCa = Array.from( |
| 73 | new Set([...tls.rootCertificates, ...globalCerts, ...extraCerts]), |
| 74 | ); |
| 75 | this._initialized = true; |
| 76 | return this._fixedCa; |
| 77 | } |
| 78 | |
| 79 | async getCachedCustomCert(path: string): Promise<string | undefined> { |
| 80 | if (this._customCerts.has(path)) { |