tlsing
Version:
tlsing is an open source library available on npm for testing TLS security on websites. It is designed to analyze certificates, check HTTPS protocols, and detect potential security holes. The library is used in the Marchol browser and is based on Node.js,
61 lines (49 loc) • 1.48 kB
JavaScript
import tls from "tls";
import validator from "validator";
export const checkTLS = (url) => {
try {
const port = checkPortInURL(url) || "443";
if (!port || port === "80") return false;
let authorized = false;
// Połączenie TLS bez użycia HTTPS
const socket = tls.connect({ host: url, port }, () => {
const cert = socket.getPeerCertificate();
socket.end();
if (cert && cert.valid_to) {
authorized = socket.authorized;
}
});
socket.on("error", () => {
authorized = false;
});
return authorized;
} catch (error) {
return false;
}
};
export const checkPortInURL = (url) => {
if (validator.isURL(url) || validator.isIP(url)) {
const hasPort = url.match(/:\d+$/);
return hasPort ? hasPort[0].replace(":", "") : null;
}
return null;
};
export const generateMassURL = (url) => {
const port = checkPortInURL(url);
return port !== null ? port : isHttps(url) ? "443" : "80";
};
export const isHttps = (url) => {
const port = checkPortInURL(url);
return port === "443" || checkTLS(url); // Sprawdzanie przez TLS i port
};
export const isHttp = (url) => {
return !isHttps(url);
};
const table = {
checkTLS,
generateMassURL,
checkPortInURL,
isHttps,
isHttp
};
export default table;