Skip to content

Commit

Permalink
clear out cache variables before serializing
Browse files Browse the repository at this point in the history
This is required on 1.10 where Downloads and NetworkOptions are in the sysimage (see JuliaLang/julia#53339) but it seems like a good idea here anyway in case someone adds a precompile workload to this package
  • Loading branch information
KristofferC committed Feb 15, 2024
1 parent aab83e5 commit 2eb7348
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/NetworkOptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ include("ca_roots.jl")
include("ssh_options.jl")
include("verify_host.jl")

function __init__()
SYSTEM_CA_ROOTS[] = nothing
BUNDLED_KNOWN_HOSTS_FILE[] = nothing
empty!(ENV_HOST_PATTERN_CACHE)
end

end # module
45 changes: 25 additions & 20 deletions src/ca_roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const BSD_CA_ROOTS = [
]

const SYSTEM_CA_ROOTS_LOCK = ReentrantLock()
const SYSTEM_CA_ROOTS = Ref{String}()
const SYSTEM_CA_ROOTS = Ref{Union{String,Nothing}}(nothing)

const BEGIN_CERT_REGULAR = "-----BEGIN CERTIFICATE-----"
const BEGIN_CERT_OPENSSL = "-----BEGIN TRUSTED CERTIFICATE-----"
Expand All @@ -84,29 +84,34 @@ NetworkOptions could only find OpenSSL-specific TLS certificates which cannot be

function system_ca_roots()
lock(SYSTEM_CA_ROOTS_LOCK) do
isassigned(SYSTEM_CA_ROOTS) && 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
SYSTEM_CA_ROOTS[] = path
return # from lock()
elseif line == BEGIN_CERT_OPENSSL
openssl_only = true
roots = SYSTEM_CA_ROOTS[]
if roots === nothing
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
roots = path
openssl_only = false
break
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
if roots === nothing
roots = bundled_ca_roots()
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()
return SYSTEM_CA_ROOTS[] = roots::String
end
return SYSTEM_CA_ROOTS[]
end

const CA_ROOTS_VARS = [
Expand Down
7 changes: 0 additions & 7 deletions src/ssh_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ function bundled_known_hosts()
end
end

function __init__()
# Reset in case we serialized a value here.
lock(BUNDLED_KNOWN_HOSTS_LOCK) do
BUNDLED_KNOWN_HOSTS_FILE[] = nothing
end
end

const BUNDLED_KNOWN_HOSTS = """
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
Expand Down

0 comments on commit 2eb7348

Please sign in to comment.