Skip to content

MacOS CA Bundle regression after b3a11018ae1fe99190fb6fb7ae82a486c40f6f15 #22870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jedisct1 opened this issue Feb 12, 2025 · 5 comments · Fixed by #22927
Closed

MacOS CA Bundle regression after b3a11018ae1fe99190fb6fb7ae82a486c40f6f15 #22870

jedisct1 opened this issue Feb 12, 2025 · 5 comments · Fixed by #22927
Labels
bug Observed behavior contradicts documented or intended behavior os-macos regression It worked in a previous version of Zig, but stopped working. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@jedisct1
Copy link
Contributor

Zig Version

0.14.0-dev.3213+53216d2f2

Steps to Reproduce and Observed Behavior

After b3a1101 , root CAs are not properly loaded any more on macOS.

Random example while trying to compile zls:

zls/build.zig.zon:16:20: error: unable to connect to server: CertificateBundleLoadFailure
            .url = "https://github.com/ziglibs/known-folders/archive/1cceeb70e77dec941a4178160ff6c8d05a74de6f.tar.gz",

Reverting b3a1101 fixes this.

Expected Behavior

root CAs can be loaded.

@jedisct1 jedisct1 added the bug Observed behavior contradicts documented or intended behavior label Feb 12, 2025
@ifreund ifreund added this to the 0.14.0 milestone Feb 12, 2025
@ifreund ifreund added the regression It worked in a previous version of Zig, but stopped working. label Feb 12, 2025
@alexrp
Copy link
Member

alexrp commented Feb 12, 2025

FYI @dreilly1982

We'll have to revert that PR if this can't be fixed in time for 0.14.0.

@dreilly1982
Copy link
Contributor

That is odd, I'll look into this today.

@jedisct1
Copy link
Contributor Author

The bundle properly loads if the order of the keychains is switched:

diff --git a/lib/std/crypto/Certificate/Bundle/macos.zig b/lib/std/crypto/Certificate/Bundle/macos.zig
index 7fb16af543..4589adb217 100644
--- a/lib/std/crypto/Certificate/Bundle/macos.zig
+++ b/lib/std/crypto/Certificate/Bundle/macos.zig
@@ -12,8 +12,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
     cb.map.clearRetainingCapacity();
 
     const keychainPaths = [2][]const u8{
-        "/System/Library/Keychains/SystemRootCertificates.keychain",
         "/Library/Keychains/System.keychain",
+        "/System/Library/Keychains/SystemRootCertificates.keychain",
     };
 
     for (keychainPaths) |keychainPath| {

@alexrp alexrp added standard library This issue involves writing Zig code for the standard library. os-macos labels Feb 12, 2025
@dreilly1982
Copy link
Contributor

So I couldn't reproduce your issue on my end, but swapping the order didn't affect my functionality. What is weird, and I'm looking into it, is the cb.bytes.items.len IS different based of the order, which I find odd. I'm looking more into this tonight.

@nurpax
Copy link
Contributor

nurpax commented Feb 16, 2025

If it helps, I can also try to repro this with and w/o this change. I seem to be hitting this regression too. I just don't know where to download aarch64 macOS builds of zig for past changes, I can only find the latest master.

EDIT: I got some help finding the right nightlies. Here's a log of when the problem started happening:

➜  ~/dev/zig2d git:(main) ~/zig-macos-aarch64-0.14.0-dev.3066+1a1389c51/zig fetch --save git+https://github.com/natecraddock/ziglua
info: resolved to commit daa99a28a21523f680ebade522202440bbe720db
info: existing dependency named 'ziglua' is up-to-date

➜  ~/dev/zig2d git:(main) ~/zig-macos-aarch64-0.14.0-dev.3089+87bbb49d5/zig fetch --save git+https://github.com/natecraddock/ziglua
info: resolved to commit daa99a28a21523f680ebade522202440bbe720db
info: existing dependency named 'ziglua' is up-to-date

➜  ~/dev/zig2d git:(main) ~/zig-macos-aarch64-0.14.0-dev.3091+42e48b83b/zig fetch --save git+https://github.com/natecraddock/ziglua
info: resolved to commit daa99a28a21523f680ebade522202440bbe720db
info: existing dependency named 'ziglua' is up-to-date

➜  ~/dev/zig2d git:(main) ~/zig-macos-aarch64-0.14.0-dev.3187+d4c85079c/zig fetch --save git+https://github.com/natecraddock/ziglua
error: unable to discover remote git server capabilities: CertificateBundleLoadFailure

alexrp added a commit to alexrp/zig that referenced this issue Feb 17, 2025
@alexrp alexrp mentioned this issue Feb 17, 2025
squeek502 added a commit to squeek502/zig that referenced this issue Feb 18, 2025
In the original PR that implemented this (ziglang#14325), it included a list of references for the keychain format. Multiple of those references include the checks that are added in this commit, and empirically this fixes the loading of a real keychain file that was previously failing (it had both a record with offset 0 and a record with cert_size 0).

Fixes ziglang#22870
@alexrp alexrp closed this as completed in 0779e84 Feb 18, 2025
T1nk3r1 pushed a commit to T1nk3r1/zig-frictionless that referenced this issue Apr 5, 2025
In the original PR that implemented this (ziglang#14325), it included a list of references for the keychain format. Multiple of those references include the checks that are added in this commit, and empirically this fixes the loading of a real keychain file that was previously failing (it had both a record with offset 0 and a record with cert_size 0).

Fixes ziglang#22870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos regression It worked in a previous version of Zig, but stopped working. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants