mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-28 08:15:02 +03:00
Implementred Certificate Transparency Log Search tool
This commit is contained in:
1 parent
968ad27344
commit
a6fa72dbae
8 files changed
+1466
No files matched your search
@@ -260,6 +260,8 @@ export const iconMap: Record<string, string> = {
|
||||
signpost: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M144.4 192L144.4 288C144.4 296.8 151.6 304 160.4 304L458.3 304L513.2 240L458.3 176L160.4 176C151.6 176 144.4 183.2 144.4 192z"/><path d="M296.4 88C296.4 74.7 307.1 64 320.4 64C333.7 64 344.4 74.7 344.4 88L344.4 128L465.7 128C475 128 483.9 132.1 490 139.2L567.5 229.6C572.6 235.6 572.6 244.4 567.5 250.4L490 340.8C483.9 347.9 475 352 465.7 352L344.4 352L344.4 552C344.4 565.3 333.7 576 320.4 576C307.1 576 296.4 565.3 296.4 552L296.4 352L160.4 352C125.1 352 96.4 323.3 96.4 288L96.4 192C96.4 156.7 125.1 128 160.4 128L296.4 128L296.4 88zM296.4 304L458.3 304L513.2 240L458.3 176L160.4 176C151.6 176 144.4 183.2 144.4 192L144.4 288C144.4 296.8 151.6 304 160.4 304L296.4 304z"/></svg>`,
|
||||
wifi: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M72.9 245.4C136.4 182.7 223.7 144 320.1 144C416.5 144 503.7 182.7 567.3 245.4C576.7 254.7 591.9 254.6 601.2 245.2C610.5 235.8 610.4 220.6 601 211.3C528.8 140 429.5 96 320.1 96C210.7 96 111.3 140 39.1 211.3C29.7 220.6 29.6 235.8 38.9 245.2C48.2 254.6 63.4 254.7 72.8 245.4zM320.1 320C373.7 320 421.7 343.9 454 381.7C462.6 391.8 477.8 393 487.8 384.4C497.8 375.8 499.1 360.6 490.5 350.6C449.5 302.6 388.3 272 320.1 272C251.9 272 190.8 302.5 149.7 350.6C141.1 360.7 142.3 375.8 152.4 384.4C162.5 393 177.6 391.8 186.2 381.7C218.5 343.9 266.5 320 320.1 320zM368.1 496C368.1 469.5 346.6 448 320.1 448C293.6 448 272.1 469.5 272.1 496C272.1 522.5 293.6 544 320.1 544C346.6 544 368.1 522.5 368.1 496z"/></svg>`,
|
||||
// '': ``,
|
||||
asterisk: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M320 64C333.3 64 344 74.7 344 88L344 278.3L508 183.2C519.5 176.5 534.2 180.5 540.8 191.9C547.4 203.3 543.5 218.1 532.1 224.7L367.8 320L532 415.2C543.5 421.8 547.4 436.5 540.7 448C534 459.5 519.4 463.4 507.9 456.7L344 361.7L344 552C344 565.3 333.3 576 320 576C306.7 576 296 565.3 296 552L296 361.7L132 456.8C120.5 463.5 105.8 459.5 99.2 448.1C92.6 436.7 96.5 421.9 108 415.2L272.2 320L108 224.8C96.5 218.1 92.6 203.4 99.2 192C105.8 180.6 120.5 176.6 132 183.3L296 278.3L296 88C296 74.7 306.7 64 320 64z"/></svg>`,
|
||||
certificate: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M208 128C208 119.2 215.2 112 224 112L336 112L336 200C336 239.8 368.2 272 408 272L496 272L496 512C496 520.8 488.8 528 480 528L288 528L288 504.8C317.8 473.3 336 430.8 336 384C336 303.4 281.9 235.5 208 214.6L208 128z"/><path d="M224 112L336 112L336 200C336 239.8 368.2 272 408 272L496 272L496 512C496 520.8 488.8 528 480 528L288 528L288 576L480 576C515.3 576 544 547.3 544 512L544 250.5C544 233.5 537.3 217.2 525.3 205.2L402.7 82.7C390.7 70.7 374.5 64 357.5 64L224 64C188.7 64 160 92.7 160 128L160 208C176.6 208 192.7 210.3 208 214.6L208 128C208 119.2 215.2 112 224 112zM384 131.9L476.1 224L408 224C394.7 224 384 213.3 384 200L384 131.9zM288 384C288 313.3 230.7 256 160 256C89.3 256 32 313.3 32 384C32 424.4 50.7 460.5 80 483.9L80 589C80 599.5 88.5 608 99 608C102.3 608 105.5 607.1 108.4 605.5L160 576L211.6 605.5C214.5 607.1 217.7 608 221 608C231.5 608 240 599.5 240 589L240 483.9C269.3 460.4 288 424.4 288 384zM160 336C186.5 336 208 357.5 208 384C208 410.5 186.5 432 160 432C133.5 432 112 410.5 112 384C112 357.5 133.5 336 160 336z"/></svg>`,
|
||||
'ipv6-check': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M160 274.8L336 105.3L480 244L480 448C480 456.8 472.8 464 464 464L309.5 464C279.5 400.2 225.9 349.7 160 323.5L160 274.8zM288 280L288 328C288 341.3 298.7 352 312 352L360 352C373.3 352 384 341.3 384 328L384 280C384 266.7 373.3 256 360 256L312 256C298.7 256 288 266.7 288 280z"/><path d="M319.4 54.7C328.7 45.8 343.4 45.8 352.7 54.7L568.7 262.7C578.2 271.9 578.5 287.1 569.3 296.6C560.1 306.1 544.9 306.4 535.4 297.2L528 290.1L528 447.9C528 483.2 499.3 511.9 464 511.9L327 511.9C322.6 495.2 316.8 479.2 309.6 463.9L464 464C472.8 464 480 456.8 480 448L480 244L336 105.3L136.6 297.3C127.1 306.5 111.9 306.2 102.7 296.7C93.5 287.2 93.8 272 103.3 262.8L319.3 54.8zM288 280C288 266.7 298.7 256 312 256L360 256C373.3 256 384 266.7 384 280L384 328C384 341.3 373.3 352 360 352L312 352C298.7 352 288 341.3 288 328L288 280zM56 352C184.1 352 288 455.9 288 584C288 597.3 277.3 608 264 608C250.7 608 240 597.3 240 584C240 482.4 157.6 400 56 400C42.7 400 32 389.3 32 376C32 362.7 42.7 352 56 352zM64 544C81.7 544 96 558.3 96 576C96 593.7 81.7 608 64 608C46.3 608 32 593.7 32 576C32 558.3 46.3 544 64 544zM32 472C32 458.7 42.7 448 56 448C131.1 448 192 508.9 192 584C192 597.3 181.3 608 168 608C154.7 608 144 597.3 144 584C144 535.4 104.6 496 56 496C42.7 496 32 485.3 32 472z"/></svg>`,
|
||||
handshake: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M48 143.9L129.9 203.5C139.5 210.4 152.6 209.4 161 201.1L164.9 197.2C178.4 183.7 196.7 176.1 215.8 176.1L262.1 176.1L170.4 267.8C154.8 283.4 154.8 308.7 170.4 324.4L171.2 325.2C218 372 294 372 340.9 325.1L368 298L465.8 395.8C481.4 411.4 481.4 436.7 465.8 452.4L456 462.2L425 431.2C415.6 421.8 400.4 421.8 391.1 431.2C381.8 440.6 381.7 455.8 391.1 465.1L419.1 493.1C401.6 503.5 381.9 509.8 361.5 511.6L313 463C303.6 453.6 288.4 453.6 279.1 463C269.8 472.4 269.7 487.6 279.1 496.9L294.1 511.9L290.3 511.9C254.2 511.9 219.6 497.6 194.1 472.1L65 343C60.3 338.3 54.2 336 48 336L48 143.9zM210.2 295.8L308.9 197.1C322.3 183.7 340.5 176.1 359.5 176L368 176C385.1 176 402 176 418.9 176C433.1 176 447 180.2 458.8 188.1L482.7 204C491.1 209.6 502 209.3 510.1 203.4L592 143.9L592 336C585.9 336 579.7 338.3 575 343L521.2 396.8C517 384 509.9 371.9 499.7 361.7L385 247C375.6 237.6 360.4 237.6 351.1 247L307 291.1C280.5 317.6 238.5 319.1 210.3 295.7z"/><path d="M598.1 139.4C608.8 131.6 611.2 116.6 603.4 105.9C595.6 95.2 580.6 92.8 569.9 100.6L495.4 154.8L485.5 148.2C465.8 135 442.6 128 418.9 128L359.7 128L359.3 128L215.7 128C189 128 163.2 136.9 142.3 153.1L70.1 100.6C59.4 92.8 44.4 95.2 36.6 105.9C28.8 116.6 31.2 131.6 41.9 139.4L129.9 203.4C139.5 210.3 152.6 209.3 161 201L164.9 197.1C178.4 183.6 196.7 176 215.8 176L262.1 176L170.4 267.7C154.8 283.3 154.8 308.6 170.4 324.3L171.2 325.1C218 372 294 372 340.9 325.1L368 298L465.8 395.8C481.4 411.4 481.4 436.7 465.8 452.4L456 462.2L425 431.2C415.6 421.8 400.4 421.8 391.1 431.2C381.8 440.6 381.7 455.8 391.1 465.1L419.1 493.1C401.6 503.5 381.9 509.8 361.5 511.6L313 463C303.6 453.6 288.4 453.6 279.1 463C269.8 472.4 269.7 487.6 279.1 496.9L294.1 511.9L290.3 511.9C254.2 511.9 219.6 497.6 194.1 472.1L65 343C55.6 333.6 40.4 333.6 31.1 343C21.8 352.4 21.7 367.6 31.1 376.9L160.2 506.1C194.7 540.6 241.5 560 290.3 560L342.1 560L343.1 561L344.1 560L349.8 560C398.6 560 445.4 540.6 479.9 506.1L499.8 486.2C501 485 502.1 483.9 503.2 482.7C503.9 482.2 504.5 481.6 505.1 481L609 377C618.4 367.6 618.4 352.4 609 343.1C599.6 333.8 584.4 333.7 575.1 343.1L521.3 396.9C517.1 384.1 510 372 499.8 361.8L385 247C375.6 237.6 360.4 237.6 351.1 247L307 291.1C280.5 317.6 238.5 319.1 210.3 295.7L309 197C322.4 183.6 340.6 176 359.6 175.9L368.1 175.9L368.3 175.9L419.1 175.9C433.3 175.9 447.2 180.1 459 188L482.7 204C491.1 209.6 502 209.3 510.1 203.4L598.1 139.4z"/></svg>`,
|
||||
circle: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320z"/><path d="M528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320zM64 320C64 178.6 178.6 64 320 64C461.4 64 576 178.6 576 320C576 461.4 461.4 576 320 576C178.6 576 64 461.4 64 320z"/></svg>`,
|
||||
|
||||
@@ -1403,6 +1403,29 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
|
||||
'negotiation',
|
||||
],
|
||||
},
|
||||
{
|
||||
href: makePath('/diagnostics/tls/ct-log-search'),
|
||||
label: 'CT Log Search',
|
||||
description: 'Search Certificate Transparency logs to discover all certificates issued for a domain',
|
||||
icon: 'certificate',
|
||||
keywords: [
|
||||
'ct',
|
||||
'certificate',
|
||||
'transparency',
|
||||
'log',
|
||||
'search',
|
||||
'crt.sh',
|
||||
'ssl',
|
||||
'tls',
|
||||
'san',
|
||||
'subdomains',
|
||||
'discovery',
|
||||
'issuer',
|
||||
'validity',
|
||||
'wildcard',
|
||||
'monitoring',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
export const ctLogContent = {
|
||||
title: 'Certificate Transparency Log Search',
|
||||
description: 'Search Certificate Transparency logs to discover all certificates issued for a domain',
|
||||
sections: {
|
||||
whatIsCT: {
|
||||
title: 'What is Certificate Transparency?',
|
||||
content:
|
||||
'Certificate Transparency (CT) is an open framework for monitoring and auditing SSL/TLS certificates. All publicly-trusted Certificate Authorities are required to log certificates to public CT logs, creating an append-only, cryptographically-assured record of all certificates issued.',
|
||||
},
|
||||
benefits: {
|
||||
title: 'Benefits of CT Logs',
|
||||
benefits: [
|
||||
{
|
||||
benefit: 'Security Monitoring',
|
||||
description: 'Detect unauthorized or mis-issued certificates for your domains in real-time',
|
||||
},
|
||||
{
|
||||
benefit: 'Asset Discovery',
|
||||
description:
|
||||
'Discover all subdomains and hostnames that have certificates, useful for inventory and security audits',
|
||||
},
|
||||
{
|
||||
benefit: 'Certificate Management',
|
||||
description: 'Track certificate renewals, expirations, and issuer patterns across your infrastructure',
|
||||
},
|
||||
{
|
||||
benefit: 'Compliance & Auditing',
|
||||
description: 'Maintain compliance by ensuring only authorized CAs issue certificates for your domains',
|
||||
},
|
||||
],
|
||||
},
|
||||
useCases: {
|
||||
title: 'Common Use Cases',
|
||||
cases: [
|
||||
{
|
||||
useCase: 'Subdomain Enumeration',
|
||||
description: 'Discover all subdomains for a domain by analyzing SANs in issued certificates',
|
||||
example: 'Security teams use this for attack surface mapping',
|
||||
},
|
||||
{
|
||||
useCase: 'Mis-issuance Detection',
|
||||
description: 'Identify certificates issued by unauthorized CAs or for unexpected hostnames',
|
||||
example: 'Detect phishing domains or internal names leaked to public logs',
|
||||
},
|
||||
{
|
||||
useCase: 'Certificate Lifecycle Tracking',
|
||||
description: 'Monitor certificate renewals, track expiration dates, and plan migrations',
|
||||
example: 'DevOps teams use this to prevent outages from expired certificates',
|
||||
},
|
||||
{
|
||||
useCase: 'CA Diversity Analysis',
|
||||
description: 'Understand which CAs are issuing certificates for your organization',
|
||||
example: 'Compliance teams verify approved CA usage',
|
||||
},
|
||||
],
|
||||
},
|
||||
certificateFields: {
|
||||
title: 'Key Certificate Fields',
|
||||
fields: [
|
||||
{
|
||||
field: 'Common Name (CN)',
|
||||
description: 'Primary domain name the certificate is issued for',
|
||||
},
|
||||
{
|
||||
field: 'Subject Alternative Names (SANs)',
|
||||
description: 'Additional hostnames covered by the certificate, including wildcards',
|
||||
},
|
||||
{
|
||||
field: 'Issuer',
|
||||
description: "Certificate Authority that issued the certificate (e.g., Let's Encrypt, DigiCert)",
|
||||
},
|
||||
{
|
||||
field: 'Validity Period',
|
||||
description: 'Start (Not Before) and end (Not After) dates when the certificate is valid',
|
||||
},
|
||||
{
|
||||
field: 'Serial Number',
|
||||
description: 'Unique identifier assigned by the CA, used for revocation lookups',
|
||||
},
|
||||
{
|
||||
field: 'Entry Timestamp',
|
||||
description: 'When the certificate was logged to CT, which may differ from issuance date',
|
||||
},
|
||||
],
|
||||
},
|
||||
security: {
|
||||
title: 'Security Considerations',
|
||||
points: [
|
||||
{
|
||||
point: 'CT Logs are Public',
|
||||
description:
|
||||
'All logged certificates are publicly visible. Avoid including sensitive hostnames in SANs if they should remain private.',
|
||||
},
|
||||
{
|
||||
point: 'Monitor for Unexpected Issuance',
|
||||
description:
|
||||
'Regularly check CT logs for your domains to detect phishing attempts or unauthorized certificates.',
|
||||
},
|
||||
{
|
||||
point: 'CAA Records',
|
||||
description: 'Use DNS CAA records to restrict which CAs can issue certificates for your domains.',
|
||||
},
|
||||
{
|
||||
point: 'Certificate Pinning',
|
||||
description: 'For high-security applications, consider certificate pinning to prevent MITM attacks.',
|
||||
},
|
||||
],
|
||||
},
|
||||
bestPractices: {
|
||||
title: 'Best Practices',
|
||||
practices: [
|
||||
{
|
||||
practice: 'Regular Monitoring',
|
||||
description: 'Periodically search CT logs for your domains to detect anomalies',
|
||||
},
|
||||
{
|
||||
practice: 'Automate Alerts',
|
||||
description: 'Set up automated monitoring to alert on new certificate issuance',
|
||||
},
|
||||
{
|
||||
practice: 'Review SANs Carefully',
|
||||
description: 'Ensure certificates only include necessary hostnames to minimize exposure',
|
||||
},
|
||||
{
|
||||
practice: 'Track Expiration Dates',
|
||||
description: 'Monitor certificates expiring soon to prevent service disruptions',
|
||||
},
|
||||
{
|
||||
practice: 'Validate Issuers',
|
||||
description: 'Ensure only authorized CAs are issuing certificates for your domains',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
quickTips: [
|
||||
'CT logs are append-only and cannot be modified or deleted',
|
||||
'Wildcard certificates (*.example.com) cover all subdomains',
|
||||
'Internal hostnames in SANs become publicly visible via CT logs',
|
||||
'Most browsers require CT compliance for certificates to be trusted',
|
||||
'crt.sh searches multiple CT log servers for comprehensive results',
|
||||
'Certificate issuance != activation - check validity dates carefully',
|
||||
'Use CAA records to specify which CAs can issue for your domain',
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,169 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
interface CTLogRequest {
|
||||
domain: string;
|
||||
}
|
||||
|
||||
interface CTCertificate {
|
||||
id: number;
|
||||
issuer_ca_id: number;
|
||||
issuer_name: string;
|
||||
common_name: string;
|
||||
name_value: string;
|
||||
entry_timestamp: string;
|
||||
not_before: string;
|
||||
not_after: string;
|
||||
serial_number: string;
|
||||
}
|
||||
|
||||
interface ProcessedCertificate {
|
||||
id: number;
|
||||
commonName: string;
|
||||
sans: string[];
|
||||
issuer: string;
|
||||
issuerId: number;
|
||||
entryTimestamp: string;
|
||||
notBefore: string;
|
||||
notAfter: string;
|
||||
serialNumber: string;
|
||||
isValid: boolean;
|
||||
daysUntilExpiry: number;
|
||||
isWildcard: boolean;
|
||||
ctLogUrl: string;
|
||||
}
|
||||
|
||||
interface CTLogResponse {
|
||||
domain: string;
|
||||
certificates: ProcessedCertificate[];
|
||||
totalCertificates: number;
|
||||
discoveredHostnames: string[];
|
||||
issuers: Array<{ name: string; count: number }>;
|
||||
validCertificates: number;
|
||||
expiringSoon: number;
|
||||
wildcardCertificates: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
try {
|
||||
const body: CTLogRequest = await request.json();
|
||||
const { domain } = body;
|
||||
|
||||
if (!domain || typeof domain !== 'string' || !domain.trim()) {
|
||||
throw error(400, 'Domain is required');
|
||||
}
|
||||
|
||||
const trimmedDomain = domain.trim().toLowerCase();
|
||||
|
||||
// Basic domain validation
|
||||
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i.test(trimmedDomain)) {
|
||||
throw error(400, 'Invalid domain format');
|
||||
}
|
||||
|
||||
const result = await searchCTLogs(trimmedDomain);
|
||||
return json(result);
|
||||
} catch (err) {
|
||||
console.error('CT log search error:', err);
|
||||
if (err && typeof err === 'object' && 'status' in err) {
|
||||
throw err;
|
||||
}
|
||||
throw error(500, `CT log search failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
||||
}
|
||||
};
|
||||
|
||||
async function searchCTLogs(domain: string): Promise<CTLogResponse> {
|
||||
// Query crt.sh API
|
||||
const url = `https://crt.sh/?q=${encodeURIComponent(domain)}&output=json`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent': 'CT-Log-Search/1.0',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`crt.sh API returned ${response.status}`);
|
||||
}
|
||||
|
||||
const data: CTCertificate[] = await response.json();
|
||||
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return {
|
||||
domain,
|
||||
certificates: [],
|
||||
totalCertificates: 0,
|
||||
discoveredHostnames: [],
|
||||
issuers: [],
|
||||
validCertificates: 0,
|
||||
expiringSoon: 0,
|
||||
wildcardCertificates: 0,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const thirtyDaysFromNow = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// Process certificates
|
||||
const processedCerts: ProcessedCertificate[] = data.map((cert) => {
|
||||
const sans = cert.name_value
|
||||
.split('\n')
|
||||
.map((n) => n.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const notBefore = new Date(cert.not_before);
|
||||
const notAfter = new Date(cert.not_after);
|
||||
const isValid = now >= notBefore && now <= notAfter;
|
||||
const daysUntilExpiry = Math.ceil((notAfter.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
|
||||
const isWildcard = cert.common_name.startsWith('*.') || sans.some((san) => san.startsWith('*.'));
|
||||
|
||||
return {
|
||||
id: cert.id,
|
||||
commonName: cert.common_name,
|
||||
sans,
|
||||
issuer: cert.issuer_name,
|
||||
issuerId: cert.issuer_ca_id,
|
||||
entryTimestamp: cert.entry_timestamp,
|
||||
notBefore: cert.not_before,
|
||||
notAfter: cert.not_after,
|
||||
serialNumber: cert.serial_number,
|
||||
isValid,
|
||||
daysUntilExpiry,
|
||||
isWildcard,
|
||||
ctLogUrl: `https://crt.sh/?id=${cert.id}`,
|
||||
};
|
||||
});
|
||||
|
||||
// Deduplicate and collect all hostnames
|
||||
const hostnamesSet = new Set<string>();
|
||||
processedCerts.forEach((cert) => {
|
||||
cert.sans.forEach((san) => hostnamesSet.add(san));
|
||||
});
|
||||
const discoveredHostnames = Array.from(hostnamesSet).sort();
|
||||
|
||||
// Count issuers
|
||||
const issuerCounts = new Map<string, number>();
|
||||
processedCerts.forEach((cert) => {
|
||||
issuerCounts.set(cert.issuer, (issuerCounts.get(cert.issuer) || 0) + 1);
|
||||
});
|
||||
const issuers = Array.from(issuerCounts.entries())
|
||||
.map(([name, count]) => ({ name, count }))
|
||||
.sort((a, b) => b.count - a.count);
|
||||
|
||||
const validCertificates = processedCerts.filter((c) => c.isValid).length;
|
||||
const expiringSoon = processedCerts.filter((c) => c.isValid && new Date(c.notAfter) <= thirtyDaysFromNow).length;
|
||||
const wildcardCertificates = processedCerts.filter((c) => c.isWildcard).length;
|
||||
|
||||
return {
|
||||
domain,
|
||||
certificates: processedCerts,
|
||||
totalCertificates: processedCerts.length,
|
||||
discoveredHostnames,
|
||||
issuers,
|
||||
validCertificates,
|
||||
expiringSoon,
|
||||
wildcardCertificates,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,845 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { ctLogContent as content } from '$lib/content/ct-log-search';
|
||||
import '../../../../styles/diagnostics-pages.scss';
|
||||
|
||||
interface ProcessedCertificate {
|
||||
id: number;
|
||||
commonName: string;
|
||||
sans: string[];
|
||||
issuer: string;
|
||||
issuerId: number;
|
||||
entryTimestamp: string;
|
||||
notBefore: string;
|
||||
notAfter: string;
|
||||
serialNumber: string;
|
||||
isValid: boolean;
|
||||
daysUntilExpiry: number;
|
||||
isWildcard: boolean;
|
||||
ctLogUrl: string;
|
||||
}
|
||||
|
||||
interface CTLogResponse {
|
||||
domain: string;
|
||||
certificates: ProcessedCertificate[];
|
||||
totalCertificates: number;
|
||||
discoveredHostnames: string[];
|
||||
issuers: Array<{ name: string; count: number }>;
|
||||
validCertificates: number;
|
||||
expiringSoon: number;
|
||||
wildcardCertificates: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
const examples = [
|
||||
{ domain: 'as93.net', desc: 'Domain hosting multiple apps' },
|
||||
{ domain: 'github.com', desc: 'Popular tech platform with modern certificate infrastructure' },
|
||||
{ domain: 'google.com', desc: 'Shows historic DigiNotar breach certificate from 2011' },
|
||||
{ domain: 'reddit.com', desc: 'Demonstrates subdomain discovery capabilities' },
|
||||
{ domain: 'wikipedia.org', desc: 'Example of wildcard certificate usage' },
|
||||
{ domain: 'twitter.com', desc: 'Shows certificate lifecycle and expiration tracking' },
|
||||
];
|
||||
|
||||
const statsConfig = [
|
||||
{
|
||||
icon: 'check-circle',
|
||||
label: 'Valid Certificates',
|
||||
key: 'validCertificates',
|
||||
valueClass: 'success',
|
||||
desc: 'Currently valid',
|
||||
},
|
||||
{
|
||||
icon: 'alert-triangle',
|
||||
label: 'Expiring Soon',
|
||||
key: 'expiringSoon',
|
||||
valueClass: 'warning',
|
||||
desc: 'Within 30 days',
|
||||
},
|
||||
{
|
||||
icon: 'asterisk',
|
||||
label: 'Wildcard Certs',
|
||||
key: 'wildcardCertificates',
|
||||
valueClass: '',
|
||||
desc: 'Covering subdomains',
|
||||
},
|
||||
{
|
||||
icon: 'globe',
|
||||
label: 'Discovered Hosts',
|
||||
key: 'discoveredHostnames',
|
||||
valueClass: '',
|
||||
desc: 'Unique hostnames',
|
||||
isArray: true,
|
||||
},
|
||||
];
|
||||
|
||||
const certDetailFields = [
|
||||
{
|
||||
icon: 'calendar',
|
||||
label: 'Valid Period',
|
||||
key: 'validPeriod',
|
||||
formatter: (cert: ProcessedCertificate) =>
|
||||
`${new Date(cert.notBefore).toLocaleDateString()} - ${new Date(cert.notAfter).toLocaleDateString()}`,
|
||||
},
|
||||
{ icon: 'building', label: 'Issuer', key: 'issuer' },
|
||||
{ icon: 'hash', label: 'Serial Number', key: 'serialNumber', mono: true },
|
||||
{ icon: 'globe', label: 'SANs', key: 'sans', isSans: true },
|
||||
{ icon: 'external-link', label: 'View Details', key: 'ctLogUrl', isLink: true },
|
||||
];
|
||||
|
||||
let domain = $state('');
|
||||
let loading = $state(false);
|
||||
let results = $state<CTLogResponse | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
let copiedState = $state(false);
|
||||
let expandedCert = $state<number | null>(null);
|
||||
let selectedExample = $state<string | null>(null);
|
||||
|
||||
async function loadExample(exampleDomain: string) {
|
||||
domain = exampleDomain;
|
||||
selectedExample = exampleDomain;
|
||||
await searchCTLogs();
|
||||
}
|
||||
|
||||
async function searchCTLogs() {
|
||||
if (!domain.trim()) {
|
||||
error = 'Please enter a domain name';
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
results = null;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/internal/diagnostics/ct-log-search', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ domain: domain.trim() }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ message: `HTTP ${response.status}` }));
|
||||
throw new Error(errorData.message || 'Search failed');
|
||||
}
|
||||
|
||||
results = await response.json();
|
||||
} catch (err: unknown) {
|
||||
error = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copyResults() {
|
||||
if (!results) return;
|
||||
|
||||
let text = `Certificate Transparency Log Search\nDomain: ${results.domain}\nGenerated at: ${results.timestamp}\n\n`;
|
||||
text += `Total Certificates: ${results.totalCertificates}\n`;
|
||||
text += `Valid Certificates: ${results.validCertificates}\n`;
|
||||
text += `Expiring Soon (30 days): ${results.expiringSoon}\n`;
|
||||
text += `Wildcard Certificates: ${results.wildcardCertificates}\n\n`;
|
||||
text += `Discovered Hostnames (${results.discoveredHostnames.length}):\n`;
|
||||
results.discoveredHostnames.forEach((h) => (text += ` - ${h}\n`));
|
||||
text += `\nTop Issuers:\n`;
|
||||
results.issuers.forEach((i) => (text += ` - ${i.name}: ${i.count} certificates\n`));
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedState = true;
|
||||
setTimeout(() => (copiedState = false), 1500);
|
||||
}
|
||||
|
||||
function toggleCert(id: number) {
|
||||
expandedCert = expandedCert === id ? null : id;
|
||||
}
|
||||
|
||||
function getCertBadges(cert: ProcessedCertificate) {
|
||||
const badges = [];
|
||||
if (cert.isValid) {
|
||||
badges.push({ text: 'Valid', class: 'success' });
|
||||
if (cert.daysUntilExpiry <= 30) {
|
||||
badges.push({ text: `Expires in ${cert.daysUntilExpiry}d`, class: 'warning' });
|
||||
}
|
||||
} else if (cert.daysUntilExpiry > 0) {
|
||||
badges.push({ text: 'Expired', class: 'warning' });
|
||||
} else {
|
||||
badges.push({ text: 'Not Yet Valid', class: 'muted' });
|
||||
}
|
||||
return badges;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h1>{content.title}</h1>
|
||||
<p>{content.description}</p>
|
||||
</header>
|
||||
|
||||
<!-- Input Form -->
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Search CT Logs</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="lookup-form">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={domain}
|
||||
placeholder="example.com"
|
||||
onkeydown={(e) => e.key === 'Enter' && searchCTLogs()}
|
||||
disabled={loading}
|
||||
/>
|
||||
<button class="lookup-btn" onclick={searchCTLogs} disabled={loading}>
|
||||
<Icon name={loading ? 'loader' : 'search'} size="sm" animate={loading ? 'spin' : undefined} />
|
||||
{loading ? 'Searching...' : 'Search CT Logs'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Examples -->
|
||||
<div class="card examples-card">
|
||||
<details class="examples-details">
|
||||
<summary class="examples-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>Quick Examples</h4>
|
||||
</summary>
|
||||
<div class="examples-grid">
|
||||
{#each examples as example (example.domain)}
|
||||
<button
|
||||
class="example-card"
|
||||
class:selected={selectedExample === example.domain}
|
||||
onclick={() => loadExample(example.domain)}
|
||||
type="button"
|
||||
>
|
||||
<h5>{example.domain}</h5>
|
||||
<p>{example.desc}</p>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- Loading -->
|
||||
{#if loading}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="loading-state">
|
||||
<Icon name="loader" size="lg" animate="spin" />
|
||||
<div class="loading-text">
|
||||
<h3>Searching Certificate Transparency Logs</h3>
|
||||
<p>Querying CT logs for {domain}...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Error -->
|
||||
{#if error}
|
||||
<div class="card error-card">
|
||||
<div class="card-content">
|
||||
<div class="error-message">
|
||||
<Icon name="alert-circle" size="md" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Results -->
|
||||
{#if results}
|
||||
<div class="card results-card">
|
||||
<div class="card-header row">
|
||||
<h3>CT Log Results for {results.domain}</h3>
|
||||
<button class="copy-btn" onclick={copyResults} disabled={copiedState}>
|
||||
<Icon name={copiedState ? 'check' : 'copy'} size="xs" />
|
||||
{copiedState ? 'Copied!' : 'Copy Results'}
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Statistics Overview -->
|
||||
<div class="status-overview">
|
||||
<div class="status-item info">
|
||||
<Icon name="text-file" size="md" />
|
||||
<div>
|
||||
<h4>{results.totalCertificates} Total Certificates</h4>
|
||||
<p>Found in Certificate Transparency logs</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats Grid -->
|
||||
<div class="results-grid">
|
||||
{#each statsConfig as stat (stat.key)}
|
||||
<div class="result-card">
|
||||
<h4>
|
||||
<Icon name={stat.icon} size="sm" />
|
||||
{stat.label}
|
||||
</h4>
|
||||
<div class="stat-value {stat.valueClass}">
|
||||
{stat.isArray
|
||||
? (results[stat.key as keyof CTLogResponse] as any[]).length
|
||||
: results[stat.key as keyof CTLogResponse]}
|
||||
</div>
|
||||
<p class="stat-label">{stat.desc}</p>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<!-- Discovered Hostnames -->
|
||||
{#if results.discoveredHostnames.length > 0}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="list" size="sm" />
|
||||
Discovered Hostnames ({results.discoveredHostnames.length})
|
||||
</h4>
|
||||
<div class="hostname-list">
|
||||
{#each results.discoveredHostnames.slice(0, 50) as hostname (hostname)}
|
||||
<span class="hostname-tag {hostname.startsWith('*') ? 'wildcard' : ''}">
|
||||
{#if hostname.startsWith('*')}
|
||||
<Icon name="asterisk" size="xs" />
|
||||
{/if}
|
||||
{hostname}
|
||||
</span>
|
||||
{/each}
|
||||
{#if results.discoveredHostnames.length > 50}
|
||||
<span class="hostname-tag muted">
|
||||
+{results.discoveredHostnames.length - 50} more
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Top Issuers -->
|
||||
{#if results.issuers.length > 0}
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="building" size="sm" />
|
||||
Certificate Issuers ({results.issuers.length})
|
||||
</h4>
|
||||
<div class="issuer-list">
|
||||
{#each results.issuers.slice(0, 10) as issuer (issuer.name)}
|
||||
<div class="issuer-item">
|
||||
<span class="issuer-name">{issuer.name}</span>
|
||||
<span class="issuer-count">{issuer.count}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Certificates List -->
|
||||
<div class="subsection">
|
||||
<h4>
|
||||
<Icon name="file-text" size="sm" />
|
||||
Certificates ({results.certificates.length})
|
||||
</h4>
|
||||
<div class="cert-list">
|
||||
{#each results.certificates.slice(0, 20) as cert (cert.id)}
|
||||
<div class="cert-item">
|
||||
<div
|
||||
class="cert-header"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => toggleCert(cert.id)}
|
||||
onkeydown={(e) => e.key === 'Enter' && toggleCert(cert.id)}
|
||||
>
|
||||
<div class="cert-title">
|
||||
{#if cert.isWildcard}
|
||||
<Icon name="asterisk" size="xs" />
|
||||
{/if}
|
||||
<strong>{cert.commonName}</strong>
|
||||
{#each getCertBadges(cert) as badge (badge.text)}
|
||||
<span class="badge {badge.class}">{badge.text}</span>
|
||||
{/each}
|
||||
</div>
|
||||
<Icon name={expandedCert === cert.id ? 'chevron-up' : 'chevron-down'} size="sm" />
|
||||
</div>
|
||||
|
||||
{#if expandedCert === cert.id}
|
||||
<div class="cert-details">
|
||||
<div class="info-list">
|
||||
{#each certDetailFields as field (field.key)}
|
||||
<div class="info-item">
|
||||
<Icon name={field.icon} size="sm" />
|
||||
<div class="info-content">
|
||||
<span class="info-label">{field.label}{field.isSans ? ` (${cert.sans.length})` : ''}</span>
|
||||
{#if field.isSans}
|
||||
<div class="sans-list">
|
||||
{#each cert.sans.slice(0, 10) as san (san)}
|
||||
<span class="san-tag">{san}</span>
|
||||
{/each}
|
||||
{#if cert.sans.length > 10}
|
||||
<span class="san-tag muted">+{cert.sans.length - 10} more</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if field.isLink}
|
||||
<a href={cert.ctLogUrl} target="_blank" rel="noopener noreferrer">
|
||||
crt.sh #{cert.id}
|
||||
</a>
|
||||
{:else if field.formatter}
|
||||
<span class="info-value {field.mono ? 'mono' : ''}">{field.formatter(cert)}</span>
|
||||
{:else}
|
||||
<span class="info-value {field.mono ? 'mono' : ''}"
|
||||
>{cert[field.key as keyof ProcessedCertificate]}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
{#if results.certificates.length > 20}
|
||||
<div class="cert-item muted-text">
|
||||
Showing first 20 of {results.certificates.length} certificates
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Info Sections -->
|
||||
<div class="card info-card">
|
||||
<div class="card-header">
|
||||
<h3>About Certificate Transparency</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- What is CT -->
|
||||
<details class="info-accordion">
|
||||
<summary class="accordion-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>{content.sections.whatIsCT.title}</h4>
|
||||
</summary>
|
||||
<div class="accordion-content">
|
||||
<p>{content.sections.whatIsCT.content}</p>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
{#each [{ title: content.sections.benefits.title, items: content.sections.benefits.benefits, keys: ['benefit', 'description'] }, { title: content.sections.useCases.title, items: content.sections.useCases.cases, keys: ['useCase', 'description', 'example'] }, { title: content.sections.certificateFields.title, items: content.sections.certificateFields.fields, keys: ['field', 'description'] }, { title: content.sections.security.title, items: content.sections.security.points, keys: ['point', 'description'] }, { title: content.sections.bestPractices.title, items: content.sections.bestPractices.practices, keys: ['practice', 'description'] }] as section (section.title)}
|
||||
<details class="info-accordion">
|
||||
<summary class="accordion-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>{section.title}</h4>
|
||||
</summary>
|
||||
<div class="accordion-content">
|
||||
<ul>
|
||||
{#each section.items as item ((item as any)[section.keys[0]])}
|
||||
<li>
|
||||
<strong>{(item as any)[section.keys[0]]}:</strong>
|
||||
{(item as any)[section.keys[1]]}
|
||||
{#if section.keys[2] && (item as any)[section.keys[2]]}
|
||||
<em class="example-text">({(item as any)[section.keys[2]]})</em>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</details>
|
||||
{/each}
|
||||
|
||||
<!-- Quick Tips -->
|
||||
<details class="info-accordion">
|
||||
<summary class="accordion-summary">
|
||||
<Icon name="chevron-right" size="sm" />
|
||||
<h4>Quick Tips</h4>
|
||||
</summary>
|
||||
<div class="accordion-content">
|
||||
<ul>
|
||||
{#each content.quickTips as tip (tip)}
|
||||
<li>{tip}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
color: var(--color-error);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin: var(--spacing-sm) 0;
|
||||
|
||||
&.success {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: var(--color-warning);
|
||||
}
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.subsection {
|
||||
margin-top: var(--spacing-lg);
|
||||
padding-top: var(--spacing-lg);
|
||||
border-top: 1px solid var(--border-primary);
|
||||
|
||||
h4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
}
|
||||
|
||||
.hostname-list,
|
||||
.sans-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.hostname-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.85rem;
|
||||
|
||||
&.wildcard {
|
||||
background: color-mix(in srgb, var(--color-primary), transparent 90%);
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&.muted {
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.issuer-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.issuer-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: var(--spacing-sm);
|
||||
background: var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.issuer-name {
|
||||
font-size: 0.9rem;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.issuer-count {
|
||||
font-weight: 600;
|
||||
color: var(--color-primary);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.cert-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.cert-item {
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
|
||||
&.muted-text {
|
||||
text-align: center;
|
||||
padding: var(--spacing-md);
|
||||
color: var(--color-text-muted);
|
||||
font-style: italic;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.cert-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: var(--border-primary);
|
||||
cursor: pointer;
|
||||
transition: background var(--transition-fast);
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--border-primary), var(--bg-primary) 5%);
|
||||
}
|
||||
}
|
||||
|
||||
.cert-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 2px var(--spacing-xs);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
|
||||
&.success {
|
||||
background: var(--color-success-bg);
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: var(--color-warning-bg);
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
&.muted {
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
}
|
||||
|
||||
.cert-details {
|
||||
padding: var(--spacing-md);
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.info-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-sm);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text-muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: var(--color-text);
|
||||
font-weight: 500;
|
||||
|
||||
&.mono {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.san-tag {
|
||||
padding: 2px var(--spacing-xs);
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius-sm);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
|
||||
&.muted {
|
||||
font-style: italic;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
}
|
||||
|
||||
.example-text {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.results-grid {
|
||||
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
|
||||
gap: var(--spacing-md);
|
||||
.result-card {
|
||||
background: var(--border-primary);
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-sm);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
h4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.lookup-form {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
align-items: stretch;
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.card-content {
|
||||
ul {
|
||||
list-style-type: disc;
|
||||
padding-left: var(--spacing-lg);
|
||||
margin-top: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
font-family: var(--font-mono);
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.status-item {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.info-accordion {
|
||||
border: none;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
overflow: hidden;
|
||||
transition: all var(--transition-fast);
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--bg-secondary), var(--bg-primary) 30%);
|
||||
}
|
||||
|
||||
&[open] {
|
||||
.accordion-summary {
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
|
||||
:global(svg) {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-content {
|
||||
animation: accordionOpen 0.2s ease-out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-md);
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
user-select: none;
|
||||
transition: all var(--transition-fast);
|
||||
|
||||
&::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:global(svg) {
|
||||
transition: transform var(--transition-fast);
|
||||
color: var(--color-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-md);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
:global(svg) {
|
||||
color: var(--color-primary-hover);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-content {
|
||||
padding: var(--spacing-md);
|
||||
padding-top: var(--spacing-sm);
|
||||
animation: accordionOpen 0.2s ease-out;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding-left: var(--spacing-lg);
|
||||
|
||||
li {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes accordionOpen {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.info-card {
|
||||
margin-top: var(--spacing-lg);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,113 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { API_BASE_URL } from '../utils/api-test-helpers';
|
||||
|
||||
describe('CT Log Search API', () => {
|
||||
async function makeRequest(domain: string) {
|
||||
const response = await fetch(`${API_BASE_URL}/api/internal/diagnostics/ct-log-search`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ domain })
|
||||
});
|
||||
const data = await response.json();
|
||||
return { status: response.status, data };
|
||||
}
|
||||
|
||||
describe('Valid Domain Searches', () => {
|
||||
it('should search example.com', async () => {
|
||||
const { status, data } = await makeRequest('example.com');
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(data.domain).toBe('example.com');
|
||||
expect(data.certificates).toBeInstanceOf(Array);
|
||||
expect(data.totalCertificates).toBeGreaterThan(0);
|
||||
expect(data.discoveredHostnames).toBeInstanceOf(Array);
|
||||
expect(data.issuers).toBeInstanceOf(Array);
|
||||
expect(data.validCertificates).toBeGreaterThanOrEqual(0);
|
||||
expect(data.expiringSoon).toBeGreaterThanOrEqual(0);
|
||||
expect(data.wildcardCertificates).toBeGreaterThanOrEqual(0);
|
||||
expect(data.timestamp).toBeDefined();
|
||||
});
|
||||
|
||||
it('should include required certificate fields', async () => {
|
||||
const { status, data } = await makeRequest('example.com');
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(data.certificates.length).toBeGreaterThan(0);
|
||||
|
||||
const cert = data.certificates[0];
|
||||
expect(cert).toHaveProperty('id');
|
||||
expect(cert).toHaveProperty('commonName');
|
||||
expect(cert).toHaveProperty('sans');
|
||||
expect(cert).toHaveProperty('issuer');
|
||||
expect(cert).toHaveProperty('issuerId');
|
||||
expect(cert).toHaveProperty('entryTimestamp');
|
||||
expect(cert).toHaveProperty('notBefore');
|
||||
expect(cert).toHaveProperty('notAfter');
|
||||
expect(cert).toHaveProperty('serialNumber');
|
||||
expect(cert).toHaveProperty('isValid');
|
||||
expect(cert).toHaveProperty('daysUntilExpiry');
|
||||
expect(cert).toHaveProperty('isWildcard');
|
||||
expect(cert).toHaveProperty('ctLogUrl');
|
||||
});
|
||||
|
||||
it('should discover hostnames from SANs', async () => {
|
||||
const { status, data } = await makeRequest('example.com');
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(data.discoveredHostnames).toBeInstanceOf(Array);
|
||||
expect(data.discoveredHostnames.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should aggregate issuer statistics', async () => {
|
||||
const { status, data } = await makeRequest('example.com');
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(data.issuers).toBeInstanceOf(Array);
|
||||
|
||||
if (data.issuers.length > 0) {
|
||||
const issuer = data.issuers[0];
|
||||
expect(issuer).toHaveProperty('name');
|
||||
expect(issuer).toHaveProperty('count');
|
||||
expect(typeof issuer.name).toBe('string');
|
||||
expect(typeof issuer.count).toBe('number');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should reject empty domain', async () => {
|
||||
const { status, data } = await makeRequest('');
|
||||
|
||||
expect(status).toBe(400);
|
||||
expect(data.message).toMatch(/domain.*required/i);
|
||||
});
|
||||
|
||||
it('should reject missing domain', async () => {
|
||||
const response = await fetch(`${API_BASE_URL}/api/internal/diagnostics/ct-log-search`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
const data = await response.json();
|
||||
expect(data.message).toMatch(/domain.*required/i);
|
||||
});
|
||||
|
||||
it('should reject invalid domain format', async () => {
|
||||
const { status, data } = await makeRequest('invalid..domain');
|
||||
|
||||
expect(status).toBe(400);
|
||||
expect(data.message).toMatch(/invalid|format/i);
|
||||
});
|
||||
|
||||
it('should handle domain with no certificates', async () => {
|
||||
const { status, data } = await makeRequest('this-domain-has-no-certificates-123456789.example');
|
||||
|
||||
expect(status).toBe(200);
|
||||
expect(data.totalCertificates).toBe(0);
|
||||
expect(data.certificates).toHaveLength(0);
|
||||
expect(data.discoveredHostnames).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ctLogContent } from '$lib/content/ct-log-search';
|
||||
|
||||
describe('CT Log Search Content', () => {
|
||||
it('should have title and description', () => {
|
||||
expect(ctLogContent.title).toBe('Certificate Transparency Log Search');
|
||||
expect(ctLogContent.description).toBeTruthy();
|
||||
expect(typeof ctLogContent.description).toBe('string');
|
||||
});
|
||||
|
||||
it('should have whatIsCT section', () => {
|
||||
expect(ctLogContent.sections.whatIsCT).toBeDefined();
|
||||
expect(ctLogContent.sections.whatIsCT.title).toBeTruthy();
|
||||
expect(ctLogContent.sections.whatIsCT.content).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have benefits section with array', () => {
|
||||
expect(ctLogContent.sections.benefits).toBeDefined();
|
||||
expect(ctLogContent.sections.benefits.title).toBeTruthy();
|
||||
expect(Array.isArray(ctLogContent.sections.benefits.benefits)).toBe(true);
|
||||
expect(ctLogContent.sections.benefits.benefits.length).toBeGreaterThan(0);
|
||||
ctLogContent.sections.benefits.benefits.forEach((item) => {
|
||||
expect(item.benefit).toBeTruthy();
|
||||
expect(item.description).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have useCases section with array', () => {
|
||||
expect(ctLogContent.sections.useCases).toBeDefined();
|
||||
expect(ctLogContent.sections.useCases.title).toBeTruthy();
|
||||
expect(Array.isArray(ctLogContent.sections.useCases.cases)).toBe(true);
|
||||
expect(ctLogContent.sections.useCases.cases.length).toBeGreaterThan(0);
|
||||
ctLogContent.sections.useCases.cases.forEach((item) => {
|
||||
expect(item.useCase).toBeTruthy();
|
||||
expect(item.description).toBeTruthy();
|
||||
expect(item.example).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have certificateFields section with array', () => {
|
||||
expect(ctLogContent.sections.certificateFields).toBeDefined();
|
||||
expect(ctLogContent.sections.certificateFields.title).toBeTruthy();
|
||||
expect(Array.isArray(ctLogContent.sections.certificateFields.fields)).toBe(true);
|
||||
expect(ctLogContent.sections.certificateFields.fields.length).toBeGreaterThan(0);
|
||||
ctLogContent.sections.certificateFields.fields.forEach((item) => {
|
||||
expect(item.field).toBeTruthy();
|
||||
expect(item.description).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have security section with array', () => {
|
||||
expect(ctLogContent.sections.security).toBeDefined();
|
||||
expect(ctLogContent.sections.security.title).toBeTruthy();
|
||||
expect(Array.isArray(ctLogContent.sections.security.points)).toBe(true);
|
||||
expect(ctLogContent.sections.security.points.length).toBeGreaterThan(0);
|
||||
ctLogContent.sections.security.points.forEach((item) => {
|
||||
expect(item.point).toBeTruthy();
|
||||
expect(item.description).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have bestPractices section with array', () => {
|
||||
expect(ctLogContent.sections.bestPractices).toBeDefined();
|
||||
expect(ctLogContent.sections.bestPractices.title).toBeTruthy();
|
||||
expect(Array.isArray(ctLogContent.sections.bestPractices.practices)).toBe(true);
|
||||
expect(ctLogContent.sections.bestPractices.practices.length).toBeGreaterThan(0);
|
||||
ctLogContent.sections.bestPractices.practices.forEach((item) => {
|
||||
expect(item.practice).toBeTruthy();
|
||||
expect(item.description).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have quickTips array', () => {
|
||||
expect(Array.isArray(ctLogContent.quickTips)).toBe(true);
|
||||
expect(ctLogContent.quickTips.length).toBeGreaterThan(0);
|
||||
ctLogContent.quickTips.forEach((tip) => {
|
||||
expect(typeof tip).toBe('string');
|
||||
expect(tip.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { POST } from '../../../../../../../src/routes/api/internal/diagnostics/ct-log-search/+server';
|
||||
|
||||
describe('CT Log Search API', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should return error for missing domain', async () => {
|
||||
const request = new Request('http://localhost', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
|
||||
await expect(POST({ request } as any)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should return error for invalid domain format', async () => {
|
||||
const request = new Request('http://localhost', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ domain: 'invalid..domain' }),
|
||||
});
|
||||
|
||||
await expect(POST({ request } as any)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should accept valid domain', async () => {
|
||||
const mockResponse = {
|
||||
ok: true,
|
||||
json: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: 123456,
|
||||
issuer_ca_id: 1,
|
||||
issuer_name: "Let's Encrypt",
|
||||
common_name: 'example.com',
|
||||
name_value: 'example.com\nwww.example.com',
|
||||
entry_timestamp: '2024-01-01T00:00:00Z',
|
||||
not_before: '2024-01-01T00:00:00Z',
|
||||
not_after: '2024-04-01T00:00:00Z',
|
||||
serial_number: 'abc123',
|
||||
},
|
||||
]),
|
||||
};
|
||||
|
||||
globalThis.fetch = vi.fn().mockResolvedValue(mockResponse);
|
||||
|
||||
const request = new Request('http://localhost', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ domain: 'example.com' }),
|
||||
});
|
||||
|
||||
const response = await POST({ request } as any);
|
||||
const data = await response.json();
|
||||
|
||||
expect(data.domain).toBe('example.com');
|
||||
expect(data.totalCertificates).toBe(1);
|
||||
expect(data.certificates).toHaveLength(1);
|
||||
expect(data.discoveredHostnames).toContain('example.com');
|
||||
expect(data.discoveredHostnames).toContain('www.example.com');
|
||||
});
|
||||
|
||||
it('should handle empty results from crt.sh', async () => {
|
||||
const mockResponse = {
|
||||
ok: true,
|
||||
json: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
|
||||
globalThis.fetch = vi.fn().mockResolvedValue(mockResponse);
|
||||
|
||||
const request = new Request('http://localhost', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ domain: 'nonexistent.example' }),
|
||||
});
|
||||
|
||||
const response = await POST({ request } as any);
|
||||
const data = await response.json();
|
||||
|
||||
expect(data.domain).toBe('nonexistent.example');
|
||||
expect(data.totalCertificates).toBe(0);
|
||||
expect(data.certificates).toHaveLength(0);
|
||||
expect(data.discoveredHostnames).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user