Zig
Zig
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 Zig Downloads
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();
// 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;
};
socket.initSslServer(cert) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
const my_cert = try chilkat.Cert.init();
defer my_cert.deinit();
socket.getMyServerCert(my_cert) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
std.debug.print("Server certificate subject: {s}\n", .{try my_cert.getSubjectCN(alloc)});
}