smartacme/ts/smartacme.classes.certmatcher.ts

27 lines
961 B
TypeScript
Raw Normal View History

import * as plugins from './plugins.js';
2022-09-27 15:40:55 +02:00
import * as interfaces from './interfaces/index.js';
2019-01-13 02:10:00 +01:00
2019-02-06 14:37:00 +01:00
/**
* certmatcher is responsible for matching certificates
*/
export class SmartacmeCertMatcher {
2019-02-06 14:37:00 +01:00
/**
* creates a domainName for the certificate that will include the broadest scope
* for wild card certificates
* @param domainNameArg the domainNameArg to create the scope from
*/
2025-05-04 10:29:33 +00:00
public getCertificateDomainNameByDomainName(domainNameArg: string): string | undefined {
// Handle wildcard domains by stripping the '*.' prefix.
if (domainNameArg.startsWith('*.')) {
return domainNameArg.slice(2);
}
2019-01-13 02:10:00 +01:00
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
2025-05-04 10:29:33 +00:00
// For domains with up to 3 levels (no level4), return base domain.
2019-01-13 02:10:00 +01:00
if (!originalDomain.level4) {
return `${originalDomain.level2}.${originalDomain.level1}`;
}
2025-05-04 10:29:33 +00:00
// Deeper domains (4+ levels) are not supported.
return undefined;
2019-01-13 02:10:00 +01:00
}
}