Skip to content

Commit d83fe25

Browse files
WIP: add enclaved express configurations
TICKET: WP-4376
1 parent 9bf6627 commit d83fe25

File tree

7 files changed

+75
-27
lines changed

7 files changed

+75
-27
lines changed

modules/express/README.md

Lines changed: 28 additions & 27 deletions
Large diffs are not rendered by default.

modules/express/src/args.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ parser.addArgument(['--externalSignerUrl'], {
9696
help: 'URL which specifies the external signing API.',
9797
});
9898

99+
parser.addArgument(['--enclavedlExpressUrl'], {
100+
help: 'URL to an Express instance in a secure environment.',
101+
});
102+
103+
parser.addArgument(['--enclavedExpressSSLCert'], {
104+
help: 'Path to the SSL certificate file for communicating with enclavedlExpressUrl.',
105+
});
106+
99107
parser.addArgument(['--signerMode'], {
100108
action: 'storeConst',
101109
constant: true,

modules/express/src/clientRoutes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type { ParamsDictionary } from 'express-serve-static-core';
3838
import * as _ from 'lodash';
3939
import * as url from 'url';
4040
import * as superagent from 'superagent';
41+
import { handlePingEnclavedExpress } from './enclavedExpressRoutes';
4142

4243
// RequestTracer should be extracted into a separate npm package (along with
4344
// the rest of the BitGoJS HTTP request machinery)
@@ -1770,6 +1771,10 @@ export function setupSigningRoutes(app: express.Application, config: Config): vo
17701771
);
17711772
}
17721773

1774+
export function setupEnclavedSigningRoutes(app: express.Application, config: Config): void {
1775+
app.post('/ping/enclavedExpress', parseBody, prepareBitGo(config), promiseWrapper(handlePingEnclavedExpress));
1776+
}
1777+
17731778
export function setupLightningSignerNodeRoutes(app: express.Application, config: Config): void {
17741779
app.post(
17751780
'/api/v2/:coin/wallet/:id/initwallet',

modules/express/src/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface Config {
3838
customBitcoinNetwork?: V1Network;
3939
authVersion: number;
4040
externalSignerUrl?: string;
41+
enclavedlExpressUrl?: string;
42+
enclavedExpressSSLCert?: string;
4143
signerMode?: boolean;
4244
signerFileSystemPath?: string;
4345
lightningSignerFileSystemPath?: string;
@@ -64,6 +66,8 @@ export const ArgConfig = (args): Partial<Config> => ({
6466
customBitcoinNetwork: args.custombitcoinnetwork,
6567
authVersion: args.authVersion,
6668
externalSignerUrl: args.externalSignerUrl,
69+
enclavedlExpressUrl: args.enclavedlExpressUrl,
70+
enclavedExpressSSLCert: args.enclavedExpressSSLCert,
6771
signerMode: args.signerMode,
6872
signerFileSystemPath: args.signerFileSystemPath,
6973
lightningSignerFileSystemPath: args.lightningSignerFileSystemPath,
@@ -90,6 +94,8 @@ export const EnvConfig = (): Partial<Config> => ({
9094
customBitcoinNetwork: readEnvVar('BITGO_CUSTOM_BITCOIN_NETWORK') as V1Network,
9195
authVersion: Number(readEnvVar('BITGO_AUTH_VERSION')),
9296
externalSignerUrl: readEnvVar('BITGO_EXTERNAL_SIGNER_URL'),
97+
enclavedlExpressUrl: readEnvVar('BITGO_ENCLAVEDL_EXPRESS_URL'),
98+
enclavedExpressSSLCert: readEnvVar('BITGO_ENCLAVED_EXPRESS_SSL_CERT'),
9399
signerMode: readEnvVar('BITGO_SIGNER_MODE') ? true : undefined,
94100
signerFileSystemPath: readEnvVar('BITGO_SIGNER_FILE_SYSTEM_PATH'),
95101
lightningSignerFileSystemPath: readEnvVar('BITGO_LIGHTNING_SIGNER_FILE_SYSTEM_PATH'),
@@ -110,6 +116,8 @@ export const DefaultConfig: Config = {
110116
disableEnvCheck: true,
111117
timeout: 305 * 1000,
112118
authVersion: 2,
119+
enclavedlExpressUrl: undefined,
120+
enclavedExpressSSLCert: undefined,
113121
};
114122

115123
/**
@@ -147,6 +155,7 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
147155
const disableSSL = get('disableSSL') || false;
148156
let customRootUri = get('customRootUri');
149157
let externalSignerUrl = get('externalSignerUrl');
158+
let enclavedlExpressUrl = get('enclavedlExpressUrl');
150159

151160
if (disableSSL !== true) {
152161
if (customRootUri) {
@@ -155,6 +164,9 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
155164
if (externalSignerUrl) {
156165
externalSignerUrl = forceSecureUrl(externalSignerUrl);
157166
}
167+
if (enclavedlExpressUrl) {
168+
enclavedlExpressUrl = forceSecureUrl(enclavedlExpressUrl);
169+
}
158170
}
159171

160172
return {
@@ -176,6 +188,8 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
176188
customBitcoinNetwork: get('customBitcoinNetwork'),
177189
authVersion: get('authVersion'),
178190
externalSignerUrl,
191+
enclavedlExpressUrl,
192+
enclavedExpressSSLCert: get('enclavedExpressSSLCert'),
179193
signerMode: get('signerMode'),
180194
signerFileSystemPath: get('signerFileSystemPath'),
181195
lightningSignerFileSystemPath: get('lightningSignerFileSystemPath'),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as superagent from 'superagent';
2+
import * as debug from 'debug';
3+
import * as express from 'express';
4+
import { retryPromise } from '../retryPromise';
5+
6+
export async function handlePingEnclavedExpress(req: express.Request) {
7+
return await retryPromise(
8+
() =>
9+
superagent
10+
.post(`${req.config?.enclavedlExpressUrl}/ping`)
11+
.ca(req.config?.enclavedExpressSSLCert as string)
12+
.send({}),
13+
(err, tryCount) => {
14+
debug(`Failed to ping enclavedExpress: ${err.message}`);
15+
}
16+
);
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './enclavedExpressRoutes';

modules/express/src/expressApp.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ function checkPreconditions(config: Config) {
271271
export function setupRoutes(app: express.Application, config: Config): void {
272272
if (config.signerMode) {
273273
clientRoutes.setupSigningRoutes(app, config);
274+
} else if (config.enclavedlExpressUrl && config.enclavedExpressSSLCert) {
275+
clientRoutes.setupEnclavedSigningRoutes(app, config);
274276
} else {
275277
if (config.lightningSignerFileSystemPath) {
276278
clientRoutes.setupLightningSignerNodeRoutes(app, config);

0 commit comments

Comments
 (0)