Skip to content

Commit 59b4af4

Browse files
outSHpetermetz
authored andcommitted
feat(secret): remove Validator/Verifier secret keys from repository
- Remove validator sample CA keys hardcoded inside the repository. - Generate fresh ECDSA keys when starting up electricity-trade or discounted-asset-trade sample apps. - Add support for RSA CA keys in fabric-socketio validator. I couldn't find any trivial way of generating ECDSA self-signed certificate (without calling openssl cmdline, which seems poor from functional test perspective), so I've added support for RSA keys to simplify the tests. - Allow selection of jwt algorithm in fabric-socketio validator. It must correspond to the key used. - Update the READMEs, add short description of SSL config option of fabric-socketio validator. Closes: 2016 Closes: 2017 Depends on: 1977 Depends on: 2030 Signed-off-by: Michal Bajer <[email protected]>
1 parent 3c561a8 commit 59b4af4

File tree

35 files changed

+353
-151
lines changed

35 files changed

+353
-151
lines changed

examples/cactus-example-discounted-asset-trade/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update \
1717
# Note - indy_sdk:latest must be ABI compatible with this image OS
1818
COPY --from=indy-sdk-cli:latest /usr/lib/libindy.so /usr/lib/
1919

20-
COPY ./package.json ./dist/yarn.lock ./dist/fabric-connector.crt ./dist/ethereum-connector.crt ./dist/indy-connector.crt ./
20+
COPY ./package.json ./dist/yarn.lock ./
2121
RUN yarn add "${CACTUS_CMD_SOCKETIO_PATH}" "@hyperledger/cactus-verifier-client@${NPM_PKG_VERSION}" \
2222
--production --ignore-engines --non-interactive --cache-folder ./.yarnCache && \
2323
rm -rf ./.yarnCache

examples/cactus-example-discounted-asset-trade/config/validator-registry-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ledgerPluginInfo:
33
validatorID: 84jUisrs
44
validatorType: legacy-socketio
55
validatorURL: https://ethereum-validator:5050
6-
validatorKeyPath: /root/cactus/ethereum-connector.crt
6+
validatorKeyPath: /etc/cactus/connector-go-ethereum-socketio/CA/connector.crt
77
maxCounterRequestID: 100
88
syncFunctionTimeoutMillisecond: 5000
99
socketOptions:
@@ -42,7 +42,7 @@ ledgerPluginInfo:
4242
validatorID: r9IS4dDf
4343
validatorType: legacy-socketio
4444
validatorURL: https://fabric-socketio-validator:5040
45-
validatorKeyPath: /root/cactus/fabric-connector.crt
45+
validatorKeyPath: /etc/cactus/connector-fabric-socketio/CA/connector.crt
4646
maxCounterRequestID: 100
4747
syncFunctionTimeoutMillisecond: 5000
4848
socketOptions:
@@ -57,7 +57,7 @@ ledgerPluginInfo:
5757
validatorID: 3PfTJw8g
5858
validatorType: legacy-socketio
5959
validatorURL: http://indy-validator-nginx:10080
60-
validatorKeyPath: /root/cactus/indy-connector.crt
60+
validatorKeyPath: /etc/cactus/validator_socketio_indy/CA/connector.crt
6161
maxCounterRequestID: 100
6262
syncFunctionTimeoutMillisecond: 5000
6363
socketOptions:

