UNPKG

sslko

Version:

A simple tool to check SSL/TLS certificate information for a given domain.

57 lines (56 loc) 2.52 kB
import type { DetailedPeerCertificate, PeerCertificate } from "node:tls"; import type { CertificateInfo, GetCertificateOptions } from "./types.js"; /** * Verifies if the given hostname matches the Common Name (CN) or Subject Alternative Names (SANs) of the certificate. * * @param host The hostname to check. * @param certificate The certificate to getCertificateInfo against. * @returns `true` if the hostname matches, otherwise `false`. */ export declare function verifyHostname(host: string, certificate: PeerCertificate | DetailedPeerCertificate): boolean; /** * Checks if a certificate appears to be self-signed by comparing subject and issuer. * @param certificate The certificate to check * @returns true if the certificate appears to be self-signed */ export declare function isSelfSignedCertificate(certificate: PeerCertificate | DetailedPeerCertificate): boolean; /** * Validates the basic structure and content of a certificate. * @param certificate The certificate to validate * @returns An array of validation warning messages (empty if valid) */ export declare function validateCertificateStructure(certificate: PeerCertificate | DetailedPeerCertificate): string[]; /** * Checks for security weaknesses in a certificate's cryptographic properties. * @param certificate The certificate to analyze for security issues * @returns An array of security warning messages */ export declare function checkCertificateSecurity(certificate: PeerCertificate | DetailedPeerCertificate): string[]; /** * Retrieves information about a certificate for a given host. * * @example Retrieve certificate info for example.com * ```typescript * import { getCertificateInfo } from "sslko"; * const info = await getCertificateInfo("example.com"); * console.log(`Valid: ${info.valid}, Days left: ${info.daysLeft}`); * ``` * * @example Retrieve expired certificate info for expired.badssl.com * ```typescript * import { getCertificateInfo } from "sslko"; * const info = await getCertificateInfo("expired.badssl.com"); * if (!info.valid) { * console.log(`Errors: ${info.errors.join(", ")}`); * } * ``` * * @example Check certificate for custom port * ```typescript * import { getCertificateInfo } from "sslko"; * const info = await getCertificateInfo("example.com", { port: 8443 }); * ``` * * Will return an object with `valid: false` and an error message. */ export declare function getCertificateInfo(host: string, options?: Partial<GetCertificateOptions>): Promise<CertificateInfo>;