import useSWR from 'swr' import axios from 'axios' import { useState } from 'react' import { Download, Terminal, Smartphone, Shield, Monitor, FileCode, Check, Copy, AlertCircle } from 'lucide-react' import clsx from 'clsx' // Interface matching the API response interface CaCertificate { name: string; type: string; serial: string; family_id?: string | null; expires_at: string; cdn_url?: string | null; linux_cdn_url?: string | null; der_cdn_url?: string | null; bat_cdn_url?: string | null; mac_cdn_url?: string | null; } const fetcher = (url: string) => axios.get(url).then(res => res.data.data) export function DynamicInstallationGuide() { const { data: certificates, error, isLoading } = useSWR('https://api.trustlab.dyzulk.com/api/public/ca-certificates', fetcher) const [selectedIndex, setSelectedIndex] = useState(0) const [copiedId, setCopiedId] = useState(null) const handleCopy = (text: string, id: string) => { navigator.clipboard.writeText(text) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) } if (error) return (
Unable to load live certificates.

Please ensure you can access api.trustlab.dyzulk.com.

) if (isLoading || !certificates) return (
Loading installer data...
) const root = certificates.find(c => c.type === 'root') const intermediates = certificates.filter(c => c.type !== 'root') const tabs = [ { id: 'windows', label: 'Windows', icon: Monitor }, { id: 'mac', label: 'macOS', icon: Monitor }, // Changed icon to Monitor for consistency or distinctiveness? User has 'Smartphone' for Mac in previous code, likely mistake. I will use Monitor or Laptop. Actually let's keeps consistent. { id: 'ios', label: 'iOS', icon: Smartphone }, { id: 'android', label: 'Android', icon: Smartphone }, { id: 'linux', label: 'Linux (CLI)', icon: Terminal }, ] const activeTab = tabs[selectedIndex].id as 'windows' | 'mac' | 'ios' | 'linux' | 'android' return (
{/* Tabs Header - Nextra Style (Bottom Border) */}
{tabs.map((tab, idx) => { const isActive = selectedIndex === idx const Icon = tab.icon return ( ) })}
{/* Tab Content */}
{/* Root Row */} {root && ( )} {/* Intermediates Rows */} {intermediates.map(cert => ( ))}
Certificate Raw Format {activeTab === 'linux' ? 'One-Liner Installer' : activeTab === 'android' ? 'Alternative (.der)' : activeTab === 'ios' ? 'Config Profile' : activeTab === 'mac' ? 'Config Profile' : 'Auto-Installer'}
Root CA
{root.name}
Exp: {new Date(root.expires_at).getFullYear()}
Download .crt
Intermediate CA
{cert.name}
Download .crt
{/* Contextual Instructions Footer - Detailed Manual Steps */}
{activeTab === 'windows' && (

Manual Installation (Raw .crt)

For Root CA:
  1. Double-click dydev-its-true.crtInstall Certificate.
  2. Select Local Machine (requires Admin).
  3. Select "Place all certificates in the following store".
  4. Browse & select Trusted Root Certification Authorities.
For Intermediates:
  1. Double-click the .crt file.
  2. Follow the same steps but choose Intermediate Certification Authorities as the store.
Recommended: Auto-Installer Script (.bat)
  • Download the .bat script from the table above.
  • Right-click the file and select "Run as Administrator".
  • The script will automatically install both Root and Intermediate CAs.
)} {activeTab === 'mac' && (

Installation Methods

Method A: Config Profile (Recommended)
  1. Download the .mobileconfig file.
  2. Go to System SettingsPrivacy & Security.
  3. Scroll down to Profiles and double-click the profile to install.
Method B: Keychain (Raw .crt)
  1. Open Keychain Access.
  2. Drag the .crt files into the System keychain.
  3. Double-click the Root CA → expand Trust.
  4. Set "When using this certificate" to Always Trust.
)} {activeTab === 'ios' && (

Installing on iOS (iPhone/iPad)

Important: Installing on iOS is a two-step process (Install Profile → Enable Trust).
  1. Tap Auto-Installer Script to download the configuration profile.
  2. Open Settings. Tap the "Profile Downloaded" banner at the top.
  3. Tap Install and enter your passcode.
  4. Required Step: Go to SettingsGeneralAboutCertificate Trust Settings.
  5. Under "Enable full trust for root certificates", toggle on the switch for "{root?.name || 'TrustLab Root CA'}".
)} {activeTab === 'android' && (

Installing on Android

  1. Download the .crt file (or .der if your specific Android version requires it).
  2. Go to **Settings** → **Security** → **Encryption & Credentials**.
  3. Tap **Install a certificate** → **CA Certificate**.
  4. Select "Install anyway" if prompted, then verify your identity (PIN/Fingerprint).
  5. Select the downloaded file.
)} {activeTab === 'linux' && (

Manual CLI Installation

If you cannot use the one-liner, follow these standard steps (Debian/Ubuntu example):

{`# 1. Copy certificates to local store
sudo cp *.crt /usr/local/share/ca-certificates/

# 2. Update the CA store
sudo update-ca-certificates`}

Note: For RHEL/CentOS, copy to /etc/pki/ca-trust/source/anchors/ and run update-ca-trust.

)}
) } // Sub-component for cleaner render logic function InstallerCell({ cert, os, handleCopy, copiedId }: { cert: CaCertificate, os: string, handleCopy: Function, copiedId: string | null }) { if (os === 'windows' && cert.bat_cdn_url) { return ( Installer Script (.bat) ) } // Shared Logic for macOS AND iOS using the same mobileconfig if ((os === 'mac' || os === 'ios') && cert.mac_cdn_url) { return ( Config Profile ) } if (os === 'android' && cert.der_cdn_url) { return ( Download .der ) } if (os === 'linux' && cert.linux_cdn_url) { const cmd = `curl -sL ${cert.linux_cdn_url} | sudo bash` const isCopied = copiedId === cert.serial return (
{cmd}
) } return Not available }