authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-17 16:27:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-18 12:51:45-04:00
log8804d726842037e923f532ea477e559779c24587
tree33104d0bf62250b49b8c9d6e5857f08ab8c6ef5f
parentc3120d5089df155937a2ab78140cbe8c0b215e06

std certs: solaris can use the BSD path


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

lib/std/crypto/Certificate/Bundle.zig+9-13
......@@ -63,8 +63,8 @@ pub fn rescan(cb: *Bundle, gpa: Allocator) RescanError!void {
6363 .freebsd, .openbsd => return rescanBSD(cb, gpa, "/etc/ssl/cert.pem"),
6464 .netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"),
6565 .dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"),
66 .solaris, .illumos => return rescanBSD(cb, gpa, "/etc/ssl/cacert.pem"),
6667 .windows => return rescanWindows(cb, gpa),
67 .solaris, .illumos => return rescanSolaris(cb, gpa, "/etc/ssl/cacert.pem"),
6868 else => {},
6969 }
7070}
......@@ -152,15 +152,6 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
152152 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
153153}
154154
155const RescanSolarisError = AddCertsFromFilePathError;
156
157fn rescanSolaris(cb: *Bundle, gpa: Allocator, cert_file_path: []const u8) RescanSolarisError!void {
158 cb.bytes.clearRetainingCapacity();
159 cb.map.clearRetainingCapacity();
160 try addCertsFromFilePathAbsolute(cb, gpa, cert_file_path);
161 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
162}
163
164155pub const AddCertsFromDirPathError = fs.File.OpenError || AddCertsFromDirError;
165156
166157pub fn addCertsFromDirPath(
......@@ -223,7 +214,12 @@ pub fn addCertsFromFilePath(
223214 return addCertsFromFile(cb, gpa, file);
224215}
225216
226pub const AddCertsFromFileError = Allocator.Error || fs.File.GetSeekPosError || fs.File.ReadError || ParseCertError || std.base64.Error || error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker };
217pub const AddCertsFromFileError = Allocator.Error ||
218 fs.File.GetSeekPosError ||
219 fs.File.ReadError ||
220 ParseCertError ||
221 std.base64.Error ||
222 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker };
227223
228224pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFromFileError!void {
229225 const size = try file.getEndPos();
......@@ -235,7 +231,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
235231 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse
236232 return error.CertificateAuthorityBundleTooBig;
237233 try cb.bytes.ensureUnusedCapacity(gpa, needed_capacity);
238 const end_reserved = @as(u32, @intCast(cb.bytes.items.len + decoded_size_upper_bound));
234 const end_reserved: u32 = @intCast(cb.bytes.items.len + decoded_size_upper_bound);
239235 const buffer = cb.bytes.allocatedSlice()[end_reserved..];
240236 const end_index = try file.readAll(buffer);
241237 const encoded_bytes = buffer[0..end_index];
......@@ -252,7 +248,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
252248 return error.MissingEndCertificateMarker;
253249 start_index = cert_end + end_marker.len;
254250 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");
255 const decoded_start = @as(u32, @intCast(cb.bytes.items.len));
251 const decoded_start: u32 = @intCast(cb.bytes.items.len);
256252 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];
257253 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);
258254 try cb.parseCert(gpa, decoded_start, now_sec);