Skip to content

Commit dda35f6

Browse files
committed
feat: set hostname for SNI
Set the hostname so that the server can use it to select the correct certificate (SNI). 1. add host parameter to TLSTransport function and set hostname SSLContext parameter only if it was not provided as an IPV4 or IPV6 address 2. forward host from transport function call to TLSTransport.
1 parent 4fa531d commit dda35f6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/transport/tls.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ struct TLSTransport <: RedisTransport
44
sslconfig::MbedTLS.SSLConfig
55
buff::IOBuffer
66

7-
function TLSTransport(sock::TCPSocket, sslconfig::MbedTLS.SSLConfig)
7+
function TLSTransport(host::AbstractString, sock::TCPSocket, sslconfig::MbedTLS.SSLConfig)
88
ctx = MbedTLS.SSLContext()
99
MbedTLS.setup!(ctx, sslconfig)
1010
MbedTLS.associate!(ctx, sock)
11+
# set hostname only if it's not an IP adress
12+
try
13+
parse(IPAddr, host)
14+
catch x
15+
MbedTLS.hostname!(ctx, host)
16+
end
1117
MbedTLS.handshake(ctx)
1218

1319
return new(sock, ctx, sslconfig, PipeBuffer())

src/transport/transport.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ include("tcp.jl")
2626

2727
function transport(host::AbstractString, port::Integer, sslconfig::Union{MbedTLS.SSLConfig, Nothing}=nothing)
2828
socket = connect(host, port)
29-
return (sslconfig !== nothing) ? TLSTransport(socket, sslconfig) : TCPTransport(socket)
29+
return (sslconfig !== nothing) ? TLSTransport(host, socket, sslconfig) : TCPTransport(socket)
3030
end
3131

3232
end # module Transport

0 commit comments

Comments
 (0)