[BREAKING CHANGE] add _. for TXT

Just realized I can't put TXT on CNAME :/
This commit is contained in:
Wildan M 2021-09-21 06:12:17 +07:00
commit 6b2a6e8186
4 changed files with 23 additions and 11 deletions

View file

@ -35,12 +35,12 @@ const acme_prefix = '/.well-known/acme-challenge/';
const listener = async function (/** @type {import('http').IncomingMessage} */ req, /** @type {import('http').ServerResponse} */ res) {
try {
if (req.url.startsWith(acme_prefix)) {
if (client.challengeCallbacks) {
if (client.challengeCallbacks[req.headers.host]) {
res.writeHead(200, {
// This is important :)
'content-type': 'application/octet-stream'
});
res.write(client.challengeCallbacks());
res.write(client.challengeCallbacks[req.headers.host]());
} else {
res.writeHead(404)
}

View file

@ -22,10 +22,16 @@ function getCertCachePath(host) {
return path.join(certsDir, hash.substr(0, 2), hash.substr(2), host);
}
/**
* @param {string} host
*/
async function findMaintainerEmail(host) {
return await findTxtRecord(host, record_email_prefix);
}
/**
* @param {string} host
*/
async function buildCache(host) {
const dir = getCertCachePath(host);
const keyP = path.join(dir, 'privateKey.pem');
@ -64,6 +70,9 @@ async function buildCache(host) {
}
/**
* @param {string} servername
*/
async function getKeyCert(servername) {
let cache = resolveCache[servername];
await ensureDir(certsDir);

View file

@ -17,8 +17,12 @@ async function ensureDir(dir) {
}
}
/**
* @param {string} host
* @param {string} prefix
*/
async function findTxtRecord(host, prefix, required = true) {
const resolve = await axios(`https://dns.google/resolve?name=${encodeURIComponent(host)}&type=TXT`);
const resolve = await axios(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`);
if (resolve.data.Answer) {
for (const head of resolve.data.Answer) {
if (!head.data.startsWith(prefix))