Skip to content

Commit 0347f25

Browse files
authored
Merge pull request #113 from billy34/billy34/feat-hostname-for-sni
feat: set hostname for SNI
2 parents 4fa531d + dda35f6 commit 0347f25

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)