This commit is contained in:
2025-05-18 15:51:09 +00:00
parent 01b4a79e1a
commit 538d22f81b
5 changed files with 289 additions and 249 deletions

View File

@ -69,16 +69,13 @@ export class SmartCertManager {
);
if (hasAcmeRoutes && this.acmeOptions?.email) {
// Create SmartAcme instance with our challenge handler
// Create SmartAcme instance with built-in MemoryCertManager
this.smartAcme = new plugins.smartacme.SmartAcme({
accountEmail: this.acmeOptions.email,
environment: this.acmeOptions.useProduction ? 'production' : 'integration',
certManager: new InMemoryCertManager()
certManager: new plugins.smartacme.certmanagers.MemoryCertManager()
});
// The challenge handler is now embedded in the SmartAcme config above
// SmartAcme will handle the challenge internally
await this.smartAcme.start();
}
@ -163,13 +160,18 @@ export class SmartCertManager {
// Use smartacme to get certificate
const cert = await this.smartAcme.getCertificateForDomain(primaryDomain);
// smartacme returns a Cert object with these properties
// SmartAcme's Cert object has these properties:
// - certPem: The certificate PEM string
// - privateKeyPem: The private key PEM string
// - csr: Certificate signing request
// - validUntil: Expiry date as Date object
// - domainName: The domain name
const certData: ICertificateData = {
cert: cert.publicKey,
key: cert.privateKey,
ca: cert.publicKey, // Use same as cert for now
expiryDate: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000), // 90 days
issueDate: new Date()
cert: cert.certPem,
key: cert.privateKeyPem,
ca: cert.certPem, // Use same as cert for now
expiryDate: cert.validUntil,
issueDate: new Date() // SmartAcme doesn't provide issue date
};
await this.certStore.saveCertificate(routeName, certData);
@ -473,45 +475,3 @@ export class SmartCertManager {
}
}
/**
* Simple in-memory certificate manager for SmartAcme
* We only use this to satisfy SmartAcme's interface - actual storage is handled by CertStore
*/
class InMemoryCertManager implements plugins.smartacme.ICertManager {
private store = new Map<string, any>();
// Required methods from ICertManager interface
public async init(): Promise<void> {
// Initialization if needed
}
public async retrieveCertificate(domainName: string): Promise<plugins.smartacme.Cert | null> {
return this.store.get(domainName) || null;
}
public async storeCertificate(cert: plugins.smartacme.Cert): Promise<void> {
this.store.set(cert.domainName, cert);
}
public async deleteCertificate(domainName: string): Promise<void> {
this.store.delete(domainName);
}
public async getCertificates(): Promise<plugins.smartacme.Cert[]> {
return Array.from(this.store.values());
}
public async stop(): Promise<void> {
// Cleanup if needed
}
public async close(): Promise<void> {
// Required by interface
await this.stop();
}
public async wipe(): Promise<void> {
// Required by interface
this.store.clear();
}
}