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,53 +298,45 @@ module.exports.create = function (deps) {
} }
log('Successfully verified cert at '+certUrl); log('Successfully verified cert at '+certUrl);
log('Requesting issuer certificate...'); downloadIssuerCert(links);
request({ });
method: 'GET' }
, url: links.up
, encoding: null
}, function(err, res, body) {
if (!err) {
try {
body = bodyToError(res, body);
} catch(e) {
err = e;
}
}
if (err || res.statusCode!==200) { function downloadIssuerCert(links) {
return handleErr(err, 'Failed to fetch issuer certificate'); log('Requesting issuer certificate...');
request({
method: 'GET'
, url: links.up
, encoding: null
}, function(err, res, body) {
if (!err) {
try {
body = bodyToError(res, body);
} catch(e) {
err = e;
} }
}
state.caCertPem=certBufferToPem(body); if (err || res.statusCode!==200) {
log('Requesting issuer certificate: done'); return handleErr(err, 'Failed to fetch issuer certificate');
done(); }
});
state.chainPem=certBufferToPem(body);
log('Requesting issuer certificate: 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;