Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a problem with parsing "Public Key size" in different OS #122

Merged
merged 5 commits into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function fetchCertificateData(certData, callback) {
certValues.signatureAlgorithm = tmp[1]|| '';
}

if (( tmp = certData.match(/Public Key: ([^\n]*)\n/)) && tmp.length > 1) {
if (( tmp = certData.match(/Public[ -]Key: ([^\n]*)\n/)) && tmp.length > 1) {
certValues.publicKeySize = (tmp[1]|| '').replace(/[()]/g,'');
}

Expand Down
24 changes: 8 additions & 16 deletions test/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ exports['General Tests'] = {
emailAddress: 'andris@node.ee',
dc: '',
signatureAlgorithm: 'sha256WithRSAEncryption',
publicKeyAlgorithm: 'rsaEncryption'
publicKeyAlgorithm: 'rsaEncryption',
publicKeySize: '2048 bit'
};

pem.createCSR({ csrConfigFile: './test/fixtures/test.cnf' }, function(error, data) {
Expand All @@ -119,9 +120,6 @@ exports['General Tests'] = {

pem.readCertificateInfo(csr, function(error, data) {
test.ifError(error);
if (data.publicKeySize){
delete data.publicKeySize;
}
test.deepEqual(data, certInfo);
test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
Expand Down Expand Up @@ -221,9 +219,6 @@ exports['General Tests'] = {

pem.readCertificateInfo(csr, function(error, data) {
test.ifError(error);
if (data.publicKeySize){
delete data.publicKeySize;
}
test.deepEqual(data, {
issuer : {},
country: '',
Expand All @@ -235,7 +230,8 @@ exports['General Tests'] = {
emailAddress: '',
dc: '',
signatureAlgorithm: 'sha256WithRSAEncryption',
publicKeyAlgorithm: 'rsaEncryption'
publicKeyAlgorithm: 'rsaEncryption',
publicKeySize: '2048 bit'
});
test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
Expand All @@ -255,7 +251,8 @@ exports['General Tests'] = {
emailAddress: 'andris@node.ee',
dc: '',
signatureAlgorithm: 'sha256WithRSAEncryption',
publicKeyAlgorithm: 'rsaEncryption'
publicKeyAlgorithm: 'rsaEncryption',
publicKeySize: '2048 bit'
};
pem.createCSR(Object.create(certInfo), function(error, data) {
var csr = (data && data.csr || '').toString();
Expand All @@ -264,9 +261,6 @@ exports['General Tests'] = {

pem.readCertificateInfo(csr, function(error, data) {
test.ifError(error);
if (data.publicKeySize){
delete data.publicKeySize;
}
test.deepEqual(data, certInfo);
test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
Expand Down Expand Up @@ -347,7 +341,8 @@ exports['General Tests'] = {
emailAddress: 'andris@node.ee',
dc: '',
signatureAlgorithm: 'sha256WithRSAEncryption',
publicKeyAlgorithm: 'rsaEncryption'
publicKeyAlgorithm: 'rsaEncryption',
publicKeySize: '2048 bit'
};
pem.createCertificate(Object.create(certInfo), function(error, data) {
var certificate = (data && data.certificate || '').toString();
Expand All @@ -363,9 +358,6 @@ exports['General Tests'] = {
if (data.serial) {
delete data.serial;
}
if (data.publicKeySize){
delete data.publicKeySize;
}

test.deepEqual(data, certInfo);
test.ok(fs.readdirSync('./tmp').length === 0);
Expand Down