@@ -47,22 +47,15 @@ const defaultEnclavedConfig: EnclavedConfig = {
4747 timeout : 305 * 1000 ,
4848 logFile : '' ,
4949 kmsUrl : '' , // Will be overridden by environment variable
50- tlsMode : TlsMode . ENABLED ,
51- mtlsRequestCert : false ,
52- mtlsRejectUnauthorized : false ,
50+ tlsMode : TlsMode . MTLS ,
51+ mtlsRequestCert : true ,
52+ allowSelfSigned : false ,
5353} ;
5454
5555function determineTlsMode ( ) : TlsMode {
5656 const disableTls = readEnvVar ( 'MASTER_BITGO_EXPRESS_DISABLE_TLS' ) === 'true' ;
57- const mtlsEnabled = readEnvVar ( 'MTLS_ENABLED' ) === 'true' ;
58-
59- if ( disableTls && mtlsEnabled ) {
60- throw new Error ( 'Cannot have both TLS disabled and mTLS enabled' ) ;
61- }
62-
6357 if ( disableTls ) return TlsMode . DISABLED ;
64- if ( mtlsEnabled ) return TlsMode . MTLS ;
65- return TlsMode . ENABLED ;
58+ return TlsMode . MTLS ;
6659}
6760
6861function enclavedEnvConfig ( ) : Partial < EnclavedConfig > {
@@ -86,16 +79,15 @@ function enclavedEnvConfig(): Partial<EnclavedConfig> {
8679 headersTimeout : Number ( readEnvVar ( 'MASTER_BITGO_EXPRESS_HEADERS_TIMEOUT' ) ) ,
8780 // KMS settings
8881 kmsUrl,
89- // TLS settings
82+ // mTLS settings
9083 keyPath : readEnvVar ( 'MASTER_BITGO_EXPRESS_KEYPATH' ) ,
9184 crtPath : readEnvVar ( 'MASTER_BITGO_EXPRESS_CRTPATH' ) ,
9285 tlsKey : readEnvVar ( 'MASTER_BITGO_EXPRESS_TLS_KEY' ) ,
9386 tlsCert : readEnvVar ( 'MASTER_BITGO_EXPRESS_TLS_CERT' ) ,
9487 tlsMode : determineTlsMode ( ) ,
95- // mTLS settings
96- mtlsRequestCert : readEnvVar ( 'MTLS_REQUEST_CERT' ) === 'true' ,
97- mtlsRejectUnauthorized : readEnvVar ( 'MTLS_REJECT_UNAUTHORIZED' ) === 'true' ,
88+ mtlsRequestCert : readEnvVar ( 'MTLS_REQUEST_CERT' ) !== 'false' ,
9889 mtlsAllowedClientFingerprints : readEnvVar ( 'MTLS_ALLOWED_CLIENT_FINGERPRINTS' ) ?. split ( ',' ) ,
90+ allowSelfSigned : readEnvVar ( 'ALLOW_SELF_SIGNED' ) === 'true' ,
9991 } ;
10092}
10193
@@ -125,8 +117,8 @@ function mergeEnclavedConfigs(...configs: Partial<EnclavedConfig>[]): EnclavedCo
125117 tlsCert : get ( 'tlsCert' ) ,
126118 tlsMode : get ( 'tlsMode' ) ,
127119 mtlsRequestCert : get ( 'mtlsRequestCert' ) ,
128- mtlsRejectUnauthorized : get ( 'mtlsRejectUnauthorized' ) ,
129120 mtlsAllowedClientFingerprints : get ( 'mtlsAllowedClientFingerprints' ) ,
121+ allowSelfSigned : get ( 'allowSelfSigned' ) ,
130122 } ;
131123}
132124
@@ -166,12 +158,13 @@ const defaultMasterExpressConfig: MasterExpressConfig = {
166158 timeout : 305 * 1000 ,
167159 logFile : '' ,
168160 env : 'test' ,
169- enableSSL : true ,
170- enableProxy : true ,
171161 disableEnvCheck : true ,
172162 authVersion : 2 ,
173163 enclavedExpressUrl : '' , // Will be overridden by environment variable
174- enclavedExpressSSLCert : '' , // Will be overridden by environment variable
164+ enclavedExpressCert : '' , // Will be overridden by environment variable
165+ tlsMode : TlsMode . MTLS ,
166+ mtlsRequestCert : true ,
167+ allowSelfSigned : false ,
175168} ;
176169
177170function forceSecureUrl ( url : string ) : string {
@@ -184,16 +177,14 @@ function forceSecureUrl(url: string): string {
184177
185178function masterExpressEnvConfig ( ) : Partial < MasterExpressConfig > {
186179 const enclavedExpressUrl = readEnvVar ( 'ENCLAVED_EXPRESS_URL' ) ;
187- const enclavedExpressSSLCert = readEnvVar ( 'ENCLAVED_EXPRESS_SSL_CERT ' ) ;
180+ const enclavedExpressCert = readEnvVar ( 'ENCLAVED_EXPRESS_CERT ' ) ;
188181
189182 if ( ! enclavedExpressUrl ) {
190183 throw new Error ( 'ENCLAVED_EXPRESS_URL environment variable is required and cannot be empty' ) ;
191184 }
192185
193- if ( ! enclavedExpressSSLCert ) {
194- throw new Error (
195- 'ENCLAVED_EXPRESS_SSL_CERT environment variable is required and cannot be empty' ,
196- ) ;
186+ if ( ! enclavedExpressCert ) {
187+ throw new Error ( 'ENCLAVED_EXPRESS_CERT environment variable is required and cannot be empty' ) ;
197188 }
198189
199190 return {
@@ -209,18 +200,20 @@ function masterExpressEnvConfig(): Partial<MasterExpressConfig> {
209200 // BitGo API settings
210201 env : readEnvVar ( 'BITGO_ENV' ) as EnvironmentName ,
211202 customRootUri : readEnvVar ( 'BITGO_CUSTOM_ROOT_URI' ) ,
212- enableSSL : readEnvVar ( 'BITGO_ENABLE_SSL' ) !== 'false' , // Default to true unless explicitly set to false
213- enableProxy : readEnvVar ( 'BITGO_ENABLE_PROXY' ) !== 'false' , // Default to true unless explicitly set to false
214203 disableEnvCheck : readEnvVar ( 'BITGO_DISABLE_ENV_CHECK' ) === 'true' ,
215204 authVersion : Number ( readEnvVar ( 'BITGO_AUTH_VERSION' ) ) ,
216205 enclavedExpressUrl,
217- enclavedExpressSSLCert ,
206+ enclavedExpressCert ,
218207 customBitcoinNetwork : readEnvVar ( 'BITGO_CUSTOM_BITCOIN_NETWORK' ) ,
219- // SSL settings
208+ // mTLS settings
220209 keyPath : readEnvVar ( 'BITGO_KEYPATH' ) ,
221210 crtPath : readEnvVar ( 'BITGO_CRTPATH' ) ,
222- sslKey : readEnvVar ( 'BITGO_SSL_KEY' ) ,
223- sslCert : readEnvVar ( 'BITGO_SSL_CERT' ) ,
211+ tlsKey : readEnvVar ( 'BITGO_TLS_KEY' ) ,
212+ tlsCert : readEnvVar ( 'BITGO_TLS_CERT' ) ,
213+ tlsMode : determineTlsMode ( ) ,
214+ mtlsRequestCert : readEnvVar ( 'MTLS_REQUEST_CERT' ) !== 'false' ,
215+ mtlsAllowedClientFingerprints : readEnvVar ( 'MTLS_ALLOWED_CLIENT_FINGERPRINTS' ) ?. split ( ',' ) ,
216+ allowSelfSigned : readEnvVar ( 'ALLOW_SELF_SIGNED' ) === 'true' ,
224217 } ;
225218}
226219
@@ -247,50 +240,50 @@ function mergeMasterExpressConfigs(
247240 headersTimeout : get ( 'headersTimeout' ) ,
248241 env : get ( 'env' ) ,
249242 customRootUri : get ( 'customRootUri' ) ,
250- enableSSL : get ( 'enableSSL' ) ,
251- enableProxy : get ( 'enableProxy' ) ,
252243 disableEnvCheck : get ( 'disableEnvCheck' ) ,
253244 authVersion : get ( 'authVersion' ) ,
254245 enclavedExpressUrl : get ( 'enclavedExpressUrl' ) ,
255- enclavedExpressSSLCert : get ( 'enclavedExpressSSLCert ' ) ,
246+ enclavedExpressCert : get ( 'enclavedExpressCert ' ) ,
256247 customBitcoinNetwork : get ( 'customBitcoinNetwork' ) ,
257248 keyPath : get ( 'keyPath' ) ,
258249 crtPath : get ( 'crtPath' ) ,
259- sslKey : get ( 'sslKey' ) ,
260- sslCert : get ( 'sslCert' ) ,
250+ tlsKey : get ( 'tlsKey' ) ,
251+ tlsCert : get ( 'tlsCert' ) ,
252+ tlsMode : get ( 'tlsMode' ) ,
253+ mtlsRequestCert : get ( 'mtlsRequestCert' ) ,
254+ mtlsAllowedClientFingerprints : get ( 'mtlsAllowedClientFingerprints' ) ,
255+ allowSelfSigned : get ( 'allowSelfSigned' ) ,
261256 } ;
262257}
263258
264- function configureMasterExpressMode ( ) : MasterExpressConfig {
259+ export function configureMasterExpressMode ( ) : MasterExpressConfig {
265260 const env = masterExpressEnvConfig ( ) ;
266261 let config = mergeMasterExpressConfigs ( env ) ;
267262
268- // Post-process URLs if SSL is enabled
269- if ( config . enableSSL ) {
270- const updates : Partial < MasterExpressConfig > = { } ;
271- if ( config . customRootUri ) {
272- updates . customRootUri = forceSecureUrl ( config . customRootUri ) ;
273- }
274- if ( config . enclavedExpressUrl ) {
275- updates . enclavedExpressUrl = forceSecureUrl ( config . enclavedExpressUrl ) ;
276- }
277- config = { ...config , ...updates } ;
263+ // Post-process URLs to ensure they use HTTPS
264+ const updates : Partial < MasterExpressConfig > = { } ;
265+ if ( config . customRootUri ) {
266+ updates . customRootUri = forceSecureUrl ( config . customRootUri ) ;
267+ }
268+ if ( config . enclavedExpressUrl ) {
269+ updates . enclavedExpressUrl = forceSecureUrl ( config . enclavedExpressUrl ) ;
278270 }
271+ config = { ...config , ...updates } ;
279272
280- // Handle SSL cert loading
281- if ( config . enclavedExpressSSLCert ) {
273+ // Handle cert loading
274+ if ( config . enclavedExpressCert ) {
282275 try {
283- if ( fs . existsSync ( config . enclavedExpressSSLCert ) ) {
276+ if ( fs . existsSync ( config . enclavedExpressCert ) ) {
284277 config = {
285278 ...config ,
286- enclavedExpressSSLCert : fs . readFileSync ( config . enclavedExpressSSLCert , 'utf-8' ) ,
279+ enclavedExpressCert : fs . readFileSync ( config . enclavedExpressCert , 'utf-8' ) ,
287280 } ;
288281 } else {
289- throw new Error ( `Certificate file not found: ${ config . enclavedExpressSSLCert } ` ) ;
282+ throw new Error ( `Certificate file not found: ${ config . enclavedExpressCert } ` ) ;
290283 }
291284 } catch ( e ) {
292285 const err = e instanceof Error ? e : new Error ( String ( e ) ) ;
293- throw new Error ( `Failed to read enclaved express SSL cert: ${ err . message } ` ) ;
286+ throw new Error ( `Failed to read enclaved express cert: ${ err . message } ` ) ;
294287 }
295288 }
296289
0 commit comments