Zig Requires Chilkat v11.0.0+
Zig
Use a Custom Set of Trusted Root Certificates
See more Certificates Examples
Demonstrates how to build a set of trusted root certificates to be used globally by all Chilkat classes.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const trusted_roots = try chilkat.TrustedRoots.init();
defer trusted_roots.deinit();
// Indicate that we will NOT trust any pre-installed certificates on the system.
trusted_roots.setTrustSystemCaRoots(false);
// Thawte is a certificate authority that provides a .zip download of their
// root CA certificates: https://www.thawte.com/roots/index.html
// The direct download link is: https://www.verisign.com/support/thawte-roots.zip
// Note: The above URLs are valid at the time of writing this example (29-May-2015).
// Assuming the .zip has already been downloaded, open it and load each .pem file into
// our trusted roots object.
const zip = try chilkat.Zip.init();
defer zip.deinit();
// Open a .zip containing PEM files, among other things..
zip.openZip("qa_data/certs/thawte-roots.zip") catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
var pem_str: [:0]const u8 = "";
const cert = try chilkat.Cert.init();
defer cert.deinit();
const pattern = "*.pem";
var b_has_more_entries: bool = if (zip.entryMatching(pattern, entry)) true else |_| false;
while (b_has_more_entries) {
std.debug.print("Entry: {s}\n", .{try entry.getFileName(alloc)});
// Get the PEM of the CA cert:
pem_str = try entry.unzipToString(alloc, 0, "utf-8");
// Load it into a certificate object:
cert.loadPem(pem_str) catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
};
// Add it to the trusted roots.
trusted_roots.addCert(cert) catch {};
b_has_more_entries = if (entry.getNextMatch(pattern)) true else |_| false;
}
// Activate the trusted roots globally for all Chilkat objects.
// This call really shouldn't fail, so we're not checking the return value.
try trusted_roots.activate();
}