Skip to content

Commit 4048f3e

Browse files
fix(dast): ccp, sshconfig missing
Primary Changes ---------------- 1. Fix the issue on plugin-ledger-connector-fabric that throws an error when there is no sshConfig available. Fixes #3671 Signed-off-by: raynato.c.pedrajeta <[email protected]>
1 parent c66a1c6 commit 4048f3e

File tree

4 files changed

+21
-92
lines changed

4 files changed

+21
-92
lines changed

.github/workflows/.dast-nuclei-cmd-api-server.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ jobs:
5353
run: |
5454
echo https://localhost:4000/ > urls.txt
5555
{
56-
echo https://localhost:4000/api/v1/api-server/healthcheck
5756
echo https://localhost:4000/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/node/jws
5857
echo https://localhost:4000/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/consortium/jws
5958
echo https://localhost:4000/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/get-prometheus-exporter-metrics
@@ -85,7 +84,7 @@ jobs:
8584
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-keychain-memory","type":"org.hyperledger.cactus.plugin_import_type.LOCAL","action":"org.hyperledger.cactus.plugin_import_action.INSTALL","options":{"packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-keychain-memory/","instanceId":"0daacd05-d1cd-4eab-9332-4ad1aff4b909","keychainId":"d29d728e-eaa0-4e2d-b187-d132242b0d9a"}}]' .config.json > .config2.json && mv .config2.json .config.json
8685

8786
- name: Install Fabric connector into the API server
88-
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-ledger-connector-fabric", "type":"org.hyperledger.cactus.plugin_import_type.LOCAL", "action":"org.hyperledger.cactus.plugin_import_action.INSTALL", "options":{ "packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-fabric/", "instanceId":"some-unique-fabric-connector-instance-id", "peerBinary":"/fabric-samples/bin/peer", "connectionProfile":"{}", "dockerBinary":"usr/local/bin/docker","cliContainerEnv":{"CORE_PEER_LOCALMSPID":"Org1MSP","CORE_PEER_ADDRESS":"peer0.org1.example.com:7051","CORE_PEER_MSPCONFIGPATH":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp","CORE_PEER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt","ORDERER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"},"discoveryOptions":{"enabled":true,"asLocalhost":true}}}] ' .config.json > .config2.json && mv .config2.json .config.json
87+
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-ledger-connector-fabric", "type":"org.hyperledger.cactus.plugin_import_type.LOCAL", "action":"org.hyperledger.cactus.plugin_import_action.INSTALL", "options":{ "packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-fabric/", "instanceId":"some-unique-fabric-connector-instance-id", "peerBinary":"/fabric-samples/bin/peer", "connectionProfile":"{}", "connectionProfile":"{}", "dockerBinary":"usr/local/bin/docker","cliContainerEnv":{"CORE_PEER_LOCALMSPID":"Org1MSP","CORE_PEER_ADDRESS":"peer0.org1.example.com:7051","CORE_PEER_MSPCONFIGPATH":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp","CORE_PEER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt","ORDERER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"},"discoveryOptions":{"enabled":true,"asLocalhost":true}}}] ' .config.json > .config2.json && mv .config2.json .config.json
8988

9089
- name: Install Besu connector into the API server
9190
run: jq '.plugins += [{"packageName":"@hyperledger/cactus-plugin-ledger-connector-besu","type":"org.hyperledger.cactus.plugin_import_type.LOCAL","action":"org.hyperledger.cactus.plugin_import_action.INSTALL","options":{"packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-besu/", "rpcApiHttpHost":"http://127.0.0.1:8545", "rpcApiWsHost":"ws://127.0.0.1:8546", "instanceId":"some-unique-besu-connector-instance-id"}}]' .config.json > .config2.json && mv .config2.json .config.json
@@ -116,7 +115,7 @@ jobs:
116115
start: yarn start:api-server
117116
command: "nuclei -version"
118117
command-windows: echo "The project build is not supported on the Windows operating system. Please use Linux or macOS"
119-
wait-on: "https://localhost:4000/api/v1/api-server/healthcheck"
118+
wait-on: "https://localhost:4000/api/v1/plugins/@hyperledger/cactus-plugin-consortium-manual/node/jws"
120119
# wait for 10 minutes for the server to respond
121120
wait-on-timeout: 120
122121

packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract-go-source/deploy-contract-go-source-impl-fabric-v2-5-6.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import temp from "temp";
33
import fs from "fs/promises";
44

