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 {...@@ -63,8 +63,8 @@ pub fn rescan(cb: *Bundle, gpa: Allocator) RescanError!void {
63 .freebsd, .openbsd => return rescanBSD(cb, gpa, "/etc/ssl/cert.pem"),63 .freebsd, .openbsd => return rescanBSD(cb, gpa, "/etc/ssl/cert.pem"),
64 .netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"),64 .netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"),
65 .dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"),65 .dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"),
66 .solaris, .illumos => return rescanBSD(cb, gpa, "/etc/ssl/cacert.pem"),
66 .windows => return rescanWindows(cb, gpa),67 .windows => return rescanWindows(cb, gpa),
67 .solaris, .illumos => return rescanSolaris(cb, gpa, "/etc/ssl/cacert.pem"),
68 else => {},68 else => {},
69 }69 }
70}70}
...@@ -152,15 +152,6 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {...@@ -152,15 +152,6 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
152 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);152 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
153}153}
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
164pub const AddCertsFromDirPathError = fs.File.OpenError || AddCertsFromDirError;155pub const AddCertsFromDirPathError = fs.File.OpenError || AddCertsFromDirError;
165156
166pub fn addCertsFromDirPath(157pub fn addCertsFromDirPath(
...@@ -223,7 +214,12 @@ pub fn addCertsFromFilePath(...@@ -223,7 +214,12 @@ pub fn addCertsFromFilePath(
223 return addCertsFromFile(cb, gpa, file);214 return addCertsFromFile(cb, gpa, file);
224}215}
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
228pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFromFileError!void {224pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFromFileError!void {
229 const size = try file.getEndPos();225 const size = try file.getEndPos();
...@@ -235,7 +231,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom...@@ -235,7 +231,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
235 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse231 const needed_capacity = std.math.cast(u32, decoded_size_upper_bound + size) orelse
236 return error.CertificateAuthorityBundleTooBig;232 return error.CertificateAuthorityBundleTooBig;
237 try cb.bytes.ensureUnusedCapacity(gpa, needed_capacity);233 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);
239 const buffer = cb.bytes.allocatedSlice()[end_reserved..];235 const buffer = cb.bytes.allocatedSlice()[end_reserved..];
240 const end_index = try file.readAll(buffer);236 const end_index = try file.readAll(buffer);
241 const encoded_bytes = buffer[0..end_index];237 const encoded_bytes = buffer[0..end_index];
...@@ -252,7 +248,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom...@@ -252,7 +248,7 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file: fs.File) AddCertsFrom
252 return error.MissingEndCertificateMarker;248 return error.MissingEndCertificateMarker;
253 start_index = cert_end + end_marker.len;249 start_index = cert_end + end_marker.len;
254 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");250 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);
256 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];252 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];
257 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);253 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);
258 try cb.parseCert(gpa, decoded_start, now_sec);254 try cb.parseCert(gpa, decoded_start, now_sec);