Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE-840] Fix discovery error on mutual TLS #197

Merged
merged 5 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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