2022-09-27 15:40:55 +02:00
|
|
|
import * as plugins from './smartacme.plugins.js';
|
2019-01-09 00:01:01 +01:00
|
|
|
|
2025-04-30 17:27:17 +00:00
|
|
|
/**
|
|
|
|
* Plain certificate record.
|
|
|
|
*/
|
|
|
|
export class SmartacmeCert {
|
2019-01-16 22:34:38 +01:00
|
|
|
public id: string;
|
2019-01-09 00:01:01 +01:00
|
|
|
public domainName: string;
|
|
|
|
public created: number;
|
|
|
|
public privateKey: string;
|
|
|
|
public publicKey: string;
|
|
|
|
public csr: string;
|
2020-02-10 20:13:06 +00:00
|
|
|
public validUntil: number;
|
|
|
|
|
2025-04-30 17:27:17 +00:00
|
|
|
constructor(data: Partial<SmartacmeCert> = {}) {
|
|
|
|
this.id = data.id || '';
|
|
|
|
this.domainName = data.domainName || '';
|
|
|
|
this.created = data.created || Date.now();
|
|
|
|
this.privateKey = data.privateKey || '';
|
|
|
|
this.publicKey = data.publicKey || '';
|
|
|
|
this.csr = data.csr || '';
|
|
|
|
this.validUntil = data.validUntil || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if certificate is still valid.
|
|
|
|
*/
|
2020-02-10 20:13:06 +00:00
|
|
|
public isStillValid(): boolean {
|
|
|
|
return this.validUntil >= Date.now();
|
2019-02-06 14:37:00 +01:00
|
|
|
}
|
|
|
|
|
2025-04-30 17:27:17 +00:00
|
|
|
/**
|
|
|
|
* Check if certificate needs renewal (e.g., expires in <10 days).
|
|
|
|
*/
|
2020-02-10 20:13:06 +00:00
|
|
|
public shouldBeRenewed(): boolean {
|
2025-04-30 17:27:17 +00:00
|
|
|
const threshold = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({ days: 10 });
|
|
|
|
return this.validUntil < threshold;
|
2019-01-08 20:45:35 +01:00
|
|
|
}
|
|
|
|
}
|