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",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.9",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -137,6 +137,15 @@
|
||||
"@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": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartacme",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.9",
|
||||
"private": false,
|
||||
"description": "acme implementation in TypeScript",
|
||||
"main": "dist/index.js",
|
||||
@ -26,6 +26,7 @@
|
||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartdns": "^3.0.8",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"acme-client": "^2.2.1"
|
||||
},
|
||||
|
@ -16,7 +16,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
||||
console.log(args);
|
||||
}
|
||||
});
|
||||
await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -8,19 +8,20 @@ export interface ISmartAcmeStorage {}
|
||||
export class SmartAcme {
|
||||
// the acme client
|
||||
private client: any;
|
||||
private smartdns = new plugins.smartdns.Smartdns();
|
||||
|
||||
// the account private key
|
||||
private privateKey: string;
|
||||
|
||||
// challenge fullfillment
|
||||
private setChallenge: (authz, challenge, keyAuthorization) => Promise<any>;
|
||||
private removeChallenge: (authz, challenge, keyAuthorization) => Promise<any>;
|
||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||
private removeChallenge: (domainName: string) => Promise<any>;
|
||||
|
||||
public async init(optionsArg: {
|
||||
accountPrivateKey?: string;
|
||||
accountEmail: string;
|
||||
setChallenge: (authz, challenge, keyAuthorization) => Promise<any>;
|
||||
removeChallenge: (authz, challenge, keyAuthorization) => Promise<any>;
|
||||
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>
|
||||
removeChallenge: (domainName: string) => Promise<any>;
|
||||
}) {
|
||||
this.privateKey = optionsArg.accountPrivateKey || (await plugins.acme.forge.createPrivateKey());
|
||||
this.setChallenge = optionsArg.setChallenge;
|
||||
@ -48,34 +49,38 @@ export class SmartAcme {
|
||||
/* Get authorizations and select challenges */
|
||||
const authorizations = await this.client.getAuthorizations(order);
|
||||
|
||||
const promises = authorizations.map(async authz => {
|
||||
const challenge = authz.challenges.pop();
|
||||
const keyAuthorization = await this.client.getChallengeKeyAuthorization(challenge);
|
||||
for (const authz of authorizations) {
|
||||
console.log(authz);
|
||||
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 {
|
||||
/* 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 */
|
||||
await this.client.verifyChallenge(authz, challenge);
|
||||
await this.client.verifyChallenge(authz, dnsChallenge);
|
||||
|
||||
/* 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 */
|
||||
await this.client.waitForValidStatus(challenge);
|
||||
await this.client.waitForValidStatus(dnsChallenge);
|
||||
} finally {
|
||||
/* Clean up challenge response */
|
||||
try {
|
||||
await this.removeChallenge(authz, challenge, keyAuthorization);
|
||||
await this.removeChallenge(domainDnsName);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Wait for challenges to complete */
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
/* Finalize order */
|
||||
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||
@ -92,5 +97,5 @@ export class SmartAcme {
|
||||
console.log(`Certificate:\n${cert.toString()}`);
|
||||
}
|
||||
|
||||
toStorageObject () {};
|
||||
toStorageObject() {}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
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
|
||||
import * as acme from 'acme-client';
|
||||
|
Reference in New Issue
Block a user