smartacme/dist/smartacme.classes.smartacme.js

101 lines
7.2 KiB
JavaScript
Raw Normal View History

2016-11-01 17:27:57 +00:00
"use strict";
2016-11-11 13:17:50 +00:00
require("typings-global");
const q = require("q");
let rsaKeygen = require('rsa-keygen');
let rawacme = require('rawacme');
const smartacme_classes_helper_1 = require("./smartacme.classes.helper");
2016-11-11 13:17:50 +00:00
/**
* class SmartAcme exports methods for maintaining SSL Certificates
*/
2016-11-01 17:27:57 +00:00
class SmartAcme {
2016-11-07 17:41:52 +00:00
/**
* the constructor for class SmartAcme
2016-11-11 13:17:50 +00:00
*/
constructor(productionArg = false) {
this.productionBool = productionArg;
2017-01-01 20:20:12 +00:00
this.helper = new smartacme_classes_helper_1.SmartacmeHelper(this);
this.keyPair = this.helper.createKeypair();
if (this.productionBool) {
2017-01-01 20:20:12 +00:00
this.acmeUrl = rawacme.LETSENCRYPT_URL;
2016-11-11 13:17:50 +00:00
}
else {
2017-01-01 20:20:12 +00:00
this.acmeUrl = rawacme.LETSENCRYPT_STAGING_URL;
2016-11-11 13:17:50 +00:00
}
}
/**
* creates an account if not currently present in module
* @executes ASYNC
2016-11-07 17:41:52 +00:00
*/
2016-11-01 19:16:43 +00:00
createAccount() {
2016-11-11 13:17:50 +00:00
let done = q.defer();
rawacme.createClient({
url: this.acmeUrl,
publicKey: this.keyPair.publicKey,
privateKey: this.keyPair.privateKey
}, (err, client) => {
if (err) {
console.error('smartacme: something went wrong:');
console.log(err);
done.reject(err);
return;
}
2017-01-01 20:20:12 +00:00
// make client available in class
this.rawacmeClient = client;
// create the registration
client.newReg({
contact: ['mailto:domains@lossless.org']
}, (err, res) => {
2016-11-11 13:17:50 +00:00
if (err) {
console.error('smartacme: something went wrong:');
2016-11-11 13:17:50 +00:00
console.log(err);
done.reject(err);
return;
2016-11-11 13:17:50 +00:00
}
this.JWK = res.body.key;
2017-01-01 20:20:12 +00:00
this.link = res.headers.link;
console.log(this.link);
this.location = res.headers.location;
done.resolve();
2016-11-17 12:32:16 +00:00
});
2016-11-11 13:17:50 +00:00
});
return done.promise;
2016-11-07 17:41:52 +00:00
}
2017-01-01 20:20:12 +00:00
agreeTos() {
let done = q.defer();
let tosPart = this.link.split(',')[1];
let tosLinkPortion = tosPart.split(';')[0];
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '');
this.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
if (err) {
console.log(err);
done.reject(err);
return;
}
done.resolve();
});
return done.promise;
}
/**
* requests a certificate
*/
requestCertificate(domainNameArg) {
let done = q.defer();
this.rawacmeClient.newAuthz({
identifier: {
type: 'dns',
value: domainNameArg
}
}, this.keyPair, (err, res) => {
if (err) {
console.error('smartacme: something went wrong:');
console.log(err);
done.reject(err);
}
console.log(JSON.stringify(res.body));
done.resolve();
});
return done.promise;
}
2016-11-01 17:27:57 +00:00
}
exports.SmartAcme = SmartAcme;
2017-01-01 20:20:12 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsdUJBQXNCO0FBRXRCLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQTtBQUdyQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUE7QUFHaEMseUVBQXlFO0FBRXpFOztHQUVHO0FBQ0g7SUFVSTs7T0FFRztJQUNILFlBQVksZ0JBQXlCLEtBQUs7UUFDdEMsSUFBSSxDQUFDLGNBQWMsR0FBRyxhQUFhLENBQUE7UUFDbkMsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLDBDQUFlLENBQUMsSUFBSSxDQ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