Skip to content

Commit

Permalink
TLSify: TLS validation settings (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi committed Jul 28, 2021
1 parent 5aea3d5 commit 61a502f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 2 additions & 3 deletions TLSify/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import PackageDescription
let package = Package(
name: "TLSify",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "TLSify", targets: ["TLSify"]),
.executable(name: "TLSify", targets: ["TLSify"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.17.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.5.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("0.0.6")),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
],
Expand Down
16 changes: 13 additions & 3 deletions TLSify/Sources/TLSify/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import TLSifyLib
var rootLogger = Logger(label: "TLSify")
rootLogger.logLevel = .debug

let sslContext = try NIOSSLContext(configuration: TLSConfiguration.forClient())

struct TLSifyCommand: ParsableCommand {
@Option(name: .shortAndLong, default: "localhost", help: "The host to listen to.")
var listenHost: String
Expand All @@ -37,7 +35,20 @@ struct TLSifyCommand: ParsableCommand {
@Argument(help: "The port to connect to.")
var connectPort: Int

@Option(name: .long, default: "full", help: "TLS certificate verfication: full (default)/no-hostname/none.")
var tlsCertificateValidation: String

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)
Expand All @@ -59,7 +70,6 @@ struct TLSifyCommand: ParsableCommand {
}
}
}

}
}
}
Expand Down

0 comments on commit 61a502f

Please sign in to comment.