Skip to content

Commit

Permalink
[BE-840] Fix discovery error on mutual TLS (#197)
Browse files Browse the repository at this point in the history
* Fix discovery error on mutual TLS & Delete trailing spaces
* Define 'clientTlsIdentity' variable as the exact type and initialize to null
* Update Identity to X509Identity
* Add getClientTlsIdentity() function
* Modify the part of obtaining clientTlsIdentity to use fabricConfig

Signed-off-by: myeongkil <clevermk7211@gmail.com>
  • Loading branch information
myeongkil authored Oct 19, 2020
1 parent 699dfb2 commit 2902885
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ $ npm install
$ npm run build
```

## Run Hyperledger Explorer
## Run Hyperledger Explorer

### Run Locally in Same Location

Expand All @@ -320,7 +320,7 @@ $ npm run build
```json
"sync": {
"type": "local"
}
}
```

* `npm start`
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/platform/fabric/FabricConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ export class FabricConfig {
return this.config.client.enableAuthentication;
}

/**
*
*
* @returns
* @memberof FabricConfig
*/
getClientTlsIdentity() {
return this.config.client.clientTlsIdentity;
}

/**
*
*
Expand Down
19 changes: 13 additions & 6 deletions app/platform/fabric/gateway/FabricGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*SPDX-License-Identifier: Apache-2.0
*/

import { 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';
Expand All @@ -28,6 +28,7 @@ export class FabricGateway {
defaultChannelName: string;
fabricCaEnabled: boolean;
client: any;
clientTlsIdentity: X509Identity;
FSWALLET: string;
enableAuthentication: boolean;
asLocalhost: boolean;
Expand All @@ -47,6 +48,7 @@ export class FabricGateway {
this.gateway = new Gateway();
this.fabricCaEnabled = false;
this.client = null;
this.clientTlsIdentity = null;
this.FSWALLET = null;
this.enableAuthentication = false;
this.asLocalhost = false;
Expand Down Expand Up @@ -121,11 +123,11 @@ 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;
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(
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit 2902885

Please sign in to comment.