Git Product home page Git Product logo

firefly-dataexchange-https's Introduction

Firefly MTLS Data Exchange

The following steps show how to setup Firefly MTLS Data Exchange for two organizations named org-a and org-b running on localhost.

Data exchange diagram

org-a will use port 3000 for API and port 3001 for P2P. org-b will use port 4000 for API and port 4001 for P2P. Each organization will have its own private key and self-signed certificate.

Setup org-a

Environment variables

Open a command line window and set the following environment variables, assigning an appropriate location to DATA_DIRECTORY. This is where configuration and certificate files will reside:

export DATA_DIRECTORY=/data-a
export LOG_LEVEL=info

Configuration file

Create config.json in the data directory and set its content to:

{
  "$schema": "../../src/schemas/config.json",
  "api": {
    "hostname": "0.0.0.0",
    "port": 3000
  },
  "p2p": {
    "hostname": "0.0.0.0",
    "port": 3001
  },
  "apiKey": "xxxxx",
  "peers": [
    {
      "id": "org-b",
      "endpoint": "https://localhost:4001"
    }
  ]
}

Based on this configuration:

  • API will be accessed via 0.0.0.0:3000
  • P2P communications will use 0.0.0.0:3001
  • The API key will be set to xxxxx (this is optional)
  • There is one peer named org-b whose P2P endpoint is https://localhost:4001

Note: the property p2p.endpoint can optionally be used to specify a front facing endpoint. If this property is not provided, the p2p endpoint will be calculated as p2p.hostname:p2p.port

Generate certificate

In the data directory, run the following command:

openssl req -new -x509 -nodes -days 365 -subj '/CN=localhost/O=org-a' -keyout key.pem -out cert.pem

This will generate files key.pem and cert.pem. Notice that the common name is localhost while the organization name is org-a.

Setup org-b

Environment variables

Open a second command line window and set the following environment variables, assigning an appropriate location to DATA_DIRECTORY. This is where configuration and certificate files will reside:

export DATA_DIRECTORY=/data-b
export LOG_LEVEL=info

Configuration file

{
  "$schema": "../../src/schemas/config.json",
  "api": {
    "hostname": "0.0.0.0",
    "port": 4000
  },
  "p2p": {
    "hostname": "0.0.0.0",
    "port": 4001
  },
  "apiKey": "xxxxx",
  "peers": [
    {
      "id": "org-b",
      "endpoint": "https://0.0.0.0:3001"
    }
  ]
}

Based on this configuration:

  • API will be accessed via 0.0.0.0:4000
  • P2P communications will use 0.0.0.0:4001
  • The API key will be set to xxxxx (this is optional)
  • There is one peer named org-a whose P2P endpoint is https://localhost:3001

Note: the property p2p.endpoint can optionally be used to specify a front facing endpoint. If this property is not provided, the p2p endpoint will be calculated as p2p.hostname:p2p.port

Generate certificate

openssl req -new -x509 -nodes -days 365 -subj '/CN=localhost/O=org-b' -keyout key.pem -out cert.pem

This will generate files key.pem and cert.pem. Notice that the common name is localhost while the organization name is org-b.

Copy certificates

  • Copy /org-a/cert.pem to /org-b/peer-certs/org-a.pem.
  • Copy /org-b/cert.pem to /org-a/peer-certs/org-b.pem.

This will make it possible for the organizations to establish MTLS communications with each other.

Build and run the processes

  • Run npm run build.
  • In the command line window for org-a run npm start
  • In the command line window for org-b run npm start

Access the API Swagger

  • Open a new web browser window and navigate to http://localhost:3000
  • Open another web browser window and navigate to http://localhost:4000

WebSocket Events

Type Description Additional properties
blob-received Emitted to the recipient when a blob has been transferred sender, path, hash
blob-delivered Emitted to the sender when a blob has been delivered recipient, path, requestID (optional)
blob-failed Emitted to the sender when a blob could not be delivered recipient, path, requestID (optional)
message-received Emitted to the recipient when a message has been sent sender, message
message-delivered Emitted to the sender when a message has been delivered recipient, message, requestID (optional)
message-failed Emitted to the sender when a message could not be delivered recipient, message, requestID (optional)
  • After receiving a websocket message, a commit must be sent in order to receive the next one:
    { "action": "commit" }
    
  • Messages arrive in the same order they were sent
  • Up to 1,000 messages will be queued

Alternative setup using CA

Generate CA key and cert:

openssl req -new -x509 -nodes -days 365 -subj '/CN=blob-exchange-ca' -keyout ca-key.pem -out ca.crt

Generate org-a key:

openssl genrsa -out org-a.key 2048

Generate org-a CSR:

openssl req -new -key org-a.key -subj '/CN=localhost,O=org-a' -out org-a.csr

Create signed certificate using CSR, CA

openssl x509 -req -in org-a.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 365 -out org-a.crt

Generate org-b key:

openssl genrsa -out org-b.key 2048

Generate org-b CSR:

openssl req -new -key org-b.key -subj '/CN=localhost,O=org-b' -out org-b.csr

Create signed certificate using CSR, CA

openssl x509 -req -in org-b.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 365 -out org-b.crt

firefly-dataexchange-https's People

Contributors

gabriel-indik avatar github-actions[bot] avatar hfuss avatar nguyer avatar peterbroadhurst avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.