fix(core): now creating certs all right

This commit is contained in:
2018-08-12 01:35:14 +02:00
parent 651ef6d281
commit 223a47c997
5 changed files with 69 additions and 15 deletions

View File

@ -15,33 +15,75 @@ const acme = require('acme-v2').ACME.create({
},
// don't try to validate challenges locally
skipChallengeTest: false
skipChallengeTest: true
});
import { KeyPair } from './smartacme.classes.keypair';
import * as plugins from './smartacme.plugins';
const rsa = require('rsa-compat').RSA;
export class SmartAcme {
keyPair: KeyPair;
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 keyPair
this.keyPair = await KeyPair.generateFresh();
// 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.keyPair.rsaKeyPair,
agreeToTerms: async tosUrl => {
return tosUrl;
}
}).catch(e => {
console.log(e);
});
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;
}
console.log(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);
}
}

View File

@ -1,5 +1,7 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
export {
smartpromise
smartpromise,
smartdelay
}