Skip to content

Commit

Permalink
feat: set hostname for SNI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Guillaume Cornu committed Aug 30, 2024
1 parent 4fa531d commit dda35f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit dda35f6

Please sign in to comment.