examples/cactus-example-discounted-asset-trade/package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
"build": "npm run build-ts && npm run build:dev:backend:postbuild",
1212
"build-ts": "tsc",
1313
"build_pip_indy_package": "cd ../../packages-python/cactus_validator_socketio_indy && python3 setup.py bdist_wheel",
14-
"build:dev:backend:postbuild": "npm run copy-yarn-lock && npm run copy-validator-keys",
15-
"copy-yarn-lock": "cp -f ../../yarn.lock ./dist/",
16-
"copy-validator-keys": "npm run copy-fabric-key && npm run copy-ethereum-key && npm run copy-indy-key",
17-
"copy-fabric-key": "cp -fr ../../packages/cactus-plugin-ledger-connector-fabric-socketio/sample-config/CA/connector.crt ./dist/fabric-connector.crt",
18-
"copy-ethereum-key": "cp -fr ../../packages/cactus-plugin-ledger-connector-go-ethereum-socketio/sample-config/CA/connector.crt ./dist/ethereum-connector.crt",
19-
"copy-indy-key": "cp -fr ../../packages-python/cactus_validator_socketio_indy/sample-CA/connector.crt ./dist/indy-connector.crt"
14+
"build:dev:backend:postbuild": "cp -f ../../yarn.lock ./dist/"
2015
},
2116
"dependencies": {
2217
"axios": "0.24.0",

examples/cactus-example-discounted-asset-trade/script-start-ledgers.sh

+47-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,50 @@ export CACTUS_FABRIC_ALL_IN_ONE_CONTAINER_NAME="asset_trade_faio2x_testnet"
1313
export CACTUS_FABRIC_ALL_IN_ONE_VERSION="2.2.0"
1414
export CACTUS_FABRIC_TEST_LOOSE_MEMBERSHIP=1
1515

16+
# Cert options
17+
CERT_CURVE_NAME="prime256v1"
18+
CERT_COUNTRY="JP"
19+
CERT_STATE="Tokyo"
20+
CERT_LOCALITY="Minato-Ku"
21+
CERT_ORG="CactusSamples"
22+
23+
# generate_certificate <common-name> <destination>
24+
function generate_certificate() {
25+
# Check OpenSSL command existance
26+
if ! openssl version > /dev/null; then
27+
echo "Could not execute [openssl version], check if OpenSSL tool is available on the system."
28+
exit 1;
29+
fi
30+
31+
# Check input parameters
32+
ARGS_NUMBER=2
33+
if [ "$#" -lt "$ARGS_NUMBER" ]; then
34+
echo "generate_certificate called with wrong number of arguments (expected - $ARGS_NUMBER, actual - $#)";
35+
exit 2
36+
fi
37+
38+
common_name=$1
39+
destination=$2
40+
subject="/C=$CERT_COUNTRY/ST=$CERT_STATE/L=$CERT_LOCALITY/O=$CERT_ORG/CN=$common_name"
41+
echo "Create new cert in '${destination}' with subject '${subject}'"
42+
43+
# Crete destination path
44+
if [ ! -d "$destination" ]; then
45+
echo "Re-create destination dir..."
46+
rm -rf "$destination"
47+
mkdir -p "$destination"
48+
fi
49+
50+
keyPath="${destination}/connector.priv"
51+
csrPath="${destination}/connector.csr"
52+
certPath="${destination}/connector.crt"
53+
54+
# Generate keys
55+
openssl ecparam -genkey -name "$CERT_CURVE_NAME" -out "$keyPath"
56+
openssl req -new -sha256 -key "$keyPath" -out "$csrPath" -subj "$subject"
57+
openssl req -x509 -sha256 -days 365 -key "$keyPath" -in "$csrPath" -out "$certPath"
58+
}
59+
1660
function start_fabric_testnet() {
1761
echo ">> start_fabric_testnet()"
1862
pushd "${ROOT_DIR}/tools/docker/fabric-all-in-one"
@@ -54,6 +98,7 @@ function copy_fabric_validator_config() {
5498
echo ">> copy_fabric_validator_config()"
5599
cp -fr ${ROOT_DIR}/packages/cactus-plugin-ledger-connector-fabric-socketio/sample-config/* \
56100
"${CONFIG_VOLUME_PATH}/connector-fabric-socketio/"
101+
generate_certificate "FabricSocketIOCactusValidator" "${CONFIG_VOLUME_PATH}/connector-fabric-socketio/CA/"
57102
echo ">> copy_fabric_validator_config() done."
58103

59104
echo ">> copy_fabric_wallet()"
@@ -71,6 +116,7 @@ function copy_ethereum_validator_config() {
71116
echo ">> copy_ethereum_validator_config()"
72117
cp -fr ${ROOT_DIR}/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/sample-config/* \
73118
"${CONFIG_VOLUME_PATH}/connector-go-ethereum-socketio/"
119+
generate_certificate "GoEthereumCactusValidator" "${CONFIG_VOLUME_PATH}/connector-go-ethereum-socketio/CA/"
74120
echo ">> copy_ethereum_validator_config() done."
75121
}
76122

@@ -91,7 +137,7 @@ function copy_indy_validator_config() {
91137

92138
function copy_indy_validator_ca() {
93139
echo ">> copy_indy_validator_ca()"
94-
cp -fr "${ROOT_DIR}/packages-python/cactus_validator_socketio_indy/sample-CA/" "${CONFIG_VOLUME_PATH}/validator_socketio_indy/CA"
140+
generate_certificate "IndyCactusValidator" "${CONFIG_VOLUME_PATH}/validator_socketio_indy/CA/"
95141
echo ">> copy_indy_validator_ca() done."
96142
}
97143

examples/cactus-example-electricity-trade/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV APP_HOME=/root/cactus
66

77
WORKDIR ${APP_HOME}
88

9-
COPY ./dist/yarn.lock ./package.json ./dist/ethereum-connector.crt ./dist/sawtooth-connector.crt ./
9+
COPY ./dist/yarn.lock ./package.json ./
1010
RUN yarn add "${CACTUS_CMD_SOCKETIO_PATH}" "@hyperledger/cactus-verifier-client@${NPM_PKG_VERSION}" \
1111
--production --ignore-engines --non-interactive --cache-folder ./.yarnCache && \
1212
rm -rf ./.yarnCache

examples/cactus-example-electricity-trade/config/validator-registry-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ledgerPluginInfo:
33
validatorID: 84jUisrs
44
validatorType: legacy-socketio
55
validatorURL: https://ethereum-validator:5050
6-
validatorKeyPath: /root/cactus/ethereum-connector.crt
6+
validatorKeyPath: /etc/cactus/connector-go-ethereum-socketio/CA/connector.crt
77
maxCounterRequestID: 100
88
syncFunctionTimeoutMillisecond: 5000
99
socketOptions:
@@ -42,7 +42,7 @@ ledgerPluginInfo:
4242
validatorID: sUr7d10R
4343
validatorType: legacy-socketio
4444
validatorURL: https://sawtooth-validator:5140
45-
validatorKeyPath: /root/cactus/sawtooth-connector.crt
45+
validatorKeyPath: /etc/cactus/connector-sawtooth-socketio/CA/connector.crt
4646
maxCounterRequestID: 100
4747
syncFunctionTimeoutMillisecond: 5000
4848
socketOptions:

examples/cactus-example-electricity-trade/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
"start": "docker-compose build && docker-compose up",
1111
"build": "npm run build-ts && npm run build:dev:backend:postbuild",
1212
"build-ts": "tsc",
13-
"build:dev:backend:postbuild": "npm run copy-yarn-lock && npm run copy-validator-keys",
14-
"copy-yarn-lock": "cp -f ../../yarn.lock ./dist/",
15-
"copy-validator-keys": "npm run copy-ethereum-key && npm run copy-sawtooth-key",
16-
"copy-ethereum-key": "cp -fr ../../packages/cactus-plugin-ledger-connector-go-ethereum-socketio/sample-config/CA/connector.crt ./dist/ethereum-connector.crt",
17-
"copy-sawtooth-key": "cp -fr ../../packages/cactus-plugin-ledger-connector-sawtooth-socketio/sample-config/CA/connector.crt ./dist/sawtooth-connector.crt"
13+
"build:dev:backend:postbuild": "cp -f ../../yarn.lock ./dist/"
1814
},
1915
"dependencies": {
2016
"@types/node": "14.18.12",

examples/cactus-example-electricity-trade/script-start-ledgers.sh

+46
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,50 @@ set -e
77
ROOT_DIR="../.." # Path to cactus root dir
88
CONFIG_VOLUME_PATH="./etc/cactus" # Docker volume with shared configuration
99

10+
# Cert options
11+
CERT_CURVE_NAME="prime256v1"
12+
CERT_COUNTRY="JP"
13+
CERT_STATE="Tokyo"
14+
CERT_LOCALITY="Minato-Ku"
15+
CERT_ORG="CactusSamples"
16+
17+
# generate_certificate <common-name> <destination>
18+
function generate_certificate() {
19+
# Check OpenSSL command existance
20+
if ! openssl version > /dev/null; then
21+
echo "Could not execute [openssl version], check if OpenSSL tool is available on the system."
22+
exit 1;
23+
fi
24+
25+
# Check input parameters
26+
ARGS_NUMBER=2
27+
if [ "$#" -lt "$ARGS_NUMBER" ]; then
28+
echo "generate_certificate called with wrong number of arguments (expected - $ARGS_NUMBER, actual - $#)";
29+
exit 2
30+
fi
31+
32+
common_name=$1
33+
destination=$2
34+
subject="/C=$CERT_COUNTRY/ST=$CERT_STATE/L=$CERT_LOCALITY/O=$CERT_ORG/CN=$common_name"
35+
echo "Create new cert in '${destination}' with subject '${subject}'"
36+
37+
# Crete destination path
38+
if [ ! -d "$destination" ]; then
39+
echo "Re-create destination dir..."
40+
rm -rf "$destination"
41+
mkdir -p "$destination"
42+
fi
43+
44+
keyPath="${destination}/connector.priv"
45+
csrPath="${destination}/connector.csr"
46+
certPath="${destination}/connector.crt"
47+
48+
# Generate keys
49+
openssl ecparam -genkey -name "$CERT_CURVE_NAME" -out "$keyPath"
50+
openssl req -new -sha256 -key "$keyPath" -out "$csrPath" -subj "$subject"
51+
openssl req -x509 -sha256 -days 365 -key "$keyPath" -in "$csrPath" -out "$certPath"
52+
}
53+
1054
function start_ethereum_testnet() {
1155
pushd "${ROOT_DIR}/tools/docker/geth-testnet"
1256
./script-start-docker.sh
@@ -17,6 +61,7 @@ function copy_ethereum_validator_config() {
1761
echo ">> copy_ethereum_validator_config()"
1862
cp -fr ${ROOT_DIR}/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/sample-config/* \
1963
"${CONFIG_VOLUME_PATH}/connector-go-ethereum-socketio/"
64+
generate_certificate "GoEthereumCactusValidator" "${CONFIG_VOLUME_PATH}/connector-go-ethereum-socketio/CA/"
2065
echo ">> copy_ethereum_validator_config() done."
2166
}
2267

@@ -33,6 +78,7 @@ function copy_sawtooth_validator_config() {
3378
echo ">> copy_sawtooth_validator_config()"
3479
cp -fr ${ROOT_DIR}/packages/cactus-plugin-ledger-connector-sawtooth-socketio/sample-config/* \
3580
"${CONFIG_VOLUME_PATH}/connector-sawtooth-socketio/"
81+
generate_certificate "SawtoothCactusValidator" "${CONFIG_VOLUME_PATH}/connector-sawtooth-socketio/CA/"
3682
echo ">> copy_sawtooth_validator_config() done."
3783
}
3884

Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
CactusValidatorSocketIOIndy.egg-info/
1+
CactusValidatorSocketIOIndy.egg-info/
2+
testcli/connector.crt

packages-python/cactus_validator_socketio_indy/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ WORKDIR /home/indy
1010
COPY --chown=indy:indy './dist/CactusValidatorSocketIOIndy-0.0.1-py3-none-any.whl' '/home/indy'
1111
RUN pip3 install /home/indy/CactusValidatorSocketIOIndy-0.0.1-py3-none-any.whl
1212

13-
user root
13+
USER root
1414
RUN python3 /home/indy/.local/lib/python3.8/site-packages/other/post_install_script.py
1515

16-
user indy
16+
USER indy
1717
ARG pool_ip=172.16.0.2
1818
ENV TEST_POOL_IP=$pool_ip
1919

packages-python/cactus_validator_socketio_indy/README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@
1515
1. Start indy testnet pool (follow instructions from `../../tools/docker/indy-testnet/` README). It should create docker network `indy-testnet_indy_net`, pool should be available at `172.16.0.2`.
1616
1. Generate proof and store it in local `/etc/cactus`:
1717
```
18+
rm -r /etc/cactus/validator_socketio_indy/*
1819
cd ../../examples/register-indy-data/
19-
2020
./script-build-docker.sh
21-
2221
docker run --rm -ti -v/etc/cactus/:/etc/cactus/ --net="host" register-indy-data --proof_only
2322
```
2423
1. Copy indy validator config
2524
```
26-
mkdir -p /etc/cactus/validator_socketio_indy/
27-
rm -r /etc/cactus/validator_socketio_indy/*
2825
cp -rf ./config/* /etc/cactus/validator_socketio_indy/
2926
```
30-
1. Copy default validator CA
27+
1. Generate validator certificate using OpenSSL tool
3128
```
32-
rm -r /etc/cactus/validator_socketio_indy/CA
33-
cp -rf ./sample-CA/ /etc/cactus/validator_socketio_indy/CA
29+
mkdir -p "/etc/cactus/validator_socketio_indy/CA/"
30+
openssl ecparam -genkey -name "prime256v1" -out "/etc/cactus/validator_socketio_indy/CA/connector.priv"
31+
openssl req -new -sha256 -key "/etc/cactus/validator_socketio_indy/CA/connector.priv" \
32+
-out "/etc/cactus/validator_socketio_indy/CA/connector.csr" \
33+
-subj "/C=JP/ST=Tokyo/L=Minato-Ku/O=CactusSamples/CN=IndyValidator"
34+
openssl req -x509 -sha256 -days 365 -key "/etc/cactus/validator_socketio_indy/CA/connector.priv" \
35+
-in "/etc/cactus/validator_socketio_indy/CA/connector.csr" \
36+
-out "/etc/cactus/validator_socketio_indy/CA/connector.crt"
3437
```
3538
1. Build and run validator container:
3639
```
@@ -41,9 +44,8 @@
4144
1. Open separate console, install dependencies and run the testing script:
4245
```
4346
cd testcli/
44-
47+
ln -s /etc/cactus/validator_socketio_indy/CA/connector.crt .
4548
npm install
46-
4749
node testsock.js
4850
```
4951

packages-python/cactus_validator_socketio_indy/post_install_script.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __copy(source: str, destination: str) -> bool:
7373
# Copy supervisord.conf file
7474
if __copy(source=f'{SITE_PACKAGES}/other/supervisord.conf', destination='/etc'):
7575
print('supervisord file successfully copied')
76+
7677
# Copy utils.py
7778
if __copy(source=f'{UTILS_LOCATION}/utils.py',
7879
destination=f'{VALIDATOR_DST_DIR}/validator_socketio_module'):

packages-python/cactus_validator_socketio_indy/sample-CA/connector.crt

-10
This file was deleted.

packages-python/cactus_validator_socketio_indy/sample-CA/connector.priv

-8
This file was deleted.

packages-python/cactus_validator_socketio_indy/testcli/connector.crt

-1
This file was deleted.

packages/cactus-api-client/src/main/typescript/socketio-api-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function verifyValidatorJwt(
3636
): Promise<JwtPayload> {
3737
return new Promise((resolve, reject) => {
3838
const option: VerifyOptions = {
39-
algorithms: ["ES256"],
39+
algorithms: ["ES256", "ES384", "ES512", "RS256", "RS384", "RS512"],
4040
};
4141

4242
verify(

packages/cactus-cmd-api-server/src/main/typescript/config/self-signed-pki-generator.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
/**
2+
* @deprecated Moved to packages/cactus-test-tooling/src/main/typescript/pki/self-signed-pki-generator.ts
3+
*/
4+
15
import { pki, md } from "node-forge";
26
import { v4 as uuidV4 } from "uuid";
37
import { Strings } from "@hyperledger/cactus-common";
48

9+
/**
10+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
11+
*/
512
export type ForgeKeyPair = pki.rsa.KeyPair;
13+
/**
14+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
15+
*/
616
export type ForgePrivateKey = pki.rsa.PrivateKey;
17+
/**
18+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
19+
*/
720
export type ForgeCertificate = pki.Certificate;
21+
/**
22+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
23+
*/
824
export type ForgeCertificateField = pki.CertificateField;
925

1026
/**
27+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
28+
*
1129
* PKI as in public key infrastructure and x509 certificates.
1230
*/
1331
export interface IPki {
@@ -18,6 +36,8 @@ export interface IPki {
1836
}
1937

2038
/**
39+
* @deprecated Moved to \@hyperledger/cactus-test-tooling
40+
*
2141
* Do not use this for anything in a production deployment. It's meant as a helper
2242
* class for development and testing purposes (enhancing developer experience).
2343
*

packages/cactus-plugin-ledger-connector-fabric-socketio/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ docker run -v/etc/cactus/:/etc/cactus -p 5040:5040 --net=fabric-all-in-one_testn
6464
npm run start
6565
```
6666
67+
## Configuration
68+
- Validator can be configured in `/etc/cactus/connector-fabric-socketio/default.yaml` (see [sample-config](./sample-config/default.yaml) for details).
69+
- This configuration can be overwriten in `NODE_CONFIG` environment variable (JSON format). See functional tests for example of that.
70+
6771
## Usage samples
6872
- To confirm the operation of this package, please refer to the following business-logic sample application:
6973
- [cactus-example-discounted-asset-trade](../../examples/cactus-example-discounted-asset-trade)

0 commit comments

Comments
 (0)