Skip to content
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
Expand Up @@ -31,7 +31,7 @@ Parsers = "3"
PrecompileTools = "1"
Printf = "1"
Random = "1"
Reseau = "1.4.1"
Reseau = "1.7"
SHA = "0.7.0, 1"
Tables = "1"
Test = "1"
Expand Down
3 changes: 2 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ raise `ArgumentError` unless their value is `nothing` or `false`.
| keyword | default | meaning |
|---|---|---|
| `ssl_mode` | `:preferred` | `:disabled`, `:preferred` (TLS when offered, no fallback after a failed handshake), `:required`, `:verify_ca`, `:verify_identity`; only the last two authenticate the server |
| `ssl_ca` / `ssl_capath` | `nothing` | CA bundle file / hashed CA directory (one of them); supplying one raises the default mode to `:verify_ca` |
| `ssl_ca` / `ssl_capath` | `nothing` | CA bundle file / CA directory; with both, both are trusted; supplying either raises the default mode to `:verify_ca` |
| `ssl_cert`, `ssl_key` | `nothing` | client certificate and key (mutual TLS) |
| `passphrase` | `nothing` | passphrase for an encrypted `ssl_key`; it is never printed |
| `ssl_server_name` | host | the name used for SNI and certificate verification |
| `tls_version` | TLS 1.2 and 1.3 | e.g. `"TLSv1.3"` |
| `ssl_enforce`, `ssl_verify_server_cert` | `nothing` | `true` requires TLS / identity verification; `false` does not lower the mode; contradictions with an explicit keyword `ssl_mode` are errors |
Expand Down
4 changes: 2 additions & 2 deletions docs/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Deliberate, documented changes relative to Connector/C 1.6.0:
| `local_files=true` | accepted without a handler | requires `local_infile_handler`, otherwise `ArgumentError` at connect; a server upload request without a configured handler is a `ProtocolError` |
| Unknown keywords | silently swallowed | `ArgumentError` |
| `ssl_mode` | #240: enum collision, `SSL_MODE_DISABLED` unimplementable | five real modes; default `:preferred`; explicit `ssl_mode` wins over `ssl_enforce`/`ssl_verify_server_cert`/CA-material escalation; contradictions are `ArgumentError`s; **no plaintext fallback after a failed TLS handshake** |
| `ssl_ca` + `ssl_capath` together | both applied | `ArgumentError` (Reseau has a single trust-root source); each alone works |
| `ssl_ca` + `ssl_capath` together | both applied | both applied |
| `connect_timeout` | C socket timeout with platform-dependent meaning | one monotonic establishment deadline spanning dial, greeting, TLS, the whole auth exchange, and the charset bootstrap |
| `read_timeout` / `write_timeout` | `MYSQL_OPT_READ_TIMEOUT`/`MYSQL_OPT_WRITE_TIMEOUT`: per socket operation | same meaning: re-armed before every transport read/write, so a slowly-consumed streaming result never expires while the server keeps answering; expiry closes the connection |
| `reconnect` | C auto-reconnect | the same contract, made explicit: the command that hits a dead connection reports it (`MySQL.Error` 2006/2013), and the *next* command reconnects — only before a send, never mid-command, never inside a transaction; a reconnect that itself fails leaves the connection retryable, not closed |
Expand Down Expand Up @@ -155,7 +155,7 @@ Deliberate, documented changes relative to Connector/C 1.6.0:

## Temporarily unavailable (compatibility names are reserved)

