Executing fabcar without fabric-ca

Viewed 714

I built a Fabric network with multiple orgs and tls enabled. Crypto material was built with cryptogen. I do not intend to use fabric-ca in my example.

I installed and instantiated fabcar through CLI. Invoke and Query with CLI commands work as charm.

Now, for the purpose of using nodejs scripts query.js and invoke.js I concatenated a private and public key in order to create PeerAdmin credential for Fabcar. I also altered a configuration in .js files to aim at peers and orderers with grpcs.

Whenever I execute any .js script, I am constantly getting the following error:

Create a client and set the wallet location
Set wallet path, and associate user  PeerAdmin  with application
Check user is enrolled, and set a query URL in the network
Caught Error Error: PEM encoded certificate is required.
    at new Endpoint (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:146:11)
    at new Remote (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:95:20)
    at new Peer (/home/hl/fabcar/node_modules/fabric-client/lib/Peer.js:53:3)
    at Client.newPeer (/home/hl/fabcar/node_modules/fabric-client/lib/Client.js:173:14)
    at Promise.resolve.then.then.then (/home/hl/fabcar/query.js:39:28)
    at <anonymous>

When I try to query the chaincode without grpcs I receive the following error:

Create a client and set the wallet location
Set wallet path, and associate user  PeerAdmin  with application
Check user is enrolled, and set a query URL in the network
Make query
Assigning transaction_id:  9cbf355cda03db2b1971fe10af27d66686ea9b913eda80f667cac48bada015bf
error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: Endpoint read failed
    at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15
returned from query
Query result count =  1
error from query =  { Error: Endpoint read failed
    at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15 code: 14, metadata: Metadata { _internal_repr: {} } }
Response is  Error: Endpoint read failed

PeerAdmin content:

{"name":"PeerAdmin","mspid":"PeerOrgMSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"[...]","identity":{"certificate":"-----BEGIN CERTIFICATE-----\n[...]-----END CERTIFICATE-----\n"}}}

Any help in pointing me to a right procedure or troubleshooting with the above would be greatly appreciated.

2 Answers

When you enable gRPCs you must pass the pem as a parameter in the instantiation of the various Hyperledger element objects (e.g. peer, orderer). In the case of the fabcar example (invoke.js):

// This is a new line
var options = {                                                                 
    tls_cert: {                                                                 
        pem: fs.readFileSync(path.join(__dirname, './network/tls') + '/peer.cert').toString(),
    }                                                                           
};                                                                              

...

// Replace the original instantiation by adding the pem option
var peer = fabric_client.newPeer('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:26268', {
    pem: options.tls_cert.pem                                                   
});                                                                             
channel.addPeer(peer);                                                          
// Replace the original instantiation by adding the pem option
var order = fabric_client.newOrderer('grpcs://fft-zbc03b.4.secure.blockchain.ibm.com:20161', {
    pem: options.tls_cert.pem                                                   
})                                                                              
...
// Replace the original instantiation by adding the pem option
event_hub.setPeerAddr('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:23972', {
    pem: options.tls_cert.pem                                                   
});                                                                             

The code above assumes that you downloaded the right certificates to network/tls/. These certificates can be downloaded by sending requests to the CA. For a full example refer to the Bluemix documentation here.

Related