Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
ac515f5e80 | |||
6abbf58b83 | |||
9c25ecdc02 | |||
81a15da2d0 | |||
86929251ba | |||
1d8fb2b296 | |||
9d5f0d7a5d | |||
82b1d68576 | |||
e04b23aceb | |||
8e255938b5 | |||
f2eb9666a7 | |||
cbdb0c8b08 | |||
f821f4d9cc | |||
6cfcf21d95 | |||
a33090bb5e | |||
3151829f85 | |||
eca63e588c | |||
9d23e205d8 | |||
5ecdf7c9fd | |||
2817a65e21 | |||
09a8bc5cb5 | |||
a1134cf227 | |||
4ee1c4b08c | |||
08c3eaa65f | |||
2717f08476 | |||
f16dbeea32 | |||
a0c0230419 |
63
README.md
63
README.md
@ -1,24 +1,19 @@
|
||||
# smartacme
|
||||
# @pushrocks/smartuniverse
|
||||
acme with an easy yet powerful interface in TypeScript
|
||||
|
||||
acme implementation in TypeScript
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartacme)
|
||||
[](https://GitLab.com/umbrellazone/smartacme)
|
||||
[](https://github.com/umbrellazone/smartacme)
|
||||
[](https://umbrellazone.gitlab.io/smartacme/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||
[](https://www.npmjs.com/package/smartacme)
|
||||
[](https://david-dm.org/umbrellazone/smartacme)
|
||||
[](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/umbrellazone/smartacme)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
@ -28,36 +23,14 @@ Use TypeScript for best in class instellisense.
|
||||
```javascript
|
||||
import { SmartAcme } from 'smartacme';
|
||||
|
||||
let smac = new SmartAcme()(async () => {
|
||||
// learn async/await, it'll make your life easier
|
||||
let smac = new SmartAcme()
|
||||
|
||||
// optionally accepts a filePath Arg with a stored acmeaccount.json
|
||||
// will create an account and
|
||||
let myAccount = await smac.createAcmeAccount();
|
||||
|
||||
// will return a dnsHash to set in your DNS record
|
||||
let myCert = await myAccount.createAcmeCert('example.com');
|
||||
|
||||
// gets and accepts the specified challenge
|
||||
// first argument optional, defaults to dns-01 (which is the cleanest method for production use)
|
||||
let myChallenge = await myCert.getChallenge('dns-01');
|
||||
|
||||
/* ----------
|
||||
Now you need to set the challenge in your DNS
|
||||
myChallenge.domainNamePrefixed is the address for the record
|
||||
myChallenge.dnsKeyHash is the ready to use txt record value expected by letsencrypt
|
||||
-------------*/
|
||||
})();
|
||||
// TODO
|
||||
```
|
||||
|
||||
## Other relevant npm modules
|
||||
|
||||
| module name | description |
|
||||
| ----------- | ------------------------------------------------------------------- |
|
||||
| cert | a higlevel production module that uses smartacme to manage certs |
|
||||
| smartnginx | a highlevel production tool for docker environments to manage nginx |
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://umbrella.zone
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
@ -1,4 +1,15 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartuniverse",
|
||||
"shortDescription": "acme with an easy yet powerful interface in TypeScript",
|
||||
"npmPackagename": "@pushrocks/smartuniverse",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
|
2341
package-lock.json
generated
2341
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@pushrocks/smartacme",
|
||||
"version": "2.0.25",
|
||||
"version": "2.1.1",
|
||||
"private": false,
|
||||
"description": "acme implementation in TypeScript",
|
||||
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
@ -25,27 +25,28 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.4",
|
||||
"@pushrocks/smartdata": "^3.1.13",
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/lik": "^3.0.13",
|
||||
"@pushrocks/smartdata": "^3.1.23",
|
||||
"@pushrocks/smartdelay": "^2.0.6",
|
||||
"@pushrocks/smartdns": "^3.0.8",
|
||||
"@pushrocks/smartexpress": "^3.0.0",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartrequest": "^1.1.14",
|
||||
"@pushrocks/smartstring": "^3.0.8",
|
||||
"@pushrocks/smarttime": "^3.0.5",
|
||||
"@pushrocks/smartexpress": "^3.0.54",
|
||||
"@pushrocks/smartlog": "^2.0.21",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartrequest": "^1.1.47",
|
||||
"@pushrocks/smartstring": "^3.0.17",
|
||||
"@pushrocks/smarttime": "^3.0.12",
|
||||
"@pushrocks/smartunique": "^3.0.1",
|
||||
"acme-client": "^2.2.2"
|
||||
"acme-client": "2.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@mojoio/cloudflare": "^2.0.0",
|
||||
"@pushrocks/qenv": "^3.0.2",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@mojoio/cloudflare": "^3.0.5",
|
||||
"@pushrocks/qenv": "^4.0.6",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^13.1.8",
|
||||
"tslint": "^5.20.1",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
}
|
||||
}
|
||||
|
10
test/test.ts
10
test/test.ts
@ -12,9 +12,9 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
||||
accountEmail: 'domains@lossless.org',
|
||||
accountPrivateKey: null,
|
||||
mongoDescriptor: {
|
||||
mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'),
|
||||
mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'),
|
||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL')
|
||||
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
||||
},
|
||||
removeChallenge: async (...args) => {
|
||||
console.log(args);
|
||||
@ -22,9 +22,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
||||
setChallenge: async (...args) => {
|
||||
console.log(args);
|
||||
},
|
||||
validateRemoteRequest: async () => {
|
||||
return true;
|
||||
}
|
||||
environment: 'integration'
|
||||
});
|
||||
await smartAcmeInstance.init();
|
||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
|
@ -1,6 +1,7 @@
|
||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
||||
|
||||
export interface ICert {
|
||||
id: string;
|
||||
domainName: string;
|
||||
created: number;
|
||||
privateKey: string;
|
||||
|
@ -5,14 +5,13 @@ import * as interfaces from './interfaces';
|
||||
import { CertManager } from './smartacme.classes.certmanager';
|
||||
|
||||
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
||||
import { ICert } from './interfaces';
|
||||
|
||||
@plugins.smartdata.Collection(() => {
|
||||
return CertManager.activeDB;
|
||||
})
|
||||
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
||||
@unI()
|
||||
public index: string;
|
||||
public id: string;
|
||||
|
||||
@svDb()
|
||||
public domainName: string;
|
||||
@ -29,7 +28,26 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
||||
@svDb()
|
||||
public csr: string;
|
||||
|
||||
constructor(optionsArg: ICert) {
|
||||
|
||||
|
||||
/**
|
||||
* computed value for when the certificate is still valid
|
||||
*/
|
||||
get validUntil (): number {
|
||||
return this.created + plugins.smarttime.getMilliSecondsFromUnits({
|
||||
days: 90
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
get isStillValid (): boolean {
|
||||
const shouldBeValitAtLeastUntil = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({
|
||||
days: 10
|
||||
});
|
||||
return this.validUntil >= shouldBeValitAtLeastUntil;
|
||||
}
|
||||
|
||||
constructor(optionsArg: interfaces.ICert) {
|
||||
super();
|
||||
if (optionsArg) {
|
||||
Object.keys(optionsArg).forEach(key => {
|
||||
|
@ -3,8 +3,6 @@ import { Cert } from './smartacme.classes.cert';
|
||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
import { ICert } from './interfaces';
|
||||
|
||||
|
||||
export class CertManager {
|
||||
// =========
|
||||
@ -12,7 +10,6 @@ export class CertManager {
|
||||
// =========
|
||||
public static activeDB: plugins.smartdata.SmartdataDb;
|
||||
|
||||
|
||||
// =========
|
||||
// INSTANCE
|
||||
// =========
|
||||
@ -21,9 +18,12 @@ export class CertManager {
|
||||
|
||||
public pendingMap: plugins.lik.Stringmap;
|
||||
|
||||
constructor(smartAcmeArg: SmartAcme,optionsArg: {
|
||||
constructor(
|
||||
smartAcmeArg: SmartAcme,
|
||||
optionsArg: {
|
||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ export class CertManager {
|
||||
|
||||
// Pending Map
|
||||
this.pendingMap = new plugins.lik.Stringmap();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves a certificate
|
||||
@ -53,32 +53,39 @@ export class CertManager {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* stores the certificate with the
|
||||
* @param publicKeyArg
|
||||
* @param privateKeyArg
|
||||
* @param csrArg
|
||||
* stores the certificate
|
||||
* @param optionsArg
|
||||
*/
|
||||
public async storeCertificate(optionsArg: ICert) {
|
||||
public async storeCertificate(optionsArg: interfaces.ICert) {
|
||||
const cert = new Cert(optionsArg);
|
||||
await cert.save();
|
||||
this.pendingMap.removeString(optionsArg.domainName);
|
||||
}
|
||||
|
||||
public async deleteCertificate(domainNameArg: string) {
|
||||
public async deleteCertificate(domainNameArg: string) {}
|
||||
|
||||
/**
|
||||
* announce a certificate as being in the process of being retrieved
|
||||
*/
|
||||
public async announceCertificate(domainNameArg: string) {
|
||||
this.pendingMap.addString(domainNameArg);
|
||||
}
|
||||
|
||||
public async getCertificateStatus(domainNameArg: string): Promise<interfaces.TCertStatus> {
|
||||
const isPending = this.pendingMap.checkString('domainNameArg');
|
||||
/**
|
||||
* gets the status of a certificate by certDomain name
|
||||
* @param certDomainArg
|
||||
*/
|
||||
public async getCertificateStatus(certDomainArg: string): Promise<interfaces.TCertStatus> {
|
||||
const isPending = this.pendingMap.checkString(certDomainArg);
|
||||
if (isPending) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
// otherwise lets continue
|
||||
const existingCertificate = this.retrieveCertificate(domainNameArg);
|
||||
const existingCertificate = await this.retrieveCertificate(certDomainArg);
|
||||
if (existingCertificate) {
|
||||
return 'existing';
|
||||
}
|
||||
@ -89,5 +96,7 @@ export class CertManager {
|
||||
/**
|
||||
* checks all certs for expiration
|
||||
*/
|
||||
private async checkCerts() {};
|
||||
private async checkCerts() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,15 @@
|
||||
import * as plugins from './smartacme.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
/**
|
||||
* certmatcher is responsible for matching certificates
|
||||
*/
|
||||
export class CertMatcher {
|
||||
/**
|
||||
* creates a domainName for the certificate that will include the broadest scope
|
||||
* for wild card certificates
|
||||
* @param domainNameArg the domainNameArg to create the scope from
|
||||
*/
|
||||
public getCertificateDomainNameByDomainName(domainNameArg: string): string {
|
||||
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
|
||||
if (!originalDomain.level4) {
|
||||
|
@ -1,40 +1,49 @@
|
||||
import * as plugins from './smartacme.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
import { ICertRemoteResponse } from './interfaces';
|
||||
|
||||
// tslint:disable-next-line: max-classes-per-file
|
||||
export class CertRemoteClient {
|
||||
private remoteUrl: string;
|
||||
private secret: string;
|
||||
private logger: plugins.smartlog.Smartlog;
|
||||
|
||||
constructor(optionsArg: {
|
||||
remoteUrl: string;
|
||||
secret: string;
|
||||
logger?: plugins.smartlog.Smartlog;
|
||||
}) {
|
||||
this.remoteUrl = optionsArg.remoteUrl;
|
||||
this.secret = optionsArg.secret;
|
||||
optionsArg.logger
|
||||
? (this.logger = optionsArg.logger)
|
||||
: (this.logger = plugins.smartlog.defaultLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param domainNameArg
|
||||
*/
|
||||
async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
|
||||
public async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
|
||||
let certificate: interfaces.ICert;
|
||||
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
||||
const response: ICertRemoteResponse = (await plugins.smartrequest.postJson(this.remoteUrl, {
|
||||
const responseBody: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson(
|
||||
this.remoteUrl,
|
||||
{
|
||||
requestBody: <interfaces.ICertRemoteRequest>{
|
||||
domainName: domainNameArg,
|
||||
secret: this.secret
|
||||
}
|
||||
})).body;
|
||||
switch(response.status) {
|
||||
}
|
||||
)).body;
|
||||
switch (responseBody.status as interfaces.TCertStatus) {
|
||||
case 'pending':
|
||||
this.logger.log('info', `request for ${domainNameArg} still pending!`);
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
const finalResponse = await doRequestCycle();
|
||||
return finalResponse;
|
||||
case 'existing':
|
||||
return response.certificate;
|
||||
this.logger.log('ok', `got certificate for ${domainNameArg}`);
|
||||
return responseBody.certificate;
|
||||
case 'failed':
|
||||
default:
|
||||
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
||||
|
@ -15,7 +15,8 @@ export interface ISmartAcmeOptions {
|
||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||
removeChallenge: (domainName: string) => Promise<any>;
|
||||
validateRemoteRequest: () => Promise<boolean>;
|
||||
environment: 'production' | 'integration';
|
||||
logger?: plugins.smartlog.Smartlog;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,6 +35,7 @@ export class SmartAcme {
|
||||
// the acme client
|
||||
private client: any;
|
||||
private smartdns = new plugins.smartdns.Smartdns();
|
||||
public logger: plugins.smartlog.Smartlog;
|
||||
|
||||
// the account private key
|
||||
private privateKey: string;
|
||||
@ -41,15 +43,56 @@ export class SmartAcme {
|
||||
// challenge fullfillment
|
||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||
private removeChallenge: (domainName: string) => Promise<any>;
|
||||
private validateRemoteRequest: () => Promise<boolean>;
|
||||
|
||||
// certmanager
|
||||
private certmanager: CertManager;
|
||||
private certmatcher: CertMatcher;
|
||||
private certremoteHandler: plugins.smartexpress.Handler;
|
||||
|
||||
/**
|
||||
* the remote handler to hand the request and response to.
|
||||
*/
|
||||
public certremoteHandler = async (
|
||||
req: plugins.smartexpress.Request,
|
||||
res: plugins.smartexpress.Response
|
||||
) => {
|
||||
const requestBody: interfaces.ICertRemoteRequest = req.body;
|
||||
this.logger.log('ok', `got certificate request for ${requestBody.domainName}`);
|
||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(
|
||||
requestBody.domainName
|
||||
);
|
||||
this.logger.log('ok', `mapping ${requestBody.domainName} to ${certDomain}`);
|
||||
let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(certDomain);
|
||||
let response: interfaces.ICertRemoteResponse;
|
||||
switch (status) {
|
||||
case 'existing':
|
||||
this.logger.log('ok', `certificate exists for ${certDomain}. Sending certificate!`);
|
||||
response = {
|
||||
status,
|
||||
certificate: await (await this.certmanager.retrieveCertificate(
|
||||
certDomain
|
||||
)).createSavableObject()
|
||||
};
|
||||
break;
|
||||
default:
|
||||
if (status === 'nonexisting') {
|
||||
this.getCertificateForDomain(certDomain);
|
||||
status = 'pending';
|
||||
}
|
||||
response = {
|
||||
status
|
||||
};
|
||||
break;
|
||||
}
|
||||
res.status(200);
|
||||
res.send(response);
|
||||
res.end();
|
||||
};
|
||||
|
||||
constructor(optionsArg: ISmartAcmeOptions) {
|
||||
this.options = optionsArg;
|
||||
this.options.logger
|
||||
? (this.logger = optionsArg.logger)
|
||||
: (this.logger = plugins.smartlog.defaultLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,41 +116,15 @@ export class SmartAcme {
|
||||
// CertMatcher
|
||||
this.certmatcher = new CertMatcher();
|
||||
|
||||
// CertRemoteHandler
|
||||
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
|
||||
const requestBody: interfaces.ICertRemoteRequest = req.body;
|
||||
const status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(requestBody.domainName);
|
||||
const existingCertificate = await this.certmanager.retrieveCertificate(
|
||||
requestBody.domainName
|
||||
);
|
||||
let response: interfaces.ICertRemoteResponse;
|
||||
switch (status) {
|
||||
case 'existing':
|
||||
response = {
|
||||
status,
|
||||
certificate: {
|
||||
created: existingCertificate.created,
|
||||
csr: existingCertificate.csr,
|
||||
domainName: existingCertificate.domainName,
|
||||
privateKey: existingCertificate.privateKey,
|
||||
publicKey: existingCertificate.publicKey
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
response = {
|
||||
status
|
||||
};
|
||||
break;
|
||||
}
|
||||
res.status(200);
|
||||
res.send(response);
|
||||
res.end();
|
||||
});
|
||||
|
||||
// ACME Client
|
||||
this.client = new plugins.acme.Client({
|
||||
directoryUrl: plugins.acme.directory.letsencrypt.staging,
|
||||
directoryUrl: (() => {
|
||||
if (this.options.environment === 'production') {
|
||||
return plugins.acme.directory.letsencrypt.production;
|
||||
} else {
|
||||
return plugins.acme.directory.letsencrypt.staging;
|
||||
}
|
||||
})(),
|
||||
accountKey: this.privateKey
|
||||
});
|
||||
|
||||
@ -122,13 +139,28 @@ export class SmartAcme {
|
||||
await this.certmanager.smartdataDb.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a certificate
|
||||
* it runs through the following steps
|
||||
*
|
||||
* * look in the database
|
||||
* * if in the database return it
|
||||
* * of not in the database announce it
|
||||
* * then get it from letsencrypt
|
||||
* * store it
|
||||
* * remove it from the pending map (which it go onto by announcing it)
|
||||
* * retrieve it from the databse and return it
|
||||
*
|
||||
* @param domainArg
|
||||
*/
|
||||
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||
|
||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
||||
|
||||
if (retrievedCertificate) {
|
||||
return retrievedCertificate;
|
||||
} else {
|
||||
await this.certmanager.announceCertificate(certDomain);
|
||||
}
|
||||
|
||||
/* Place new order */
|
||||
@ -183,11 +215,9 @@ export class SmartAcme {
|
||||
const cert = await this.client.getCertificate(order);
|
||||
|
||||
/* Done */
|
||||
console.log(`CSR:\n${csr.toString()}`);
|
||||
console.log(`Private key:\n${key.toString()}`);
|
||||
console.log(`Certificate:\n${cert.toString()}`);
|
||||
|
||||
await this.certmanager.storeCertificate({
|
||||
id: plugins.smartunique.shortId(),
|
||||
domainName: certDomain,
|
||||
privateKey: key.toString(),
|
||||
publicKey: cert.toString(),
|
||||
|
@ -4,13 +4,26 @@ import * as smartdata from '@pushrocks/smartdata';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartdns from '@pushrocks/smartdns';
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
|
||||
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smartstring, smarttime };
|
||||
export {
|
||||
lik,
|
||||
smartdata,
|
||||
smartdelay,
|
||||
smartdns,
|
||||
smartexpress,
|
||||
smartlog,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
smartunique,
|
||||
smartstring,
|
||||
smarttime
|
||||
};
|
||||
|
||||
// thirs party scope
|
||||
import * as acme from 'acme-client';
|
||||
|
Reference in New Issue
Block a user