2018-08-11 22:29:02 +00:00
|
|
|
const acme = require('acme-v2').ACME.create({
|
|
|
|
RSA: require('rsa-compat').RSA,
|
2017-01-14 13:14:50 +00:00
|
|
|
|
2018-08-11 22:29:02 +00:00
|
|
|
// used for constructing user-agent
|
|
|
|
os: require('os'),
|
|
|
|
process: require('process'),
|
2017-01-01 23:18:51 +00:00
|
|
|
|
2018-08-11 22:29:02 +00:00
|
|
|
// used for overriding the default user-agent
|
|
|
|
userAgent: 'My custom UA String',
|
|
|
|
getUserAgentString: function(deps) {
|
|
|
|
return 'My custom UA String';
|
|
|
|
},
|
2016-11-01 19:16:43 +00:00
|
|
|
|
2018-08-11 22:29:02 +00:00
|
|
|
// don't try to validate challenges locally
|
2018-08-11 23:35:14 +00:00
|
|
|
skipChallengeTest: true
|
2018-08-11 22:29:02 +00:00
|
|
|
});
|
2016-11-07 17:41:52 +00:00
|
|
|
|
2018-08-11 22:29:02 +00:00
|
|
|
import { KeyPair } from './smartacme.classes.keypair';
|
2018-08-11 23:35:14 +00:00
|
|
|
import * as plugins from './smartacme.plugins';
|
|
|
|
const rsa = require('rsa-compat').RSA;
|
2016-11-01 19:16:43 +00:00
|
|
|
|
2018-08-11 22:29:02 +00:00
|
|
|
export class SmartAcme {
|
2018-08-11 23:35:14 +00:00
|
|
|
domainKeyPair: KeyPair;
|
|
|
|
accountKeyPair: KeyPair;
|
|
|
|
accountData: any;
|
2018-08-11 22:29:02 +00:00
|
|
|
directoryUrls: any;
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
// get directory url
|
|
|
|
this.directoryUrls = await acme.init('https://acme-staging-v02.api.letsencrypt.org/directory');
|
|
|
|
|
2018-08-11 23:35:14 +00:00
|
|
|
// create keyPairs
|
|
|
|
this.domainKeyPair = await KeyPair.generateFresh();
|
|
|
|
this.accountKeyPair = await KeyPair.generateFresh();
|
2018-08-11 22:29:02 +00:00
|
|
|
|
|
|
|
// get account
|
2018-08-11 23:35:14 +00:00
|
|
|
const registrationData = await acme.accounts
|
|
|
|
.create({
|
|
|
|
email: 'domains@lossless.org', // valid email (server checks MX records)
|
|
|
|
accountKeypair: this.accountKeyPair.rsaKeyPair,
|
|
|
|
agreeToTerms: async tosUrl => {
|
|
|
|
return tosUrl;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
this.accountData = registrationData;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getCertificateForDomain(domain) {
|
|
|
|
const result = await acme.certificates
|
|
|
|
.create({
|
|
|
|
domainKeypair: this.domainKeyPair.rsaKeyPair,
|
|
|
|
accountKeypair: this.accountKeyPair.rsaKeyPair,
|
|
|
|
domains: ['bleu.de'],
|
|
|
|
challengeType: 'dns-01',
|
|
|
|
|
|
|
|
setChallenge: async (hostname, key, val, cb) => {
|
|
|
|
console.log('set challenge');
|
|
|
|
console.log(hostname);
|
|
|
|
//console.log(key);
|
|
|
|
//console.log(val);
|
|
|
|
const dnsKey = rsa.utils.toWebsafeBase64(
|
|
|
|
require('crypto')
|
|
|
|
.createHash('sha256')
|
|
|
|
.update(val)
|
|
|
|
.digest('base64')
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log(dnsKey);
|
|
|
|
await plugins.smartdelay.delayFor(20000);
|
|
|
|
console.log('ready!');
|
|
|
|
cb();
|
|
|
|
}, // return Promise
|
|
|
|
removeChallenge: async (hostname, key) => {
|
|
|
|
console.log('removing challenge');
|
|
|
|
return;
|
|
|
|
} // return Promise
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log(e);
|
|
|
|
}); // returns Promise<pems={ privkey (key), cert, chain (ca) }>
|
|
|
|
console.log(result);
|
2017-04-28 16:56:55 +00:00
|
|
|
}
|
2016-11-01 17:27:57 +00:00
|
|
|
}
|