Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4d50b7dcf | |||
2492fd4de2 | |||
bef54799b6 | |||
dbe09f320a | |||
18045dadaf | |||
ee300c3e12 | |||
ed4ba0cb61 | |||
a8ab27045d | |||
975c3ed190 | |||
a99dea549b |
11
package-lock.json
generated
11
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.4",
|
"version": "2.0.9",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -137,6 +137,15 @@
|
|||||||
"@pushrocks/smartpromise": "^2.0.5"
|
"@pushrocks/smartpromise": "^2.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartdns": {
|
||||||
|
"version": "3.0.8",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdns/-/smartdns-3.0.8.tgz",
|
||||||
|
"integrity": "sha512-f6cyO3FOnUJQTjHUjcePP6xMDytjk4DrmRDpqooQtMipTf8t0R25Yvg7GooSdWiBJDrIXHrXVu+oq82L5mFuUQ==",
|
||||||
|
"requires": {
|
||||||
|
"@pushrocks/smartdelay": "^2.0.2",
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/smartevent": {
|
"@pushrocks/smartevent": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.4",
|
"version": "2.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "acme implementation in TypeScript",
|
"description": "acme implementation in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -26,6 +26,7 @@
|
|||||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.2",
|
||||||
|
"@pushrocks/smartdns": "^3.0.8",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"acme-client": "^2.2.1"
|
"acme-client": "^2.2.1"
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
console.log(args);
|
console.log(args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -8,19 +8,20 @@ export interface ISmartAcmeStorage {}
|
|||||||
export class SmartAcme {
|
export class SmartAcme {
|
||||||
// the acme client
|
// the acme client
|
||||||
private client: any;
|
private client: any;
|
||||||
|
private smartdns = new plugins.smartdns.Smartdns();
|
||||||
|
|
||||||
// the account private key
|
// the account private key
|
||||||
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;
|
||||||
@ -48,34 +49,38 @@ export class SmartAcme {
|
|||||||
/* Get authorizations and select challenges */
|
/* Get authorizations and select challenges */
|
||||||
const authorizations = await this.client.getAuthorizations(order);
|
const authorizations = await this.client.getAuthorizations(order);
|
||||||
|
|
||||||
const promises = authorizations.map(async authz => {
|
for (const authz of authorizations) {
|
||||||
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);
|
||||||
|
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
/* Wait for challenges to complete */
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
/* Finalize order */
|
/* Finalize order */
|
||||||
const [key, csr] = await plugins.acme.forge.createCsr({
|
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||||
@ -92,5 +97,5 @@ export class SmartAcme {
|
|||||||
console.log(`Certificate:\n${cert.toString()}`);
|
console.log(`Certificate:\n${cert.toString()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
toStorageObject () {};
|
toStorageObject() {}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
|
import * as smartdns from '@pushrocks/smartdns';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export { smartpromise, smartdelay };
|
export { smartdelay, smartdns, smartpromise };
|
||||||
|
|
||||||
// thirs party scope
|
// thirs party scope
|
||||||
import * as acme from 'acme-client';
|
import * as acme from 'acme-client';
|
||||||
|
Reference in New Issue
Block a user