Sample code for 30+ languages & platforms
Zig

Get Certificate CRL Distribution Points

See more Certificates Examples

Demonstrates how to get a certificate's CRL Distribution Points extension data (assuming it exists). In the vast majority of cases, there will be one CRL Distribution Point.

Note: This example requires Chilkat v9.5.0.76 or greater.

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 cert = try chilkat.Cert.init();
    defer cert.deinit();

    cert.loadFromFile("qa_data/certs/test_haswdt.cer") catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    // Get the CRL Distribution Points extension, which is at OID 2.5.29.31
    const extension_xml_str = cert.getExtensionAsXml(alloc, "2.5.29.31") catch {
        std.debug.print("Certificate does not have the CDP extension.\n", .{});
        return;
    };

    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.loadXml(extension_xml_str) catch {};

    // See what we have..
    std.debug.print("{s}\n", .{try xml.getXml(alloc)});

    // We should get XML like this:

    // <?xml version="1.0" encoding="utf-8" ?>
    // <sequence>
    //     <sequence>
    //         <contextSpecific tag="0" constructed="1">
    //             <contextSpecific tag="0" constructed="1">
    //                 <contextSpecific tag="6" constructed="0">aHR0cDovL2NybC5jb21vZG9jYS5jb20vQ09NT0RPUlNBQ2xpZW50QXV0aGVudGljYXRpb25hbmRTZWN1
    // cmVFbWFpbENBLmNybA==</contextSpecific>
    //             </contextSpecific>
    //         </contextSpecific>
    //     </sequence>
    // </sequence>
    //

    // Assuming there is one CRL Distribution Point...
    const sb_dist_point = try chilkat.StringBuilder.init();
    defer sb_dist_point.deinit();
    if (xml.getChildContentSb("sequence|contextSpecific|contextSpecific|contextSpecific", sb_dist_point)) {
        sb_dist_point.decode("base64", "utf-8") catch {};
        std.debug.print("CRL Distribution Point:  {s}\n", .{try sb_dist_point.getAsString(alloc)});
    } else |_| {}

    // Sample output:
    // CRL Distribution Point:  http://crl.comodoca.com/COMODORSAClientAuthenticationandSecureEmailCA.crl
}