[FAB-14532] Make LL FabCar use BYFN, not basic-network

Update low level FabCar to use BYFN. As a result, the
sample client applications need to change so that they
use the correct TLS certificates and URLs, and so that
they use service discovery.

Change-Id: I2805a00fd745416e6b006af7b87147551e511922
Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
This commit is contained in:
Simon Stone 2019-03-07 14:22:05 +00:00
parent 2a5a59b60a
commit 0bc0a69793
5 changed files with 115 additions and 22 deletions

79
fabcar/javascript-low-level/.gitignore vendored Normal file
View file

@ -0,0 +1,79 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
hfc-key-store

View file

@ -11,15 +11,17 @@
var Fabric_Client = require('fabric-client');
var Fabric_CA_Client = require('fabric-ca-client');
var fs = require('fs');
var path = require('path');
var util = require('util');
var os = require('os');
var firstnetwork_path = path.resolve('..', '..', 'first-network');
var org1tlscacert_path = path.resolve(firstnetwork_path, 'crypto-config', 'peerOrganizations', 'org1.example.com', 'tlsca', 'tlsca.org1.example.com-cert.pem');
var org1tlscacert = fs.readFileSync(org1tlscacert_path, 'utf8');
//
var fabric_client = new Fabric_Client();
var fabric_ca_client = null;
var admin_user = null;
var member_user = null;
var store_path = path.join(__dirname, 'hfc-key-store');
console.log(' Store path:'+store_path);
@ -35,11 +37,11 @@ Fabric_Client.newDefaultKeyValueStore({ path: store_path
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
var tlsOptions = {
trustedRoots: [],
trustedRoots: [org1tlscacert],
verify: false
};
// be sure to change the http to https when the CA is running TLS enabled
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', tlsOptions , 'ca.example.com', crypto_suite);
fabric_ca_client = new Fabric_CA_Client('https://localhost:7054', tlsOptions , 'ca-org1', crypto_suite);
// first check to see if the admin is already enrolled
return fabric_client.getUserContext('admin', true);

View file

@ -9,9 +9,13 @@
*/
const Fabric_Client = require('fabric-client');
const fs = require('fs');
const path = require('path');
const util = require('util');
const os = require('os');
var firstnetwork_path = path.resolve('..', '..', 'first-network');
var org1tlscacert_path = path.resolve(firstnetwork_path, 'crypto-config', 'peerOrganizations', 'org1.example.com', 'tlsca', 'tlsca.org1.example.com-cert.pem');
var org1tlscacert = fs.readFileSync(org1tlscacert_path, 'utf8');
invoke();
@ -28,16 +32,15 @@ async function invoke() {
const channel = fabric_client.newChannel('mychannel');
console.log('Created client side object to represent the channel');
// -- peer instance to represent a peer on the channel
const peer = fabric_client.newPeer('grpc://localhost:7051');
const peer = fabric_client.newPeer('grpcs://localhost:7051', {
'ssl-target-name-override': 'peer0.org1.example.com',
pem: org1tlscacert
});
console.log('Created client side object to represent the peer');
// -- orderer instance to reprsent the channel's orderer
const orderer = fabric_client.newOrderer('grpc://localhost:7050')
console.log('Created client side object to represent the orderer');
// This sample application uses a file based key value stores to hold
// the user information and credentials. These are the same stores as used
// by the 'registerUser.js' sample code
const member_user = null;
const store_path = path.join(__dirname, 'hfc-key-store');
console.log('Setting up the user store at path:'+store_path);
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
@ -63,6 +66,10 @@ async function invoke() {
console.log('Successfully setup client side');
console.log('\n\nStart invoke processing');
// Use service discovery to initialize the channel
await channel.initialize({ discover: true, asLocalhost: true, target: peer });
console.log('Used service discovery to initialize the channel');
// get a transaction id object based on the current user assigned to fabric client
// Transaction ID objects contain more then just a transaction ID, also includes
// a nonce value and if built from the client's admin user.
@ -116,7 +123,6 @@ async function invoke() {
// committed.
const commit_request = {
orderer: orderer,
proposalResponses: proposalResponses,
proposal: proposal
};

View file

@ -9,23 +9,27 @@
*/
var Fabric_Client = require('fabric-client');
var fs = require('fs');
var path = require('path');
var util = require('util');
var os = require('os');
var firstnetwork_path = path.resolve('..', '..', 'first-network');
var org1tlscacert_path = path.resolve(firstnetwork_path, 'crypto-config', 'peerOrganizations', 'org1.example.com', 'tlsca', 'tlsca.org1.example.com-cert.pem');
var org1tlscacert = fs.readFileSync(org1tlscacert_path, 'utf8');
//
var fabric_client = new Fabric_Client();
// setup the fabric network
var channel = fabric_client.newChannel('mychannel');
var peer = fabric_client.newPeer('grpc://localhost:7051');
var peer = fabric_client.newPeer('grpcs://localhost:7051', {
'ssl-target-name-override': 'peer0.org1.example.com',
pem: org1tlscacert
});
channel.addPeer(peer);
//
var member_user = null;
var store_path = path.join(__dirname, 'hfc-key-store');
console.log('Store path:'+store_path);
var tx_id = null;
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
Fabric_Client.newDefaultKeyValueStore({ path: store_path
@ -44,7 +48,6 @@ Fabric_Client.newDefaultKeyValueStore({ path: store_path
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded user1 from persistence');
member_user = user_from_store;
} else {
throw new Error('Failed to get user1.... run registerUser.js');
}

View file

@ -11,9 +11,12 @@
var Fabric_Client = require('fabric-client');
var Fabric_CA_Client = require('fabric-ca-client');
var fs = require('fs');
var path = require('path');
var util = require('util');
var os = require('os');
var firstnetwork_path = path.resolve('..', '..', 'first-network');
var org1tlscacert_path = path.resolve(firstnetwork_path, 'crypto-config', 'peerOrganizations', 'org1.example.com', 'tlsca', 'tlsca.org1.example.com-cert.pem');
var org1tlscacert = fs.readFileSync(org1tlscacert_path, 'utf8');
//
var fabric_client = new Fabric_Client();
@ -35,11 +38,11 @@ Fabric_Client.newDefaultKeyValueStore({ path: store_path
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
var tlsOptions = {
trustedRoots: [],
trustedRoots: [org1tlscacert],
verify: false
};
// be sure to change the http to https when the CA is running TLS enabled
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', null , '', crypto_suite);
fabric_ca_client = new Fabric_CA_Client('https://localhost:7054', tlsOptions , 'ca-org1', crypto_suite);
// first check to see if the admin is already enrolled
return fabric_client.getUserContext('admin', true);