mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-22 14:01:44 +03:00
Simplifies SNI handling on TLS tools, adds it to OCSP stapling
Co-authored-by: Alicia Sykes <1862727+lissy93@users.noreply.github.com>
This commit is contained in:
1 parent
e2650dcea7
commit
23b78faa4e
6 files changed
+146
-172
No files matched your search
@@ -19,7 +19,6 @@ interface HandshakePhase {
|
||||
|
||||
interface TLSHandshakeResponse {
|
||||
hostname: string;
|
||||
servername?: string;
|
||||
port: number;
|
||||
success: boolean;
|
||||
totalTime: number;
|
||||
@@ -130,7 +129,6 @@ function performTLSHandshake(hostname: string, port: number, servername?: string
|
||||
|
||||
const response: TLSHandshakeResponse = {
|
||||
hostname,
|
||||
servername: servername || hostname,
|
||||
port,
|
||||
success: true,
|
||||
totalTime,
|
||||
|
||||
@@ -36,13 +36,14 @@ interface OCSPStaplingReq extends BaseReq {
|
||||
action: 'ocsp-stapling';
|
||||
hostname: string;
|
||||
port?: number;
|
||||
servername?: string;
|
||||
}
|
||||
|
||||
interface CipherPresetsReq extends BaseReq {
|
||||
action: 'cipher-presets';
|
||||
hostname: string;
|
||||
servername?: string;
|
||||
port?: number;
|
||||
servername?: string;
|
||||
}
|
||||
|
||||
interface BannerReq extends BaseReq {
|
||||
@@ -313,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,
|
||||
@@ -859,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() === '') {
|
||||
@@ -871,7 +872,7 @@ 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 });
|
||||
}
|
||||
|
||||
@@ -889,7 +890,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
}
|
||||
|
||||
const result = await testCipherPresets(hostname, port, servername);
|
||||
return json({ ...result, hostname, port, servername });
|
||||
return json({ ...result, hostname, port });
|
||||
}
|
||||
|
||||
case 'banner': {
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
let host = $state('');
|
||||
let port = $state<number | null>(null);
|
||||
let servername = $state('');
|
||||
let useCustomServername = $state(false);
|
||||
let service = $state('custom');
|
||||
|
||||
const diagnosticState = useDiagnosticState<any>();
|
||||
@@ -81,7 +79,6 @@
|
||||
body: JSON.stringify({
|
||||
action: 'banner',
|
||||
host: host.trim(),
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
port: port,
|
||||
}),
|
||||
});
|
||||
@@ -213,45 +210,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) grabBanner();
|
||||
}}
|
||||
/>
|
||||
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 (isInputValid()) grabBanner();
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button onclick={grabBanner} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Connecting...
|
||||
{:else}
|
||||
<Icon name="terminal" size="sm" />
|
||||
Grab Banner
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
<button onclick={grabBanner} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Connecting...
|
||||
{:else}
|
||||
<Icon name="terminal" size="sm" />
|
||||
Grab Banner
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
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');
|
||||
@@ -16,17 +17,6 @@
|
||||
{ host: 'google.com', port: '443', description: 'Google cipher support' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedHost = host.trim();
|
||||
if (!trimmedHost) return false;
|
||||
if (port === null || port < 1 || port > 65535) return false;
|
||||
// Basic hostname/IP validation
|
||||
const hostPattern =
|
||||
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|^\[?[a-fA-F0-9:]+\]?$/;
|
||||
return hostPattern.test(trimmedHost);
|
||||
});
|
||||
|
||||
async function testCiphers() {
|
||||
if (!hostname?.trim()) {
|
||||
@@ -43,8 +33,8 @@
|
||||
body: JSON.stringify({
|
||||
action: 'cipher-presets',
|
||||
hostname: hostname.trim().toLowerCase(),
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
port: parseInt(port) || 443,
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -63,6 +53,8 @@
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.host;
|
||||
port = example.port;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
examples.select(index);
|
||||
testCiphers();
|
||||
}
|
||||
@@ -108,72 +100,56 @@
|
||||
<h3>Cipher Presets Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="hostname">Hostname and Port</label>
|
||||
<div class="input-flex-container">
|
||||
<input
|
||||
id="hostname"
|
||||
type="text"
|
||||
bind:value={hostname}
|
||||
placeholder="example.com"
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="flex-grow"
|
||||
/>
|
||||
<input
|
||||
id="port"
|
||||
type="text"
|
||||
bind:value={port}
|
||||
placeholder="443"
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="port-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="hostname">Hostname and Port</label>
|
||||
<div class="input-flex-container">
|
||||
<input
|
||||
id="hostname"
|
||||
type="text"
|
||||
bind:value={hostname}
|
||||
placeholder="example.com"
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="flex-grow"
|
||||
/>
|
||||
<input
|
||||
id="port"
|
||||
type="text"
|
||||
bind:value={port}
|
||||
placeholder="443"
|
||||
disabled={diagnosticState.loading}
|
||||
onchange={() => examples.clear()}
|
||||
onkeydown={(e) => e.key === 'Enter' && testCiphers()}
|
||||
class="port-input"
|
||||
/>
|
||||
<button onclick={testCiphers} disabled={diagnosticState.loading} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Testing...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
Test
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) testCiphers();
|
||||
}}
|
||||
/>
|
||||
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 (isInputValid()) testCiphers();
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button onclick={testCiphers} disabled={diagnosticState.loading || !isInputValid} class="primary">
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
Testing...
|
||||
{:else}
|
||||
<Icon name="search" size="sm" />
|
||||
Test
|
||||
{/if}
|
||||
</button>
|
||||
<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 {
|
||||
@@ -47,17 +48,6 @@
|
||||
{ hostname: 'zoom.us', port: 443, description: 'Zoom' },
|
||||
];
|
||||
const examples = useExamples(examplesList);
|
||||
|
||||
// Reactive validation
|
||||
const isInputValid = $derived(() => {
|
||||
const trimmedHost = host.trim();
|
||||
if (!trimmedHost) return false;
|
||||
if (port === null || port < 1 || port > 65535) return false;
|
||||
// Basic hostname/IP validation
|
||||
const hostPattern =
|
||||
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|^\[?[a-fA-F0-9:]+\]?$/;
|
||||
return hostPattern.test(trimmedHost);
|
||||
});
|
||||
|
||||
async function analyzeHandshake() {
|
||||
diagnosticState.startOperation();
|
||||
@@ -67,9 +57,9 @@
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
hostname: hostname.trim(),
|
||||
hostname: hostname.trim(),
|
||||
port,
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined
|
||||
servername: useCustomServername && servername ? servername.trim() : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -87,6 +77,8 @@
|
||||
function loadExample(example: (typeof examplesList)[0], index: number) {
|
||||
hostname = example.hostname;
|
||||
port = example.port;
|
||||
servername = '';
|
||||
useCustomServername = false;
|
||||
examples.select(index);
|
||||
analyzeHandshake();
|
||||
}
|
||||
@@ -141,8 +133,8 @@
|
||||
<h3>Handshake Analysis</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<div class="lookup-form">
|
||||
<div class="input-row">
|
||||
<label for="hostname"> Hostname </label>
|
||||
<input
|
||||
id="hostname"
|
||||
@@ -159,37 +151,6 @@
|
||||
<label for="port"> Port </label>
|
||||
<input id="port" type="number" bind:value={port} placeholder="443" min="1" max="65535" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="checkbox-group">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={useCustomServername}
|
||||
onchange={() => {
|
||||
examples.clear();
|
||||
if (isInputValid()) analyzeHandshake();
|
||||
}}
|
||||
/>
|
||||
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 (isInputValid()) analyzeHandshake();
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<button class="lookup-btn" onclick={analyzeHandshake} disabled={diagnosticState.loading || !hostname.trim()}>
|
||||
{#if diagnosticState.loading}
|
||||
<Icon name="loader" size="sm" animate="spin" />
|
||||
@@ -200,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>
|
||||
|
||||
@@ -390,6 +369,36 @@
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.lookup-form {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
align-items: flex-end;
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
|
||||
.input-row {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.port-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -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