55
import {
6-
Config as SshConfig,
76
NodeSSH,
87
SSHExecCommandOptions,
98
SSHExecCommandResponse,
@@ -36,7 +35,6 @@ export interface IDeployContractGoSourceImplFabricV256Context {
3635
readonly log: Logger;
3736
readonly className: string;
3837
readonly dockerBinary: string;
39-
readonly sshConfig: SshConfig;
4038
readonly opts: IPluginLedgerConnectorFabricOptions;
4139
}
4240

@@ -55,7 +53,7 @@ export async function deployContractGoSourceImplFabricV256(
5553
ctx.opts.cliContainerGoPath || K_DEFAULT_CLI_CONTAINER_GO_PATH;
5654

5755
const ssh = new NodeSSH();
58-
await ssh.connect(ctx.sshConfig);
56+
await ssh.connect(ctx.opts.sshConfig);
5957
log.debug(`SSH connection OK`);
6058

6159
try {

packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts

+18-60
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ import {
147147
formatCactiFullBlockResponse,
148148
formatCactiTransactionsBlockResponse,
149149
} from "./get-block/cacti-block-formatters";
150-
151150
import { GetBlockEndpointV1 } from "./get-block/get-block-endpoint-v1";
152151
import { GetChainInfoEndpointV1 } from "./get-chain-info/get-chain-info-endpoint-v1";
153152
import { querySystemChainCode } from "./common/query-system-chain-code";
@@ -159,17 +158,17 @@ import {
159158
} from "./common/utils";
160159
import { findAndReplaceFabricLoggingSpec } from "./common/find-and-replace-fabric-logging-spec";
161160
import { deployContractGoSourceImplFabricV256 } from "./deploy-contract-go-source/deploy-contract-go-source-impl-fabric-v2-5-6";
162-
import { Observable, ReplaySubject } from "rxjs";
163161

164162
const { loadFromConfig } = require("fabric-network/lib/impl/ccp/networkconfig");
165163
assertFabricFunctionIsAvailable(loadFromConfig, "loadFromConfig");
164+
import { Observable, ReplaySubject } from "rxjs";
165+
166166

167167
export interface IRunTxReqWithTxId {
168168
request: RunTransactionRequest;
169169
transactionId: string;
170170
timestamp: Date;
171171
}
172-
173172
/**
174173
* Constant value holding the default $GOPATH in the Fabric CLI container as
175174
* observed on fabric deployments that are produced by the official examples
@@ -197,11 +196,9 @@ export interface IPluginLedgerConnectorFabricOptions
197196
cliContainerGoPath?: string;
198197
cliContainerEnv: NodeJS.ProcessEnv;
199198
pluginRegistry: PluginRegistry;
200-
sshConfig?: SshConfig;
201-
sshConfigB64?: string;
199+
sshConfig: SshConfig;
202200
readonly sshDebugOn?: boolean;
203-
connectionProfile?: ConnectionProfile;
204-
connectionProfileB64?: string;
201+
connectionProfile: ConnectionProfile;
205202
prometheusExporter?: PrometheusExporter;
206203
discoveryOptions?: GatewayDiscoveryOptions;
207204
eventHandlerOptions?: GatewayEventHandlerOptions;
@@ -229,8 +226,6 @@ export class PluginLedgerConnectorFabric
229226
private readonly peerBinary: string;
230227
private readonly goBinary: string;
231228
private readonly cliContainerGoPath: string;
232-
private readonly sshConfig: SshConfig;
233-
private readonly connectionProfile: ConnectionProfile;
234229
public prometheusExporter: PrometheusExporter;
235230
private endpoints: IWebServiceEndpoint[] | undefined;
236231
private readonly secureIdentity: SecureIdentityProviders;
@@ -254,6 +249,7 @@ export class PluginLedgerConnectorFabric
254249
Checks.truthy(opts.instanceId, `${fnTag} options.instanceId`);
255250
Checks.truthy(opts.peerBinary, `${fnTag} options.peerBinary`);
256251
Checks.truthy(opts.pluginRegistry, `${fnTag} options.pluginRegistry`);
252+
Checks.truthy(opts.connectionProfile, `${fnTag} options.connectionProfile`);
257253
this.prometheusExporter =
258254
opts.prometheusExporter ||
259255
new PrometheusExporter({ pollingIntervalInMin: 1 });
@@ -289,33 +285,9 @@ export class PluginLedgerConnectorFabric
289285
});
290286
this.certStore = new CertDatastore(opts.pluginRegistry);
291287

292-
if (this.opts.connectionProfile) {
293-
this.connectionProfile = this.opts.connectionProfile;
294-
} else if (this.opts.connectionProfileB64) {
295-
const connectionProfileBuffer = Buffer.from(
296-
this.opts.connectionProfileB64,
297-
"base64",
298-
);
299-
const connectionProfileString = connectionProfileBuffer.toString("utf-8");
300-
this.connectionProfile = JSON.parse(connectionProfileString);
301-
} else {
302-
throw new Error(
303-
"Cannot instantiate Fabric connector without connection profile.",
304-
);
305-
}
306-
307288
this.sshDebugOn = opts.sshDebugOn === true;
308-
if (this.opts.sshConfig) {
309-
this.sshConfig = this.opts.sshConfig;
310-
} else if (this.opts.sshConfigB64) {
311-
const sshConfigBuffer = Buffer.from(this.opts.sshConfigB64, "base64");
312-
const sshConfigString = sshConfigBuffer.toString("utf-8");
313-
this.sshConfig = JSON.parse(sshConfigString);
314-
} else {
315-
throw new Error("Cannot instantiate Fabric connector without SSH config");
316-
}
317289
if (this.sshDebugOn) {
318-
this.sshConfig = this.enableSshDebugLogs(this.sshConfig);
290+
this.opts.sshConfig = this.enableSshDebugLogs(this.opts.sshConfig);
319291
}
320292

321293
this.signCallback = opts.signCallback;
@@ -348,10 +320,6 @@ export class PluginLedgerConnectorFabric
348320
return `@hyperledger/cactus-plugin-ledger-connector-fabric`;
349321
}
350322

351-
public getTxSubjectObservable(): Observable<IRunTxReqWithTxId> {
352-
return this.txSubject.asObservable();
353-
}
354-
355323
public async onPluginInit(): Promise<unknown> {
356324
return;
357325
}
@@ -366,6 +334,10 @@ export class PluginLedgerConnectorFabric
366334
return consensusHasTransactionFinality(currentConsensusAlgorithmFamily);
367335
}
368336

337+
public getTxSubjectObservable(): Observable<IRunTxReqWithTxId> {
338+
return this.txSubject.asObservable();
339+
}
340+
369341
private enableSshDebugLogs(cfg: SshConfig): SshConfig {
370342
const fnTag = `${this.className}#decorateSshConfigWithLogger()`;
371343
Checks.truthy(cfg, `${fnTag} cfg must be truthy.`);
@@ -382,6 +354,7 @@ export class PluginLedgerConnectorFabric
382354
sshCmdOptions: SSHExecCommandOptions,
383355
): Promise<SSHExecCommandResponse> {
384356
this.log.debug(`${label} CMD: ${cmd}`);
357+
385358
const cmdRes = await ssh.execCommand(cmd, sshCmdOptions);
386359
this.log.debug(`${label} CMD Response .code: %o`, cmdRes.code);
387360
this.log.debug(`${label} CMD Response .signal: %o`, cmdRes.signal);
@@ -401,11 +374,11 @@ export class PluginLedgerConnectorFabric
401374
req: DeployContractV1Request,
402375
): Promise<DeployContractV1Response> {
403376
const fnTag = `${this.className}#deployContract()`;
404-
const { log } = this;
377+
const { log, opts } = this;
405378

406379
const ssh = new NodeSSH();
407380
this.log.debug(`${fnTag} Establishing SSH connection to peer...`);
408-
await ssh.connect(this.sshConfig);
381+
await ssh.connect(opts.sshConfig);
409382
this.log.debug(`${fnTag} Established SSH connection to peer OK.`);
410383

411384
if (req.collectionsConfigFile) {
@@ -706,7 +679,6 @@ export class PluginLedgerConnectorFabric
706679
log,
707680
opts: this.opts,
708681
dockerBinary: this.dockerBinary,
709-
sshConfig: this.sshConfig,
710682
className: this.className,
711683
};
712684
return deployContractGoSourceImplFabricV256(ctx, req);
@@ -951,7 +923,7 @@ export class PluginLedgerConnectorFabric
951923
return createGateway({
952924
logLevel: this.opts.logLevel,
953925
pluginRegistry: this.opts.pluginRegistry,
954-
defaultConnectionProfile: this.connectionProfile,
926+
defaultConnectionProfile: this.opts.connectionProfile,
955927
defaultDiscoveryOptions: this.opts.discoveryOptions || {
956928
enabled: true,
957929
asLocalhost: true,
@@ -976,8 +948,7 @@ export class PluginLedgerConnectorFabric
976948
protected async createGatewayLegacy(
977949
signingCredential: FabricSigningCredential,
978950
): Promise<Gateway> {
979-
const { eventHandlerOptions: eho } = this.opts;
980-
const connectionProfile = this.connectionProfile;
951+
const { connectionProfile, eventHandlerOptions: eho } = this.opts;
981952

982953
const iType = signingCredential.type || FabricSigningCredentialType.X509;
983954

@@ -1191,7 +1162,6 @@ export class PluginLedgerConnectorFabric
11911162
): Promise<RunTransactionResponse> {
11921163
const fnTag = `${this.className}#transact()`;
11931164
this.log.debug("%s ENTER", fnTag);
1194-
11951165
const {
11961166
channelName,
11971167
contractName,
@@ -1261,7 +1231,6 @@ export class PluginLedgerConnectorFabric
12611231
const transactionProposal = await contract.createTransaction(fnName);
12621232
transactionProposal.setEndorsingPeers(endorsingTargets);
12631233
out = await transactionProposal.setTransient(transientMap).submit();
1264-
transactionId = transactionProposal.getTransactionId();
12651234
break;
12661235
}
12671236
default: {
@@ -1270,17 +1239,6 @@ export class PluginLedgerConnectorFabric
12701239
}
12711240
}
12721241

1273-
// create IRunTxReqWithTxId for transaction monitoring
1274-
const receiptData: IRunTxReqWithTxId = {
1275-
request: req,
1276-
transactionId: transactionId == "" ? uuidv4() : transactionId,
1277-
timestamp: new Date(),
1278-
};
1279-
this.log.debug(
1280-
`IRunTxReqWithTxId created with ID: ${receiptData.transactionId}`,
1281-
);
1282-
this.txSubject.next(receiptData);
1283-
12841242
const res: RunTransactionResponse = {
12851243
functionOutput: this.convertToTransactionResponseType(
12861244
out,
@@ -1319,7 +1277,7 @@ export class PluginLedgerConnectorFabric
13191277
public async createCaClient(caId: string): Promise<FabricCAServices> {
13201278
const fnTag = `${this.className}#createCaClient()`;
13211279
try {
1322-
const ccp = this.connectionProfile;
1280+
const ccp = this.opts.connectionProfile;
13231281
if (!ccp.certificateAuthorities) {
13241282
throw new Error(`${fnTag} conn. profile certificateAuthorities falsy.`);
13251283
}
@@ -1724,7 +1682,7 @@ export class PluginLedgerConnectorFabric
17241682
this.log.debug("Create Fabric Client without a signer with ID", clientId);
17251683
const client = new Client(clientId);
17261684
// Use fabric SDK methods for parsing connection profile into Client structure
1727-
await loadFromConfig(client, this.connectionProfile);
1685+
await loadFromConfig(client, this.opts.connectionProfile);
17281686

17291687
// Create user
17301688
const user = User.createUser("", "", signerMspID, signerCertificate);
@@ -1937,4 +1895,4 @@ export class PluginLedgerConnectorFabric
19371895
}
19381896
}
19391897
}
1940-
}
1898+
}

packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts

-26
Original file line numberDiff line numberDiff line change
@@ -251,32 +251,6 @@ describe(testCase, () => {
251251
}
252252

253253
{
254-
const connectionProfileString = JSON.stringify(connectionProfile);
255-
const connectionProfileB64Buffer = Buffer.from(connectionProfileString);
256-
const sshConfigString = JSON.stringify(sshConfig);
257-
const connectionProfileB64 =
258-
connectionProfileB64Buffer.toString("base64");
259-
const sshConfigB64Buffer = Buffer.from(sshConfigString);
260-
const sshConfigB64 = sshConfigB64Buffer.toString("base64");
261-
const pluginOptionsSerialized: IPluginLedgerConnectorFabricOptions = {
262-
instanceId: uuidv4(),
263-
pluginRegistry,
264-
sshConfigB64,
265-
cliContainerEnv: {},
266-
peerBinary: "/fabric-samples/bin/peer",
267-
logLevel,
268-
connectionProfileB64,
269-
discoveryOptions,
270-
eventHandlerOptions: {
271-
strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx,
272-
commitTimeout: 300,
273-
},
274-
};
275-
const pluginWithSerializedInputs = new PluginLedgerConnectorFabric(
276-
pluginOptionsSerialized,
277-
);
278-
await pluginWithSerializedInputs.getOrCreateWebServices();
279-
await pluginWithSerializedInputs.registerWebServices(expressApp);
280254
const req: RunTransactionRequest = {
281255
signingCredential,
282256
gatewayOptions: {

0 commit comments

Comments
 (0)