Sample code for 30+ languages & platforms
C

Enumerate Server-Advertised Acceptable Client CAs

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetSslAcceptableClientCaDn, which returns a certificate-authority distinguished name advertised by a TLS server when it requests a client certificate.

Background. Valid indexes range from 0 through NumSslAcceptableClientCAs minus one. A client can use these names to select an appropriate client certificate.

Chilkat C Downloads

C
#include <C_CkSocket.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSocket socket;
    BOOL bTls;
    int maxWaitMs;
    int numCAs;
    int i;
    const char *caDn;

    success = FALSE;

    socket = CkSocket_Create();

    //  Connect to the server using TLS.
    bTls = TRUE;
    maxWaitMs = 5000;
    success = CkSocket_Connect(socket,"example.com",5000,bTls,maxWaitMs);
    if (success == FALSE) {
        printf("%s\n",CkSocket_lastErrorText(socket));
        CkSocket_Dispose(socket);
        return;
    }

    //  After connecting to a server that requests a client certificate, enumerate the certificate-
    //  authority distinguished names the server advertised as acceptable.
    numCAs = CkSocket_getNumSslAcceptableClientCAs(socket);

    for (i = 0; i <= numCAs - 1; i++) {
        caDn = CkSocket_getSslAcceptableClientCaDn(socket,i);
        if (CkSocket_getLastMethodSuccess(socket) == FALSE) {
            printf("%s\n",CkSocket_lastErrorText(socket));
            CkSocket_Dispose(socket);
            return;
        }

        printf("%s\n",caDn);
    }



    CkSocket_Dispose(socket);

    }