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.accountPublicJwk = null
|
||||||
this.accountPublicKey = null
|
this.accountPublicKey = null
|
||||||
this.directoryUrl = directoryUrl
|
this.directoryUrl = directoryUrl
|
||||||
|
this.challengeCallbacks = {}
|
||||||
this.hasDirectory = false
|
this.hasDirectory = false
|
||||||
this.myAccountUrl = ''
|
this.myAccountUrl = ''
|
||||||
this.newAccountUrl = ''
|
this.newAccountUrl = ''
|
||||||
this.newNonceUrl = ''
|
this.newNonceUrl = ''
|
||||||
this.newOrderUrl = ''
|
this.newOrderUrl = ''
|
||||||
this.replayNonce = ''
|
this.replayNonce = ''
|
||||||
this.server = null
|
|
||||||
this.thumbprint = ''
|
this.thumbprint = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,8 +89,6 @@ class Client {
|
||||||
await this.pollAuthz(authzUrls[0])
|
await this.pollAuthz(authzUrls[0])
|
||||||
const { certificate, privateKeyData } = await this.finalizeOrder(finalizeUrl, domain, email)
|
const { certificate, privateKeyData } = await this.finalizeOrder(finalizeUrl, domain, email)
|
||||||
|
|
||||||
this.server?.close()
|
|
||||||
|
|
||||||
return { certificate, privateKeyData }
|
return { certificate, privateKeyData }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -394,41 +392,17 @@ class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
receiveServerRequest (challenge, cb) {
|
receiveServerRequest (challenge, cb) {
|
||||||
this.server?.close()
|
|
||||||
this.server = http.createServer()
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.server
|
const time = setTimeout(() => {
|
||||||
.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(() => {
|
|
||||||
reject(new Error('Timed out waiting for server request'))
|
reject(new Error('Timed out waiting for server request'))
|
||||||
}, 10e3)
|
}, 10e3);
|
||||||
|
this.challengeCallbacks[challenge.token] = function () {
|
||||||
cb && cb()
|
setTimeout(cb, 100);
|
||||||
})
|
clearTimeout(time);
|
||||||
|
resolve();
|
||||||
|
return challenge.token + '.' + this.thumbprint;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setReplayNonce (res) {
|
setReplayNonce (res) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
const record_prefix = 'forward-domain=';
|
const record_prefix = 'forward-domain=';
|
||||||
|
|
||||||
const {
|
|
||||||
default: axios
|
|
||||||
} = require('axios');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const {
|
||||||
|
client
|
||||||
|
} = require('./sni');
|
||||||
const {
|
const {
|
||||||
findTxtRecord
|
findTxtRecord
|
||||||
} = require('./util');
|
} = 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 {
|
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];
|
let cache = resolveCache[req.headers.host];
|
||||||
if (!cache || (Date.now() > cache.expire)) {
|
if (!cache || (Date.now() > cache.expire)) {
|
||||||
cache = await buildCache(req.headers.host);
|
cache = await buildCache(req.headers.host);
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue