Compare commits

..

12 Commits

Author SHA1 Message Date
1ef3615a49 2.0.19 2019-01-13 00:06:00 +01:00
3653cdc797 fix(core): update 2019-01-13 00:06:00 +01:00
c0271648fc 2.0.18 2019-01-12 21:06:29 +01:00
5546fa5f49 fix(core): update 2019-01-12 21:06:29 +01:00
54fe89860e 2.0.17 2019-01-12 19:12:53 +01:00
d1edf75f6f fix(core): update 2019-01-12 19:12:52 +01:00
6f9c644221 2.0.16 2019-01-12 19:11:39 +01:00
0b26054687 fix(core): update 2019-01-12 19:11:39 +01:00
e3323ed4ef 2.0.15 2019-01-12 13:52:21 +01:00
24f692636c fix(core): update 2019-01-12 13:52:21 +01:00
a9f709ee7b 2.0.14 2019-01-12 13:44:18 +01:00
1b11b637a5 fix(core): update 2019-01-12 13:44:18 +01:00
6 changed files with 50 additions and 15 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.13", "version": "2.0.19",
"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",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.13", "version": "2.0.19",
"private": false, "private": false,
"description": "acme implementation in TypeScript", "description": "acme implementation in TypeScript",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -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();

View File

@ -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,12 @@ 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; this.created = optionsArg.created;
this.publicKey = publicKeyArg; this.domainName = optionsArg.domainName;
this.csr = csrArg; this.privateKey = optionsArg.privateKey;
this.publicKey = optionsArg.publicKey;
this.csr = optionsArg.csr;
} }
} }

View File

@ -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();
}; };

View File

@ -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;
} }
} }