Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ extension ClientConnection.Builder.Secure {
self.tls.trustRoots = trustRoots
return self
}

/// Whether to verify remote certificates. Defaults to `.fullVerification` if not otherwise
/// configured.
@discardableResult
public func withTLS(certificateVerification: CertificateVerification) -> Self {
self.tls.certificateVerification = certificateVerification
return self
}
}

extension ClientConnection.Builder {
Expand Down
25 changes: 25 additions & 0 deletions Tests/GRPCTests/ClientTLSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,29 @@ class ClientTLSHostnameOverrideTests: GRPCTestCase {

try self.doTestUnary()
}

func testTLSWithNoCertificateVerification() throws {
self.server = try Server.secure(
group: self.eventLoopGroup,
certificateChain: [SampleCertificate.server.certificate],
privateKey: SamplePrivateKey.server
)
.withServiceProviders([EchoProvider()])
.withLogger(self.serverLogger)
.bind(host: "localhost", port: 0)
.wait()

guard let port = self.server.channel.localAddress?.port else {
XCTFail("could not get server port")
return
}

self.connection = ClientConnection.secure(group: self.eventLoopGroup)
.withTLS(trustRoots: .certificates([]))
.withTLS(certificateVerification: .none)
.withBackgroundActivityLogger(self.clientLogger)
.connect(host: "localhost", port: port)

try self.doTestUnary()
}
}
1 change: 1 addition & 0 deletions Tests/GRPCTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extension ClientTLSHostnameOverrideTests {
// to regenerate.
static let __allTests__ClientTLSHostnameOverrideTests = [
("testTLSWithHostnameOverride", testTLSWithHostnameOverride),
("testTLSWithNoCertificateVerification", testTLSWithNoCertificateVerification),
("testTLSWithoutHostnameOverride", testTLSWithoutHostnameOverride),
]
}
Expand Down