|
| 1 | +/** |
| 2 | + * Minimal Bun type definitions for TLS support |
| 3 | + * Based on: https://bun.com/docs/guides/http/tls |
| 4 | + * https://bun.sh/docs/api/tcp |
| 5 | + */ |
| 6 | + |
| 7 | +import {BufferSource} from "node:stream/web"; |
| 8 | + |
| 9 | +/** |
| 10 | + * TLS options for Bun's fetch API |
| 11 | + */ |
| 12 | +export interface BunTlsOptions { |
| 13 | + /** |
| 14 | + * Passphrase for the TLS key |
| 15 | + */ |
| 16 | + passphrase?: string; |
| 17 | + |
| 18 | + /** |
| 19 | + * File path to a .pem file custom Diffie Helman parameters |
| 20 | + */ |
| 21 | + dhParamsFile?: string; |
| 22 | + |
| 23 | + /** |
| 24 | + * Explicitly set a server name |
| 25 | + */ |
| 26 | + serverName?: string; |
| 27 | + |
| 28 | + /** |
| 29 | + * This sets `OPENSSL_RELEASE_BUFFERS` to 1. |
| 30 | + * It reduces overall performance but saves some memory. |
| 31 | + * @default false |
| 32 | + */ |
| 33 | + lowMemoryMode?: boolean; |
| 34 | + |
| 35 | + /** |
| 36 | + * If set to `false`, any certificate is accepted. |
| 37 | + * Default is `$NODE_TLS_REJECT_UNAUTHORIZED` environment variable, or `true` if it is not set. |
| 38 | + */ |
| 39 | + rejectUnauthorized?: boolean; |
| 40 | + |
| 41 | + /** |
| 42 | + * If set to `true`, the server will request a client certificate. |
| 43 | + * |
| 44 | + * Default is `false`. |
| 45 | + */ |
| 46 | + requestCert?: boolean; |
| 47 | + |
| 48 | + /** |
| 49 | + * Optionally override the trusted CA certificates. Default is to trust |
| 50 | + * the well-known CAs curated by Mozilla. Mozilla's CAs are completely |
| 51 | + * replaced when CAs are explicitly specified using this option. |
| 52 | + */ |
| 53 | + ca?: string | BufferSource | Array<string | BufferSource> | undefined; |
| 54 | + |
| 55 | + /** |
| 56 | + * Cert chains in PEM format. One cert chain should be provided per |
| 57 | + * private key. Each cert chain should consist of the PEM formatted |
| 58 | + * certificate for a provided private key, followed by the PEM |
| 59 | + * formatted intermediate certificates (if any), in order, and not |
| 60 | + * including the root CA (the root CA must be pre-known to the peer, |
| 61 | + * see ca). When providing multiple cert chains, they do not have to |
| 62 | + * be in the same order as their private keys in key. If the |
| 63 | + * intermediate certificates are not provided, the peer will not be |
| 64 | + * able to validate the certificate, and the handshake will fail. |
| 65 | + */ |
| 66 | + cert?: string | BufferSource | Array<string | BufferSource> | undefined; |
| 67 | + |
| 68 | + /** |
| 69 | + * Private keys in PEM format. PEM allows the option of private keys |
| 70 | + * being encrypted. Encrypted keys will be decrypted with |
| 71 | + * options.passphrase. Multiple keys using different algorithms can be |
| 72 | + * provided either as an array of unencrypted key strings or buffers, |
| 73 | + * or an array of objects in the form {pem: <string|buffer>[, |
| 74 | + * passphrase: <string>]}. The object form can only occur in an array. |
| 75 | + * object.passphrase is optional. Encrypted keys will be decrypted with |
| 76 | + * object.passphrase if provided, or options.passphrase if it is not. |
| 77 | + */ |
| 78 | + key?: string | BufferSource | Array<string | BufferSource> | undefined; |
| 79 | + |
| 80 | + /** |
| 81 | + * Optionally affect the OpenSSL protocol behavior, which is not |
| 82 | + * usually necessary. This should be used carefully if at all! Value is |
| 83 | + * a numeric bitmask of the SSL_OP_* options from OpenSSL Options |
| 84 | + */ |
| 85 | + secureOptions?: number | undefined; |
| 86 | + |
| 87 | + /** |
| 88 | + * ALPN protocols |
| 89 | + */ |
| 90 | + ALPNProtocols?: string | BufferSource; |
| 91 | + |
| 92 | + /** |
| 93 | + * Cipher suite specification |
| 94 | + */ |
| 95 | + ciphers?: string; |
| 96 | + |
| 97 | + /** |
| 98 | + * Client renegotiation limit |
| 99 | + */ |
| 100 | + clientRenegotiationLimit?: number; |
| 101 | + |
| 102 | + /** |
| 103 | + * Client renegotiation window |
| 104 | + */ |
| 105 | + clientRenegotiationWindow?: number; |
| 106 | + |
| 107 | + /** |
| 108 | + * PFX or PKCS12 encoded certificate and private key |
| 109 | + * |
| 110 | + * @warning This property is included for Node.js compatibility, but PFX certificates |
| 111 | + * are NOT currently supported in Bun runtime. Use PEM certificates (cert/key/ca) instead. |
| 112 | + */ |
| 113 | + pfx?: Buffer; |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * Bun-specific fetch request initialization options |
| 118 | + * Extend standard RequestInit with Bun-specific TLS options |
| 119 | + */ |
| 120 | +export interface BunFetchRequestInit extends RequestInit { |
| 121 | + /** |
| 122 | + * TLS configuration for HTTPS requests |
| 123 | + */ |
| 124 | + tls?: BunTlsOptions; |
| 125 | +} |
0 commit comments