Sample code for 30+ languages & platforms
Zig

Advertise Acceptable Client CA Names for Mutual TLS

See more Socket/SSL/TLS Examples

Demonstrates Socket.AddSslAcceptableClientCaDn, which adds a certificate-authority distinguished name to the list a TLS server advertises when requesting a client certificate for mutual TLS.

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. Call this once for each acceptable CA distinguished name, and add all names before calling InitSslServer. The server then requests a client certificate and advertises the configured acceptable CAs.

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

    // For mutual TLS, advertise the acceptable client-certificate CA distinguished names BEFORE
    // initializing server-side TLS.  Call once for each acceptable CA distinguished name.
    socket.addSslAcceptableClientCaDn("CN=Example Root CA, O=Example, C=US") catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    socket.addSslAcceptableClientCaDn("CN=Example Intermediate CA, O=Example, C=US") catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    // 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 pfx_password = "myPfxPassword";
    const cert = try chilkat.Cert.init();
    defer cert.deinit();
    cert.loadPfxFile("qa_data/server.pfx", pfx_password) catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    // Initialize server-side TLS.  The server will now request a client certificate and advertise the
    // acceptable CA distinguished names added above.
    socket.initSslServer(cert) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Server-side TLS configured to request client certificates.\n", .{});
}