Skip to content

Commit fc9ab5f

Browse files
mikdusanandrewrk
authored andcommitted
tls certificates: support more BSDs
- add support for freebsd, netbsd, dragonfly - refactor rescanOpenBSD -> rescanBSD - make os-specific rescan*() non-public closes #16279
1 parent 689f316 commit fc9ab5f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/std/crypto/Certificate/Bundle.zig

+13-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn deinit(cb: *Bundle, gpa: Allocator) void {
5050
cb.* = undefined;
5151
}
5252

53-
pub const RescanError = RescanLinuxError || RescanMacError || RescanWindowsError;
53+
pub 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

69-
pub const rescanMac = @import("Bundle/macos.zig").rescanMac;
70-
pub const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
71+
const rescanMac = @import("Bundle/macos.zig").rescanMac;
72+
const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
7173

72-
pub const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;
74+
const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;
7375

74-
pub fn rescanLinux(cb: *Bundle, gpa: Allocator) RescanLinuxError!void {
76+
fn 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

116-
pub const RescanOpenBSDError = AddCertsFromFilePathError;
117-
118-
pub fn rescanOpenBSD(cb: *Bundle, gpa: Allocator) RescanOpenBSDError!void {
119-
const cert_file_path = "/etc/ssl/cert.pem";
118+
const RescanBSDError = AddCertsFromFilePathError;
120119

120+
fn 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

129-
pub const RescanWindowsError = Allocator.Error || ParseCertError || std.os.UnexpectedError || error{FileNotFound};
127+
const RescanWindowsError = Allocator.Error || ParseCertError || std.os.UnexpectedError || error{FileNotFound};
130128

131-
pub fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
129+
fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
132130
cb.bytes.clearRetainingCapacity();
133131
cb.map.clearRetainingCapacity();
134132

0 commit comments

Comments
 (0)