fix #11 output pems with CRLF, end in CRLF

This commit is contained in:
AJ ONeal 2016-08-06 18:55:19 -06:00
parent b980fde859
commit 572621086e
1 changed files with 30 additions and 38 deletions

View File

@ -298,6 +298,11 @@ module.exports.create = function (deps) {
} }
log('Successfully verified cert at '+certUrl); log('Successfully verified cert at '+certUrl);
downloadIssuerCert(links);
});
}
function downloadIssuerCert(links) {
log('Requesting issuer certificate...'); log('Requesting issuer certificate...');
request({ request({
method: 'GET' method: 'GET'
@ -316,35 +321,22 @@ module.exports.create = function (deps) {
return handleErr(err, 'Failed to fetch issuer certificate'); return handleErr(err, 'Failed to fetch issuer certificate');
} }
state.caCertPem=certBufferToPem(body); state.chainPem=certBufferToPem(body);
log('Requesting issuer certificate: done'); log('Requesting issuer certificate: done');
done(); done();
}); });
});
} }
function done() { function done() {
var certPem; var privkeyPem = RSA.exportPrivatePem(state.certKeypair);
var privkeyPem;
try {
certPem = certBufferToPem(state.certificate);
} catch(e) {
console.error(e.stack);
//cb(new Error("Could not write output files. Please check permissions!"));
handleErr(e, 'Could not write output files. Please check permissions!');
return;
}
privkeyPem = RSA.exportPrivatePem(state.certKeypair);
cb(null, { cb(null, {
cert: certPem cert: certBufferToPem(state.certificate)
// TODO privkey isn't necessary
, privkey: privkeyPem , privkey: privkeyPem
, chain: state.caCertPem , chain: state.chainPem
// TODO nix key, ca // TODO nix backwards compat
, key: privkeyPem , key: privkeyPem
, ca: state.caCertPem , ca: state.chainPem
}); });
} }
@ -412,8 +404,8 @@ module.exports.create = function (deps) {
function certBufferToPem(cert) { function certBufferToPem(cert) {
cert=_toStandardBase64(cert.toString('base64')); cert=_toStandardBase64(cert.toString('base64'));
cert=cert.match(/.{1,64}/g).join('\n'); cert=cert.match(/.{1,64}/g).join('\r\n');
return '-----BEGIN CERTIFICATE-----\n'+cert+'\n-----END CERTIFICATE-----'; return '-----BEGIN CERTIFICATE-----\r\n'+cert+'\r\n-----END CERTIFICATE-----\r\n';
} }
return getCert; return getCert;