Post

Replies

Boosts

Views

Activity

Reply to NWConnection never send failed status
I am also trying out the Tic Tac Toe app and I want to know how to check for invalid passcode. I am able to get everything working with the correct code, but when I enter an invalid code, I want to close out the connection, but I am unable to act on the TLS PSK authentication. Does anyone know how to handle events on an invalid TLS handshake? I am using this code in a convenience init for NWParameters. var authenticationCode = HMAC<SHA256>.authenticationCode(for: "mysharedsecret".data(using: .utf8)!, using: authenticationKey) let authenticationDispatchData = withUnsafeBytes(of: &authenticationCode) { (ptr: UnsafeRawBufferPointer) in DispatchData(bytes: ptr) } sec_protocol_options_add_pre_shared_key(tlsOptions.securityProtocolOptions, authenticationDispatchData as __DispatchData, stringToDispatchData("mysharedsecret")! as __DispatchData) sec_protocol_options_append_tls_ciphersuite(tlsOptions.securityProtocolOptions, tls_ciphersuite_t(rawValue: TLS_PSK_WITH_AES_128_GCM_SHA256)!) I assumed that the Connection Failed state would execute, but it does not. Here is what I received when I send an invalid code: 2023-04-25 15:03:22.703980-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.8.1:3] Socket SO_ERROR [54: Connection reset by peer] 2023-04-25 15:03:22.710169-0400 objcbonjour[26277:983754] [boringssl] boringssl_context_handle_fatal_alert(1991) [C1.1.10.1:2][0x7fe32e1337a0] read alert, level: fatal, description: bad record mac 2023-04-25 15:03:22.710933-0400 objcbonjour[26277:983754] [boringssl] boringssl_session_handshake_incomplete(88) [C1.1.10.1:2][0x7fe32e1337a0] SSL library error 2023-04-25 15:03:22.711191-0400 objcbonjour[26277:983754] [boringssl] boringssl_session_handshake_error_print(43) [C1.1.10.1:2][0x7fe32e1337a0] Error: 140613710266504:error:100003fc:SSL routines:OPENSSL_internal:SSLV3_ALERT_BAD_RECORD_MAC:/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/ssl/tls_record.cc:594:SSL alert number 20 2023-04-25 15:03:22.711388-0400 objcbonjour[26277:983754] [boringssl] nw_protocol_boringssl_handshake_negotiate_proceed(771) [C1.1.10.1:2][0x7fe32e1337a0] handshake failed at state 12288: not completed 2023-04-25 15:03:22.712345-0400 objcbonjour[26277:983754] [] nw_protocol_default_input_finished called with null protocol->default_input_handler 2023-04-25 15:03:22.712959-0400 objcbonjour[26277:983754] [] nw_protocol_default_input_finished called with null protocol->default_input_handler, dumping backtrace: [x86_64] libnetcore-3100.102.1 0 Network 0x00007ff8058fe557 __nw_create_backtrace_string + 135 1 Network 0x00007ff805628528 _ZL34nw_protocol_default_input_finishedP11nw_protocolS0_ + 376 2 libboringssl.dylib 0x00007ff804fbfc7c nw_protocol_boringssl_input_finished + 301 3 Network 0x00007ff805ab2045 _ZL29nw_socket_handle_socket_eventP9nw_socket + 1445 4 libdispatch.dylib 0x000000010acec7ec _dispatch_client_callout + 8 5 libdispatch.dylib 0x000000010acefa44 _dispatch_continuation_pop + 836 6 libdispatch.dylib 0x000000010ad07851 _dispatch_source_invoke + 2226 7 libdispatch.dylib 0x000000010acf6c76 _dispatch_workloop_invoke + 2692 8 libdispatch.dylib 0x000000010ad03982 _dispatch_workloop_worker_thread + 962 9 libsystem_pthread.dylib 0x00007ff837749c55 _pthread_wqthread + 327 10 libsystem_pthread.dylib 0x00007ff837748bbf start_wqthread + 15 2023-04-25 15:03:27.691437-0400 objcbonjour[26277:983753] [connection] nw_socket_handle_socket_event [C1.1.7.1:3] Socket SO_ERROR [60: Operation timed out] 2023-04-25 15:03:29.707140-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.9.2:3] Socket SO_ERROR [60: Operation timed out] 2023-04-25 15:03:31.714222-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.9.3:3] Socket SO_ERROR [60: Operation timed out] 2023-04-25 15:03:33.723231-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.9.4:3] Socket SO_ERROR [60: Operation timed out] 2023-04-25 15:03:33.725218-0400 objcbonjour[26277:983754] [connection] nw_connection_add_timestamp_locked_on_nw_queue [C1] Hit maximum timestamp count, will start dropping events 2023-04-25 15:03:35.729161-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.9.5:3] Socket SO_ERROR [60: Operation timed out] 2023-04-25 15:03:37.734531-0400 objcbonjour[26277:983754] [connection] nw_socket_handle_socket_event [C1.1.9.6:3] Socket SO_ERROR [60: Operation timed out]
Apr ’23