Sample code for 30+ languages & platforms
Zig

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 Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const socket = try chilkat.Socket.init();
    defer socket.deinit();

    // Connect to the server using TLS.
    const b_tls = true;
    const max_wait_ms = 5000;
    socket.connect("example.com", 5000, b_tls, max_wait_ms) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    // After connecting to a server that requests a client certificate, enumerate the certificate-
    // authority distinguished names the server advertised as acceptable.
    const num_c_as = socket.getNumSslAcceptableClientCAs();
    var i: i32 = 0;
    i = 0;
    while (i < num_c_as) : (i += 1) {
        const ca_dn = socket.getSslAcceptableClientCaDn(alloc, i) catch {
            std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
            return;
        };

        std.debug.print("{s}\n", .{ca_dn});
    }
}