-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cmd-socketio-server): remove code duplication
- Moved verifyValidatorJwt to `cactus-common` to keep encrypt/decrypt logic of socketio-based validators in one, common location. - Move config-reading and signMessageJwt helper functions from validators to cmd-socketio-server to remove code duplication. Refactor validators to use these common instead of own implementation. - Remove ValidatorAuthentication.ts that is not used anymore (not part of public interface, it was copied by validators during before couple commits ago). - Create jwt-message-authentication.test.ts from old, similar one in cactus-api-client. - Updated readme with instructions of how to start asset-trade and electricity-trade samples without docker-compose (to be used during development). Added helper script for patching the config. Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
- Loading branch information
Showing
38 changed files
with
480 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
examples/cactus-example-discounted-asset-trade/script-dockerless-config-patch.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2020-2022 Hyperledger Cactus Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
COMMON_CACTUS_CONFIG="/etc/cactus/" | ||
|
||
echo "Note - script must executed from within cactus-example-discounted-asset-trade directory!" | ||
|
||
echo "Copy local cactus config to common location ($COMMON_CACTUS_CONFIG)" | ||
sudo rm -rf "$COMMON_CACTUS_CONFIG" | ||
sudo cp -ar "./etc/cactus" "/etc" | ||
sudo chown -hR $(whoami) "$COMMON_CACTUS_CONFIG" | ||
|
||
echo "Patch validators..." | ||
sed -i 's/asset_trade_faio2x_testnet/localhost/g' "${COMMON_CACTUS_CONFIG}/connector-fabric-socketio/default.yaml" | ||
sed -i 's/geth1/localhost/g' "${COMMON_CACTUS_CONFIG}/connector-go-ethereum-socketio/default.yaml" | ||
|
||
echo "Patch validator-registry-config.yaml..." | ||
sed -i 's/ethereum-validator/localhost/g' "${COMMON_CACTUS_CONFIG}/validator-registry-config.yaml" | ||
sed -i 's/fabric-socketio-validator/localhost/g' "${COMMON_CACTUS_CONFIG}/validator-registry-config.yaml" | ||
sed -i 's/indy-validator-nginx/localhost/g' "${COMMON_CACTUS_CONFIG}/validator-registry-config.yaml" | ||
|
||
echo "Patch path to asset-trade modules." | ||
current_pwd=$(pwd) | ||
escaped_pwd=${current_pwd//\//\\/} | ||
sed -i "s/\/root\/cactus/$escaped_pwd/g" "${COMMON_CACTUS_CONFIG}/usersetting.yaml" | ||
|
||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
examples/cactus-example-electricity-trade/script-dockerless-config-patch.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2020-2022 Hyperledger Cactus Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
COMMON_CACTUS_CONFIG="/etc/cactus/" | ||
|
||
echo "Note - script must executed from within cactus-example-electricity-trade directory!" | ||
|
||
echo "Copy local cactus config to common location ($COMMON_CACTUS_CONFIG)" | ||
sudo rm -rf "$COMMON_CACTUS_CONFIG" | ||
sudo cp -ar "./etc/cactus" "/etc" | ||
sudo chown -hR $(whoami) "$COMMON_CACTUS_CONFIG" | ||
|
||
echo "Patch validators..." | ||
sed -i 's/geth1/localhost/g' "${COMMON_CACTUS_CONFIG}/connector-go-ethereum-socketio/default.yaml" | ||
sed -i 's/rest-api/localhost/g' "${COMMON_CACTUS_CONFIG}/connector-sawtooth-socketio/default.yaml" | ||
|
||
echo "Patch validator-registry-config.yaml..." | ||
sed -i 's/ethereum-validator/localhost/g' "${COMMON_CACTUS_CONFIG}/validator-registry-config.yaml" | ||
sed -i 's/sawtooth-validator/localhost/g' "${COMMON_CACTUS_CONFIG}/validator-registry-config.yaml" | ||
|
||
echo "Patch path to electricity-trade modules." | ||
current_pwd=$(pwd) | ||
escaped_pwd=${current_pwd//\//\\/} | ||
sed -i "s/\/root\/cactus/$escaped_pwd/g" "${COMMON_CACTUS_CONFIG}/usersetting.yaml" | ||
|
||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
packages/cactus-cmd-socketio-server/src/main/typescript/verifier/ValidatorAuthentication.ts
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
packages/cactus-cmd-socketio-server/src/main/typescript/verifier/validator-authentication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2020-2022 Hyperledger Cactus Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import fs from "fs"; | ||
import jwt from "jsonwebtoken"; | ||
import { configRead } from "../util/config"; | ||
import { signValidatorMessageJwt } from "@hyperledger/cactus-common" | ||
|
||
// Will keep the private key once it's succesfully read | ||
let privateKey: string; | ||
|
||
/** | ||
* Validator-side function to sign message to be sent to the client. | ||
* Will read the private key either as value in validator config `sslParam.keyValue`, | ||
* or read from filesystem under path `sslParam.key`. | ||
* | ||
* @param payload - Message to sign | ||
* @returns Signed message | ||
*/ | ||
export function signMessageJwt(payload: object): string { | ||
if (!privateKey) { | ||
try { | ||
privateKey = configRead<string>('sslParam.keyValue'); | ||
} catch { | ||
privateKey = fs.readFileSync(configRead('sslParam.key'), "ascii"); | ||
} | ||
} | ||
const jwtAlgo = configRead<jwt.Algorithm>('sslParam.jwtAlgo', 'ES256'); | ||
return signValidatorMessageJwt(privateKey, payload, jwtAlgo); | ||
} |
Oops, something went wrong.