Skip to content

Commit cc5b79b

Browse files
authored
Merge pull request #184 from VRamakrishna/main
Enable TLS in Relay, Drivers, and Apps
2 parents ef4d7ae + d6795f6 commit cc5b79b

File tree

44 files changed

+561
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+561
-401
lines changed

common/protos-java-kt/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ buildscript {
1414

1515
plugins {
1616
id "maven-publish"
17-
id 'java'
18-
id 'com.google.protobuf' version '0.8.12'
17+
id 'java'
18+
id 'com.google.protobuf' version '0.8.12'
1919
id 'idea'
2020
}
2121

@@ -124,4 +124,4 @@ publishing {
124124
}
125125
}
126126
}
127-
}
127+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name=Interop Protos
22
group=com.weaver
3-
version=1.2.4-alpha.4
3+
version=1.2.4-alpha.5
44
kotlin.incremental=false

core/drivers/corda-driver/README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ To run the driver, use the following:
5757

5858
The driver gRPC server will be listening on port `9099`.
5959

60+
### With TLS
61+
62+
If the relay expects a TLS connection over gRPC, you need to specify the following environment variables in the `corda-driver` command:
63+
- `RELAY_TLS`: should be set to `true`
64+
- One of the following:
65+
* If the relay server TLS CA certificates are in a password-protected Java Key Store (JKS file):
66+
- `RELAY_TLSCA_TRUST_STORE`: JKS file path
67+
- `RELAY_TLSCA_TRUST_STORE_PASSWORD`: password used to create the JKS file
68+
* If the relay server TLS CA certificates are in separate PEM files in the filesystem:
69+
- `RELAY_TLSCA_CERT_PATHS`: colon-separated list of CA certificate file paths
70+
If you wish to run the driver service with TLS enabled, you need to specify the following environment variables in the `corda-driver` command:
71+
- `DRIVER_TLS`: should be set to `true`
72+
- `DRIVER_CERT_PATH`: driver's TLS certificate file path
73+
- `DRIVER_KEY_PATH`: driver's TLS private key file path
74+
- Example: both relay and driver are TLS-enabled, and a trust store is used as a certificate repository:
75+
```bash
76+
RELAY_TLS=true RELAY_TLSCA_TRUST_STORE_PASSWORD=password RELAY_TLSCA_TRUST_STORE=trust_store.jks DRIVER_TLS=true DRIVER_CERT_PATH=cert.pem DRIVER_KEY_PATH=key.pem ./build/install/corda-driver/bin/corda-driver
77+
```
78+
- Example: only relay is TLS-enabled, and the driver's trusted certificates are in separate files in the filesystem:
79+
```bash
80+
RELAY_TLS=true RELAY_TLSCA_CERT_PATHS=ca_cert1.pem:ca_cert2.pem ./build/install/corda-driver/bin/corda-driver
81+
```
82+
6083
## Driver configuration
6184

6285
By default, the driver gRPC server listens on port `9099`. To change the port, set
@@ -84,15 +107,18 @@ To push image to github container registry:
84107

85108
**NOTE:** Push image to `hyperledger-labs` only after PR approval, first test it by deploying it on your fork by running (instead of last step above): `make push-image DOCKER_REGISTRY=ghcr.io/<username>`, where replace `<username>` with your git username.
86109

87-
### Docker-compose Deployment
110+
### Docker-Compose Deployment
88111

