Skip to content

Commit

Permalink
BE-774 Add pem format support (#137)
Browse files Browse the repository at this point in the history
* BE-774 Add support of pem format in connection profile

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* BE-774 Add e2e test for PEM format connection profile

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia authored Jul 11, 2020
1 parent 864b622 commit 471d261
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 137 deletions.
3 changes: 2 additions & 1 deletion app/common/ExplorerMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ exports.explorer = {
ERROR_2011: 'There is no client found for Hyperledger fabric scanner',
ERROR_2013:
'Channel name [%s] already exist in DB , Kindly re-run the DB scripts to proceed',
ERROR_2014: 'Invalid platform configuration, Please check the log'
ERROR_2014: 'Invalid platform configuration, Please check the log',
ERROR_2015: 'Invalid network configuration, Please check the log'
},
message: {
// Generic Message
Expand Down
6 changes: 1 addition & 5 deletions app/platform/fabric/FabricClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class FabricClient {
async initializeNewChannel(channel_name) {
// Get genesis block for the channel
const block = await this.getGenesisBlock(channel_name);
logger.debug('Genesis Block for client [%s] >> %j', this.client_name, block);
logger.debug('Genesis Block for client [%s]', this.client_name);

const channel_genesis_hash = await FabricUtils.generateBlockHash(
block.header
Expand Down Expand Up @@ -200,10 +200,6 @@ class FabricClient {
const discover_results = await this.fabricGateway.getDiscoveryResult(
channel_name
);
logger.debug(
`Discover results for channel [${channel_name}] >>`,
discover_results
);

if ('peers_by_org' in discover_results) {
for (const org in discover_results.peers_by_org) {
Expand Down
75 changes: 57 additions & 18 deletions app/platform/fabric/FabricConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/

const fs = require('fs');
const path = require('path');
const helper = require('../../common/helper');
const explorer_mess = require('../../common/ExplorerMessage').explorer;
const ExplorerError = require('../../common/ExplorerError');

const logger = helper.getLogger('FabricConfig');

Expand Down Expand Up @@ -208,9 +211,24 @@ class FabricConfig {
* @returns
* @memberof FabricConfig
*/
getOrgSignedCertPath() {
getOrgSignedCertPem() {
const organization = this.config.organizations[this.getOrganization()];
return organization.signedCert.path;
if (
organization.signedCert === undefined ||
(organization.signedCert.path === undefined &&
organization.signedCert.pem === undefined)
) {
logger.error('Not found signedCert configuration');
throw new ExplorerError(explorer_mess.error.ERROR_2015);
}

if (organization.signedCert.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', organization.signedCert.path),
'utf8'
);
}
return organization.signedCert.pem;
}

/**
Expand All @@ -219,9 +237,24 @@ class FabricConfig {
* @returns
* @memberof FabricConfig
*/
getOrgAdminPrivateKeyPath() {
getOrgAdminPrivateKeyPem() {
const organization = this.config.organizations[this.getOrganization()];
return organization.adminPrivateKey.path;
if (
organization.adminPrivateKey === undefined ||
(organization.adminPrivateKey.path === undefined &&
organization.adminPrivateKey.pem === undefined)
) {
logger.error('Not found adminPrivateKey configuration');
throw new ExplorerError(explorer_mess.error.ERROR_2015);
}

if (organization.adminPrivateKey.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', organization.adminPrivateKey.path),
'utf8'
);
}
return organization.adminPrivateKey.pem;
}

/**
Expand All @@ -230,9 +263,23 @@ class FabricConfig {
* @returns
* @memberof FabricConfig
*/
getMspId() {
const organization = this.config.organizations[this.getOrganization()];
return organization.mspid;
getPeerTlsCACertsPem(peer) {
const tlsCACerts = this.config.peers[peer].tlsCACerts;
if (
tlsCACerts === undefined ||
(tlsCACerts.path === undefined && tlsCACerts.pem === undefined)
) {
logger.error(`Not found tlsCACerts configuration: ${peer.url}`);
return '';
}

if (tlsCACerts.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', tlsCACerts.path),
'utf8'
);
}
return tlsCACerts.pem;
}

/**
Expand All @@ -241,17 +288,9 @@ class FabricConfig {
* @returns
* @memberof FabricConfig
*/
getServerCertPath() {
let serverCertPath = null;
if (this.config.certificateAuthorities) {
for (const x in this.config.certificateAuthorities) {
if (this.config.certificateAuthorities[x].tlsCACerts) {
serverCertPath = this.config.certificateAuthorities[x].tlsCACerts.path;
}
}
}

return serverCertPath;
getMspId() {
const organization = this.config.organizations[this.getOrganization()];
return organization.mspid;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions app/platform/fabric/e2e-test/configs/config_single-pem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"network-configs": {
"org1-network": {
"name": "org1-network",
"profile": "./e2e-test/configs/connection-profile/org1-network-pem.json"
}
},
"license": "Apache-2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "org1-network",
"version": "1.0.0",
"license": "Apache-2.0",
"client": {
"tlsEnable": true,
"adminCredential": {
"id": "exploreradmin",
"password": "exploreradminpw"
},
"enableAuthentication": false,
"organization": "org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"commonchannel": {
"peers": {
"peer0-org1": {}
},
"connection": {
"timeout": {
"peer": {
"endorser": "6000",
"eventHub": "6000",
"eventReg": "6000"
}
}
}
}
},
"organizations": {
"org1": {
"mspid": "Org1ExampleCom",
"adminPrivateKey": {
"pem": "-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgMwFI31oAw7BLotqD\nlt83zXPSFdcG9s68O8xjsmuEcDChRANCAAQeGSJN2yd9m1m0rRnXnO2/kjiZywRE\nIpjVDyBArAgoFwIAVgmkkps4NI3EMPMBXiTw8NTHjeEEkuovbohNAEal\n-----END PRIVATE KEY-----\n\n"
},
"peers": ["peer0-org1"],
"signedCert": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICBTCCAaugAwIBAgIQKSCQe3pGrCx15SgsHg6I+TAKBggqhkjOPQQDAjBbMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU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ZIzj0CAQYIKoZIzj0D\nAQcDQgAEXREuqNRHBPddBxwWT+01LZzkLjnFHhI0j+xpcGvLurqSpHwuh8XEe+nW\ncN2vzP6v16W6F2pjiYrqTwAvwrwUfqNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1Ud\nJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1Ud\nDgQiBCCRDXS4hPlBUrW2wLu+fNy2PYfY1maQe1b6eLXjgoXclzAKBggqhkjOPQQD\nAgNIADBFAiEA3vNlfA2AKI9+lFHVKl9MD3+ZLN4M0K1HYlfx2BkuZToCIG7Nky+/\nPOT1iS3XCRPfZq4EAd4S2hQs5i7vuXB0b47o\n-----END CERTIFICATE-----\n\n"
},
"url": "grpcs://localhost:31000",
"grpcOptions": {
"ssl-target-name-override": "peer0-org1"
}
}
}
}
25 changes: 25 additions & 0 deletions app/platform/fabric/e2e-test/specs/apitest_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package apitest

import (
"fmt"
"os"
"os/exec"
"testing"

. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

var failed = false

func TestRestApi(t *testing.T) {
RegisterFailHandler(Fail)
junitReporter := reporters.NewJUnitReporter("results_rest-api-test-suite.xml")
Expand All @@ -21,4 +27,23 @@ var _ = BeforeSuite(func() {
// Cleaning up network launched from BeforeSuite and removing all chaincode containers
// and chaincode container images using AfterSuite
var _ = AfterSuite(func() {
if failed {
dumpLog()
}
})

var _ = AfterEach(func() {
failed = failed || CurrentGinkgoTestDescription().Failed
})

func dumpLog() {
cwd, _ := os.Getwd()
fmt.Println("=== Dump Explorer app log ===")
fmt.Println(cwd)
os.Chdir(relativePahtToRoot)
cmd := exec.Command("cat", "logs/console/console.log")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
session.Wait()
fmt.Println(session.Out)
}
Loading

0 comments on commit 471d261

Please sign in to comment.