mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-28 16:19:49 +03:00
Merge branch 'main' into fix/assorted-bugs
This commit is contained in:
5 files changed
+90
-12
No files matched your search
@@ -6,6 +6,7 @@ import { errorManager } from '$lib/utils/error-manager';
|
||||
|
||||
interface TLSHandshakeRequest {
|
||||
hostname: string;
|
||||
servername?: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ interface TLSHandshakeResponse {
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
try {
|
||||
const body: TLSHandshakeRequest = await request.json();
|
||||
const { hostname, port = 443 } = body;
|
||||
const { hostname, port = 443, servername } = body;
|
||||
|
||||
if (!hostname || typeof hostname !== 'string' || !hostname.trim()) {
|
||||
throw error(400, 'Hostname is required');
|
||||
@@ -46,7 +47,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
|
||||
const trimmedHostname = hostname.trim();
|
||||
|
||||
const result = await performTLSHandshake(trimmedHostname, port);
|
||||
const result = await performTLSHandshake(trimmedHostname, port, servername);
|
||||
return json(result);
|
||||
} catch (err) {
|
||||
errorManager.captureException(err, 'error', { component: 'TLS Handshake API' });
|
||||
@@ -57,7 +58,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
}
|
||||
};
|
||||
|
||||
function performTLSHandshake(hostname: string, port: number): Promise<TLSHandshakeResponse> {
|
||||
function performTLSHandshake(hostname: string, port: number, servername?: string): Promise<TLSHandshakeResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const phases: HandshakePhase[] = [];
|
||||
const startTime = Date.now();
|
||||
@@ -101,7 +102,7 @@ function performTLSHandshake(hostname: string, port: number): Promise<TLSHandsha
|
||||
const tlsSocket = (tls as any).connect(
|
||||
{
|
||||
socket: tcpSocket,
|
||||
servername: hostname,
|
||||
servername: servername || hostname,
|
||||
// SECURITY: rejectUnauthorized must be false for this TLS diagnostic tool.
|
||||
// This tool analyzes TLS handshakes including servers with certificate issues.
|
||||
rejectUnauthorized: false,
|
||||
|
||||
@@ -36,12 +36,14 @@ interface OCSPStaplingReq extends BaseReq {
|
||||
action: 'ocsp-stapling';
|
||||
hostname: string;
|
||||
port?: number;
|
||||
servername?: string;
|
||||
}
|
||||
|
||||
interface CipherPresetsReq extends BaseReq {
|
||||
action: 'cipher-presets';
|
||||
hostname: string;
|
||||
port?: number;
|
||||
servername?: string;
|
||||
}
|
||||
|
||||
interface BannerReq extends BaseReq {
|
||||
@@ -312,12 +314,12 @@ async function probeALPN(host: string, port: number, protocols: string[], server
|
||||
}
|
||||
|
||||
// OCSP Stapling check implementation
|
||||
async function checkOCSPStapling(hostname: string, port: number = 443): Promise<any> {
|
||||
async function checkOCSPStapling(hostname: string, port: number = 443, servername?: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
host: hostname,
|
||||
port,
|
||||
servername: hostname,
|
||||
servername: servername || hostname,
|
||||
requestOCSP: true,
|
||||
// SECURITY: rejectUnauthorized must be false to test OCSP stapling (see above)
|
||||
rejectUnauthorized: false,
|
||||
@@ -388,7 +390,7 @@ async function checkOCSPStapling(hostname: string, port: number = 443): Promise<
|
||||
}
|
||||
|
||||
// Cipher Presets test implementation
|
||||
async function testCipherPresets(hostname: string, port: number = 443): Promise<any> {
|
||||
async function testCipherPresets(hostname: string, port: number = 443, servername?: string): Promise<any> {
|
||||
// First verify the host is reachable by attempting a basic TLS connection
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
@@ -396,6 +398,7 @@ async function testCipherPresets(hostname: string, port: number = 443): Promise<
|
||||
{
|
||||
host: hostname,
|
||||
port,
|
||||
servername: servername || hostname,
|
||||
// SECURITY: rejectUnauthorized must be false to test cipher presets (see above)
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
@@ -857,7 +860,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
}
|
||||
|
||||
case 'ocsp-stapling': {
|
||||
const { hostname, port = 443 } = body as OCSPStaplingReq;
|
||||
const { hostname, port = 443, servername } = body as OCSPStaplingReq;
|
||||
|
||||
// Validate hostname
|
||||
if (!hostname || typeof hostname !== 'string' || hostname.trim() === '') {
|
||||
@@ -869,12 +872,12 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
throw error(400, 'Invalid port number');
|
||||
}
|
||||
|
||||
const result = await checkOCSPStapling(hostname, port);
|
||||
const result = await checkOCSPStapling(hostname, port, servername);
|
||||
return json({ ...result, hostname, port });
|
||||
}
|
||||
|
||||
case 'cipher-presets': {
|
||||
const { hostname, port = 443 } = body as CipherPresetsReq;
|
||||
const { hostname, port = 443, servername } = body as CipherPresetsReq;
|
||||
|
||||
// Validate hostname
|
||||
if (!hostname || typeof hostname !== 'string' || hostname.trim() === '') {
|
||||
@@ -886,7 +889,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
throw error(400, 'Invalid port number');
|
||||
}
|
||||
|
||||
const result = await testCipherPresets(hostname, port);
|
||||
const result = await testCipherPresets(hostname, port, servername);
|
||||
return json({ ...result, hostname, port });
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let hostname = $state('example.com');
|
||||
let port = $state('443');
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const examplesList = [
|
||||
{ host: 'github.com', port: '443', description: 'GitHub cipher support' },
|
||||
@@ -31,6 +34,7 @@
|
||||
action: 'cipher-presets',
|
||||
hostname: hostname.trim().toLowerCase(),
|
||||
port: parseInt(port) || 443,
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -49,6 +53,8 @@
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.host;
|
||||
port = example.port;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
examples.select(index);
|
||||
testCiphers();
|
||||
}
|
||||
@@ -128,6 +134,23 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input type="checkbox" bind:checked={useCustomServername} />
|
||||
Use custom SNI servername
|
||||
</label>
|
||||
{#if useCustomServername}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={servername}
|
||||
placeholder="example.com"
|
||||
disabled={diagnosticState.loading}
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { tlsHandshakeContent } from '$lib/content/tls-handshake';
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
interface HandshakePhase {
|
||||
@@ -34,6 +35,8 @@
|
||||
|
||||
let hostname = $state('google.com');
|
||||
let port = $state(443);
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
const diagnosticState = useDiagnosticState<TLSHandshakeResponse>();
|
||||
const clipboard = useClipboard();
|
||||
const examplesList = [
|
||||
@@ -53,7 +56,11 @@
|
||||
const response = await fetch('/api/internal/diagnostics/tls-handshake', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ hostname: hostname.trim(), port }),
|
||||
body: JSON.stringify({
|
||||
hostname: hostname.trim(),
|
||||
port,
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -70,6 +77,8 @@
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.hostname;
|
||||
port = example.port;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
examples.select(index);
|
||||
analyzeHandshake();
|
||||
}
|
||||
@@ -152,6 +161,24 @@
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input type="checkbox" bind:checked={useCustomServername} />
|
||||
Use custom SNI servername
|
||||
</label>
|
||||
{#if useCustomServername}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={servername}
|
||||
placeholder="example.com"
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (hostname.trim()) analyzeHandshake();
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -346,6 +373,7 @@
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
align-items: flex-end;
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
label {
|
||||
display: block;
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
import { useDiagnosticState, useExamples } from '$lib/composables';
|
||||
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
|
||||
import ErrorCard from '$lib/components/common/ErrorCard.svelte';
|
||||
import { tooltip } from '$lib/actions/tooltip.js';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
let hostname = $state('example.com');
|
||||
let port = $state('443');
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
const examplesList = [
|
||||
{ host: 'cloudflare.com', port: '443', description: 'Cloudflare - OCSP stapling enabled' },
|
||||
@@ -31,6 +34,7 @@
|
||||
action: 'ocsp-stapling',
|
||||
hostname: hostname.trim().toLowerCase(),
|
||||
port: parseInt(port) || 443,
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -49,6 +53,8 @@
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.host;
|
||||
port = example.port;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
examples.select(index);
|
||||
checkOCSP();
|
||||
}
|
||||
@@ -115,6 +121,23 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input type="checkbox" bind:checked={useCustomServername} />
|
||||
Use custom SNI servername
|
||||
</label>
|
||||
{#if useCustomServername}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={servername}
|
||||
placeholder="example.com"
|
||||
disabled={diagnosticState.loading}
|
||||
use:tooltip={'Custom servername for SNI (Server Name Indication)'}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && checkOCSP()}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user