- `ssl_cipher`, `ssl_crl`, `ssl_crlpath`, and `passphrase` need matching transport support
- `ssl_cipher`, `ssl_crl`, and `ssl_crlpath` need matching transport support
in Reseau. MySQL.jl keeps these option names reserved and reports that they are not
available in 2.0; it does not silently ignore recognized option-file forms, and the
options are not declared permanently removed.
Expand Down
55 changes: 37 additions & 18 deletions src/Protocol/tls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,38 @@ ssl_mode_string(str::String)::SSLMode = return ssl_mode_named(Symbol(replace(low
end

"""
TLSOptions(; mode=SSL_PREFERRED, ca_file=nothing, cert_file=nothing, key_file=nothing,
server_name=nothing, min_version=nothing, max_version=nothing)
TLSOptions(; mode=SSL_PREFERRED, ca_file=nothing, ca_dir=nothing, cert_file=nothing, key_file=nothing,
key_passphrase=nothing, server_name=nothing, min_version=nothing, max_version=nothing)

`ca_file` may be a bundle or a hashed CA directory (Reseau accepts both); `cert_file`/`key_file`
enable mutual TLS; `server_name` overrides the SNI/verification name derived from the host.
`ca_file` may be a bundle or a CA directory (Reseau accepts both); `ca_dir` is a CA directory
trusted together with `ca_file`. `cert_file`/`key_file` enable mutual TLS, and `key_passphrase`
unlocks an encrypted `key_file`. `server_name` overrides the SNI/verification name derived
from the host. `show` never prints the passphrase.
"""
struct TLSOptions
mode::SSLMode
ca_file::Union{Nothing, String}
ca_dir::Union{Nothing, String}
cert_file::Union{Nothing, String}
key_file::Union{Nothing, String}
key_passphrase::Union{Nothing, String}
server_name::Union{Nothing, String}
min_version::Union{Nothing, UInt16}
max_version::Union{Nothing, UInt16}
end

function TLSOptions(; mode=SSL_PREFERRED, ca_file=nothing, cert_file=nothing, key_file=nothing, server_name=nothing, min_version=nothing, max_version=nothing)
function TLSOptions(; mode=SSL_PREFERRED, ca_file=nothing, ca_dir=nothing, cert_file=nothing, key_file=nothing, key_passphrase=nothing, server_name=nothing, min_version=nothing, max_version=nothing)
xor(cert_file === nothing, key_file === nothing) && throw(ArgumentError("ssl_cert and ssl_key must be provided together"))
m = ssl_mode(mode)
return TLSOptions(m, ca_file === nothing ? nothing : String(ca_file), cert_file === nothing ? nothing : String(cert_file), key_file === nothing ? nothing : String(key_file), server_name === nothing ? nothing : String(server_name), min_version, max_version)
str(x) = x === nothing ? nothing : String(x)
return TLSOptions(m, str(ca_file), str(ca_dir), str(cert_file), str(key_file), str(key_passphrase), str(server_name), min_version, max_version)
end

function Base.show(io::IO, o::TLSOptions)
print(io, "TLSOptions(mode=", o.mode, ", ca_file=", repr(o.ca_file), ", ca_dir=", repr(o.ca_dir),
", cert_file=", repr(o.cert_file), ", key_file=", repr(o.key_file),
", key_passphrase=", o.key_passphrase === nothing ? "nothing" : "\"…\"", ", server_name=", repr(o.server_name), ")")
return nothing
end

is_ip_literal(host::AbstractString) = return occursin(r"^\d{1,3}(\.\d{1,3}){3}$", host) || occursin(':', host)
Expand All @@ -70,20 +82,27 @@ end

# Reseau's `Config` constructors take `Union{Nothing, ...}` arguments, and a call whose
# arguments are still unions is not statically resolvable under `--trim=safe`. The nested
# `=== nothing` branches below narrow each optional (SNI name, the client cert/key pair,
# the CA file) to a concrete type before the one positional `Config` call in each leaf.
@inline function tls_config_leaf(sn::Union{Nothing, String}, vp::Bool, vh::Bool, cf::Union{Nothing, String}, kf::Union{Nothing, String}, caf::Union{Nothing, String}, hs::Int64, minv::UInt16, maxv::UInt16)
return Reseau.TLS.Config(sn, vp, vh, Reseau.TLS.ClientAuthMode.NoClientCert, cf, kf, caf, nothing, String[], UInt16[], hs, minv, maxv, false)
# `=== nothing` branches below narrow each optional (SNI name, the client cert/key pair and
# its passphrase, the CA file and directory) to a concrete type before the one positional
# `Config` call in each leaf.
@inline function tls_config_leaf(sn::Union{Nothing, String}, vp::Bool, vh::Bool, cf::Union{Nothing, String}, kf::Union{Nothing, String}, kp::Union{Nothing, String}, caf::Union{Nothing, String}, cad::Union{Nothing, String}, hs::Int64, minv::UInt16, maxv::UInt16)
return Reseau.TLS.Config(sn, vp, vh, Reseau.TLS.ClientAuthMode.NoClientCert, cf, kf, caf, nothing, String[], UInt16[], hs, minv, maxv, false, 64, nothing, cad, nothing, kp)
end

@inline function tls_config_cadir(sn, vp::Bool, vh::Bool, cf, kf, kp, caf, cad::Union{Nothing, String}, hs::Int64, minv::UInt16, maxv::UInt16)
cad === nothing && return tls_config_leaf(sn, vp, vh, cf, kf, kp, caf, nothing, hs, minv, maxv)
return tls_config_leaf(sn, vp, vh, cf, kf, kp, caf, cad, hs, minv, maxv)
end

@inline function tls_config_ca(sn, vp::Bool, vh::Bool, cf, kf, caf::Union{Nothing, String}, hs::Int64, minv::UInt16, maxv::UInt16)
caf === nothing && return tls_config_leaf(sn, vp, vh, cf, kf, nothing, hs, minv, maxv)
return tls_config_leaf(sn, vp, vh, cf, kf, caf, hs, minv, maxv)
@inline function tls_config_ca(sn, vp::Bool, vh::Bool, cf, kf, kp, caf::Union{Nothing, String}, cad, hs::Int64, minv::UInt16, maxv::UInt16)
caf === nothing && return tls_config_cadir(sn, vp, vh, cf, kf, kp, nothing, cad, hs, minv, maxv)
return tls_config_cadir(sn, vp, vh, cf, kf, kp, caf, cad, hs, minv, maxv)
end

@inline function tls_config_cert(sn, vp::Bool, vh::Bool, cf::Union{Nothing, String}, kf::Union{Nothing, String}, caf, hs::Int64, minv::UInt16, maxv::UInt16)
(cf === nothing || kf === nothing) && return tls_config_ca(sn, vp, vh, nothing, nothing, caf, hs, minv, maxv)
return tls_config_ca(sn, vp, vh, cf, kf, caf, hs, minv, maxv)
@inline function tls_config_cert(sn, vp::Bool, vh::Bool, cf::Union{Nothing, String}, kf::Union{Nothing, String}, kp::Union{Nothing, String}, caf, cad, hs::Int64, minv::UInt16, maxv::UInt16)
(cf === nothing || kf === nothing) && return tls_config_ca(sn, vp, vh, nothing, nothing, nothing, caf, cad, hs, minv, maxv)
kp === nothing && return tls_config_ca(sn, vp, vh, cf, kf, nothing, caf, cad, hs, minv, maxv)
return tls_config_ca(sn, vp, vh, cf, kf, kp, caf, cad, hs, minv, maxv)
end

function tls_config(opts::TLSOptions, host::AbstractString, handshake_timeout_ns::Integer)
Expand All @@ -93,8 +112,8 @@ function tls_config(opts::TLSOptions, host::AbstractString, handshake_timeout_ns
hs = max(Int64(0), Int64(handshake_timeout_ns))
minv = opts.min_version === nothing ? Reseau.TLS.TLS1_2_VERSION : opts.min_version
maxv = opts.max_version === nothing ? Reseau.TLS.TLS1_3_VERSION : opts.max_version
sn === nothing && return tls_config_cert(nothing, verify_peer, verify_hostname, opts.cert_file, opts.key_file, opts.ca_file, hs, minv, maxv)
return tls_config_cert(sn, verify_peer, verify_hostname, opts.cert_file, opts.key_file, opts.ca_file, hs, minv, maxv)
sn === nothing && return tls_config_cert(nothing, verify_peer, verify_hostname, opts.cert_file, opts.key_file, opts.key_passphrase, opts.ca_file, opts.ca_dir, hs, minv, maxv)
return tls_config_cert(sn, verify_peer, verify_hostname, opts.cert_file, opts.key_file, opts.key_passphrase, opts.ca_file, opts.ca_dir, hs, minv, maxv)
end

raw_tcp(t::Reseau.TCP.Conn) = return t
Expand Down
8 changes: 4 additions & 4 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const UNAVAILABLE_KEYWORDS = Dict{Symbol, String}(
:ssl_cipher => "cipher selection requires transport support that Reseau does not expose yet",
:ssl_crl => "certificate-revocation lists require transport support that Reseau does not expose yet",
:ssl_crlpath => "certificate-revocation lists require transport support that Reseau does not expose yet",
:passphrase => "encrypted private-key passphrases require transport support that Reseau does not expose yet",
:compress => "the compressed-packet protocol layer is planned for a later 2.x release",
)

Expand Down Expand Up @@ -509,8 +508,8 @@ function ConnectOptions(host::AbstractString, user::AbstractString, password::Un
lowercase(charset) == UTF8MB4 || throw(ArgumentError("only charset_name=\"utf8mb4\" is supported by the native backend"))
ssl_ca = option_string_or_nothing(pick(:ssl_ca), "ssl_ca")
ssl_capath = option_string_or_nothing(pick(:ssl_capath), "ssl_capath")
(ssl_ca !== nothing && ssl_capath !== nothing) && throw(ArgumentError("ssl_ca and ssl_capath cannot be combined yet (Reseau takes a single trust root); pass one of them"))
ca_file = ssl_ca !== nothing ? ssl_ca : ssl_capath
# With both, the bundle and the directory are trusted together.
ca_file, ca_dir = ssl_ca === nothing ? (ssl_capath, nothing) : (ssl_ca, ssl_capath)
ssl_mode_kw = get(kwd, :ssl_mode, nothing)
enforce_raw = option_bool_or_nothing(get(kwd, :ssl_enforce, nothing), "ssl_enforce")
verify_raw = option_bool_or_nothing(get(kwd, :ssl_verify_server_cert, nothing), "ssl_verify_server_cert")
Expand All @@ -520,9 +519,10 @@ function ConnectOptions(host::AbstractString, user::AbstractString, password::Un
verify_raw !== nothing, verify_raw === nothing ? false : verify_raw,
ca_file !== nothing)
min_version, max_version = parse_tls_version(option_string_or_nothing(pick(:tls_version), "tls_version"))
tls = P.TLSOptions(; mode=mode, ca_file=ca_file,
tls = P.TLSOptions(; mode=mode, ca_file=ca_file, ca_dir=ca_dir,
cert_file=option_string_or_nothing(pick(:ssl_cert), "ssl_cert"),
key_file=option_string_or_nothing(pick(:ssl_key), "ssl_key"),
key_passphrase=option_string_or_nothing(get(kwd, :passphrase, nothing), "passphrase"),
server_name=option_string_or_nothing(get(kwd, :ssl_server_name, nothing), "ssl_server_name"),
min_version=min_version, max_version=max_version)
default_auth = option_string_or_nothing(get(kwd, :default_auth, nothing), "default_auth")
Expand Down
4 changes: 2 additions & 2 deletions test/behavior_manifest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ const SURFACE_ROWS = SurfaceRow[
(make, _, _) -> (connection_outcome(make; protocol=:tcp), connection_outcome(make; protocol=:memory)), (:ok, :ArgumentError)),
SurfaceRow(179, "client certificate keyword surface",
(make, _, _) -> connection_outcome(make; ssl_key=nothing, ssl_cert=nothing), :ok),
SurfaceRow(180, "combined CA file and directory conflict",
(make, _, _) -> connection_outcome(make; ssl_ca="unused", ssl_capath="unused"), :ArgumentError),
SurfaceRow(180, "combined CA file and directory are both used, so missing paths fail the handshake",
(make, _, _) -> connection_outcome(make; ssl_ca="unused", ssl_capath="unused"), :TLSNegotiationError),
SurfaceRow(181, "removed TLS options",
(make, _, _) -> connection_outcome(make; ssl_cipher="DEFAULT"), :ArgumentError),
SurfaceRow(182, "SSL mode and contradiction table",
Expand Down
30 changes: 30 additions & 0 deletions test/protocol/certs/client-encrypted.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFNTBfBgkqhkiG9w0BBQ0wUjAxBgkqhkiG9w0BBQwwJAQQnfXc3NXHpqPFUMTe
IeG4kQICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEOayD2N9JsZlXQjU
Ia4CvdsEggTQDD5NUFstngsgAnR36yBxIWn/ynIPtq2z/C7gUKh+Wq+mkQw+qrVL
Co4Q2V2r/8xeM3k0yR8svVB9OlqZejd5QfbP5eYT/99aSED+5C1g7jjYTtrzWIHI
isuQ0bDzmxS+9tUDX+TIlGnRA3ZHR9NxJ20AfTalO/JHS5V8LT7juE8i1XXJi5ha
JbH9dVRTxQ2b7/ezmp1NuZ3eqyg2K5Zy7LUqo6cAswphj3d2UA4znrl8IOacrOqj
v95HJCYvumR91PENni/q6RNMuPQ1KjaD4qqfRsw+oH8RjemEbcg9jD9NgcaD70/9
khtmYJ6r3BD/pnY4FIarNupN0D7z58SyjsRqIZtgkuenTNEOvp2vfPFdHSneJKe4
YTt/g2n2WU0bYiHl6t/PfL6xZngUoBOKDLhDMnXYZKWGGiGk3qJsiTb9KpnNGaT0
oomypUoHTdjPVGSOrCg60/Xe2MH6p9FJda9daXOiKn5xHANjwU2h5nAUsBZghK+W
7jnYNuzsO3gT+ipx3LuNPbnrl/yQR4QXKKQUIQ4QwxBXcrwVtXoAnUGfhNmjvMOR
T7O6cl1KUjsBri5J5YlCcKYrn1+BUb9FwTxGxeztUQEhdjsdT71emVHLNsdc6vY8
+hU1EG0q8FCslPH8woi/tgISYEDkWNgi3rUI78/rH4KHunJjcd+7wOF5SgiRcC72
ae13pT8sA9cMClaHGDrBWgJR6TaSko7kfD5a/UQ5rjFgJLt3vieSbun6HTZETCUw
hxdm5fQzTt+kixgEQ7m2CGoU3t+0URr6oJ4yAJJJ8Li4WNIYGXk4rqiT7+hmgOdL
uris3TadaQ3m8tJ64nEY6CZ8Mi5TN1BB+VVluYa8lQpuMiJYlAM+X4SV/CKUW8cE
h2AYcFy5F6PkK9clJ1Seasoum0zHw87BoQfqBst3w01H8lCxn3WdWA73EY9Oz1H0
xCtVIr1h3YAe/Jp4UT+wYCVXWwhR2ct1hTEoK3cLHyPtdGkMnB3a1qH7ktOA6eaF
SFO+mXjtf3X+bvOKQgf/v0ZaWU9s+nBb68s4TxKRBhcN9g8EgWynF/1AXWDXiXjd
7vGLO29tAZNvIgDf9l/zps2byVCw4hFrEi4xyXqbrjqpm3pq6k/wL9kF77zz5hSG
WkFYql/TxbiWNHH9rgO+xiCJcNIOla/GIQw8gtItDd9GyctAA1Y61wxN+ihJLW1y
4zH8f8LM1rIIR7o3nziQVuThcvON+LebeDnMAk13adyW/f4Un825b6F0rSycrwYl
TKA+VL3thIvLviQnv1z3u6fJ8aTXu/fEbPBu8xV2oX3uj4udy0QUMAEwSrtyNs56
s2A+moI5N1sX5ql53qQZfE14s+No7PyJJlTm9ItHhKDLSMIvFZASTkaYLs/ZaDa5
KvC7CwVDNTvGE7BtjT9czt4mYqgcTqQMsHh8EXrWLNoHi52Z3APOvpWbCABWJ0oy
g20eOuOZLBYfx8DGQZPGvx1+qWEhHMjNm3rsh9Wd50v4UCJzwrjUeD1NdN34Yku+
e+WsoGp9CIjXSZDuWwNLM1bAWCvpjxRRjw7F+jfdkzvUdaRpYL3rBFq8KQkuXu+t
3vm0my4cdCTIG7CH9CK1Rf7NDasKO3YJbU07TSRi/g35A9tE0sjy0fA=
-----END ENCRYPTED PRIVATE KEY-----
1 change: 1 addition & 0 deletions test/protocol/certs/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gen_leaf() { # name subject san extendedKeyUsage
gen_leaf server "/CN=localhost" "DNS:localhost,IP:127.0.0.1" serverAuth
gen_leaf server-dnsonly "/CN=localhost" "DNS:localhost" serverAuth
gen_leaf client "/CN=mysql-jl-client" "DNS:client.invalid" clientAuth
openssl pkcs8 -topk8 -v2 aes-256-cbc -in client.key -out client-encrypted.key -passout pass:mysql-jl-test
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 3650 -keyout selfsigned.key -out selfsigned.crt \
-subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" 2>/dev/null
for bits in 2048 3072 4096; do
Expand Down
8 changes: 6 additions & 2 deletions test/protocol/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
@testset "Native options truth table" begin
@test_throws ArgumentError N.ConnectOptions("h", "u"; bogus=1)
for (name, value) in ((:ssl_cipher, "AES"), (:ssl_crl, "/x"),
(:ssl_crlpath, "/x"), (:passphrase, "secret"), (:compress, true))
(:ssl_crlpath, "/x"), (:compress, true))
err = try; N.ConnectOptions("h", "u"; name => value); nothing; catch e; e; end
@test err isa ArgumentError && occursin("not available in MySQL.jl 2.0", err.msg)
end
Expand All @@ -38,7 +38,11 @@ end
@test_throws ArgumentError N.ConnectOptions("h", "u"; protocol="socket")
@test_throws ArgumentError N.ConnectOptions("h", "u"; charset_name="latin1")
@test N.ConnectOptions("h", "u"; charset_name="UTF8MB4").port == 3306
@test_throws ArgumentError N.ConnectOptions("h", "u"; ssl_ca="a", ssl_capath="b")
both = N.ConnectOptions("h", "u"; ssl_ca="a", ssl_capath="b").tls
@test both.ca_file == "a" && both.ca_dir == "b"
secret = N.ConnectOptions("h", "u"; ssl_cert="c", ssl_key="k", passphrase="hunter2")
@test secret.tls.key_passphrase == "hunter2"
@test !occursin("hunter2", sprint(show, secret.tls)) && !occursin("hunter2", sprint(show, secret))
@test N.ConnectOptions("h", "u"; ssl_capath="/etc/ssl/certs").tls.ca_file == "/etc/ssl/certs"
@test_throws ArgumentError N.ConnectOptions("h", "u"; local_files=true)
@test N.ConnectOptions("h", "u"; local_files=true, local_infile_handler=identity).client_flags & P.CLIENT_LOCAL_FILES != 0
Expand Down
31 changes: 31 additions & 0 deletions test/protocol/tls_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,37 @@ end
@test_throws ArgumentError N.ConnectOptions("h", "u"; ssl_cert=certfile("client.crt"))
end

@testset "passphrase unlocks an encrypted client key" begin
cfg = server_config(; client_auth=TLS.ClientAuthMode.RequireAndVerifyClientCert, client_ca_file=certfile("ca.crt"))
mtls = (; ssl_mode=:verify_ca, ssl_ca=certfile("ca.crt"), ssl_cert=certfile("client.crt"), ssl_key=certfile("client-encrypted.key"))
with_server(conn -> (try; tls_peer_connect!(conn; cfg=cfg); catch; end)) do port
h = native_connect(port; mtls..., passphrase="mysql-jl-test")
@test P.is_secure_transport(h.session)
N.close!(h)
end
for passphrase in ("wrong", nothing)
with_server(conn -> (try; tls_peer_connect!(conn; cfg=cfg); catch; end)) do port
err = try; native_connect(port; mtls..., passphrase); nothing; catch e; e; end
@test err isa P.TLSNegotiationError
end
end
end

@testset "ssl_ca and ssl_capath are trusted together" begin
# The bundle holds an unrelated root; only the directory holds the server's CA.
capath = mktempdir()
cp(certfile("ca.crt"), joinpath(capath, "ca.crt"))
with_server(conn -> (try; tls_peer_connect!(conn); catch; end)) do port
h = native_connect(port; ssl_mode=:verify_ca, ssl_ca=certfile("selfsigned.crt"), ssl_capath=capath)
@test P.is_secure_transport(h.session)
N.close!(h)
end
with_server(conn -> (try; tls_peer_connect!(conn); catch; end)) do port
err = try; native_connect(port; ssl_mode=:verify_ca, ssl_ca=certfile("selfsigned.crt")); nothing; catch e; e; end
@test err isa P.TLSNegotiationError
end
end

@testset "an abandoned TLS handle is reclaimed by the reaper" begin
with_server(conn -> tls_peer_connect!(conn; after=stall_until_eof)) do port
handle_ref, transport_ref, entry = abandon_tls_handle(port)
Expand Down
Loading