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

Verify SSL Server Certificate

See more Socket/SSL/TLS Examples

Demonstrates how to connect to an SSL server and verify its SSL certificate.

Chilkat React Native Downloads

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

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

  const socket = new Socket();

  const ssl = true;
  const maxWaitMillisec = 20000;

  // The SSL server hostname may be an IP address, a domain name,
  // or "localhost". 
  const sslServerHost = 'www.paypal.com';
  const sslServerPort = 443;

  // Connect to the SSL server:
  try {
    await socket.connectAsync(sslServerHost, sslServerPort, ssl, maxWaitMillisec);
  } catch {
    console.log(socket.lastErrorText);
    return;
  }

  const cert = new Cert();

  let bExpired = false;
  let bRevoked = false;
  let bSignatureVerified = false;
  let bTrustedRoot = false;

  try {
    socket.getServerCert(cert);

    console.log('Server Certificate:');
    console.log(`Distinguished Name: ${cert.subjectDN}`);
    console.log(`Common Name: ${cert.subjectCN}`);
    console.log(`Issuer Distinguished Name: ${cert.issuerDN}`);
    console.log(`Issuer Common Name: ${cert.issuerCN}`);

    bExpired = cert.expired;
    bRevoked = cert.revoked;
    bSignatureVerified = cert.signatureVerified;
    bTrustedRoot = cert.trustedRoot;

    console.log(`Expired: ${bExpired}`);
    console.log(`Revoked: ${bRevoked}`);
    console.log(`Signature Verified: ${bSignatureVerified}`);
    console.log(`Trusted Root: ${bTrustedRoot}`);
  } catch {
    // socket.getServerCert() failed; continue anyway.
  }

  // Close the connection with the server
  // Wait a max of 20 seconds (20000 millsec)
  await socket.closeAsync(20000);
}