|
| 1 | +Fixes for the server reachability test. |
| 2 | + - Do not apply HTTPs redirection for challenge used by the test. |
| 3 | + - Set the `User-Agent` to avoid 403 answer from site24x7.com. |
| 4 | + - Handle JSON parsing failure of the received body. |
| 5 | + - Better handling of different error cases. |
| 6 | + |
| 7 | +diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js |
| 8 | +index f68ef30..ecbb4bf 100644 |
| 9 | +--- a/backend/internal/certificate.js |
| 10 | ++++ b/backend/internal/certificate.js |
| 11 | +@@ -1167,6 +1167,7 @@ const internalCertificate = { |
| 12 | + const options = { |
| 13 | + method: 'POST', |
| 14 | + headers: { |
| 15 | ++ 'User-Agent': 'Mozilla/5.0', |
| 16 | + 'Content-Type': 'application/x-www-form-urlencoded', |
| 17 | + 'Content-Length': Buffer.byteLength(formBody) |
| 18 | + } |
| 19 | +@@ -1179,12 +1180,22 @@ const internalCertificate = { |
| 20 | + |
| 21 | + res.on('data', (chunk) => responseBody = responseBody + chunk); |
| 22 | + res.on('end', function () { |
| 23 | +- const parsedBody = JSON.parse(responseBody + ''); |
| 24 | +- if (res.statusCode !== 200) { |
| 25 | +- logger.warn(`Failed to test HTTP challenge for domain ${domain}`, res); |
| 26 | ++ try { |
| 27 | ++ const parsedBody = JSON.parse(responseBody + ''); |
| 28 | ++ if (res.statusCode !== 200) { |
| 29 | ++ logger.warn(`Failed to test HTTP challenge for domain ${domain} because HTTP status code ${res.statusCode} was returned: ${parsedBody.message}`); |
| 30 | ++ resolve(undefined); |
| 31 | ++ } else { |
| 32 | ++ resolve(parsedBody); |
| 33 | ++ } |
| 34 | ++ } catch (err) { |
| 35 | ++ if (res.statusCode !== 200) { |
| 36 | ++ logger.warn(`Failed to test HTTP challenge for domain ${domain} because HTTP status code ${res.statusCode} was returned`); |
| 37 | ++ } else { |
| 38 | ++ logger.warn(`Failed to test HTTP challenge for domain ${domain} because response failed to be parsed: ${err.message}`); |
| 39 | ++ } |
| 40 | + resolve(undefined); |
| 41 | + } |
| 42 | +- resolve(parsedBody); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | +@@ -1198,6 +1209,9 @@ const internalCertificate = { |
| 47 | + if (!result) { |
| 48 | + // Some error occurred while trying to get the data |
| 49 | + return 'failed'; |
| 50 | ++ } else if (result.error) { |
| 51 | ++ logger.info(`HTTP challenge test failed for domain ${domain} because error was returned: ${result.error.msg}`); |
| 52 | ++ return `other:${result.error.msg}`; |
| 53 | + } else if (`${result.responsecode}` === '200' && result.htmlresponse === 'Success') { |
| 54 | + // Server exists and has responded with the correct data |
| 55 | + return 'ok'; |
| 56 | +diff --git a/docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf b/docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf |
| 57 | +index 15f0d28..aa52f33 100644 |
| 58 | +--- a/docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf |
| 59 | ++++ b/docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf |
| 60 | +@@ -1,3 +1,10 @@ |
| 61 | ++set $test ""; |
| 62 | + if ($scheme = "http") { |
| 63 | ++ set $test "H"; |
| 64 | ++} |
| 65 | ++if ($request_uri = /.well-known/acme-challenge/test-challenge) { |
| 66 | ++ set $test "${test}T"; |
| 67 | ++} |
| 68 | ++if ($test = H) { |
| 69 | + return 301 https://$host$request_uri; |
| 70 | + } |
0 commit comments