perf: 支持中文域名

pull/409/head
xiaojunnuo 2025-04-24 11:55:14 +08:00
parent a586a92d5e
commit 162ebfd4e0
2 changed files with 23 additions and 7 deletions

View File

@ -7,7 +7,7 @@ import { IContext } from "@certd/pipeline";
import { ILogger, utils } from "@certd/basic"; import { ILogger, utils } from "@certd/basic";
import { IDnsProvider, IDomainParser } from "../../dns-provider/index.js"; import { IDnsProvider, IDomainParser } from "../../dns-provider/index.js";
import { HttpChallengeUploader } from "./uploads/api.js"; import { HttpChallengeUploader } from "./uploads/api.js";
import punycode from "node:punycode";
export type CnameVerifyPlan = { export type CnameVerifyPlan = {
type?: string; type?: string;
domain: string; domain: string;
@ -203,14 +203,15 @@ export class AcmeService {
this.logger.info("dns校验"); this.logger.info("dns校验");
const keyAuthorization = await keyAuthorizationGetter(challenge); const keyAuthorization = await keyAuthorizationGetter(challenge);
const mainDomain = dnsProvider.usePunyCode() ? domain : punycode.toUnicode(domain);
const recordValue = keyAuthorization; const recordValue = keyAuthorization;
let hostRecord = fullRecord.replace(`${domain}`, ""); let hostRecord = fullRecord.replace(`${mainDomain}`, "");
if (hostRecord.endsWith(".")) { if (hostRecord.endsWith(".")) {
hostRecord = hostRecord.substring(0, hostRecord.length - 1); hostRecord = hostRecord.substring(0, hostRecord.length - 1);
} }
const recordReq = { const recordReq = {
domain, domain: mainDomain,
fullRecord, fullRecord,
hostRecord, hostRecord,
type: "TXT", type: "TXT",
@ -321,9 +322,16 @@ export class AcmeService {
isTest?: boolean; isTest?: boolean;
privateKeyType?: string; privateKeyType?: string;
}): Promise<CertInfo> { }): Promise<CertInfo> {
const { email, isTest, domains, csrInfo, dnsProvider, domainsVerifyPlan, httpUploader } = options; const { email, isTest, csrInfo, dnsProvider, domainsVerifyPlan, httpUploader } = options;
const client: acme.Client = await this.getAcmeClient(email, isTest); const client: acme.Client = await this.getAcmeClient(email, isTest);
let domains = options.domains;
const encodingDomains = [];
for (const domain of domains) {
encodingDomains.push(punycode.toASCII(domain));
}
domains = encodingDomains;
/* Create CSR */ /* Create CSR */
const { commonName, altNames } = this.buildCommonNameByDomains(domains); const { commonName, altNames } = this.buildCommonNameByDomains(domains);
let privateKey = null; let privateKey = null;

View File

@ -1,5 +1,5 @@
import { CreateRecordOptions, DnsProviderContext, IDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert'; import {CreateRecordOptions, DnsProviderContext, IDnsProvider, RemoveRecordOptions} from '@certd/plugin-cert';
import { PlusService } from '@certd/lib-server'; import {PlusService} from '@certd/lib-server';
export type CommonCnameProvider = { export type CommonCnameProvider = {
id: number; id: number;
@ -24,7 +24,13 @@ export class CommonDnsProvider implements IDnsProvider {
this.plusService = opts.plusService; this.plusService = opts.plusService;
} }
async onInstance() {} usePunyCode(): boolean {
return false
}
async onInstance() {
}
async createRecord(options: CreateRecordOptions) { async createRecord(options: CreateRecordOptions) {
if (!this.config.domain.endsWith(options.domain)) { if (!this.config.domain.endsWith(options.domain)) {
throw new Error('cname服务域名不匹配'); throw new Error('cname服务域名不匹配');
@ -45,6 +51,7 @@ export class CommonDnsProvider implements IDnsProvider {
}); });
return res; return res;
} }
async removeRecord(options: RemoveRecordOptions<any>) { async removeRecord(options: RemoveRecordOptions<any>) {
const res = await this.plusService.requestWithToken({ const res = await this.plusService.requestWithToken({
url: '/activation/certd/cname/recordRemove', url: '/activation/certd/cname/recordRemove',
@ -60,6 +67,7 @@ export class CommonDnsProvider implements IDnsProvider {
}); });
return res; return res;
} }
setCtx(ctx: DnsProviderContext): void { setCtx(ctx: DnsProviderContext): void {
this.ctx = ctx; this.ctx = ctx;
} }