mirror of https://github.com/certd/certd
perf: 支持中文域名
parent
a586a92d5e
commit
162ebfd4e0
|
@ -7,7 +7,7 @@ import { IContext } from "@certd/pipeline";
|
|||
import { ILogger, utils } from "@certd/basic";
|
||||
import { IDnsProvider, IDomainParser } from "../../dns-provider/index.js";
|
||||
import { HttpChallengeUploader } from "./uploads/api.js";
|
||||
|
||||
import punycode from "node:punycode";
|
||||
export type CnameVerifyPlan = {
|
||||
type?: string;
|
||||
domain: string;
|
||||
|
@ -203,14 +203,15 @@ export class AcmeService {
|
|||
this.logger.info("dns校验");
|
||||
const keyAuthorization = await keyAuthorizationGetter(challenge);
|
||||
|
||||
const mainDomain = dnsProvider.usePunyCode() ? domain : punycode.toUnicode(domain);
|
||||
const recordValue = keyAuthorization;
|
||||
let hostRecord = fullRecord.replace(`${domain}`, "");
|
||||
let hostRecord = fullRecord.replace(`${mainDomain}`, "");
|
||||
if (hostRecord.endsWith(".")) {
|
||||
hostRecord = hostRecord.substring(0, hostRecord.length - 1);
|
||||
}
|
||||
|
||||
const recordReq = {
|
||||
domain,
|
||||
domain: mainDomain,
|
||||
fullRecord,
|
||||
hostRecord,
|
||||
type: "TXT",
|
||||
|
@ -321,9 +322,16 @@ export class AcmeService {
|
|||
isTest?: boolean;
|
||||
privateKeyType?: string;
|
||||
}): 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);
|
||||
|
||||
let domains = options.domains;
|
||||
const encodingDomains = [];
|
||||
for (const domain of domains) {
|
||||
encodingDomains.push(punycode.toASCII(domain));
|
||||
}
|
||||
domains = encodingDomains;
|
||||
|
||||
/* Create CSR */
|
||||
const { commonName, altNames } = this.buildCommonNameByDomains(domains);
|
||||
let privateKey = null;
|
||||
|
|
|
@ -24,7 +24,13 @@ export class CommonDnsProvider implements IDnsProvider {
|
|||
this.plusService = opts.plusService;
|
||||
}
|
||||
|
||||
async onInstance() {}
|
||||
usePunyCode(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
async onInstance() {
|
||||
}
|
||||
|
||||
async createRecord(options: CreateRecordOptions) {
|
||||
if (!this.config.domain.endsWith(options.domain)) {
|
||||
throw new Error('cname服务域名不匹配');
|
||||
|
@ -45,6 +51,7 @@ export class CommonDnsProvider implements IDnsProvider {
|
|||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>) {
|
||||
const res = await this.plusService.requestWithToken({
|
||||
url: '/activation/certd/cname/recordRemove',
|
||||
|
@ -60,6 +67,7 @@ export class CommonDnsProvider implements IDnsProvider {
|
|||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
setCtx(ctx: DnsProviderContext): void {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue