From 595942a7b1acbabd08ca110b46da225052aa629d Mon Sep 17 00:00:00 2001 From: Dave Kelsey <25582377+davidkel@users.noreply.github.com> Date: Thu, 9 Dec 2021 10:43:16 +0000 Subject: [PATCH] Fix issue where init flow errors when not using mutual TLS (#1183) fixes the issue where on the init flow you get TypeError: this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(...).isTLSEnabled is not a function closes #1160 Signed-off-by: D Co-authored-by: D --- package.json | 2 +- .../connector-versions/v1/FabricGateway.js | 2 +- .../connector-versions/v1/FabricNonGateway.js | 2 +- .../connector-versions/v2/FabricGateway.js | 2 +- .../connector-versions/v1/FabricGateway.js | 7 ++ .../connector-versions/v1/FabricNonGateway.js | 7 ++ .../connector-versions/v2/FabricGateway.js | 7 ++ .../sample-configs/BasicConfigNotMutual.yaml | 118 ++++++++++++++++++ .../BasicConfigNotMutualWithStaticCCP.yaml | 89 +++++++++++++ 9 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 packages/caliper-fabric/test/sample-configs/BasicConfigNotMutual.yaml create mode 100644 packages/caliper-fabric/test/sample-configs/BasicConfigNotMutualWithStaticCCP.yaml diff --git a/package.json b/package.json index a7d2832a9..772651ce4 100644 --- a/package.json +++ b/package.json @@ -68,4 +68,4 @@ } }, "license": "Apache-2.0" -} \ No newline at end of file +} diff --git a/packages/caliper-fabric/lib/connector-versions/v1/FabricGateway.js b/packages/caliper-fabric/lib/connector-versions/v1/FabricGateway.js index 1480e9137..70db91a07 100644 --- a/packages/caliper-fabric/lib/connector-versions/v1/FabricGateway.js +++ b/packages/caliper-fabric/lib/connector-versions/v1/FabricGateway.js @@ -133,7 +133,7 @@ class V1FabricGateway extends ConnectorBase { async init() { const defaultOrganization = this.connectorConfiguration.getOrganizations()[0]; const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual' - : (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none'); + : ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none'); logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`); const fabricChannelOperations = new FabricChannelOperations(this.connectorConfiguration); diff --git a/packages/caliper-fabric/lib/connector-versions/v1/FabricNonGateway.js b/packages/caliper-fabric/lib/connector-versions/v1/FabricNonGateway.js index f6fc61d4f..6341b5c9c 100644 --- a/packages/caliper-fabric/lib/connector-versions/v1/FabricNonGateway.js +++ b/packages/caliper-fabric/lib/connector-versions/v1/FabricNonGateway.js @@ -128,7 +128,7 @@ class V1Fabric extends ConnectorBase { await this._validateConnectionProfilesAreStatic(); const defaultOrganization = this.connectorConfiguration.getOrganizations()[0]; const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual' - : (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none'); + : ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none'); logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`); const fabricChannelOperations = new FabricChannelOperations(this.connectorConfiguration); diff --git a/packages/caliper-fabric/lib/connector-versions/v2/FabricGateway.js b/packages/caliper-fabric/lib/connector-versions/v2/FabricGateway.js index 772fcf86b..7ad0df0ba 100644 --- a/packages/caliper-fabric/lib/connector-versions/v2/FabricGateway.js +++ b/packages/caliper-fabric/lib/connector-versions/v2/FabricGateway.js @@ -129,7 +129,7 @@ class V2FabricGateway extends ConnectorBase { // will call it const defaultOrganization = this.connectorConfiguration.getOrganizations()[0]; const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual' - : (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none'); + : ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none'); logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`); } diff --git a/packages/caliper-fabric/test/connector-versions/v1/FabricGateway.js b/packages/caliper-fabric/test/connector-versions/v1/FabricGateway.js index 5b58b5e06..0e467b631 100644 --- a/packages/caliper-fabric/test/connector-versions/v1/FabricGateway.js +++ b/packages/caliper-fabric/test/connector-versions/v1/FabricGateway.js @@ -25,6 +25,7 @@ const DefaultEventHandlerStrategies = {}; const DefaultQueryHandlerStrategies = {}; const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfig.yaml'; +const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutual.yaml'; const { Client, Constants } = require('./ClientStubs'); const { Gateway, Transaction, InMemoryWallet, FileSystemWallet, X509WalletMixin, Network } = require('./V1GatewayStubs'); @@ -90,6 +91,12 @@ describe('A Node-SDK V1 Fabric Gateway', () => { await fabricGateway.init().should.not.be.rejected; }); + it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => { + const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), walletFacadeFactory); + const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric'); + await fabricGateway.init().should.not.be.rejected; + }); + it('should do nothing when attempting to install a smart contract', async () => { const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWallet), walletFacadeFactory); const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric'); diff --git a/packages/caliper-fabric/test/connector-versions/v1/FabricNonGateway.js b/packages/caliper-fabric/test/connector-versions/v1/FabricNonGateway.js index c09652cb1..b1e714cb8 100644 --- a/packages/caliper-fabric/test/connector-versions/v1/FabricNonGateway.js +++ b/packages/caliper-fabric/test/connector-versions/v1/FabricNonGateway.js @@ -23,6 +23,7 @@ const path = require('path'); const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfigWithStaticCCP.yaml'; const configWith2Orgs1AdminInWalletWithDiscover = '../../sample-configs/BasicConfig.yaml'; +const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutualWithStaticCCP.yaml'; const { Client, Channel, ChannelEventHub, Constants } = require('./ClientStubs'); const GenerateConfiguration = require('../../utils/GenerateConfiguration'); @@ -78,6 +79,12 @@ describe('A Node-SDK V1 Fabric Non Gateway', () => { await fabricNonGateway.init().should.not.be.rejected; }); + it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => { + const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), stubWalletFacadeFactory); + const fabricGateway = new FabricNonGateway(connectorConfiguration, 1, 'fabric'); + await fabricGateway.init().should.not.be.rejected; + }); + it('should throw an error if the connection profile is defined with discover when initalizing for use by caliper master', async () => { const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletWithDiscover), stubWalletFacadeFactory); const fabricNonGateway = new FabricNonGateway(connectorConfiguration, 1, 'fabric'); diff --git a/packages/caliper-fabric/test/connector-versions/v2/FabricGateway.js b/packages/caliper-fabric/test/connector-versions/v2/FabricGateway.js index 35185a646..156ec092a 100644 --- a/packages/caliper-fabric/test/connector-versions/v2/FabricGateway.js +++ b/packages/caliper-fabric/test/connector-versions/v2/FabricGateway.js @@ -25,6 +25,7 @@ const DefaultEventHandlerStrategies = {}; const DefaultQueryHandlerStrategies = {}; const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfig.yaml'; +const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutual.yaml'; const { Gateway, Transaction, Network, Wallets } = require('./V2GatewayStubs'); const GenerateConfiguration = require('../../utils/GenerateConfiguration'); @@ -78,6 +79,12 @@ describe('A Node-SDK V2 Fabric Gateway', () => { await fabricGateway.init().should.not.be.rejected; }); + it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => { + const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), walletFacadeFactory); + const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric'); + await fabricGateway.init().should.not.be.rejected; + }); + it('should do nothing when attempting to install a smart contract', async () => { const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWallet), walletFacadeFactory); const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric'); diff --git a/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutual.yaml b/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutual.yaml new file mode 100644 index 000000000..748bd8548 --- /dev/null +++ b/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutual.yaml @@ -0,0 +1,118 @@ +--- +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# The name of the benchmark +name: BasicConfig +# The caliper semantic version +version: "2.0.0" + +# Global properties that define the SUT, and options that are specific to the target SUT +caliper: + blockchain: fabric + sutOptions : + mutualTls: false + +# Array of fabric channels for creation or use +channels: + - channelName: mychannel + # [Optional] create the channel + create: + buildTransaction: + capabilities: [] + consortium: 'SampleConsortium2' + msps: ['Org1MSP', 'Org2MSP'] + version: 0 + # Array of contracts to be installed/instantiated on the named channel and available for use by the workload module + contracts: + - id: marbles + contractID: myMarbles + # define the install requirements to install chaincode if chaincode is to be installed + install: + version: v0 + language: golang + path: marbles/go + metadataPath: src/marbles/go/metadata + # define the instantiate requirements to instantiate chaincode all of this section is optional depending on chaincode requirements + instantiate: + initFunction: init + initArguments: [] + initTransientMap: + key1: value1 + key2: value2 + endorsementPolicy: '' + collectionsConfig: '' + + - channelName: somechannel + create: + prebuiltTransaction: 'channel.tx' + contracts: + - id: marbles + contractID: foundMyMarbles + version: v0 + + - channelName: yourchannel + contracts: + - id: marbles + contractID: lostMyMarbles + version: v0 + +# [Minimum 1] Array of organizations that are to be used within the benchmarking, containing one of more identities to be used by the connector +organizations: + - mspid: Org1MSP + # One or more identity specification types that may provide a unique identity for the use by the connector. + identities: + # [NOT CURRENTLY SUPPORTED] [Optional] only for use by non gateway fabric connector (could also be defined in connection profile) + credentialStore: + path: /tmp/hfc-kvs/org1 + cryptoStore: + path: /tmp/hfc-cvs/org1 + # [Optional] File path to a FileWallet, within which all entries are all for the same org. Only for use by gateway + wallet: + path: './test/sample-configs' + adminNames: + - admin + # [Optional] certificates for the client + certificates: + - name: 'User1' + clientPrivateKey: + # pem or path can be specified here can be specified here + pem: |- + -----BEGIN PRIVATE KEY----- + -----END PRIVATE KEY----- + clientSignedCert: + pem: |- + -----BEGIN CERTIFICATE----- + -----END CERTIFICATE----- + # Connection profile to be used by the connector for the organization + # - could validate this connection profile matches declared mspid + connectionProfile: + path: './test/sample-configs/Org1ConnectionProfile.yaml' + discover: true + - mspid: Org2MSP + identities: + certificates: + - name: 'User1' + clientPrivateKey: + # pem or path can be specified here can be specified here + pem: |- + -----BEGIN PRIVATE KEY----- + -----END PRIVATE KEY----- + clientSignedCert: + pem: |- + -----BEGIN CERTIFICATE----- + -----END CERTIFICATE----- + connectionProfile: + path: './test/sample-configs/StaticOrg2ConnectionProfile.json' + discover: false diff --git a/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutualWithStaticCCP.yaml b/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutualWithStaticCCP.yaml new file mode 100644 index 000000000..335f12204 --- /dev/null +++ b/packages/caliper-fabric/test/sample-configs/BasicConfigNotMutualWithStaticCCP.yaml @@ -0,0 +1,89 @@ +--- +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: BasicConfigWithStaticCCP +version: "2.0.0" + +caliper: + blockchain: fabric, + sutOptions : + mutualTls: false + +channels: + - channelName: mychannel + create: + buildTransaction: + capabilities: [] + consortium: 'SampleConsortium2' + msps: ['Org1MSP', 'Org2MSP'] + version: 0 + contracts: + - id: marbles + contractID: myMarbles + install: + version: v0 + language: golang + path: marbles/go + metadataPath: src/marbles/go/metadata + instantiate: + initFunction: init + initArguments: [] + initTransientMap: + key1: value1 + key2: value2 + endorsementPolicy: '' + collectionsConfig: '' + + - channelName: yourchannel + contracts: + - id: marbles + contractID: lostMyMarbles + version: v0 + +organizations: + - mspid: Org1MSP + identities: + wallet: + path: './test/sample-configs' + adminNames: + - admin + certificates: + - name: 'User1' + clientPrivateKey: + pem: |- + -----BEGIN PRIVATE KEY----- + -----END PRIVATE KEY----- + clientSignedCert: + pem: |- + -----BEGIN CERTIFICATE----- + -----END CERTIFICATE----- + connectionProfile: + path: './test/sample-configs/StaticOrg1ConnectionProfile.json' + discover: false + - mspid: Org2MSP + identities: + certificates: + - name: 'User1' + clientPrivateKey: + pem: |- + -----BEGIN PRIVATE KEY----- + -----END PRIVATE KEY----- + clientSignedCert: + pem: |- + -----BEGIN CERTIFICATE----- + -----END CERTIFICATE----- + connectionProfile: + path: './test/sample-configs/StaticOrg2ConnectionProfile.json' + discover: false