Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support self ca ssl #21

Merged
merged 10 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MOBILE_GATEWAY_URL="http://localhost:9082"
CUSTOMER_SERVER_URL="http://localhost:3000/api"
CUSTOMER_SERVER_URL="http://localhost:5000/api"
CUSTOMER_SERVER_AUTHORIZATION="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
CUSTOMER_SERVER_PULL_CADENCE=30000
CUSTOMER_SERVER_PULL_CADENCE_MS=30000
AGENT_REQUESTS_CACHE_SIZE=1024
4 changes: 2 additions & 2 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MOBILE_GATEWAY_URL="https://mobile-api.fireblocks.io"
CUSTOMER_SERVER_URL="http://localhost:3000/api"
CUSTOMER_SERVER_URL="http://localhost:5000/api"
CUSTOMER_SERVER_AUTHORIZATION=""
CUSTOMER_SERVER_PULL_CADENCE=30000
CUSTOMER_SERVER_PULL_CADENCE_MS=30000
AGENT_REQUESTS_CACHE_SIZE=1024
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MOBILE_GATEWAY_URL="http://localhost:9082"
CUSTOMER_SERVER_URL="http://localhost:3000"
CUSTOMER_SERVER_URL="http://localhost:5000"
CUSTOMER_SERVER_AUTHORIZATION="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
CUSTOMER_SERVER_PULL_CADENCE=30000
CUSTOMER_SERVER_PULL_CADENCE_MS=30000
AGENT_REQUESTS_CACHE_SIZE=1024
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ RUN npm install \
&& npm run build
# && rm -fr node_modules

#EXPOSE 3000

# Start the app using serve command
CMD ["/bin/bash", "-c", "pm2 start dist/index.js && pm2 attach 0"]
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ Fireblocks Agent is an open-source on-prem service written in Typescript which i
- `cd examples/server`
- `npm run build:docker`
- `npm run start:docker`
- Copy `.env.prod` and name it `.env.{env}` for example `.env.dev9`
- Edit your newly created `.env.{env}` file with the right config
- Start fireblocks agent with your desired env i.e `npm run start --env=prod`

- Configure and run Fireblocks agent:
- Copy `.env.prod` and name it `.env.{env-name}` (e.g. `.env.test`)
- Edit your newly created `.env.{env-name}` file with the right configuration
- Start the Fireblocks agent with your desired environment:
- `npm run start --env=env-name`

