smartacme/ts/smartacme.classes.smartacme.ts

87 lines
2.4 KiB
TypeScript
Raw Normal View History

const acme = require('acme-v2').ACME.create({
RSA: require('rsa-compat').RSA,
2017-01-14 13:14:50 +00:00
// used for constructing user-agent
os: require('os'),
process: require('process'),
2017-01-01 23:18:51 +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
// don't try to validate challenges locally
skipChallengeTest: true
});
2016-11-07 17:41:52 +00:00
import { KeyPair } from './smartacme.classes.keypair';
import * as plugins from './smartacme.plugins';
const rsa = require('rsa-compat').RSA;
2016-11-01 19:16:43 +00:00
export class SmartAcme {
domainKeyPair: KeyPair;
accountKeyPair: KeyPair;
accountData: any;
directoryUrls: any;
async init() {
// get directory url
this.directoryUrls = await acme.init('https://acme-staging-v02.api.letsencrypt.org/directory');
// create keyPairs
this.domainKeyPair = await KeyPair.generateFresh();
this.accountKeyPair = await KeyPair.generateFresh();
// get account
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
}