Skip to content

Commit b42405b

Browse files
committed
docs: update README and open source ready
Ticket: WP-6646
1 parent 9723ab9 commit b42405b

File tree

1 file changed

+212
-86
lines changed

1 file changed

+212
-86
lines changed

README.md

Lines changed: 212 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
A secure, mTLS-enabled cryptocurrency signing server with two operational modes: Advanced Wallet Manager (dedicated signer) and Master Express (API gateway with integrated signing capabilities).
44

5+
## Table of Contents
6+
7+
- [Overview](#overview)
8+
- [Architecture](#architecture)
9+
- [Installation](#installation)
10+
- [Prerequisites](#prerequisites)
11+
- [Quick Start](#quick-start)
12+
- [Quick Start (No mTLS)](#quick-start-no-mtls---fastest-way-to-test)
13+
- [Configuration](#configuration)
14+
- [Container Deployment](#container-deployment-with-podman)
15+
- [Docker Compose Deployment](#docker-compose-deployment)
16+
- [API Endpoints](#api-endpoints)
17+
- [API Documentation](#api-documentation)
18+
- [Production Setup](#production-setup)
19+
- [License](#license)
20+
521
## Overview
622

723
This application provides secure cryptocurrency operations with mutual TLS (mTLS) authentication:
@@ -14,7 +30,7 @@ This application provides secure cryptocurrency operations with mutual TLS (mTLS
1430
## Architecture
1531

1632
- **Advanced Wallet Manager** (Port 3080): Isolated signing server with no internet access, only connects to KMS API for key operations.
17-
- **Master Express** (Port 3081): Full BitGo API functionality with secure communication to Advanced Wallet Manager
33+
- **Master Express** (Port 3081): API gateway providing end-to-end wallet creation and transaction support, integrating BitGo APIs with secure communication to Advanced Wallet Manager
1834

1935
## Installation
2036

@@ -25,6 +41,9 @@ This application provides secure cryptocurrency operations with mutual TLS (mTLS
2541
- **OpenSSL** for certificate generation
2642
- **Docker** and **Docker Compose** (for containerized deployment)
2743
- **Podman** (alternative to Docker for containerized deployment)
44+
- **KMS API Implementation** - Advanced Wallet Manager requires a KMS (Key Management Service) API for secure key operations. See implementation guides:
45+
- [AWS HSM Implementation](./demo-kms-script/aws-interface.md)
46+
- [Dinamo HSM Implementation](./demo-kms-script/dinamo-interface.md)
2847

2948
### Setup
3049

@@ -81,47 +100,49 @@ npm run container:build:advanced-wallet-manager
81100

82101
## Quick Start
83102

84-
### 1. Start Advanced Wallet Manager
103+
### Quick Start (No mTLS) - Fastest Way to Test
104+
105+
For quick testing without mTLS security, you can disable TLS entirely. This is useful for local development and testing.
106+
107+
#### 1. Start Advanced Wallet Manager (Port 3080)
85108

86109
```bash
87-
export APP_MODE=advanced-wallet-manager
88-
export KMS_URL=https://your-kms-service
89-
export SERVER_TLS_KEY_PATH=./demo.key
90-
export SERVER_TLS_CERT_PATH=./demo.crt
91-
export KMS_CLIENT_TLS_KEY_PATH=./demo.key
92-
export KMS_CLIENT_TLS_CERT_PATH=./demo.crt
93-
export KMS_SERVER_CA_CERT_PATH=./demo.crt
94-
export KMS_SERVER_CERT_ALLOW_SELF_SIGNED=true
95-
export CLIENT_CERT_ALLOW_SELF_SIGNED=true
110+
TLS_MODE=disabled \
111+
BITGO_ENV=test \
112+
APP_MODE=advanced-wallet-manager \
113+
ADVANCED_WALLET_MANAGER_PORT=3080 \
114+
KMS_URL=http://localhost:3000 \
96115
npm start
97116
```
98117

99-
**Note:** KMS client certificates are required for outbound mTLS connections. For testing, we reuse the demo certificates, but in production, use separate certificates for security.
118+
#### 2. Start Master BitGo Express (Port 3081)
100119

101-
### 2. Start Master Express
120+
In a new terminal:
102121

103122
```bash
104-
export APP_MODE=master-express
105-
export BITGO_ENV=test
106-
export SERVER_TLS_KEY_PATH=./demo.key
107-
export SERVER_TLS_CERT_PATH=./demo.crt
108-
export ADVANCED_WALLET_MANAGER_URL=https://localhost:3080
109-
export AWM_CLIENT_TLS_KEY_PATH=./demo.key
110-
export AWM_CLIENT_TLS_CERT_PATH=./demo.crt
111-
export AWM_SERVER_CA_CERT_PATH=./demo.crt
112-
export AWM_SERVER_CERT_ALLOW_SELF_SIGNED=true
113-
export CLIENT_CERT_ALLOW_SELF_SIGNED=true
123+
TLS_MODE=disabled \
124+
BITGO_ENV=test \
125+
APP_MODE=master-express \
126+
MASTER_EXPRESS_PORT=3081 \
127+
ADVANCED_WALLET_MANAGER_URL=http://localhost:3080 \
114128
npm start
115129
```
116130

117-
**Note:** AWM client certificates are required for outbound mTLS connections to Advanced Wallet Manager. For testing, we reuse the demo certificates, but in production, use separate certificates for security.
118-
119-
### 3. Test the Connection
131+
#### 3. Test the Connection
120132

121133
```bash
122-
curl -k -X POST https://localhost:3081/ping/advancedWalletManager
134+
# Test Advanced Wallet Manager
135+
curl -X POST http://localhost:3080/ping
136+
137+
# Test Master Express
138+
curl -X POST http://localhost:3081/ping
139+
140+
# Test connection between services
141+
curl -X POST http://localhost:3081/ping/advancedWalletManager
123142
```
124143

144+
**Note:** `TLS_MODE=disabled` should only be used for local development and testing. Always use mTLS in production environments. See the [Production Setup](#production-setup) section for production mTLS configuration.
145+
125146
## Configuration
126147

127148
### Core Settings
@@ -141,22 +162,38 @@ curl -k -X POST https://localhost:3081/ping/advancedWalletManager
141162
| `ADVANCED_WALLET_MANAGER_PORT` | Port to listen on | `3080` ||
142163
| `KMS_URL` | KMS service URL | - ||
143164

165+
**Note:** See [Prerequisites](#prerequisites) for KMS API implementation requirements.
166+
144167
### Master Express Settings
145168

146-
| Variable | Description | Default | Required |
147-
| ----------------------------- | --------------------------- | ------- | -------- |
148-
| `MASTER_EXPRESS_PORT` | Port to listen on | `3081` ||
149-
| `BITGO_ENV` | BitGo environment | `test` ||
150-
| `ADVANCED_WALLET_MANAGER_URL` | Advanced Wallet Manager URL | - ||
169+
| Variable | Description | Default | Required |
170+
| ------------------------------ | ------------------------------------------------------------- | ------- | -------- |
171+
| `MASTER_EXPRESS_PORT` | Port to listen on | `3081` ||
172+
| `BITGO_ENV` | BitGo environment (`prod`, `test`, `staging`, `dev`, `local`) | `test` ||
173+
| `ADVANCED_WALLET_MANAGER_URL` | Advanced Wallet Manager URL | - ||
174+
| `BITGO_CUSTOM_ROOT_URI` | Custom BitGo API root URI (overrides `BITGO_ENV`) | - ||
175+
| `BITGO_DISABLE_ENV_CHECK` | Disable environment check | `true` ||
176+
| `BITGO_AUTH_VERSION` | BitGo authentication version | `2` ||
177+
| `BITGO_CUSTOM_BITCOIN_NETWORK` | Custom Bitcoin network | - ||
178+
179+
### Additional Settings
180+
181+
| Variable | Description | Default | Applies To |
182+
| -------------------- | --------------------------------------------------- | ---------------------- | ---------- |
183+
| `RECOVERY_MODE` | Enable recovery mode for wallet recovery operations | `false` | Both |
184+
| `HTTP_LOGFILE` | Path to HTTP access log file | `logs/http-access.log` | Both |
185+
| `KEEP_ALIVE_TIMEOUT` | Keep-alive timeout in milliseconds | - | Both |
186+
| `HEADERS_TIMEOUT` | Headers timeout in milliseconds | - | Both |
187+
| `IPC` | IPC socket path (alternative to TCP port binding) | - | Both |
151188

152189
### TLS/mTLS Configuration
153190

154191
#### Basic TLS Settings
155192

156-
| Variable | Description | Default |
157-
| ------------------- | ------------------------------- | ------- |
158-
| `TLS_MODE` | TLS mode (`mtls` or `disabled`) | `mtls` |
159-
| `ALLOW_SELF_SIGNED` | Allow self-signed certificates | `false` |
193+
| Variable | Description | Default |
194+
| ------------------------------- | ------------------------------------- | ------- |
195+
| `TLS_MODE` | TLS mode (`mtls` or `disabled`) | `mtls` |
196+
| `CLIENT_CERT_ALLOW_SELF_SIGNED` | Allow self-signed client certificates | `false` |
160197

161198
#### Server Certificates (for incoming connections)
162199

@@ -177,15 +214,29 @@ curl -k -X POST https://localhost:3081/ping/advancedWalletManager
177214

178215
**For Master Express → Advanced Wallet Manager:**
179216

180-
- `AWM_CLIENT_TLS_KEY_PATH` / `AWM_CLIENT_TLS_KEY`
181-
- `AWM_CLIENT_TLS_CERT_PATH` / `AWM_CLIENT_TLS_CERT`
182-
- `AWM_SERVER_CA_CERT_PATH` / `AWM_SERVER_CA_CERT`
217+
| Variable | Description | Format |
218+
| ----------------------------------- | ----------------------------------------- | -------------------------- |
219+
| `AWM_CLIENT_TLS_KEY_PATH` | Client private key file path | File path |
220+
| `AWM_CLIENT_TLS_KEY` | Client private key (alternative) | PEM string |
221+
| `AWM_CLIENT_TLS_CERT_PATH` | Client certificate file path | File path |
222+
| `AWM_CLIENT_TLS_CERT` | Client certificate (alternative) | PEM string |
223+
| `AWM_SERVER_CA_CERT_PATH` | AWM server CA certificate file path | File path |
224+
| `AWM_SERVER_CA_CERT` | AWM server CA certificate (alternative) | PEM string |
225+
| `AWM_SERVER_CERT_ALLOW_SELF_SIGNED` | Allow self-signed AWM server certificates | Boolean (default: `false`) |
183226

184227
**For Advanced Wallet Manager → KMS:**
185228

186-
- `KMS_CLIENT_TLS_KEY_PATH` / `KMS_CLIENT_TLS_KEY`
187-
- `KMS_CLIENT_TLS_CERT_PATH` / `KMS_CLIENT_TLS_CERT`
188-
- `KMS_SERVER_CA_CERT_PATH` / `KMS_SERVER_CA_CERT`
229+
| Variable | Description | Format |
230+
| ----------------------------------- | ----------------------------------------- | -------------------------- |
231+
| `KMS_CLIENT_TLS_KEY_PATH` | Client private key file path | File path |
232+
| `KMS_CLIENT_TLS_KEY` | Client private key (alternative) | PEM string |
233+
| `KMS_CLIENT_TLS_CERT_PATH` | Client certificate file path | File path |
234+
| `KMS_CLIENT_TLS_CERT` | Client certificate (alternative) | PEM string |
235+
| `KMS_SERVER_CA_CERT_PATH` | KMS server CA certificate file path | File path |
236+
| `KMS_SERVER_CA_CERT` | KMS server CA certificate (alternative) | PEM string |
237+
| `KMS_SERVER_CERT_ALLOW_SELF_SIGNED` | Allow self-signed KMS server certificates | Boolean (default: `false`) |
238+
239+
**Note:** When `TLS_MODE=mtls`, outbound client certificates are required and cannot reuse server certificates for security reasons. In `TLS_MODE=disabled` mode, these certificates are not required.
189240

190241
## Container Deployment with Podman
191242

@@ -328,68 +379,143 @@ docker-compose down
328379
- `POST /ping/advancedWalletManager` - Test connection to Advanced Wallet Manager
329380
- `POST /api/:coin/wallet/generate` - Generate wallet (with Advanced Wallet Manager integration)
330381

331-
## Production Security
382+
### API Documentation
332383

333-
### Best Practices
384+
**Master Express OpenAPI Specification**
334385

335-
1. **Use CA-signed certificates** instead of self-signed
336-
2. **Set `ALLOW_SELF_SIGNED=false`** in production
337-
3. **Configure client certificate allowlisting** with `MTLS_ALLOWED_CLIENT_FINGERPRINTS`
338-
4. **Use separate certificates** for each service
339-
5. **Regularly rotate certificates**
340-
6. **Secure private key storage**
386+
The OpenAPI specification for Master Express is available at [`masterBitgoExpress.json`](./masterBitgoExpress.json).
341387

342-
### Production Example
388+
To regenerate the API documentation:
389+
390+
```bash
391+
npm run generate:openapi:masterExpress
392+
```
393+
394+
This will generate/update the `masterBitgoExpress.json` file with the latest API specification. You can view this file with any OpenAPI viewer such as:
395+
396+
- [Swagger Editor](https://editor.swagger.io/)
397+
- [Redoc](https://redocly.github.io/redoc/)
398+
- VS Code OpenAPI extensions
399+
400+
## Production Setup
401+
402+
### Quick Start (With mTLS)
403+
404+
For production deployments with proper mTLS security:
405+
406+
#### 1. Start Advanced Wallet Manager (Port 3080)
343407

344408
```bash
345-
# Advanced Wallet Manager
346409
export APP_MODE=advanced-wallet-manager
347-
export KMS_URL=https://production-kms.example.com
348-
export SERVER_TLS_KEY_PATH=/secure/awm-server.key
349-
export SERVER_TLS_CERT_PATH=/secure/awm-server.crt
350-
export KMS_CLIENT_TLS_KEY_PATH=/secure/awm-kms-client.key
351-
export KMS_CLIENT_TLS_CERT_PATH=/secure/awm-kms-client.crt
352-
export KMS_SERVER_CA_CERT_PATH=/secure/kms-ca.crt
353-
export ALLOW_SELF_SIGNED=false
354-
export MTLS_ALLOWED_CLIENT_FINGERPRINTS=ABC123...,DEF456...
355-
356-
# Master Express
410+
export TLS_MODE=mtls
411+
export ADVANCED_WALLET_MANAGER_PORT=3080
412+
export KMS_URL=https://production-kms.example.com:3000
413+
# Server certificates for incoming mTLS connections
414+
export SERVER_TLS_KEY_PATH=/secure/certs/awm-server.key
415+
export SERVER_TLS_CERT_PATH=/secure/certs/awm-server.crt
416+
# Client certificates for outbound connections to KMS
417+
export KMS_CLIENT_TLS_KEY_PATH=/secure/certs/awm-kms-client.key
418+
export KMS_CLIENT_TLS_CERT_PATH=/secure/certs/awm-kms-client.crt
419+
export KMS_SERVER_CA_CERT_PATH=/secure/certs/kms-ca.crt
420+
# Security settings - production-grade
421+
export CLIENT_CERT_ALLOW_SELF_SIGNED=false
422+
export KMS_SERVER_CERT_ALLOW_SELF_SIGNED=false
423+
export MTLS_ALLOWED_CLIENT_FINGERPRINTS=sha256:1a2b3c...,sha256:4d5e6f...
424+
export BITGO_ENV=prod
425+
npm start
426+
```
427+
428+
#### 2. Start Master Express (Port 3081)
429+
430+
In a new terminal:
431+
432+
```bash
357433
export APP_MODE=master-express
434+
export TLS_MODE=mtls
435+
export MASTER_EXPRESS_PORT=3081
358436
export BITGO_ENV=prod
359-
export SERVER_TLS_KEY_PATH=/secure/master-server.key
360-
export SERVER_TLS_CERT_PATH=/secure/master-server.crt
361-
export AWM_CLIENT_TLS_KEY_PATH=/secure/master-awm-client.key
362-
export AWM_CLIENT_TLS_CERT_PATH=/secure/master-awm-client.crt
363437
export ADVANCED_WALLET_MANAGER_URL=https://awm.internal.example.com:3080
364-
export AWM_SERVER_CA_CERT_PATH=/secure/awm-ca.crt
365-
export ALLOW_SELF_SIGNED=false
438+
# Server certificates for incoming mTLS connections
439+
export SERVER_TLS_KEY_PATH=/secure/certs/mbe-server.key
440+
export SERVER_TLS_CERT_PATH=/secure/certs/mbe-server.crt
441+
# Client certificates for outbound connections to AWM
442+
export AWM_CLIENT_TLS_KEY_PATH=/secure/certs/mbe-awm-client.key
443+
export AWM_CLIENT_TLS_CERT_PATH=/secure/certs/mbe-awm-client.crt
444+
export AWM_SERVER_CA_CERT_PATH=/secure/certs/awm-ca.crt
445+
# Security settings - production-grade
446+
export CLIENT_CERT_ALLOW_SELF_SIGNED=false
447+
export AWM_SERVER_CERT_ALLOW_SELF_SIGNED=false
448+
export MTLS_ALLOWED_CLIENT_FINGERPRINTS=sha256:7g8h9i...,sha256:0j1k2l...
449+
npm start
366450
```
367451

368-
## Troubleshooting
452+
#### 3. Test the Connection
369453

370-
### Common Issues
454+
For testing, you can use the server's IP address or `localhost` if running locally. In production deployments, configure your DNS or load balancer to point to the appropriate servers.
371455

372-
| Issue | Solution |
373-
| ---------------------------- | --------------------------------------------------- |
374-
| Certificate loading errors | Check file paths, permissions, and format |
375-
| mTLS authentication failures | Verify certificates, fingerprints, and TLS settings |
376-
| Connection refused | Check ports, firewall, and URL format |
377-
| Environment variable issues | Verify required variables are set |
456+
```bash
457+
# Test Advanced Wallet Manager (replace localhost with your server IP/hostname)
458+
curl --cert /path/to/client-cert.crt --key /path/to/client-key.key \
459+
--cacert /secure/certs/awm-ca.crt \
460+
https://localhost:3080/ping
461+
462+
# Test Master Express (replace localhost with your server IP/hostname)
463+
curl --cert /path/to/client-cert.crt --key /path/to/client-key.key \
464+
--cacert /secure/certs/mbe-ca.crt \
465+
https://localhost:3081/ping
466+
467+
# Test connection between services
468+
curl --cert /path/to/client-cert.crt --key /path/to/client-key.key \
469+
--cacert /secure/certs/mbe-ca.crt \
470+
https://localhost:3081/ping/advancedWalletManager
471+
```
378472

379-
### Debug Commands
473+
**Testing with Demo Certificates:**
380474

381-
```bash
382-
# Check certificate format
383-
openssl x509 -in certificate.crt -text -noout
475+
For local testing, you can generate and use demo certificates with the self-signed configuration flags:
384476

385-
# Verify environment variables
386-
env | grep -E "(APP_MODE|KMS_URL|ADVANCED_WALLET_MANAGER|TLS_)"
477+
- Generate demo certificates: `npm run generate-test-ssl` (creates `demo.key` and `demo.crt`)
478+
- Set `CLIENT_CERT_ALLOW_SELF_SIGNED=true`, `KMS_SERVER_CERT_ALLOW_SELF_SIGNED=true`, and `AWM_SERVER_CERT_ALLOW_SELF_SIGNED=true`
479+
- Use the demo certificates for all certificate paths (server and client)
480+
- **Important:** Demo certificates and self-signed configurations should never be used in production
387481

388-
# Test connectivity
389-
curl -k -X POST https://localhost:3080/ping
390-
curl -k -X POST https://localhost:3081/ping
482+
### Best Practices
483+
484+
1. **Use CA-signed certificates** instead of self-signed
485+
2. **Set `CLIENT_CERT_ALLOW_SELF_SIGNED=false`** and server-specific allow self-signed flags to `false` in production
486+
3. **Configure client certificate allowlisting** with `MTLS_ALLOWED_CLIENT_FINGERPRINTS`
487+
4. **Use separate certificates** for each service (server, AWM client, KMS client)
488+
5. **Regularly rotate certificates**
489+
6. **Secure private key storage** and use appropriate file permissions
490+
7. **Always use `TLS_MODE=mtls`** in production environments
491+
492+
### Certificate Management
493+
494+
#### Getting Client Certificate Fingerprints
495+
496+
To obtain certificate fingerprints for `MTLS_ALLOWED_CLIENT_FINGERPRINTS`:
497+
498+
```bash
499+
openssl x509 -in /path/to/client-cert.crt -noout -fingerprint -sha256 | cut -d'=' -f2
391500
```
392501

502+
The output will be in the format: `sha256:AB:CD:EF:...` which you can use in the configuration.
503+
504+
#### Certificate Requirements for Production
505+
506+
- All certificates should be CA-signed certificates issued by your organization's PKI
507+
- Each service must use separate certificates (server cert, AWM client cert, KMS client cert)
508+
- Client certificates for outbound connections must be different from server certificates
509+
- Store private keys in secure locations with restricted file permissions:
510+
```bash
511+
chmod 400 /secure/certs/*.key
512+
chown root:root /secure/certs/*.key
513+
```
514+
- Use `BIND=0.0.0.0` only if the service needs to be accessible from other machines
515+
- Regularly rotate certificates according to your security policy
516+
393517
## License
394518

395-
MIT
519+
Apache License 2.0 - see [LICENSE](./LICENSE) file for details.
520+
521+
Copyright 2025 BitGo

0 commit comments

Comments
 (0)