sslko
Version:
A simple tool to check SSL/TLS certificate information for a given domain.
48 lines (47 loc) • 1.78 kB
TypeScript
import type { DetailedPeerCertificate, PeerCertificate } from "node:tls";
import type { GetCertificateOptions } from "./types.js";
/**
* Fetches the SSL/TLS certificate from a given host and port.
*
* @param host The hostname to connect to.
* @param options Optional parameters to configure the connection.
* @throws {CertificateError} If the connection times out or if there is an error retrieving the certificate.
*
* @example Return a PeerCertificateDetailed object:
* ```typescript
* import { getCertificate } from 'sslko';
* const cert = await getCertificate('example.com');
* console.log(cert);
* ```
*
* @example Let Node.js getCertificateInfo the certificate for you:
* ```typescript
* import { getCertificate } from 'sslko';
* const cert = await getCertificate('example.com', { rejectUnauthorized: true });
* console.log(cert);
* ```
*
* @example Return a PeerCertificateDetailed object with a custom port:
* ```typescript
* import { getCertificate } from 'sslko';
* const cert = await getCertificate('example.com', { port: 8443 });
* console.log(cert);
* ```
*
* @example Return a PeerCertificate object:
* ```typescript
* import { getCertificate } from 'sslko';
* const cert = await getCertificate('example.com', { detailed: false });
* console.log(cert);
* ```
*
* @example Enable trace - useful for debugging:
*
* When enabled, TLS packet trace information is written to `stderr`. This can be used to debug TLS connection problems.
*
* ```typescript
* import { getCertificate } from 'sslko';
* const cert = await getCertificate('example.com', { enableTrace: true });
* ```
*/
export declare function getCertificate(host: string, options?: Partial<GetCertificateOptions>): Promise<DetailedPeerCertificate | PeerCertificate>;