Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
d6b1f942b3 | |||
7eff6ea36a | |||
1ef3615a49 | |||
3653cdc797 | |||
c0271648fc | |||
5546fa5f49 | |||
54fe89860e | |||
d1edf75f6f | |||
6f9c644221 | |||
0b26054687 | |||
e3323ed4ef | |||
24f692636c | |||
a9f709ee7b | |||
1b11b637a5 |
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.13",
|
"version": "2.0.20",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -1614,9 +1614,9 @@
|
|||||||
"integrity": "sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU="
|
"integrity": "sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU="
|
||||||
},
|
},
|
||||||
"luxon": {
|
"luxon": {
|
||||||
"version": "1.9.0",
|
"version": "1.10.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/luxon/-/luxon-1.9.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/luxon/-/luxon-1.10.0.tgz",
|
||||||
"integrity": "sha512-N1kSwtIEhM/gIRGASXPgi1CwfQZX5VTjndYFjOsZdEEtWij2uSoRrgDGWwViZCUNY9Rwh4UVG/TLcUinHM20cA=="
|
"integrity": "sha512-ry3GKh//v3isD6oJN5pFWmdh+3GiScwv9q8VgG6fZ2j1guGOol2vVVdo4GBAWCrcq5RHOqSeipqHBnOu/u024Q=="
|
||||||
},
|
},
|
||||||
"make-error": {
|
"make-error": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.13",
|
"version": "2.0.20",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "acme implementation in TypeScript",
|
"description": "acme implementation in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -30,4 +30,8 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should stop correctly', async () => {
|
||||||
|
await smartAcmeInstance.stop();
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -5,6 +5,7 @@ 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;
|
||||||
@ -28,10 +29,10 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
|||||||
@svDb()
|
@svDb()
|
||||||
public csr: string;
|
public csr: string;
|
||||||
|
|
||||||
constructor(privateKeyArg: string, publicKeyArg: string, csrArg: string) {
|
constructor(optionsArg: ICert) {
|
||||||
super();
|
super();
|
||||||
this.privateKey = privateKeyArg;
|
Object.keys(optionsArg).forEach(key => {
|
||||||
this.publicKey = publicKeyArg;
|
this[key] = optionsArg[key];
|
||||||
this.csr = csrArg;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { Cert } from './smartacme.classes.cert';
|
|||||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
import { ICert } from './interfaces';
|
||||||
|
|
||||||
|
|
||||||
export class CertManager {
|
export class CertManager {
|
||||||
@ -44,7 +45,7 @@ export class CertManager {
|
|||||||
public async retrieveCertificate(domainName: string): Promise<Cert> {
|
public async retrieveCertificate(domainName: string): Promise<Cert> {
|
||||||
await this.checkCerts();
|
await this.checkCerts();
|
||||||
const existingCertificate: Cert = await Cert.getInstance({
|
const existingCertificate: Cert = await Cert.getInstance({
|
||||||
name: domainName
|
domainName
|
||||||
});
|
});
|
||||||
|
|
||||||
if(existingCertificate) {
|
if(existingCertificate) {
|
||||||
@ -61,8 +62,8 @@ export class CertManager {
|
|||||||
* @param privateKeyArg
|
* @param privateKeyArg
|
||||||
* @param csrArg
|
* @param csrArg
|
||||||
*/
|
*/
|
||||||
public async storeCertificate(privateKeyArg: string, publicKeyArg: string, csrArg: string) {
|
public async storeCertificate(optionsArg: ICert) {
|
||||||
const cert = new Cert(privateKeyArg, publicKeyArg, csrArg);
|
const cert = new Cert(optionsArg);
|
||||||
cert.save();
|
cert.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins';
|
||||||
|
import { Cert } from './smartacme.classes.cert';
|
||||||
import { CertManager } from './smartacme.classes.certmanager';
|
import { CertManager } from './smartacme.classes.certmanager';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
import { request } from 'http';
|
import { request } from 'http';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* the options for the class @see SmartAcme
|
||||||
*/
|
*/
|
||||||
export interface ISmartAcmeOptions {
|
export interface ISmartAcmeOptions {
|
||||||
accountPrivateKey?: string;
|
accountPrivateKey?: string;
|
||||||
@ -16,6 +17,16 @@ export interface ISmartAcmeOptions {
|
|||||||
validateRemoteRequest: () => Promise<boolean>;
|
validateRemoteRequest: () => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class SmartAcme
|
||||||
|
* can be used for setting up communication with an ACME authority
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const mySmartAcmeInstance = new SmartAcme({
|
||||||
|
* // see ISmartAcmeOptions for options
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
export class SmartAcme {
|
export class SmartAcme {
|
||||||
private options: ISmartAcmeOptions;
|
private options: ISmartAcmeOptions;
|
||||||
|
|
||||||
@ -41,6 +52,9 @@ export class SmartAcme {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* inits the instance
|
* inits the instance
|
||||||
|
* ```ts
|
||||||
|
* await myCloudlyInstance.init() // does not support options
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
public async init() {
|
public async init() {
|
||||||
this.privateKey =
|
this.privateKey =
|
||||||
@ -99,7 +113,11 @@ export class SmartAcme {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCertificateForDomain(domainArg: string) {
|
public async stop() {
|
||||||
|
await this.certmanager.smartdataDb.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
||||||
const domain = domainArg;
|
const domain = domainArg;
|
||||||
|
|
||||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);
|
||||||
@ -162,6 +180,15 @@ export class SmartAcme {
|
|||||||
console.log(`Private key:\n${key.toString()}`);
|
console.log(`Private key:\n${key.toString()}`);
|
||||||
console.log(`Certificate:\n${cert.toString()}`);
|
console.log(`Certificate:\n${cert.toString()}`);
|
||||||
|
|
||||||
this.certmanager.storeCertificate(key.toString(), cert.toString(), csr.toString());
|
await this.certmanager.storeCertificate({
|
||||||
|
domainName: domainArg,
|
||||||
|
privateKey: key.toString(),
|
||||||
|
publicKey: cert.toString(),
|
||||||
|
csr: csr.toString(),
|
||||||
|
created: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
const newCertificate = await this.certmanager.retrieveCertificate(domainArg);
|
||||||
|
return newCertificate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user