Skip to content

Full Toolkit for Next-Level Domain Analysis

Display Certificates on Lookup page 📜

Felix Wotschofsky3c8298e1b95d
diff --git a/components/CertInfo.tsx b/components/CertInfo.tsx
new file mode 100644
index 0000000..3a3fa26
--- /dev/null
+++ b/components/CertInfo.tsx
@@ -0,0 +1,68 @@
+import {
+ Flex,
+ Spinner,
+ Table,
+ Tbody,
+ Td,
+ Th,
+ Thead,
+ Tr,
+} from '@chakra-ui/react';
+import useSWR from 'swr';
+
+import type { CertLookupResponse } from '@/api/lookupCerts';
+
+type CertInfoProps = {
+ domain: string;
+};
+
+const CertInfo = ({ domain }: CertInfoProps) => {
+ const { data, error } = useSWR<CertLookupResponse>(
+ `/api/lookupCerts?domain=${encodeURIComponent(domain)}`
+ );
+
+ if (!data) {
+ return (
+ <Flex justify="center" align="center">
+ <Spinner size="xl" my={8} />
+ </Flex>
+ );
+ }
+
+ if (error) {
+ return <p>An error occurred!</p>;
+ }
+
+ return (
+ <Table>
+ <Thead>
+ <Tr>
+ <Th pl={0}>Logged At</Th>
+ <Th>Not Before</Th>
+ <Th>Not After</Th>
+ <Th>Common Name</Th>
+ <Th>Matching Identities</Th>
+ <Th pr={0}>Issuer Name</Th>
+ </Tr>
+ </Thead>
+ <Tbody>
+ {data.certificates.map((cert) => (
+ <Tr key={cert.id}>
+ <Td pl={0}>{cert.loggedAt}</Td>
+ <Td>{cert.notBefore}</Td>
+ <Td>{cert.notAfter}</Td>
+ <Td>{cert.commonName}</Td>
+ <Td
+ dangerouslySetInnerHTML={{
+ __html: cert.matchingIdentities.replace(/\n/g, '<br>'),
+ }}
+ ></Td>
+ <Td pr={0}>{cert.issuerName}</Td>
+ </Tr>
+ ))}
+ </Tbody>
+ </Table>
+ );
+};
+
+export default CertInfo;
diff --git a/pages/api/lookupCerts.ts b/pages/api/lookupCerts.ts
new file mode 100644
index 0000000..baf80c3
--- /dev/null
+++ b/pages/api/lookupCerts.ts
@@ -0,0 +1,53 @@
+import type { NextApiRequest, NextApiResponse } from 'next';
+import axios from 'axios';
+import isFQDN from 'validator/lib/isFQDN';
+
+export type CertLookupResponse = {
+ certificates: {
+ id: string;
+ issuerName: string;
+ commonName: string;
+ matchingIdentities: string;
+ loggedAt: string;
+ notBefore: string;
+ notAfter: string;
+ }[];
+};
+
+export type CertsLookupErrorResponse = { error: true; message: string };
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse<CertLookupResponse | CertsLookupErrorResponse>
+) {
+ if (
+ !req.query.domain ||
+ typeof req.query.domain === 'object' ||
+ !isFQDN(req.query.domain)
+ ) {
+ res.status(400).json({
+ error: true,
+ message: 'Bad Request',
+ });
+ return;
+ }
+
+ const response = await axios('https://crt.sh', {
+ params: {
+ Identity: req.query.domain,
+ output: 'json',
+ },
+ });
+
+ res.json({
+ certificates: response.data.map((c: Record<string, string | number>) => ({
+ id: c.id,
+ loggedAt: c.entry_timestamp,
+ notBefore: c.not_before,
+ notAfter: c.not_after,
+ commonName: c.common_name,
+ matchingIdentities: c.name_value,
+ issuerName: c.issuer_name,
+ })),
+ });
+}
diff --git a/pages/lookup/[domain].tsx b/pages/lookup/[domain].tsx
index 869d859..80c1fd7 100644
--- a/pages/lookup/[domain].tsx
+++ b/pages/lookup/[domain].tsx
@@ -11,6 +11,7 @@ import {
Tabs,
} from '@chakra-ui/react';
+import CertInfo from '@/components/CertInfo';
import DnsLookup, { ResolvedRecords } from '@/utils/DnsLookup';
import DnsTable from '@/components/DnsTable';
import SearchForm from '@/components/SearchForm';
@@ -77,6 +78,7 @@ const LookupDomain = ({
<TabList>
<Tab>DNS</Tab>
<Tab>Whois</Tab>
+ <Tab>Certs</Tab>
</TabList>
<TabPanels>
@@ -87,6 +89,10 @@ const LookupDomain = ({
<TabPanel>
<WhoisInfo domain={router.query.domain as string} />
</TabPanel>
+
+ <TabPanel>
+ <CertInfo domain={router.query.domain as string} />
+ </TabPanel>
</TabPanels>
</Tabs>
</Container>