Compare commits

...

2 Commits

Author SHA1 Message Date
ed4ba0cb61 2.0.6 2019-01-06 23:30:39 +01:00
a8ab27045d fix(core): update 2019-01-06 23:30:38 +01:00
3 changed files with 19 additions and 14 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.5", "version": "2.0.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.5", "version": "2.0.6",
"private": false, "private": false,
"description": "acme implementation in TypeScript", "description": "acme implementation in TypeScript",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -13,14 +13,14 @@ export class SmartAcme {
private privateKey: string; private privateKey: string;
// challenge fullfillment // challenge fullfillment
private setChallenge: (authz, challenge, keyAuthorization) => Promise<any>; private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
private removeChallenge: (authz, challenge, keyAuthorization) => Promise<any>; private removeChallenge: (domainName: string) => Promise<any>;
public async init(optionsArg: { public async init(optionsArg: {
accountPrivateKey?: string; accountPrivateKey?: string;
accountEmail: string; accountEmail: string;
setChallenge: (authz, challenge, keyAuthorization) => Promise<any>; setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>
removeChallenge: (authz, challenge, keyAuthorization) => Promise<any>; removeChallenge: (domainName: string) => Promise<any>;
}) { }) {
this.privateKey = optionsArg.accountPrivateKey || (await plugins.acme.forge.createPrivateKey()); this.privateKey = optionsArg.accountPrivateKey || (await plugins.acme.forge.createPrivateKey());
this.setChallenge = optionsArg.setChallenge; this.setChallenge = optionsArg.setChallenge;
@ -49,25 +49,30 @@ export class SmartAcme {
const authorizations = await this.client.getAuthorizations(order); const authorizations = await this.client.getAuthorizations(order);
const promises = authorizations.map(async authz => { const promises = authorizations.map(async authz => {
const challenge = authz.challenges.pop(); console.log(authz);
const keyAuthorization = await this.client.getChallengeKeyAuthorization(challenge); const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
const dnsChallenge: string = authz.challenges.find(challengeArg => {
return challengeArg.type === 'dns-01';
});
// process.exit(1);
const keyAuthorization: string = await this.client.getChallengeKeyAuthorization(dnsChallenge);
try { try {
/* Satisfy challenge */ /* Satisfy challenge */
await this.setChallenge(authz, challenge, keyAuthorization); await this.setChallenge(domainDnsName, keyAuthorization);
/* Verify that challenge is satisfied */ /* Verify that challenge is satisfied */
await this.client.verifyChallenge(authz, challenge); await this.client.verifyChallenge(authz, dnsChallenge);
/* Notify ACME provider that challenge is satisfied */ /* Notify ACME provider that challenge is satisfied */
await this.client.completeChallenge(challenge); await this.client.completeChallenge(dnsChallenge);
/* Wait for ACME provider to respond with valid status */ /* Wait for ACME provider to respond with valid status */
await this.client.waitForValidStatus(challenge); await this.client.waitForValidStatus(dnsChallenge);
} finally { } finally {
/* Clean up challenge response */ /* Clean up challenge response */
try { try {
await this.removeChallenge(authz, challenge, keyAuthorization); await this.removeChallenge(domainDnsName);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -92,5 +97,5 @@ export class SmartAcme {
console.log(`Certificate:\n${cert.toString()}`); console.log(`Certificate:\n${cert.toString()}`);
} }
toStorageObject () {}; toStorageObject() {}
} }