completed(?) example
This commit is contained in:
parent
6b7e140d68
commit
40cc0bd8a5
|
@ -2,59 +2,91 @@
|
||||||
|
|
||||||
var LeCore = require('letiny-core');
|
var LeCore = require('letiny-core');
|
||||||
|
|
||||||
var email = process.argv[2] || 'user@example.com'; // CHANGE THIS
|
var email = process.argv[2] || 'user@example.com'; // CHANGE TO YOUR EMAIL
|
||||||
var domains = [process.argv[3] || 'example.com']; // CHANGE THIS
|
var domains = [process.argv[3] || 'example.com']; // CHANGE TO YOUR DOMAIN
|
||||||
|
var acmeDiscoveryUrl = LeCore.stagingServerUrl;
|
||||||
var accountPrivateKeyPem = '...'; // leCrypto.generateRsaKeypair(bitLen, exp, cb)
|
|
||||||
var domainPrivateKeyPem = '...'; // (same)
|
|
||||||
|
|
||||||
var challengeStore = require('./challenge-store');
|
var challengeStore = require('./challenge-store');
|
||||||
var certStore = require('cert-store');
|
var certStore = require('cert-store');
|
||||||
var serve = require('./serve');
|
var serve = require('./serve');
|
||||||
|
|
||||||
LeCore.getAcmeUrls(
|
var accountPrivateKeyPem = null;
|
||||||
LeCore.stagingServerUrl // or choose LeCore.productionServerUrl
|
var domainPrivateKeyPem = null;
|
||||||
, function (err, urls) {
|
var acmeUrls = null;
|
||||||
|
|
||||||
|
|
||||||
|
console.log('Using server', acmeDiscoveryUrl);
|
||||||
|
console.log('Creating account for', email, 'and registering certificates for', domains, 'to that account');
|
||||||
|
init();
|
||||||
|
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
getPrivateKeys(function () {
|
||||||
|
|
||||||
|
LeCore.getAcmeUrls(acmeDiscoveryUrl, function (urls) {
|
||||||
|
// in production choose LeCore.productionServerUrl
|
||||||
|
|
||||||
|
acmeUrls = urls;
|
||||||
|
runDemo();
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPrivateKeys() {
|
||||||
|
LeCore.leCrypto.generateRsaKeypair(2048, 65537, function (pems) {
|
||||||
|
|
||||||
|
accountPrivateKeyPem = pems.privateKeyPem;
|
||||||
|
LeCore.leCrypto.generateRsaKeypair(2048, 65537, function (pems) {
|
||||||
|
|
||||||
|
domainPrivateKeyPem = pems.privateKeyPem;
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function runDemo() {
|
||||||
LeCore.registerNewAccount(
|
LeCore.registerNewAccount(
|
||||||
{ newRegUrl: urls.newReg
|
{ newRegUrl: acmeUrls.newReg
|
||||||
, email: email
|
, email: email
|
||||||
, accountPrivateKeyPem: accountPrivateKeyPem
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
||||||
, agreeToTerms: function (tosUrl, done) {
|
, agreeToTerms: function (tosUrl, done) {
|
||||||
// agree to these exact terms
|
|
||||||
|
|
||||||
console.log('[tosUrl]');
|
// agree to these exact terms
|
||||||
console.log(tosUrl);
|
console.log('[tosUrl]');
|
||||||
done(null, tosUrl);
|
console.log(tosUrl);
|
||||||
|
done(null, tosUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
, function (err, regr) {
|
||||||
, function (err, regr) {
|
|
||||||
|
|
||||||
// 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(regr);
|
||||||
|
|
||||||
LeCore.getCertificate(
|
LeCore.getCertificate(
|
||||||
{ domainPrivateKeyPem: domainPrivateKeyPem
|
{ domainPrivateKeyPem: domainPrivateKeyPem
|
||||||
, accountPrivateKeyPem: accountPrivateKeyPem
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
||||||
, setChallenge: challengeStore.set
|
, setChallenge: challengeStore.set
|
||||||
, removeChallenge: challengeStore.remove
|
, removeChallenge: challengeStore.remove
|
||||||
, domains: domains
|
, domains: domains
|
||||||
}
|
}
|
||||||
, function (err, certs) {
|
, function (err, certs) {
|
||||||
|
|
||||||
// Note: you should save certs to disk (or db)
|
// Note: you should save certs to disk (or db)
|
||||||
certStore
|
certStore.set(domains[0], certs, function () {
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
console.log('[certs]');
|
||||||
|
console.log(certs);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setup the Server
|
// Setup the Server
|
||||||
|
|
Loading…
Reference in New Issue