Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
ac515f5e80 | |||
6abbf58b83 | |||
9c25ecdc02 | |||
81a15da2d0 | |||
86929251ba | |||
1d8fb2b296 | |||
9d5f0d7a5d |
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 and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
## Availabililty
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme)
|
|
||||||
[](https://github.com/umbrellazone/smartacme)
|
|
||||||
[](https://umbrellazone.gitlab.io/smartacme/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||||
[](https://david-dm.org/umbrellazone/smartacme)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](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/)
|
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -28,36 +23,14 @@ Use TypeScript for best in class instellisense.
|
|||||||
```javascript
|
```javascript
|
||||||
import { SmartAcme } from 'smartacme';
|
import { SmartAcme } from 'smartacme';
|
||||||
|
|
||||||
let smac = new SmartAcme()(async () => {
|
let smac = new SmartAcme()
|
||||||
// learn async/await, it'll make your life easier
|
|
||||||
|
|
||||||
// optionally accepts a filePath Arg with a stored acmeaccount.json
|
// TODO
|
||||||
// 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
|
|
||||||
-------------*/
|
|
||||||
})();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Other relevant npm modules
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
| 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 |
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> 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": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
2342
package-lock.json
generated
2342
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.35",
|
"version": "2.1.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "acme implementation in TypeScript",
|
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -25,28 +25,28 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.4",
|
"@pushrocks/lik": "^3.0.13",
|
||||||
"@pushrocks/smartdata": "^3.1.13",
|
"@pushrocks/smartdata": "^3.1.23",
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@pushrocks/smartdns": "^3.0.8",
|
"@pushrocks/smartdns": "^3.0.8",
|
||||||
"@pushrocks/smartexpress": "^3.0.6",
|
"@pushrocks/smartexpress": "^3.0.54",
|
||||||
"@pushrocks/smartlog": "^2.0.11",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
"@pushrocks/smartstring": "^3.0.8",
|
"@pushrocks/smartstring": "^3.0.17",
|
||||||
"@pushrocks/smarttime": "^3.0.5",
|
"@pushrocks/smarttime": "^3.0.12",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"acme-client": "2.2.2"
|
"acme-client": "2.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.4",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tsrun": "^1.1.17",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.18",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@mojoio/cloudflare": "^2.0.0",
|
"@mojoio/cloudflare": "^3.0.5",
|
||||||
"@pushrocks/qenv": "^4.0.0",
|
"@pushrocks/qenv": "^4.0.6",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/node": "^10.12.18",
|
"@types/node": "^13.1.8",
|
||||||
"tslint": "^5.12.1",
|
"tslint": "^5.20.1",
|
||||||
"tslint-config-prettier": "^1.17.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
setChallenge: async (...args) => {
|
setChallenge: async (...args) => {
|
||||||
console.log(args);
|
console.log(args);
|
||||||
},
|
},
|
||||||
environment: "integration"
|
environment: 'integration'
|
||||||
});
|
});
|
||||||
await smartAcmeInstance.init();
|
await smartAcmeInstance.init();
|
||||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
|
@ -5,7 +5,6 @@ import * as interfaces from './interfaces';
|
|||||||
import { CertManager } from './smartacme.classes.certmanager';
|
import { CertManager } from './smartacme.classes.certmanager';
|
||||||
|
|
||||||
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
||||||
import { ICert } from './interfaces';
|
|
||||||
|
|
||||||
@plugins.smartdata.Collection(() => {
|
@plugins.smartdata.Collection(() => {
|
||||||
return CertManager.activeDB;
|
return CertManager.activeDB;
|
||||||
@ -29,7 +28,26 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
|||||||
@svDb()
|
@svDb()
|
||||||
public csr: string;
|
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();
|
super();
|
||||||
if (optionsArg) {
|
if (optionsArg) {
|
||||||
Object.keys(optionsArg).forEach(key => {
|
Object.keys(optionsArg).forEach(key => {
|
||||||
|
@ -4,14 +4,12 @@ import { SmartAcme } from './smartacme.classes.smartacme';
|
|||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
|
||||||
export class CertManager {
|
export class CertManager {
|
||||||
// =========
|
// =========
|
||||||
// STATIC
|
// STATIC
|
||||||
// =========
|
// =========
|
||||||
public static activeDB: plugins.smartdata.SmartdataDb;
|
public static activeDB: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
|
|
||||||
// =========
|
// =========
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// =========
|
// =========
|
||||||
@ -20,13 +18,16 @@ export class CertManager {
|
|||||||
|
|
||||||
public pendingMap: plugins.lik.Stringmap;
|
public pendingMap: plugins.lik.Stringmap;
|
||||||
|
|
||||||
constructor(smartAcmeArg: SmartAcme,optionsArg: {
|
constructor(
|
||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
smartAcmeArg: SmartAcme,
|
||||||
}) {
|
optionsArg: {
|
||||||
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
|
}
|
||||||
|
) {
|
||||||
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init () {
|
public async init() {
|
||||||
// Smartdata DB
|
// Smartdata DB
|
||||||
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
||||||
await this.smartdataDb.init();
|
await this.smartdataDb.init();
|
||||||
@ -47,12 +48,11 @@ export class CertManager {
|
|||||||
domainName
|
domainName
|
||||||
});
|
});
|
||||||
|
|
||||||
if(existingCertificate) {
|
if (existingCertificate) {
|
||||||
return existingCertificate;
|
return existingCertificate;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,14 +65,12 @@ export class CertManager {
|
|||||||
this.pendingMap.removeString(optionsArg.domainName);
|
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
|
* announce a certificate as being in the process of being retrieved
|
||||||
*/
|
*/
|
||||||
public async announceCertificate (domainNameArg: string) {
|
public async announceCertificate(domainNameArg: string) {
|
||||||
this.pendingMap.addString(domainNameArg);
|
this.pendingMap.addString(domainNameArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,5 +98,5 @@ export class CertManager {
|
|||||||
*/
|
*/
|
||||||
private async checkCerts() {
|
private async checkCerts() {
|
||||||
// TODO
|
// TODO
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* certmatcher is responsible for matching certificates
|
||||||
|
*/
|
||||||
export class CertMatcher {
|
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 {
|
public getCertificateDomainNameByDomainName(domainNameArg: string): string {
|
||||||
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
|
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
if (!originalDomain.level4) {
|
if (!originalDomain.level4) {
|
||||||
|
@ -35,9 +35,9 @@ export class CertRemoteClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)).body;
|
)).body;
|
||||||
console.log(responseBody);
|
|
||||||
switch (responseBody.status as interfaces.TCertStatus) {
|
switch (responseBody.status as interfaces.TCertStatus) {
|
||||||
case 'pending':
|
case 'pending':
|
||||||
|
this.logger.log('info', `request for ${domainNameArg} still pending!`);
|
||||||
await plugins.smartdelay.delayFor(5000);
|
await plugins.smartdelay.delayFor(5000);
|
||||||
const finalResponse = await doRequestCycle();
|
const finalResponse = await doRequestCycle();
|
||||||
return finalResponse;
|
return finalResponse;
|
||||||
|
@ -86,7 +86,7 @@ export class SmartAcme {
|
|||||||
res.status(200);
|
res.status(200);
|
||||||
res.send(response);
|
res.send(response);
|
||||||
res.end();
|
res.end();
|
||||||
}
|
};
|
||||||
|
|
||||||
constructor(optionsArg: ISmartAcmeOptions) {
|
constructor(optionsArg: ISmartAcmeOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
|
@ -11,7 +11,19 @@ import * as smartunique from '@pushrocks/smartunique';
|
|||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
|
|
||||||
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartlog, smartpromise, smartrequest, smartunique, smartstring, smarttime };
|
export {
|
||||||
|
lik,
|
||||||
|
smartdata,
|
||||||
|
smartdelay,
|
||||||
|
smartdns,
|
||||||
|
smartexpress,
|
||||||
|
smartlog,
|
||||||
|
smartpromise,
|
||||||
|
smartrequest,
|
||||||
|
smartunique,
|
||||||
|
smartstring,
|
||||||
|
smarttime
|
||||||
|
};
|
||||||
|
|
||||||
// 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