Sample code for 30+ languages & platforms
Node.js

Verify SSL Server Certificate

See more Socket/SSL/TLS Examples

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

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    var socket = new chilkat.Socket();

    var ssl = true;
    var maxWaitMillisec = 20000;

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

    //  Connect to the SSL server:
    success = socket.Connect(sslServerHost,sslServerPort,ssl,maxWaitMillisec);
    if (success == false) {
        console.log(socket.LastErrorText);
        return;
    }

    var cert = new chilkat.Cert();

    var bExpired;
    var bRevoked;
    var bSignatureVerified;
    var bTrustedRoot;

    success = socket.GetServerCert(cert);
    if (success !== false) {

        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);

    }

    //  Close the connection with the server
    //  Wait a max of 20 seconds (20000 millsec)
    success = socket.Close(20000);

}

chilkatExample();