Implement SSL SNI hostname setting for asyncnet.

This commit is contained in:
Dominik Picheta
2017-02-08 00:04:40 +01:00
parent 4ef86042f2
commit 0535b6b6bf

View File

@@ -253,6 +253,11 @@ proc connect*(socket: AsyncSocket, address: string, port: Port) {.async.} =
await connect(socket.fd.AsyncFD, address, port, socket.domain)
if socket.isSsl:
when defineSsl:
if not isIpAddress(address):
# Set the SNI address for this connection. This call can fail if
# we're not using TLSv1+.
discard SSL_set_tlsext_host_name(socket.sslHandle, address)
let flags = {SocketFlag.SafeDisconn}
sslSetConnectState(socket.sslHandle)
sslLoop(socket, flags, sslDoHandshake(socket.sslHandle))