in TLSify/Sources/TLSify/main.swift [41:74]
func run() throws {
var tlsConfig = TLSConfiguration.makeClientConfiguration()
switch self.tlsCertificateValidation {
case "none":
tlsConfig.certificateVerification = .none
case "no-hostname":
tlsConfig.certificateVerification = .noHostnameVerification
default:
tlsConfig.certificateVerification = .fullVerification
}
let sslContext = try NIOSSLContext(configuration: tlsConfig)
MultiThreadedEventLoopGroup.withCurrentThreadAsEventLoop { el in
ServerBootstrap(group: el)
.serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.childChannelInitializer { channel in
channel.pipeline.addHandler(TLSProxy(host: self.connectHost,
port: self.connectPort,
sslContext: sslContext,
logger: rootLogger))
}
.bind(host: self.listenHost, port: self.listenPort)
.map { channel in
rootLogger.info("Listening on \(channel.localAddress!)")
}
.whenFailure { error in
rootLogger.error("Couldn't bind to \(self.listenHost):\(self.listenPort): \(error)")
el.shutdownGracefully { error in
if let error = error {
preconditionFailure("EL shutdown failed: \(error)")
}
}
}
}
}