104 lines
6.3 KiB
JavaScript
104 lines
6.3 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
const q = require("q");
|
|
let ACME = require('le-acme-core').ACME.create();
|
|
let RSA = require('rsa-compat').RSA;
|
|
let bitlen = 1024;
|
|
let exp = 65537;
|
|
let options = {
|
|
public: true,
|
|
pem: true,
|
|
internal: true
|
|
};
|
|
/**
|
|
* class SmartAcme exports methods for maintaining SSL Certificates
|
|
*/
|
|
class SmartAcme {
|
|
constructor(productionArg = false) {
|
|
this.preparedBool = false;
|
|
this.productionBool = productionArg;
|
|
}
|
|
/**
|
|
* prepares the SmartAcme class
|
|
*/
|
|
prepareAcme() {
|
|
let done = q.defer();
|
|
if (this.preparedBool === false) {
|
|
this.getAcmeUrls()
|
|
.then(() => {
|
|
return this.createKeyPair();
|
|
})
|
|
.then((x) => {
|
|
console.log('prepared smartacme instance');
|
|
done.resolve();
|
|
});
|
|
}
|
|
else {
|
|
done.resolve();
|
|
}
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* creates an account if not currently present in module
|
|
*/
|
|
createAccount() {
|
|
let done = q.defer();
|
|
this.prepareAcme()
|
|
.then(() => {
|
|
return this.createKeyPair();
|
|
})
|
|
.then(() => {
|
|
let options = {
|
|
newRegUrl: this.acmeUrls.newReg,
|
|
email: 'domains@lossless.org',
|
|
accountKeypair: {
|
|
privateKeyPem: this.keyPair
|
|
},
|
|
agreeToTerms: function (tosUrl, done) {
|
|
done(null, tosUrl);
|
|
}
|
|
};
|
|
ACME.registerNewAccount(options, (err, regr) => {
|
|
if (err) {
|
|
console.log(err);
|
|
done.reject(err);
|
|
}
|
|
done.resolve(regr);
|
|
}); // returns "regr" registration data
|
|
}).catch(err => { console.log(err); });
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* creates a keyPair
|
|
*/
|
|
createKeyPair() {
|
|
let done = q.defer();
|
|
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
|
|
if (err) {
|
|
console.log(err);
|
|
done.reject(err);
|
|
}
|
|
console.log(keypair);
|
|
this.keyPair = keypair;
|
|
});
|
|
done.resolve();
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* gets the Acme Urls
|
|
*/
|
|
getAcmeUrls() {
|
|
let done = q.defer();
|
|
ACME.getAcmeUrls(ACME.stagingServerUrl, (err, urls) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
this.acmeUrls = urls;
|
|
console.log(this.acmeUrls);
|
|
done.resolve();
|
|
});
|
|
return done.promise;
|
|
}
|
|
}
|
|
exports.SmartAcme = SmartAcme;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsdUJBQXNCO0FBTXRCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUE7QUFDaEQsSUFBSSxHQUFHLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDLEdBQUcsQ0FBQTtBQUVuQyxJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUE7QUFDakIsSUFBSSxHQUFHLEdBQUcsS0FBSyxDQUFBO0FBQ2YsSUFBSSxPQUFPLEdBQUc7SUFDVixNQUFNLEVBQUUsSUFBSTtJQUNaLEdBQUcsRUFBRSxJQUFJO0lBQ1QsUUFBUSxFQUFFLElBQUk7Q0FDakIsQ0FBQTtBQUNEOztHQUVHO0FBQ0g7SUFLSSxZQUFZLGdCQUF5QixLQUFLO1FBSjFDLGlCQUFZLEdBQVksS0FBSyxDQUFBO1FBS3pCLElBQUksQ0FBQyxjQUFjLEdBQUcsYUFBYSxDQUFB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