Skip to content

Enable OpenSSL certificates #36

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

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NetworkOptions"
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
authors = ["Stefan Karpinski <[email protected]> and contributors"]
version = "1.2.0"
version = "1.3.0"

[compat]
julia = "1"
Expand Down
12 changes: 1 addition & 11 deletions src/ca_roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,21 @@ const SYSTEM_CA_ROOTS = Ref{Union{Nothing, String}}(nothing)

const BEGIN_CERT_REGULAR = "-----BEGIN CERTIFICATE-----"
const BEGIN_CERT_OPENSSL = "-----BEGIN TRUSTED CERTIFICATE-----"
const OPENSSL_WARNING = """
NetworkOptions could only find OpenSSL-specific TLS certificates which cannot be used by MbedTLS. Please open an issue at https://github.com/JuliaLang/NetworkOptions.jl/issues with details about your system, especially where generic non-OpenSSL certificates can be found. See https://stackoverflow.com/questions/55447752/what-does-begin-trusted-certificate-in-a-certificate-mean for more details.
""" |> split |> text -> join(text, " ")

function system_ca_roots()
lock(SYSTEM_CA_ROOTS_LOCK) do
SYSTEM_CA_ROOTS[] !== nothing && return # from lock()
search_path = Sys.islinux() ? LINUX_CA_ROOTS :
Sys.isbsd() && !Sys.isapple() ? BSD_CA_ROOTS : String[]
openssl_only = false
for path in search_path
ispath(path) || continue
for line in eachline(path)
if line == BEGIN_CERT_REGULAR
if line in [BEGIN_CERT_REGULAR, BEGIN_CERT_OPENSSL]
SYSTEM_CA_ROOTS[] = path
return # from lock()
elseif line == BEGIN_CERT_OPENSSL
openssl_only = true
end
end
end
# warn if we:
# 1. did not find any regular certs
# 2. did find OpenSSL-only certs
openssl_only && @warn OPENSSL_WARNING
# TODO: extract system certs on Windows & macOS
SYSTEM_CA_ROOTS[] = bundled_ca_roots()
end
Expand Down
Loading