mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
No fatal error on unexpected non-ciphertext data
This commit is contained in:
1 parent
25f4e2ceff
commit
2373863f54
5 files changed
+48
-2
No files matched your search
@@ -230,7 +230,7 @@ public class EmbeddedChannel : Channel {
|
||||
return !channelcore.outboundBuffer.isEmpty
|
||||
}
|
||||
|
||||
private func throwIfErrorCaught() throws {
|
||||
public func throwIfErrorCaught() throws {
|
||||
if let error = channelcore.error {
|
||||
channelcore.error = nil
|
||||
throw error
|
||||
|
||||
@@ -109,7 +109,8 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
case .closing:
|
||||
doShutdownStep(ctx: ctx)
|
||||
default:
|
||||
fatalError("Read during invalid TLS state")
|
||||
ctx.fireErrorCaught(error: NIOOpenSSLError.readInInvalidTLSState)
|
||||
channelClose(ctx: ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public enum NIOOpenSSLError: Error {
|
||||
case noCertificateToValidate
|
||||
case unableToValidateCertificate
|
||||
case cannotFindPeerIP
|
||||
case readInInvalidTLSState
|
||||
}
|
||||
|
||||
extension NIOOpenSSLError: Equatable {
|
||||
|
||||
@@ -39,6 +39,7 @@ extension OpenSSLIntegrationTest {
|
||||
("testDontLoseClosePromises", testDontLoseClosePromises),
|
||||
("testTrustStoreOnDisk", testTrustStoreOnDisk),
|
||||
("testChecksTrustStoreOnDisk", testChecksTrustStoreOnDisk),
|
||||
("testReadAfterCloseNotifyDoesntKillProcess", testReadAfterCloseNotifyDoesntKillProcess),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,4 +802,47 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
XCTAssertEqual(actualErrors.count, 1)
|
||||
try clientChannel.closeFuture.wait()
|
||||
}
|
||||
|
||||
func testReadAfterCloseNotifyDoesntKillProcess() throws {
|
||||
let serverChannel = EmbeddedChannel()
|
||||
let clientChannel = EmbeddedChannel()
|
||||
|
||||
let ctx = try configuredSSLContext()
|
||||
|
||||
try serverChannel.pipeline.add(handler: try OpenSSLServerHandler(context: ctx)).wait()
|
||||
try clientChannel.pipeline.add(handler: try OpenSSLClientHandler(context: ctx)).wait()
|
||||
|
||||
let addr: SocketAddress = try .unixDomainSocketAddress(path: "/tmp/whatever2")
|
||||
let connectFuture = clientChannel.connect(to: addr)
|
||||
serverChannel.pipeline.fireChannelActive()
|
||||
try interactInMemory(clientChannel: clientChannel, serverChannel: serverChannel)
|
||||
try connectFuture.wait()
|
||||
|
||||
// Ok, we're connected. Now we want to close the server, and have that trigger a client CLOSE_NOTIFY.
|
||||
// However, when we deliver that CLOSE_NOTIFY we're then going to immediately send another chunk of
|
||||
// data. We can get away with doing this because the Embedded channel fires any promise for close()
|
||||
// before it fires channelInactive, which will allow us to fire channelRead from within the callback.
|
||||
let closePromise = serverChannel.close()
|
||||
closePromise.whenComplete { _ in
|
||||
var buffer = serverChannel.allocator.buffer(capacity: 5)
|
||||
buffer.write(staticString: "hello")
|
||||
serverChannel.pipeline.fireChannelRead(data: NIOAny(buffer))
|
||||
serverChannel.pipeline.fireChannelReadComplete()
|
||||
}
|
||||
|
||||
do {
|
||||
try serverChannel.throwIfErrorCaught()
|
||||
} catch {
|
||||
XCTFail("Already has error: \(error)")
|
||||
}
|
||||
|
||||
do {
|
||||
try interactInMemory(clientChannel: clientChannel, serverChannel: serverChannel)
|
||||
XCTFail("Did not cause error")
|
||||
} catch NIOOpenSSLError.readInInvalidTLSState {
|
||||
// Nothing to do here.
|
||||
} catch {
|
||||
XCTFail("Encountered unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user