Skip to content

Commit e33618a

Browse files
committed
Don't error when initializing LibGit2 with CA roots path
When e.g. SSL_CERT_FILE is set, we cannot set this location in LibGit2_jll because it isn't built with support for that. Until now we've errored out with a message telling users to set JULIA_SSL_CA_ROOTS_PATH to an empty string. This changes the behavior to allow this expected error. Variables like SSL_CERT_FILE are for instance set by Conda, ensuring many people running into this, see e.g. https://discourse.julialang.org/search?q=JULIA_SSL_CA_ROOTS_PATH. The other part, and some more context for this, is here: JuliaLang/NetworkOptions.jl#37 (comment)
1 parent ec2b509 commit e33618a

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

stdlib/LibGit2/src/LibGit2.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,24 +1042,20 @@ function set_ssl_cert_locations(cert_loc)
10421042
else # files, /dev/null, non-existent paths, etc.
10431043
cert_file = cert_loc
10441044
end
1045-
ret = @ccall libgit2.git_libgit2_opts(
1045+
ret = @ccall libgit2.git_libgit2_opts(
10461046
Consts.SET_SSL_CERT_LOCATIONS::Cint;
10471047
cert_file::Cstring,
10481048
cert_dir::Cstring)::Cint
10491049
ret >= 0 && return ret
1050+
# On macOS and Windows LibGit2_jll is built without a TLS backend that supports
1051+
# certificate locations; don't throw on this expected error so we allow certificate
1052+
# location environment variables to be set for other purposes.
1053+
# We still try doing so to support other LibGit2 builds.
10501054
err = Error.GitError(ret)
10511055
err.class == Error.SSL &&
10521056
err.msg == "TLS backend doesn't support certificate locations" ||
10531057
throw(err)
1054-
var = nothing
1055-
for v in NetworkOptions.CA_ROOTS_VARS
1056-
haskey(ENV, v) && (var = v)
1057-
end
1058-
@assert var !== nothing # otherwise we shouldn't be here
1059-
msg = """
1060-
Your Julia is built with a SSL/TLS engine that libgit2 doesn't know how to configure to use a file or directory of certificate authority roots, but your environment specifies one via the $var variable. If you believe your system's root certificates are safe to use, you can `export JULIA_SSL_CA_ROOTS_PATH=""` in your environment to use those instead.
1061-
"""
1062-
throw(Error.GitError(err.class, err.code, chomp(msg)))
1058+
return ret
10631059
end
10641060

10651061
"""

stdlib/LibGit2/test/bad_ca_roots.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ const CAN_SET_CA_ROOTS_PATH = !Sys.isapple() && !Sys.iswindows()
1212
# Given this is a sub-processed test file, not using @testsets avoids
1313
# leaking the report print into the Base test runner report
1414
begin # empty CA roots file
15-
# these fail for different reasons on different platforms:
16-
# - on Apple & Windows you cannot set the CA roots path location
17-
# - on Linux & FreeBSD you you can but these are invalid files
15+
# different behavior on different platforms:
16+
# - on Apple & Windows you cannot set the CA roots path location; don't error
17+
# - on Linux & FreeBSD you can but these are invalid files
18+
1819
ENV["JULIA_SSL_CA_ROOTS_PATH"] = "/dev/null"
19-
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
20+
if CAN_SET_CA_ROOTS_PATH
21+
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
22+
else
23+
@test LibGit2.ensure_initialized() === nothing
24+
end
25+
2026
ENV["JULIA_SSL_CA_ROOTS_PATH"] = tempname()
21-
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
22-
# test that it still fails if called a second time
23-
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
24-
if !CAN_SET_CA_ROOTS_PATH
25-
# test that this doesn't work on macOS & Windows
26-
ENV["JULIA_SSL_CA_ROOTS_PATH"] = NetworkOptions.bundled_ca_roots()
27+
if CAN_SET_CA_ROOTS_PATH
28+
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
29+
# test that it still fails if called a second time
2730
@test_throws LibGit2.GitError LibGit2.ensure_initialized()
28-
delete!(ENV, "JULIA_SSL_CA_ROOTS_PATH")
31+
else
32+
@test LibGit2.ensure_initialized() === nothing
2933
@test LibGit2.ensure_initialized() === nothing
3034
end
3135
end

0 commit comments

Comments
 (0)