Skip to content

Commit 7582295

Browse files
authored
Use CA configuration from NetworkOptions (#53)
* Use CA configuration from NetworkOptions This patch uses CA configuration from NetworkOptions instead of directly using the certificates from MozillaCACerts_jll. The benefits are: - On Linux machines this will use system configured certificates which are typically kept up to date using the package manager or similar. - The default can be overwridden using environment variables (see NetworkOptions README). Fixes #37, fixes JuliaWeb/HTTP.jl#1239. * Set version to 1.6.0.
1 parent 4a81f00 commit 7582295

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name = "OpenSSL"
22
uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
3-
version = "1.5.0"
3+
version = "1.6.0"
44
authors = ["Greg Lapinski <[email protected]>", "Jacob Quinn <[email protected]>"]
55

66
[deps]
77
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
88
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
MozillaCACerts_jll = "14a3606d-f60d-562e-9121-12d972cd8159"
10+
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
1011
OpenSSL_jll = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
1112
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
1213

src/OpenSSL.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Dates
55
using OpenSSL_jll
66
using Sockets
77
using MozillaCACerts_jll
8+
using NetworkOptions: NetworkOptions
89

910
"""
1011
[x] Encryption, decryption

src/ssl.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,21 @@ end
127127

128128
const SSL_MODE_AUTO_RETRY = 0x00000004
129129

130+
# Use NetworkOptions for default CA file so that it can be configured using the standard
131+
# environment variables (JULIA_SSL_CA_ROOTS_PATH, SSL_CERT_DIR, and SSL_CERT_FILE).
132+
# TODO: On Windows and macOS `ca_roots` return `nothing` to indicate that system configured
133+
# certificates should be preferred but for now we fall back to the certificate from
134+
# MozillaCACerts_jll.
135+
default_cacert() = something(NetworkOptions.ca_roots(), MozillaCACerts_jll.cacert)
136+
130137
"""
131138
This is the global context structure which is created by a server or client once per program life-time
132139
and which holds mainly default values for the SSL structures which are later created for the connections.
133140
"""
134141
mutable struct SSLContext
135142
ssl_ctx::Ptr{Cvoid}
136143

137-
function SSLContext(ssl_method::SSLMethod, verify_file::String=MozillaCACerts_jll.cacert)
144+
function SSLContext(ssl_method::SSLMethod, verify_file::String = default_cacert())
138145
ssl_ctx = ccall(
139146
(:SSL_CTX_new, libssl),
140147
Ptr{Cvoid},
@@ -154,13 +161,8 @@ mutable struct SSLContext
154161
(SSLContext, Cint, Clong, Ptr{Cvoid}),
155162
ssl_context, 33, SSL_MODE_AUTO_RETRY, C_NULL)
156163
if !isempty(verify_file)
157-
@assert ccall(
158-
(:SSL_CTX_load_verify_locations, libssl),
159-
Cint,
160-
(SSLContext, Ptr{Cchar}, Ptr{Cchar}),
161-
ssl_context,
162-
verify_file,
163-
C_NULL) == 1
164+
ret = ca_chain!(ssl_context, verify_file)
165+
@assert ret == 1
164166
end
165167

166168
return ssl_context

0 commit comments

Comments
 (0)