sslko - v2.0.11
    Preparing search index...

    Function getCertificate

    • Fetches the SSL/TLS certificate from a given host and port.

      Note: When detailed is true (the default), the returned DetailedPeerCertificate contains a circular issuerCertificate reference (the root CA cert points to itself). This will cause JSON.stringify to throw. Use getCertificateInfo for a serialization-safe result, or remove the circular reference before serializing.

      Note: rejectUnauthorized defaults to false — the TLS handshake will succeed even for expired or self-signed certificates. Use getCertificateInfo for validation, or pass rejectUnauthorized: true to let Node.js verify the certificate.

      This function does not check certificate revocation (OCSP/CRL).

      Parameters

      • host: string

        The hostname to connect to.

      • options: Partial<GetCertificateOptions> = {}

        Optional parameters to configure the connection.

      Returns Promise<DetailedPeerCertificate | PeerCertificate>

      If the connection times out or if there is an error retrieving the certificate.

      import { getCertificate } from 'sslko';
      const cert = await getCertificate('example.com');
      console.log(cert);
      import { getCertificate } from 'sslko';
      const cert = await getCertificate('example.com', { rejectUnauthorized: true });
      console.log(cert);
      import { getCertificate } from 'sslko';
      const cert = await getCertificate('example.com', { port: 8443 });
      console.log(cert);
      import { getCertificate } from 'sslko';
      const cert = await getCertificate('example.com', { detailed: false });
      console.log(cert);

      When enabled, TLS packet trace information is written to stderr. This can be used to debug TLS connection problems.

      import { getCertificate } from 'sslko';
      const cert = await getCertificate('example.com', { enableTrace: true });