Skip to content

Commit

Permalink
FAB-8969 NodeSDK - '/0' fix missing on mutual tls
Browse files Browse the repository at this point in the history
Need to add the certificate fix to the cert being
used by mutual TLS.

Change-Id: I20f492c4b07c44726b7d6ee64660bd2d848bb6a0
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Mar 20, 2018
1 parent c0be611 commit ab2c8e8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fabric-client/lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ module.exports = Remote;
var Endpoint = class {
constructor(url /*string*/ , pem /*string*/ , clientKey /*string*/ , clientCert /*string*/) {

var purl = urlParser.parse(url, true);
var protocol;
const purl = urlParser.parse(url, true);
let protocol;
if (purl.protocol) {
protocol = purl.protocol.toLowerCase().slice(0, -1);
}
Expand All @@ -199,25 +199,26 @@ var Endpoint = class {
if(!(typeof pem === 'string')) {
throw new Error('PEM encoded certificate is required.');
}
const pembuf = Buffer.concat([Buffer.from(pem), Buffer.from('\0')]);
if (clientKey || clientCert){
// must have both clientKey and clientCert if either is defined
if (clientKey && clientCert){
if ((typeof clientKey === 'string') && (typeof clientCert === 'string')) {
this.creds = grpc.credentials.createSsl(Buffer.from(pem),
Buffer.from(clientKey), Buffer.from(clientCert));
const clientKeyBuf = Buffer.from(clientKey);
const clientCertBuf = Buffer.concat([Buffer.from(clientCert), Buffer.from('\0')]);
this.creds = grpc.credentials.createSsl(pembuf, clientKeyBuf, clientCertBuf);
} else {
throw new Error('PEM encoded clientKey and clientCert are required.');
}
} else {
throw new Error('clientKey and clientCert are both required.');
}
} else {
var pembuf = Buffer.concat([Buffer.from(pem), Buffer.from('\0')]);
this.creds = grpc.credentials.createSsl(pembuf);
}
this.addr = purl.host;
} else {
var error = new Error();
let error = new Error();
error.name = 'InvalidProtocol';
error.message = 'Invalid protocol: ' + protocol + '. URLs must begin with grpc:// or grpcs://';
throw error;
Expand Down

0 comments on commit ab2c8e8

Please sign in to comment.