### Fireblocks Agent Environment Variables
The fireblocks agent expect a configuration file (for production it's called `.env.prod`) with several parameters:
The Fireblocks agent expect a configuration file (for production it's called `.env.prod`) with several parameters:
* `MOBILE_GATEWAY_URL` - In production this value should be `https://mobile-api.fireblocks.io`
* `CUSTOMER_SERVER_URL` - The client's custom server url
* `CUSTOMER_SERVER_PULL_CADENCE` - Cadence of pulling messages status
* `CUSTOMER_SERVER_AUTHORIZATION` - If exists, the fireblocks agent will send its value on the `Authorization` header for each request. The client can use it for authorizing the fireblocks agent or keep track on which agent is calling it
* `CUSTOMER_SERVER_PULL_CADENCE_MS` - Cadence of pulling messages status
* `CUSTOMER_SERVER_AUTHORIZATION` - If exists, the Fireblocks agent will send its value on the `Authorization` header for each request. The client can use it for authorizing the fireblocks agent or keep track on which agent is calling it
* `SSL_CERT_PATH` - If exists, a path to a self-signed SSL certificate which will be used to validate the server certificate


# About the Fireblocks Key Link Workspace
Expand All @@ -49,10 +53,10 @@ The Fireblocks Key Link workspace consists of several components (aka actors). E

* Console - Fireblocks web console. [Link](https://console.fireblocks.io/v2/)
* Mobile App - Fireblocks mobile app.
* Mobile API Gateway - Fireblocks REST API Server. The firblocks agent communicates with this server in the registration flow and for receiving new messages.
* Mobile API Gateway - Fireblocks REST API Server. The Fireblocks agent communicates with this server in the registration flow and for receiving new messages.
* Developer API - Fireblocks back office server for workspace setup and configuration.
* Fireblocks Agent - An on-prem service written in Typescript which is responsible for receiving new messages to sign from Fireblocks, relay these messages to the client's HSM and return the signed result back to Fireblocks.
* Customer Server - The client's own server which receives messages to sign from the fireblocks agent. Sign them via the client's HSM and provide the fireblocks agent with the signed messages.
* Customer Server - The client's own server which receives messages to sign from the Fireblocks agent. Sign them via the client's HSM and provide the Fireblocks agent with the signed messages.
* HSM component - The actual HSM implementation. Can be on prem or a cloud based HSM, or a different Key Management System.

## About the Customer Server
Expand All @@ -75,7 +79,7 @@ The entry point for the server can be found [here](examples/server/src/server.ts
![Pair the Fireblocks Agent Device flow](docs/flows/pair_device_sd.png)

### Add a Validator Key
This procedure should happen once. Fireblocks will need a validator key to approve new signing keys. This flow is done via the fireblocks sdk and not via this program.
This procedure should happen once. Fireblocks will need a validator key to approve new signing keys. This flow is done via the Fireblocks sdk and not via this program.

![Add validator key flow](docs/flows/add_validator_key.png)

Expand Down
1 change: 0 additions & 1 deletion examples/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ RUN npm run initToken
RUN npm install \
&& npm run build


USER root

EXPOSE 5000
Expand Down
22 changes: 21 additions & 1 deletion examples/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@
This server implement an example integration with HSM module assuming SoftHSM.
- Hardcoded PIN used in the example is "1234"
- The example uses first available slot which is usually slot 0
- Current example supports only ECDSA secp256k1 curve.
- Current example supports ECDSA secp256k1 and EdDSA Ed25519 curves

# Support for self signed certificate
The server can support self signed certificate when accepting SSL connections from the Agent.
In order to run the server with self signed certificate, follow the following steps:
1. Make sure to have an openssl Subject Alternative Name (SAN) certificates configuration file
- You can find an example file at examples/server/env/san.cnf
2. Create a private key using openssl
- `openssl genrsa -out priv-key.txt 2048`
3. Create a Certificate certificate signing requests (CSR) file
- `openssl req -new -key priv-key.txt -out csr.txt -config san.cnf`
4. Create a self signed certificate
- `openssl x509 -req -days 3650 -in csr.txt -signkey priv-key.txt -out self-signed-cert.txt -extfile san.cnf -extensions v3_req`
5. Validate the self signed certificate has all the information required
- `openssl x509 -in self-signed-cert.txt -noout -text`
6. Add two parameters to your server environment file (e.g. /example/server/env/dev.env)
- `SELF_SIGNED_SSL_PRIV_KEY_PATH="./env/priv-key.txt"
SELF_SIGNED_SSL_CERT_PATH="./env/self-signed-cert.txt"`
7. Start the server, it will automatically run in SSL if the defined files are found
8. In order for the Agent to accept the self signed certificate, add the following to the Agent env file (e.g. .env.prod)
- `SSL_CERT_PATH="./examples/server/env/self-signed-cert.txt"`
2 changes: 1 addition & 1 deletion examples/server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- softhsm:/usr/local/lib/softhsm/
- tokens:/tokens/
ports:
- 3000:3000
- 5000:5000
- 35729:35729
customer-database:
image: mongo:6
Expand Down
23 changes: 23 additions & 0 deletions examples/server/env/san.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
copy_extensions = copy

[req_distinguished_name]
countryName = XX
stateOrProvinceName = N/A
localityName = N/A
organizationName = Self-signed certificate
commonName = 120.0.0.1: Self-signed certificate

[req_ext]
subjectAltName = @alt_names

[v3_req]
subjectAltName = @alt_names

[alt_names]
IP.1 = 127.0.0.1
Loading
Loading