updates
This commit is contained in:
parent
14d3558943
commit
2f2d0783d7
|
@ -60,8 +60,12 @@ LeCore.getAcmeUrls(
|
||||||
// record to disk (or db)
|
// record to disk (or db)
|
||||||
|
|
||||||
LeCore.getCertificate(
|
LeCore.getCertificate(
|
||||||
{ domainPrivateKeyPem: domainPrivateKeyPem
|
{ newAuthzUrl: urls.newAuthz
|
||||||
|
, newCertUrl: urls.newCert
|
||||||
|
|
||||||
|
, domainPrivateKeyPem: domainPrivateKeyPem
|
||||||
, accountPrivateKeyPem: accountPrivateKeyPem
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
||||||
|
|
||||||
, setChallenge: challengeStore.set
|
, setChallenge: challengeStore.set
|
||||||
, removeChallenge: challengeStore.remove
|
, removeChallenge: challengeStore.remove
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,8 @@ function runDemo() {
|
||||||
, accountPrivateKeyPem: accountPrivateKeyPem
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
||||||
, agreeToTerms: function (tosUrl, done) {
|
, agreeToTerms: function (tosUrl, done) {
|
||||||
|
|
||||||
// agree to these exact terms
|
// agree to the exact version of these terms
|
||||||
console.log('[tosUrl]');
|
console.log('[tosUrl]:', tosUrl);
|
||||||
console.log(tosUrl);
|
|
||||||
done(null, tosUrl);
|
done(null, tosUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,15 +73,19 @@ function runDemo() {
|
||||||
// Note: you should save the registration
|
// Note: you should save the registration
|
||||||
// record to disk (or db)
|
// record to disk (or db)
|
||||||
console.log('[regr]');
|
console.log('[regr]');
|
||||||
console.log(regr);
|
console.log(err || regr);
|
||||||
|
|
||||||
console.log('Registering New Certificate');
|
console.log('Registering New Certificate');
|
||||||
LeCore.getCertificate(
|
LeCore.getCertificate(
|
||||||
{ domainPrivateKeyPem: domainPrivateKeyPem
|
{ newAuthzUrl: acmeUrls.newAuthz
|
||||||
|
, newCertUrl: acmeUrls.newCert
|
||||||
|
|
||||||
|
, domainPrivateKeyPem: domainPrivateKeyPem
|
||||||
, accountPrivateKeyPem: accountPrivateKeyPem
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
||||||
|
, domains: domains
|
||||||
|
|
||||||
, setChallenge: challengeStore.set
|
, setChallenge: challengeStore.set
|
||||||
, removeChallenge: challengeStore.remove
|
, removeChallenge: challengeStore.remove
|
||||||
, domains: domains
|
|
||||||
}
|
}
|
||||||
, function (err, certs) {
|
, function (err, certs) {
|
||||||
|
|
||||||
|
@ -90,7 +93,7 @@ function runDemo() {
|
||||||
certStore.set(domains[0], certs, function () {
|
certStore.set(domains[0], certs, function () {
|
||||||
|
|
||||||
console.log('[certs]');
|
console.log('[certs]');
|
||||||
console.log(certs);
|
console.log(err || certs);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,18 @@ module.exports.create = function (deps) {
|
||||||
var state={
|
var state={
|
||||||
validatedDomains:[]
|
validatedDomains:[]
|
||||||
, validAuthorizationUrls:[]
|
, validAuthorizationUrls:[]
|
||||||
, newAuthorizationUrl: options.newAuthorizationUrl || options.newAuthz
|
, newAuthzUrl: options.newAuthzUrl
|
||||||
, newCertificateUrl: options.newCertificateUrl || options.newCert
|
, newCertUrl: options.newCertUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('state');
|
||||||
|
console.log(state);
|
||||||
|
if (!options.newAuthzUrl) {
|
||||||
|
return handleErr(new Error("options.newAuthzUrl must be the authorization url"));
|
||||||
|
}
|
||||||
|
if (!options.newCertUrl) {
|
||||||
|
return handleErr(new Error("options.newCertUrl must be the new certificate url"));
|
||||||
|
}
|
||||||
if (!options.accountPrivateKeyPem) {
|
if (!options.accountPrivateKeyPem) {
|
||||||
return handleErr(new Error("options.accountPrivateKeyPem must be an ascii private key pem"));
|
return handleErr(new Error("options.accountPrivateKeyPem must be an ascii private key pem"));
|
||||||
}
|
}
|
||||||
|
@ -64,7 +72,7 @@ module.exports.create = function (deps) {
|
||||||
function getChallenges(domain) {
|
function getChallenges(domain) {
|
||||||
state.domain=domain;
|
state.domain=domain;
|
||||||
|
|
||||||
state.acme.post(state.newAuthorizationUrl, {
|
state.acme.post(state.newAuthzUrl, {
|
||||||
resource:'new-authz',
|
resource:'new-authz',
|
||||||
identifier:{
|
identifier:{
|
||||||
type:'dns',
|
type:'dns',
|
||||||
|
@ -90,7 +98,7 @@ module.exports.create = function (deps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
state.authorizationUrl=res.headers.location;
|
state.authorizationUrl=res.headers.location;
|
||||||
state.newCertificateUrl=links.next;
|
state.newCertUrl=links.next;
|
||||||
|
|
||||||
authz=JSON.parse(body);
|
authz=JSON.parse(body);
|
||||||
|
|
||||||
|
@ -156,7 +164,7 @@ module.exports.create = function (deps) {
|
||||||
function getCertificate() {
|
function getCertificate() {
|
||||||
var csr=generateCsr(state.certPrivateKey, state.validatedDomains);
|
var csr=generateCsr(state.certPrivateKey, state.validatedDomains);
|
||||||
log('Requesting certificate...');
|
log('Requesting certificate...');
|
||||||
state.acme.post(state.newCertificateUrl, {
|
state.acme.post(state.newCertUrl, {
|
||||||
resource:'new-cert',
|
resource:'new-cert',
|
||||||
csr:csr,
|
csr:csr,
|
||||||
authorizations:state.validAuthorizationUrls
|
authorizations:state.validAuthorizationUrls
|
||||||
|
|
|
@ -22,8 +22,8 @@ module.exports.create = function (deps) {
|
||||||
cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))"));
|
cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!options.newReg) {
|
if (!options.newRegUrl) {
|
||||||
cb(new Error("options.newReg must be the a new registration url"));
|
cb(new Error("options.newRegUrl must be the a new registration url"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!options.email) {
|
if (!options.email) {
|
||||||
|
@ -38,7 +38,7 @@ module.exports.create = function (deps) {
|
||||||
register();
|
register();
|
||||||
|
|
||||||
function register() {
|
function register() {
|
||||||
state.acme.post(options.newReg, {
|
state.acme.post(options.newRegUrl, {
|
||||||
resource:'new-reg',
|
resource:'new-reg',
|
||||||
contact:['mailto:'+options.email]
|
contact:['mailto:'+options.email]
|
||||||
}, getTerms);
|
}, getTerms);
|
||||||
|
@ -77,7 +77,7 @@ module.exports.create = function (deps) {
|
||||||
request.get(state.termsUrl, getAgreement);
|
request.get(state.termsUrl, getAgreement);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cb();
|
cb(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +100,30 @@ module.exports.create = function (deps) {
|
||||||
resource:'reg',
|
resource:'reg',
|
||||||
agreement:state.termsUrl
|
agreement:state.termsUrl
|
||||||
}, function(err, res, body) {
|
}, function(err, res, body) {
|
||||||
|
var data;
|
||||||
|
|
||||||
if (err || Math.floor(res.statusCode/100)!==2) {
|
if (err || Math.floor(res.statusCode/100)!==2) {
|
||||||
return handleErr(err, 'Couldn\'t POST agreement back to server', body);
|
return handleErr(err, 'Couldn\'t POST agreement back to server', body);
|
||||||
} else {
|
|
||||||
cb(null, body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = body;
|
||||||
|
// handle for node and browser
|
||||||
|
if ('string' === typeof body) {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(body);
|
||||||
|
} catch(e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// might be a buffer
|
||||||
|
data = body.toString('utf8');
|
||||||
|
if (!(data.length > 10)) {
|
||||||
|
// probably json
|
||||||
|
data = body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(null, data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue