diff --git a/src/routes/api/internal/diagnostics/tls-handshake/+server.ts b/src/routes/api/internal/diagnostics/tls-handshake/+server.ts index e8e9076..551dab2 100644 --- a/src/routes/api/internal/diagnostics/tls-handshake/+server.ts +++ b/src/routes/api/internal/diagnostics/tls-handshake/+server.ts @@ -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 { +function performTLSHandshake(hostname: string, port: number, servername?: string): Promise { return new Promise((resolve, reject) => { const phases: HandshakePhase[] = []; const startTime = Date.now(); @@ -101,7 +102,7 @@ function performTLSHandshake(hostname: string, port: number): Promise { +async function checkOCSPStapling(hostname: string, port: number = 443, servername?: string): Promise { 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 { +async function testCipherPresets(hostname: string, port: number = 443, servername?: string): Promise { // First verify the host is reachable by attempting a basic TLS connection try { await new Promise((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 }); } diff --git a/src/routes/diagnostics/tls/cipher-presets/+page.svelte b/src/routes/diagnostics/tls/cipher-presets/+page.svelte index 2cb1e4e..6623150 100644 --- a/src/routes/diagnostics/tls/cipher-presets/+page.svelte +++ b/src/routes/diagnostics/tls/cipher-presets/+page.svelte @@ -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(); 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 @@ +
+ + {#if useCustomServername} + examples.clear()} + onkeydown={(e) => e.key === 'Enter' && testCiphers()} + /> + {/if} +
diff --git a/src/routes/diagnostics/tls/handshake-analyzer/+page.svelte b/src/routes/diagnostics/tls/handshake-analyzer/+page.svelte index f8d9309..09159fa 100644 --- a/src/routes/diagnostics/tls/handshake-analyzer/+page.svelte +++ b/src/routes/diagnostics/tls/handshake-analyzer/+page.svelte @@ -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(); 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} +
+ + {#if useCustomServername} + { + examples.clear(); + if (hostname.trim()) analyzeHandshake(); + }} + /> + {/if} +
@@ -346,6 +373,7 @@ display: flex; gap: var(--spacing-md); align-items: flex-end; + margin-bottom: var(--spacing-md); label { display: block; diff --git a/src/routes/diagnostics/tls/ocsp-stapling/+page.svelte b/src/routes/diagnostics/tls/ocsp-stapling/+page.svelte index d94a6eb..e665acf 100644 --- a/src/routes/diagnostics/tls/ocsp-stapling/+page.svelte +++ b/src/routes/diagnostics/tls/ocsp-stapling/+page.svelte @@ -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(); 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 @@ +
+ + {#if useCustomServername} + examples.clear()} + onkeydown={(e) => e.key === 'Enter' && checkOCSP()} + /> + {/if} +