Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

Get the Server Certificate, Certificate Chain, and Root CA Certificate

See more HTTP Examples

Demonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.

Chilkat React Native Downloads

React Native
import { Cert, CertChain, Http } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  // We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
  const sslCert = new Cert();
  try {
    await http.getServerCertAsync('apple.com', 443, sslCert);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const certChain = new CertChain();
  try {
    sslCert.buildCertChain(certChain);
  } catch {
    console.log(sslCert.lastErrorText);
    return;
  }

  const cert = new Cert();
  let i = 0;
  const numCerts = certChain.numCerts;
  while (i < numCerts) {
    certChain.certAt(i, cert);
    console.log(`SubjectDN ${i}: ${cert.subjectDN}`);
    console.log(`IssuerDN ${i}: ${cert.issuerDN}`);
    i++;
  }

  // If the certificate chain reaches the root CA cert, then the last cert in the chain
  // is the root CA cert.
  if (certChain.reachesRoot) {
    const caCert = new Cert();
    certChain.certAt(numCerts - 1, caCert);
    console.log(`CA Root Cert: ${caCert.subjectDN}`);
  }
}