Try Https
This commit is contained in:
parent
43841ff081
commit
9a6ae9f4ad
2 changed files with 27 additions and 42 deletions
|
|
@ -27,13 +27,13 @@ class Client {
|
|||
this.accountPublicJwk = null
|
||||
this.accountPublicKey = null
|
||||
this.directoryUrl = directoryUrl
|
||||
this.challengeCallbacks = {}
|
||||
this.hasDirectory = false
|
||||
this.myAccountUrl = ''
|
||||
this.newAccountUrl = ''
|
||||
this.newNonceUrl = ''
|
||||
this.newOrderUrl = ''
|
||||
this.replayNonce = ''
|
||||
this.server = null
|
||||
this.thumbprint = ''
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +89,6 @@ class Client {
|
|||
await this.pollAuthz(authzUrls[0])
|
||||
const { certificate, privateKeyData } = await this.finalizeOrder(finalizeUrl, domain, email)
|
||||
|
||||
this.server?.close()
|
||||
|
||||
return { certificate, privateKeyData }
|
||||
}
|
||||
|
||||
|
|
@ -394,41 +392,17 @@ class Client {
|
|||
}
|
||||
|
||||
receiveServerRequest (challenge, cb) {
|
||||
this.server?.close()
|
||||
this.server = http.createServer()
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.server
|
||||
.once('error', reject)
|
||||
.on('request', (req, res) => {
|
||||
if (req.method !== 'GET') {
|
||||
res.writeHead(405)
|
||||
res.writeHead(http.STATUS_CODES[405])
|
||||
return
|
||||
}
|
||||
|
||||
if (req.url !== '/.well-known/acme-challenge/' + challenge.token) {
|
||||
res.writeHead(404)
|
||||
res.end(http.STATUS_CODES[404])
|
||||
return
|
||||
}
|
||||
|
||||
res.writeHead(200, {
|
||||
'content-type': 'application/octet-stream'
|
||||
})
|
||||
|
||||
res.end(challenge.token + '.' + this.thumbprint)
|
||||
resolve()
|
||||
})
|
||||
|
||||
this.server.listen(80, '0.0.0.0')
|
||||
|
||||
setTimeout(() => {
|
||||
const time = setTimeout(() => {
|
||||
reject(new Error('Timed out waiting for server request'))
|
||||
}, 10e3)
|
||||
|
||||
cb && cb()
|
||||
})
|
||||
}, 10e3);
|
||||
this.challengeCallbacks[challenge.token] = function () {
|
||||
setTimeout(cb, 100);
|
||||
clearTimeout(time);
|
||||
resolve();
|
||||
return challenge.token + '.' + this.thumbprint;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setReplayNonce (res) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
const record_prefix = 'forward-domain=';
|
||||
|
||||
const {
|
||||
default: axios
|
||||
} = require('axios');
|
||||
const path = require('path');
|
||||
const {
|
||||
client
|
||||
} = require('./sni');
|
||||
const {
|
||||
findTxtRecord
|
||||
} = require('./util');
|
||||
|
|
@ -30,8 +29,20 @@ async function buildCache(host) {
|
|||
};
|
||||
}
|
||||
|
||||
const listener = async function (req, res) {
|
||||
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)) {
|
||||
const token = req.url.slice(acme_prefix.length);
|
||||
if (client.challengeCallbacks[token]) {
|
||||
res.write(client.challengeCallbacks[token]());
|
||||
} else {
|
||||
res.writeHead(404)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let cache = resolveCache[req.headers.host];
|
||||
if (!cache || (Date.now() > cache.expire)) {
|
||||
cache = await buildCache(req.headers.host);
|
||||
|
|
@ -49,4 +60,4 @@ const listener = async function (req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = listener;
|
||||
module.exports = listener;
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue