Following a hint in the WWDC 2019 Advances in Networking presentation (part 2) I am trying to write a framing protocol that can enable security on a plaintext NNTP connection by issuing a STARTTLS command before marking the connection as ready. My protocol has received the "let's do the handshake" response and inserted a default TLS handler into the stack but it immediately fails as shown here:
STARTTLS
handleInput
382 Begin TLS negotiation now
2020-03-04 14:30:45.628484+0000 connect[81978:3048637] [BoringSSL] boringssl_context_handle_fatal_alert(1872) [C[C1.1:1]:1][0x1007cbbd0] write alert, level: fatal, description: protocol version
2020-03-04 14:30:45.628634+0000 connect[81978:3048637] [BoringSSL] boringssl_context_error_print(1862) boringssl ctx 0x1007cd040: 4303163432:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242:
2020-03-04 14:30:45.632526+0000 connect[81978:3048637] [BoringSSL] boringssl_session_handshake_error_print(111) [C[C1.1:1]:1][0x1007cbbd0] 4303163432:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242:
2020-03-04 14:30:45.632580+0000 connect[81978:3048637] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726) [C[C1.1:1]:1][0x1007cbbd0] handshake failed at state 12288Wireshark tracing shows no attempt to perform a TLS negotiation.
Here is the part of my protocol that processes the STARTTLS response:
fileprivate func getStartTlsResponse(framer: NWProtocolFramer.Instance) {
if let startResponse = String(data: receivedLine, encoding: .utf8) {
print(startResponse)
if startResponse.starts(with: "382 ") {
// add TLS to protocol stack and mark protocol ready
do {
let tlsOpts = NWProtocolTLS.Options()
try framer.prependApplicationProtocol(options: tlsOpts)
} catch {
print("AutoTlsProtocol: error prepending TLS to protocol stack: \(error)")
framer.markFailed(error: nil)
return
}
}
}
framer.markReady()
}I have confirmed that the default TLS (NWParameters.tls) works OK on the same host's SSL port. Wireshark showed that TLSv1.2 is used.
All help gratefully received! I'm not very knowledable about TLS or Network.framework so please be gentle.
--
Colin