authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-07-02 15:10:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-02 19:24:37-07:00
logfc9ab5f0e838196e99d1706e4d4e91f3d761d509
treeae8dc64b1a526ad44f1b06f3540eefc117701993
parent689f3163af48fd6e0c08bb76fadfb711db30c97c

tls certificates: support more BSDs

- add support for freebsd, netbsd, dragonfly - refactor rescanOpenBSD -> rescanBSD - make os-specific rescan*() non-public closes #16279

1 files changed, 13 insertions(+), 15 deletions(-)

lib/std/crypto/Certificate/Bundle.zig+13-15
......@@ -50,7 +50,7 @@ pub fn deinit(cb: *Bundle, gpa: Allocator) void {
5050 cb.* = undefined;
5151}
5252
53pub const RescanError = RescanLinuxError || RescanMacError || RescanWindowsError;
53pub const RescanError = RescanLinuxError || RescanMacError || RescanBSDError || RescanWindowsError;
5454
5555/// Clears the set of certificates and then scans the host operating system
5656/// file system standard locations for certificates.
......@@ -60,18 +60,20 @@ pub fn rescan(cb: *Bundle, gpa: Allocator) RescanError!void {
6060 switch (builtin.os.tag) {
6161 .linux => return rescanLinux(cb, gpa),
6262 .macos => return rescanMac(cb, gpa),
63 .openbsd => return rescanOpenBSD(cb, gpa),
63 .freebsd, .openbsd => return rescanBSD(cb, gpa, "/etc/ssl/cert.pem"),
64 .netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"),
65 .dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"),
6466 .windows => return rescanWindows(cb, gpa),
6567 else => {},
6668 }
6769}
6870
69pub const rescanMac = @import("Bundle/macos.zig").rescanMac;
70pub const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
71const rescanMac = @import("Bundle/macos.zig").rescanMac;
72const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
7173
72pub const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;
74const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;
7375
74pub fn rescanLinux(cb: *Bundle, gpa: Allocator) RescanLinuxError!void {
76fn rescanLinux(cb: *Bundle, gpa: Allocator) RescanLinuxError!void {
7577 // Possible certificate files; stop after finding one.
7678 const cert_file_paths = [_][]const u8{
7779 "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
......@@ -113,22 +115,18 @@ pub fn rescanLinux(cb: *Bundle, gpa: Allocator) RescanLinuxError!void {
113115 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
114116}
115117
116pub const RescanOpenBSDError = AddCertsFromFilePathError;
117
118pub fn rescanOpenBSD(cb: *Bundle, gpa: Allocator) RescanOpenBSDError!void {
119 const cert_file_path = "/etc/ssl/cert.pem";
118const RescanBSDError = AddCertsFromFilePathError;
120119
120fn rescanBSD(cb: *Bundle, gpa: Allocator, cert_file_path: []const u8) RescanBSDError!void {
121121 cb.bytes.clearRetainingCapacity();
122122 cb.map.clearRetainingCapacity();
123
124 addCertsFromFilePathAbsolute(cb, gpa, cert_file_path) catch |err| return err;
125
123 try addCertsFromFilePathAbsolute(cb, gpa, cert_file_path);
126124 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
127125}
128126
129pub const RescanWindowsError = Allocator.Error || ParseCertError || std.os.UnexpectedError || error{FileNotFound};
127const RescanWindowsError = Allocator.Error || ParseCertError || std.os.UnexpectedError || error{FileNotFound};
130128
131pub fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
129fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
132130 cb.bytes.clearRetainingCapacity();
133131 cb.map.clearRetainingCapacity();
134132