-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-4847] remove node-x509 dependency
This module causes problems running on windows and prevents 'sudo npm install' on CentOS and RHEL The fix is to replace that with own impl of parsing an ECDSA cert to get the subject CN based on jsrsasign.X509 and jsrsasign.ASN1HEX utilities Change-Id: I8c9eda208689e310f8a188049839dae813312ae6 Signed-off-by: Jim Zhang <[email protected]>
- Loading branch information
1 parent
cc5356b
commit 34dd649
Showing
5 changed files
with
47 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ var path = require('path'); | |
var http = require('http'); | ||
var https = require('https'); | ||
var urlParser = require('url'); | ||
var x509 = require('x509'); | ||
var jsrsasign = require('jsrsasign'); | ||
var x509 = jsrsasign.X509; | ||
var ASN1HEX = jsrsasign.ASN1HEX; | ||
|
||
var logger = utils.getLogger('FabricCAClientImpl.js'); | ||
|
||
|
@@ -205,19 +207,16 @@ var FabricCAServices = class extends BaseClient { | |
} | ||
|
||
var cert = currentUser.getIdentity()._certificate; | ||
var subject; | ||
var subject = null; | ||
try { | ||
subject = x509.getSubject(FabricCAServices.normalizeX509(cert)); | ||
subject = getSubjectCommonName(FabricCAServices.normalizeX509(cert)); | ||
} catch(err) { | ||
logger.error(util.format('Failed to parse enrollment certificate %s for Subject. \nError: %s', cert, err)); | ||
} | ||
|
||
if (subject === null || subject === {}) | ||
if (subject === null) | ||
throw new Error('Failed to parse the enrollment certificate of the current user for its subject'); | ||
|
||
if (!subject.commonName) | ||
throw new Error('Invalid enrollment certificate of the current user: does not contain the "CN" value'); | ||
|
||
var self = this; | ||
|
||
return new Promise(function (resolve, reject) { | ||
|
@@ -227,7 +226,7 @@ var FabricCAServices = class extends BaseClient { | |
function (privateKey) { | ||
//generate CSR using the subject of the current user's certificate | ||
try { | ||
var csr = privateKey.generateCSR('CN=' + subject.commonName); | ||
var csr = privateKey.generateCSR('CN=' + subject); | ||
self._fabricCAClient.reenroll(csr, currentUser.getSigningIdentity()) | ||
.then( | ||
function (response) { | ||
|
@@ -783,5 +782,20 @@ function checkRegistrar(registrar) { | |
} | ||
} | ||
|
||
// This utility is based on jsrsasign.X509.getSubjectString() implementation | ||
// we can not use that method directly because it requires calling readCertPEM() | ||
// first which as of [email protected] always assumes RSA based certificates and | ||
// fails to parse certs that includes ECDSA keys. | ||
function getSubjectCommonName(pem) { | ||
var hex = x509.pemToHex(pem); | ||
var d = ASN1HEX.getDecendantHexTLVByNthList(hex, 0, [0, 5]); | ||
var subject = x509.hex2dn(d); // format: '/C=US/ST=California/L=San Francisco/[email protected]/[email protected]' | ||
var m = subject.match(/CN=.+[^\/]/); | ||
if (!m) | ||
throw new Error('Certificate PEM does not seem to contain a valid subject with common name "CN"'); | ||
else | ||
return m[0].substring(3); | ||
} | ||
|
||
module.exports = FabricCAServices; | ||
module.exports.FabricCAClient = FabricCAClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters