From 755e3be5e1008fc17cb67a37bd4de71ef76cd89f Mon Sep 17 00:00:00 2001 From: myeongkil Date: Fri, 16 Oct 2020 18:16:14 +0900 Subject: [PATCH 1/5] Fix discovery error on mutual TLS & Delete trailing spaces Signed-off-by: myeongkil --- README.md | 6 +++--- app/platform/fabric/gateway/FabricGateway.ts | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7fe1c27e3..59f7632c9 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ $ npm install $ npm run build ``` -## Run Hyperledger Explorer +## Run Hyperledger Explorer ### Run Locally in Same Location @@ -320,7 +320,7 @@ $ npm run build ```json "sync": { "type": "local" - } + } ``` * `npm start` @@ -342,7 +342,7 @@ $ DISCOVERY_AS_LOCALHOST=false npm start ```json "sync": { "type": "host" - } + } ``` * If the Hyperledger Explorer was used previously in your browser be sure to clear the cache before relaunching diff --git a/app/platform/fabric/gateway/FabricGateway.ts b/app/platform/fabric/gateway/FabricGateway.ts index 9fd4f6fc7..6bdf71a77 100644 --- a/app/platform/fabric/gateway/FabricGateway.ts +++ b/app/platform/fabric/gateway/FabricGateway.ts @@ -28,6 +28,7 @@ export class FabricGateway { defaultChannelName: string; fabricCaEnabled: boolean; client: any; + clientTlsIdentity: any; FSWALLET: string; enableAuthentication: boolean; asLocalhost: boolean; @@ -47,6 +48,7 @@ export class FabricGateway { this.gateway = new Gateway(); this.fabricCaEnabled = false; this.client = null; + this.clientTlsIdentity = false; this.FSWALLET = null; this.enableAuthentication = false; this.asLocalhost = false; @@ -124,8 +126,8 @@ export class FabricGateway { if ('clientTlsIdentity' in this.config.client) { logger.info('client TLS enabled'); const mTlsIdLabel = this.config.client.clientTlsIdentity; - const mTlsId = await this.wallet.get(mTlsIdLabel); - if (mTlsId !== undefined) { + this.clientTlsIdentity = await this.wallet.get(mTlsIdLabel); + if (this.clientTlsIdentity !== undefined) { connectionOptions.clientTlsIdentity = mTlsIdLabel; } else { throw new ExplorerError( @@ -374,7 +376,12 @@ export class FabricGateway { const ds = new DiscoveryService('be discovery service', channel); const client = new Client('discovery client'); - client.setTlsClientCertAndKey(); + if (this.clientTlsIdentity) { + logger.info('client TLS enabled'); + client.setTlsClientCertAndKey(this.clientTlsIdentity.credentials.certificate, this.clientTlsIdentity.credentials.privateKey); + } else { + client.setTlsClientCertAndKey(); + } const mspID = this.config.client.organization; const targets = []; From 8c0518669a0668a6728cb130b0dd400fa89c0f14 Mon Sep 17 00:00:00 2001 From: myeongkil Date: Sat, 17 Oct 2020 02:48:39 +0900 Subject: [PATCH 2/5] Define 'clientTlsIdentity' variable as the exact type and initialize to null Signed-off-by: myeongkil --- app/platform/fabric/gateway/FabricGateway.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/platform/fabric/gateway/FabricGateway.ts b/app/platform/fabric/gateway/FabricGateway.ts index 6bdf71a77..12c203536 100644 --- a/app/platform/fabric/gateway/FabricGateway.ts +++ b/app/platform/fabric/gateway/FabricGateway.ts @@ -2,7 +2,7 @@ *SPDX-License-Identifier: Apache-2.0 */ -import { Wallets, Gateway } from 'fabric-network'; +import { Identity, Wallets, Gateway } from 'fabric-network'; import * as fabprotos from 'fabric-protos'; import { Discoverer, DiscoveryService } from 'fabric-common'; import concat from 'lodash/concat'; @@ -28,7 +28,7 @@ export class FabricGateway { defaultChannelName: string; fabricCaEnabled: boolean; client: any; - clientTlsIdentity: any; + clientTlsIdentity: Identity; FSWALLET: string; enableAuthentication: boolean; asLocalhost: boolean; @@ -48,7 +48,7 @@ export class FabricGateway { this.gateway = new Gateway(); this.fabricCaEnabled = false; this.client = null; - this.clientTlsIdentity = false; + this.clientTlsIdentity = null; this.FSWALLET = null; this.enableAuthentication = false; this.asLocalhost = false; From caf098a8f4ac390b164fa27ff33c9c8e7f46321b Mon Sep 17 00:00:00 2001 From: myeongkil Date: Sun, 18 Oct 2020 16:37:26 +0900 Subject: [PATCH 3/5] Update Identity to X509Identity Signed-off-by: myeongkil --- app/platform/fabric/gateway/FabricGateway.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/platform/fabric/gateway/FabricGateway.ts b/app/platform/fabric/gateway/FabricGateway.ts index 12c203536..cc82c0926 100644 --- a/app/platform/fabric/gateway/FabricGateway.ts +++ b/app/platform/fabric/gateway/FabricGateway.ts @@ -2,7 +2,7 @@ *SPDX-License-Identifier: Apache-2.0 */ -import { Identity, Wallets, Gateway } from 'fabric-network'; +import { X509Identity, Wallets, Gateway } from 'fabric-network'; import * as fabprotos from 'fabric-protos'; import { Discoverer, DiscoveryService } from 'fabric-common'; import concat from 'lodash/concat'; @@ -28,7 +28,7 @@ export class FabricGateway { defaultChannelName: string; fabricCaEnabled: boolean; client: any; - clientTlsIdentity: Identity; + clientTlsIdentity: X509Identity; FSWALLET: string; enableAuthentication: boolean; asLocalhost: boolean; From df26c9b6096a487c2c11da95759f098c4804e5ee Mon Sep 17 00:00:00 2001 From: myeongkil Date: Mon, 19 Oct 2020 10:38:02 +0900 Subject: [PATCH 4/5] Add getClientTlsIdentity() function Signed-off-by: myeongkil --- app/platform/fabric/FabricConfig.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/platform/fabric/FabricConfig.ts b/app/platform/fabric/FabricConfig.ts index 2f6870415..e00752cda 100644 --- a/app/platform/fabric/FabricConfig.ts +++ b/app/platform/fabric/FabricConfig.ts @@ -109,6 +109,16 @@ export class FabricConfig { return this.config.client.enableAuthentication; } + /** + * + * + * @returns + * @memberof FabricConfig + */ + getClientTlsIdentity() { + return this.config.client.clientTlsIdentity; + } + /** * * From 421421d3ec1232a9ac15c08def452beb313337fa Mon Sep 17 00:00:00 2001 From: myeongkil Date: Mon, 19 Oct 2020 10:38:44 +0900 Subject: [PATCH 5/5] Modify the part of obtaining clientTlsIdentity to use fabricConfig Signed-off-by: myeongkil --- app/platform/fabric/gateway/FabricGateway.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/platform/fabric/gateway/FabricGateway.ts b/app/platform/fabric/gateway/FabricGateway.ts index cc82c0926..969254461 100644 --- a/app/platform/fabric/gateway/FabricGateway.ts +++ b/app/platform/fabric/gateway/FabricGateway.ts @@ -123,9 +123,9 @@ export class FabricGateway { clientTlsIdentity: '' }; - if ('clientTlsIdentity' in this.config.client) { + const mTlsIdLabel = this.fabricConfig.getClientTlsIdentity(); + if (mTlsIdLabel) { logger.info('client TLS enabled'); - const mTlsIdLabel = this.config.client.clientTlsIdentity; this.clientTlsIdentity = await this.wallet.get(mTlsIdLabel); if (this.clientTlsIdentity !== undefined) { connectionOptions.clientTlsIdentity = mTlsIdLabel;