Sample code for 30+ languages & platforms
Unicode C++

Get the Configured Server-Side TLS Certificate

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetMyServerCert, which copies the TLS server certificate configured by InitSslServer into a Cert object.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. This is intended for a socket acting as a TLS server and returns false when no server certificate has been configured.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkSocketW.h>
#include <CkCertW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkSocketW socket;

    //  The file path is relative to the application's current working directory.  An absolute path
    //  may also be used.  Supply the path appropriate to your own environment.
    //  The PFX password should come from a secure source rather than being hard-coded.
    const wchar_t *pfxPassword = L"myPfxPassword";
    CkCertW cert;
    success = cert.LoadPfxFile(L"qa_data/server.pfx",pfxPassword);
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    success = socket.InitSslServer(cert);
    if (success == false) {
        wprintf(L"%s\n",socket.lastErrorText());
        return;
    }

    //  Copy the TLS server certificate configured by InitSslServer, then inspect it.
    CkCertW myCert;
    success = socket.GetMyServerCert(myCert);
    if (success == false) {
        wprintf(L"%s\n",socket.lastErrorText());
        return;
    }

    wprintf(L"Server certificate subject: %s\n",myCert.subjectCN());
    }