Skip to content

Commit

Permalink
Merge pull request #113 from billy34/billy34/feat-hostname-for-sni
Browse files Browse the repository at this point in the history
feat: set hostname for SNI
  • Loading branch information
jkaye2012 authored Sep 4, 2024
2 parents 4fa531d + dda35f6 commit 0347f25
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 0347f25

Please sign in to comment.