Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set hostname for SNI #113

Merged
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
8 changes: 7 additions & 1 deletion src/transport/tls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ struct TLSTransport <: RedisTransport
sslconfig::MbedTLS.SSLConfig
buff::IOBuffer

function TLSTransport(sock::TCPSocket, sslconfig::MbedTLS.SSLConfig)
function TLSTransport(host::AbstractString, sock::TCPSocket, sslconfig::MbedTLS.SSLConfig)
ctx = MbedTLS.SSLContext()
MbedTLS.setup!(ctx, sslconfig)
MbedTLS.associate!(ctx, sock)
# set hostname only if it's not an IP adress
try
parse(IPAddr, host)
catch x
MbedTLS.hostname!(ctx, host)
end
MbedTLS.handshake(ctx)

return new(sock, ctx, sslconfig, PipeBuffer())
Expand Down
2 changes: 1 addition & 1 deletion src/transport/transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include("tcp.jl")

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

end # module Transport
Loading