2022-09-27 15:40:55 +02:00
|
|
|
import * as plugins from './smartacme.plugins.js';
|
2024-06-16 13:56:30 +02:00
|
|
|
import { SmartacmeCert } from './smartacme.classes.cert.js';
|
2022-09-27 15:40:55 +02:00
|
|
|
import { SmartAcme } from './smartacme.classes.smartacme.js';
|
2019-01-09 00:01:01 +01:00
|
|
|
|
2022-09-27 15:40:55 +02:00
|
|
|
import * as interfaces from './interfaces/index.js';
|
2019-01-08 20:45:35 +01:00
|
|
|
|
2024-06-16 13:56:30 +02:00
|
|
|
export class SmartacmeCertManager {
|
2019-01-08 20:45:35 +01:00
|
|
|
// =========
|
|
|
|
// STATIC
|
|
|
|
// =========
|
|
|
|
public static activeDB: plugins.smartdata.SmartdataDb;
|
2019-02-06 09:47:33 +01:00
|
|
|
|
2019-01-08 20:45:35 +01:00
|
|
|
// =========
|
|
|
|
// INSTANCE
|
|
|
|
// =========
|
|
|
|
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
|
|
|
public smartdataDb: plugins.smartdata.SmartdataDb;
|
|
|
|
|
2024-06-16 13:56:30 +02:00
|
|
|
public interestMap: plugins.lik.InterestMap<string, SmartacmeCert>;
|
2019-01-09 00:01:01 +01:00
|
|
|
|
2019-02-06 09:47:33 +01:00
|
|
|
constructor(
|
|
|
|
smartAcmeArg: SmartAcme,
|
|
|
|
optionsArg: {
|
|
|
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
2025-04-26 12:48:38 +00:00
|
|
|
},
|
2019-02-06 09:47:33 +01:00
|
|
|
) {
|
2019-01-08 20:45:35 +01:00
|
|
|
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
|
|
|
}
|
|
|
|
|
2019-02-06 09:47:33 +01:00
|
|
|
public async init() {
|
2019-01-09 00:01:01 +01:00
|
|
|
// Smartdata DB
|
2019-01-08 20:45:35 +01:00
|
|
|
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
|
|
|
await this.smartdataDb.init();
|
2024-06-16 13:56:30 +02:00
|
|
|
SmartacmeCertManager.activeDB = this.smartdataDb;
|
2019-01-09 00:01:01 +01:00
|
|
|
|
|
|
|
// Pending Map
|
2020-08-12 16:36:06 +00:00
|
|
|
this.interestMap = new plugins.lik.InterestMap((certName) => certName);
|
2019-01-13 21:40:40 +01:00
|
|
|
}
|
2019-01-08 20:45:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* retrieves a certificate
|
|
|
|
* @returns the Cert class or null
|
2020-02-10 20:13:06 +00:00
|
|
|
* @param certDomainNameArg the domain Name to retrieve the vcertificate for
|
2019-01-08 20:45:35 +01:00
|
|
|
*/
|
2024-06-16 13:56:30 +02:00
|
|
|
public async retrieveCertificate(certDomainNameArg: string): Promise<SmartacmeCert> {
|
|
|
|
const existingCertificate: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
|
2020-08-12 16:36:06 +00:00
|
|
|
domainName: certDomainNameArg,
|
2019-01-08 20:45:35 +01:00
|
|
|
});
|
|
|
|
|
2019-02-06 09:47:33 +01:00
|
|
|
if (existingCertificate) {
|
2019-01-08 20:45:35 +01:00
|
|
|
return existingCertificate;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-01-15 23:39:31 +01:00
|
|
|
* stores the certificate
|
2019-02-06 09:47:33 +01:00
|
|
|
* @param optionsArg
|
2019-01-08 20:45:35 +01:00
|
|
|
*/
|
2020-02-10 20:13:06 +00:00
|
|
|
public async storeCertificate(optionsArg: plugins.tsclass.network.ICert) {
|
2024-06-16 13:56:30 +02:00
|
|
|
const cert = new SmartacmeCert(optionsArg);
|
2019-01-13 19:40:32 +01:00
|
|
|
await cert.save();
|
2020-02-10 20:13:06 +00:00
|
|
|
const interest = this.interestMap.findInterest(cert.domainName);
|
|
|
|
if (interest) {
|
|
|
|
interest.fullfillInterest(cert);
|
|
|
|
interest.markLost();
|
2019-01-09 00:01:01 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 20:45:35 +01:00
|
|
|
|
2020-02-10 20:13:06 +00:00
|
|
|
public async deleteCertificate(certDomainNameArg: string) {
|
2024-06-16 13:56:30 +02:00
|
|
|
const cert: SmartacmeCert = await SmartacmeCert.getInstance<SmartacmeCert>({
|
2020-08-12 16:36:06 +00:00
|
|
|
domainName: certDomainNameArg,
|
2020-02-10 20:13:06 +00:00
|
|
|
});
|
|
|
|
await cert.delete();
|
2019-02-06 09:47:33 +01:00
|
|
|
}
|
2019-01-08 20:45:35 +01:00
|
|
|
}
|