Fixed SSL checking lambda function

This commit is contained in:
Alicia Sykes 2023-07-08 17:00:49 +01:00
parent c1ea5788c8
commit 397609e7bc
2 changed files with 22 additions and 10 deletions

View File

@ -5,9 +5,24 @@
publish = "build"
functions = "server/lambda"
# Environmental variables and optioanl secrets
[build.environment]
NODE_VERSION = "16.16.0"
GOOGLE_CLOUD_API_KEY=''
SHODAN_API_KEY=''
REACT_APP_SHODAN_API_KEY=''
WHO_API_KEY=''
REACT_APP_WHO_API_KEY=''
SECURITY_TRAILS_API_KEY=''
BUILT_WITH_API_KEY=''
CI=false
[dev]
command = "yarn start"
port = 8888
targetPort = 3000
publish = "dist"
autoLaunch = false
# Site info, used for the 1-Click deploy page
[template.environment]

View File

@ -1,5 +1,4 @@
const https = require('https');
const { stringify } = require('flatted');
exports.handler = async function (event, context) {
const { url } = event.queryStringParameters;
@ -12,10 +11,7 @@ exports.handler = async function (event, context) {
};
if (!url) {
return {
statusCode: 400,
body: errorResponse('url query parameter is required'),
};
return errorResponse('url query parameter is required');
}
return new Promise((resolve, reject) => {
@ -25,21 +21,22 @@ exports.handler = async function (event, context) {
if (!res.socket.authorized) {
resolve(errorResponse(`SSL handshake not authorized. Reason: ${res.socket.authorizationError}`));
} else {
const cert = res.socket.getPeerCertificate(true);
let cert = res.socket.getPeerCertificate(true);
if (!cert || Object.keys(cert).length === 0) {
resolve(errorResponse("No certificate presented by the server."));
} else {
// omit the raw and issuerCertificate fields
const { raw, issuerCertificate, ...certWithoutRaw } = cert;
resolve({
statusCode: 200,
body: stringify(cert),
body: JSON.stringify(certWithoutRaw),
});
}
}
});
req.on('error', (error) => {
resolve(
errorResponse(`Error fetching site certificate: ${error.message}`, 500));
resolve(errorResponse(`Error fetching site certificate: ${error.message}`, 500));
});
req.end();