| ... | ... | @@ -111,25 +111,29 @@ pub fn rescanWindows(cb: *Bundle, gpa: Allocator) !void { |
| 111 | 111 | cb.bytes.clearRetainingCapacity(); |
| 112 | 112 | cb.map.clearRetainingCapacity(); |
| 113 | 113 | |
| 114 | | const store = try os.windows.crypt32.certOpenSystemStoreW(null, &[4:0]u16{ 'R', 'O', 'O', 'T' }); |
| 115 | | defer os.windows.crypt32.certCloseStore(store, 0) catch unreachable; |
| 116 | | |
| 117 | | var ctx = os.windows.crypt32.CertEnumCertificatesInStore(store, null); |
| 118 | | while (ctx) |context| : (ctx = os.windows.crypt32.CertEnumCertificatesInStore(store, ctx)) { |
| 119 | | var start = @intCast(u32, cb.bytes.items.len); |
| 120 | | try cb.bytes.appendSlice(gpa, context.pbCertEncoded[0..context.cbCertEncoded]); |
| 121 | | var parsed = Certificate.parse(.{ |
| 114 | const w = std.os.windows; |
| 115 | const GetLastError = w.kernel32.GetLastError; |
| 116 | const root = [4:0]u16{ 'R', 'O', 'O', 'T' }; |
| 117 | const store = w.crypt32.CertOpenSystemStoreW(null, &root) orelse switch (GetLastError()) { |
| 118 | .FILE_NOT_FOUND => return error.FileNotFound, |
| 119 | else => |err| return w.unexpectedError(err), |
| 120 | }; |
| 121 | defer _ = w.crypt32.CertCloseStore(store, 0); |
| 122 | |
| 123 | var ctx = w.crypt32.CertEnumCertificatesInStore(store, null); |
| 124 | while (ctx) |context| : (ctx = w.crypt32.CertEnumCertificatesInStore(store, ctx)) { |
| 125 | const decoded_start = @intCast(u32, cb.bytes.items.len); |
| 126 | const encoded_cert = context.pbCertEncoded[0..context.cbCertEncoded]; |
| 127 | try cb.bytes.appendSlice(gpa, encoded_cert); |
| 128 | const parsed_cert = try Certificate.parse(.{ |
| 122 | 129 | .buffer = cb.bytes.items, |
| 123 | | .index = start, |
| 124 | | }) catch { |
| 125 | | cb.bytes.items.len = start; |
| 126 | | continue; |
| 127 | | }; |
| 128 | | const gop = try cb.map.getOrPutContext(gpa, parsed.subject_slice, .{ .cb = cb }); |
| 130 | .index = decoded_start, |
| 131 | }); |
| 132 | const gop = try cb.map.getOrPutContext(gpa, parsed_cert.subject_slice, .{ .cb = cb }); |
| 129 | 133 | if (gop.found_existing) { |
| 130 | | cb.bytes.items.len = start; |
| 134 | cb.bytes.items.len = decoded_start; |
| 131 | 135 | } else { |
| 132 | | gop.value_ptr.* = start; |
| 136 | gop.value_ptr.* = decoded_start; |
| 133 | 137 | } |
| 134 | 138 | } |
| 135 | 139 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); |
| ... | ... | @@ -250,7 +254,6 @@ pub fn parseCert(cb: *Bundle, gpa: Allocator, decoded_start: u32, now_sec: i64) |
| 250 | 254 | const builtin = @import("builtin"); |
| 251 | 255 | const std = @import("../../std.zig"); |
| 252 | 256 | const assert = std.debug.assert; |
| 253 | | const os = std.os; |
| 254 | 257 | const fs = std.fs; |
| 255 | 258 | const mem = std.mem; |
| 256 | 259 | const crypto = std.crypto; |