89112
* Copy `.env.docker.template` to `.env`
90-
- `NETWORK_NAME`: Used as suffix to corda-driver container name, i.e. `corda-driver-<network-name>` will be the name of container.
113+
- `NETWORK_NAME`: Used as suffix to corda-driver container name, i.e. `corda-driver-<network-name>` will be the name of the container.
91114
- `DRIVER_PORT`: Driver server port.
92-
- `EXTERNAL_NETWORK`: is the docker network in which corda-network is running.
93-
- `DOCKER_IMAGE_NAME`: Keep it same.
115+
- `DRIVER_RPC_USERNAME`: RPC user registered for Driver.
116+
- `DRIVER_RPC_PASSWORD`: Password for the above RPC user.
117+
- `EXTERNAL_NETWORK`: Name of the docker network in which the Corda containers are deployed.
118+
- `DOCKER_IMAGE_NAME`: _Keep this unchanged_.
94119
- `DOCKER_TAG`: Refer here for the image tags available: [weaver-corda-driver](https://github.com/hyperledger-labs/weaver-dlt-interoperability/pkgs/container/weaver-corda-driver)
95-
- `DOCKER_REGISTRY`: Keep it same. (replace `hyperledger-labs` with your git username if testing from your fork)
120+
- `COMPOSE_PROJECT_NAME`: Docker project name for the Corda network to which this driver is supposed to attach. By default, the folder name of the Corda network's `docker-compose.yml`, is the project name.
121+
- `COMPOSE_PROJECT_NETWORK`: Docker project network name for the Corda network to which this driver is supposed to attach. By default, `default` is the project network name.
96122
* Create a Personal Access Token with read packages access in github. Refer [Creating a Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) for help.
97123
* Run `docker login ghcr.io` and use your github username and personal access token as password.
98124
* Run: `make deploy`.

core/drivers/corda-driver/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ buildscript {
22
ext.kotlin_version = "1.3.61"
33
ext.coroutines_version = "1.3.3"
44
ext.protobuf_version = "3.11.1"
5+
ext.bcprov_version = "1.53"
56
ext.grpc_version = "1.28.1" // CURRENT_GRPC_VERSION
67
ext.grpc_kotlin_version = "0.1.3" // CURRENT_GRPC_KOTLIN_VERSION
78
ext.corda_release_group = "net.corda"
@@ -49,6 +50,7 @@ repositories {
4950
flatDir {
5051
dirs '../../network/corda-interop-app/interop-contracts/build/libs'
5152
dirs '../../network/corda-interop-app/interop-workflows/build/libs'
53+
dirs '../../../sdks/corda/build/libs'
5254
dirs '../../../common/protos-java-kt/build/libs'
5355
}
5456

@@ -60,6 +62,8 @@ apply plugin: "kotlin"
6062
dependencies {
6163
// This repo
6264
implementation "io.grpc:grpc-kotlin-stub:$grpc_kotlin_version"
65+
implementation "io.grpc:grpc-okhttp:$grpc_version"
66+
implementation "org.bouncycastle:bcprov-jdk15on:$bcprov_version"
6367

6468
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
6569
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
@@ -81,6 +85,7 @@ dependencies {
8185

8286
implementation(group: 'com.weaver.corda.app.interop', name: 'interop-contracts', version: "$weaver_version")
8387
implementation(group: 'com.weaver.corda.app.interop', name: 'interop-workflows', version: "$weaver_version")
88+
implementation(group: 'com.weaver.corda.sdk', name: 'weaver-corda-sdk', version: "$weaver_version")
8489
implementation(group: 'com.weaver', name: 'protos-java-kt', version: "$weaver_version")
8590

8691
// gRPC and protobuf dependencies

core/drivers/corda-driver/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DOCKER_IMAGE_NAME ?= weaver-corda-driver
2-
DOCKER_TAG ?= 1.2.4-alpha.1
2+
DOCKER_TAG ?= 1.2.4-alpha.5
33
DOCKER_REGISTRY ?= ghcr.io/hyperledger-labs
44
GIT_URL = https://github.com/hyperledger-labs/weaver-dlt-interoperability/core/drivers/corda-driver
55
COMPOSE_ARG ?=

core/drivers/corda-driver/src/main/kotlin/CordaDriver.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import arrow.core.extensions.either.applicative.applicative
1111
import arrow.core.extensions.list.traverse.traverse
1212
import com.google.gson.Gson
1313
import net.corda.core.messaging.startFlow
14-
import io.grpc.ManagedChannelBuilder
1514
import kotlinx.coroutines.*
1615
import com.google.protobuf.ByteString
1716
import net.corda.core.messaging.CordaRPCOps
1817
import java.util.*
1918

2019
import com.weaver.corda.app.interop.flows.HandleExternalRequest
20+
import com.weaver.corda.sdk.InteroperableHelper
2121
import com.weaver.protos.common.query.QueryOuterClass
2222
import com.weaver.protos.common.state.State
2323
import com.weaver.protos.corda.ViewDataOuterClass
@@ -144,11 +144,14 @@ fun createAggregatedCordaView(views: List<State.View>) : Either<Error, State.Vie
144144
fun createGrpcConnection(address: String) = try {
145145
parseRelayAddress(address).map { relayAddresses ->
146146
// TODO: if the first relay address fails, retry with other relay addresses in the list.
147-
GrpcClient(
148-
ManagedChannelBuilder.forAddress(relayAddresses[0].host, relayAddresses[0].port)
149-
.usePlaintext()
150-
.executor(Dispatchers.Default.asExecutor())
151-
.build())
147+
val channel = InteroperableHelper.getChannelToRelay(
148+
relayAddresses[0].host,
149+
relayAddresses[0].port,
150+
System.getenv("RELAY_TLS")?.toBoolean() ?: false,
151+
System.getenv("RELAY_TLSCA_TRUST_STORE")?.toString() ?: "",
152+
System.getenv("RELAY_TLSCA_TRUST_STORE_PASSWORD")?.toString() ?: "",
153+
System.getenv("RELAY_TLSCA_CERT_PATHS")?.toString() ?: "")
154+
GrpcClient(channel)
152155
}
153156
} catch (e: Exception) {
154157
println("Driver Error: Error creating relay gRPC client: ${e.message}")

core/drivers/corda-driver/src/main/kotlin/GrpcServer.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package com.weaver.corda.driver
88

9+
import java.io.File
910
import io.grpc.Server
1011
import io.grpc.ServerBuilder
1112
import kotlinx.coroutines.*
@@ -21,10 +22,23 @@ import com.weaver.protos.driver.driver.DriverCommunicationGrpcKt
2122
* dispatching them to the correct network node and returning an Ack to the requesting gRPC client.
2223
*/
2324
class GrpcServer(private val port: Int) {
24-
val server: Server = ServerBuilder
25-
.forPort(port)
26-
.addService(GrpcService())
27-
.build()
25+
val server: Server
26+
val useTlsForDriver = (System.getenv("DRIVER_TLS")?.toBoolean() ?: false)
27+
28+
init {
29+
if (useTlsForDriver) {
30+
server = ServerBuilder
31+
.forPort(port)
32+
.useTransportSecurity(File(System.getenv("DRIVER_CERT_PATH")?.toString() ?: ""), File(System.getenv("DRIVER_KEY_PATH")?.toString() ?: ""))
33+
.addService(GrpcService())
34+
.build()
35+
} else {
36+
server = ServerBuilder
37+
.forPort(port)
38+
.addService(GrpcService())
39+
.build()
40+
}
41+
}
2842

2943
/**
3044
* The start() method is used to bring up the gRPC server of the driver.
@@ -80,4 +94,4 @@ class GrpcServer(private val port: Int) {
8094
return ack
8195
}
8296
}
83-
}
97+
}

core/drivers/fabric-driver/.env.docker.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
CONNECTION_PROFILE=<path_to_connection_profile>
22
DRIVER_CONFIG=<path_to_config_json>
33
RELAY_ENDPOINT=<relay-hostname>:<relay-port>
4+
RELAY_TLS=false
5+
RELAY_TLSCA_CERT_PATH=<path_to_tls_ca_cert_pem_for_relay>
46
NETWORK_NAME=<network-name>
57
DRIVER_PORT=<driver-server-port>
8+
DRIVER_TLS=false
9+
DRIVER_TLS_CERT_PATH=<path_to_tls_cert_pem_for_driver>
10+
DRIVER_TLS_KEY_PATH=<path_to_tls_key_pem_for_driver>
611
INTEROP_CHAINCODE=<interop-chaincode-name>
712
DOCKER_IMAGE_NAME=ghcr.io/hyperledger-labs/weaver-fabric-driver
813
DOCKER_TAG=1.2.1
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CONNECTION_PROFILE=path_to_connection_profile
22
RELAY_ENDPOINT=localhost:9080
3+
RELAY_TLS=false
4+
RELAY_TLSCA_CERT_PATH=path_to_tls_ca_cert_pem_for_relay
35
DRIVER_ENDPOINT=localhost:9090
6+
DRIVER_TLS=false
7+
DRIVER_TLS_CERT_PATH=path_to_tls_cert_pem_for_driver
8+
DRIVER_TLS_KEY_PATH=path_to_tls_key_pem_for_driver
49
NETWORK_NAME=network1
510
DRIVER_CONFIG=
6-
INTEROP_CHAINCODE=interop
11+
INTEROP_CHAINCODE=interop

core/drivers/fabric-driver/readme.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,30 @@ NOTE: Minimum requirement of npm v5.0 for patch-package to apply the patch for t
1616

1717
### Setup
1818

19-
The .env (check .env.template, more information [here](#Environment-variables)) and config.json files need to be checked and updated to match the network and relay that it will be connecting to.
19+
Create a `.env` file using `.env.template` as the base and setting suitable environment variable values (see [here](#Environment-variables)) and `config.json` files need to be checked and updated to match the network and relay that it will be connecting to.
2020
The .env contains information related to the network and relay. The config.json contains information about the ca admin, user and its org, that is used when connecting to the network.
2121

22+
#### Enabling TLS
23+
24+
If the relay is TLS-enabled, set the following values in the `.env`:
25+
```
26+
RELAY_TLS=true
27+
RELAY_TLSCA_CERT_PATH=path_to_tls_ca_cert_pem_for_relay
28+
```
29+
- `path_to_tls_ca_cert_pem_for_relay` should be set to CA certificate file path
30+
31+
To enforce secure communication over TLS with your driver, set the following values in the `.env`:
32+
```
33+
DRIVER_TLS=true
34+
DRIVER_TLS_CERT_PATH=path_to_tls_cert_pem_for_driver
35+
DRIVER_TLS_KEY_PATH=path_to_tls_key_pem_for_driver
36+
```
37+
- `path_to_tls_cert_pem_for_driver` should be set to driver's TLS certificate file path
38+
- `path_to_tls_key_pem_for_driver` should be set to driver's TLS private key file path
39+
2240
### Running
2341

24-
To do a full build run then `make build-local`. This update/clones protos, generates js protos and compiles typescript.
42+
To do a full build run then `make build-local`. This update/clones protos, generates js protos and compiles TypeScript.
2543

2644
For tsc compilation in watch mode: `npm run watch`
2745

0 commit comments

Comments
 (0)