NWConnection(tls和tls最低版本为1.2)发布为版本1

时间:2020-02-24 12:49:14

标签: swift macos ssl networking tls1.2

尝试使用tls 1.2使用以下代码将在macOS上运行的swift程序连接到mysql服务器:

    let options = NWProtocolTLS.Options()
    sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, .TLSv12)
    sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, .TLSv12)
    let params = NWParameters(tls: options)
    self.connection =  NWConnection(host: self.host, port: self.port, using: params)
    self.connection.stateUpdateHandler = self.didChange(state:)
    self.startReceive()
    self.connection.start(queue: .main)

导致此错误:

2020-02-23 20:52:33.697486-0500 MacNetworkSQL [80612:4731202] [BoringSSL] boringssl_context_handle_fatal_alert(1872)[C1:1] [0x101e003a0]写入警报,级别:致命,描述:协议版本 2020-02-23 20:52:33.697578-0500 MacNetworkSQL [80612:4731202] [BoringSSL] boringssl_context_error_print(1862)boringssl ctx 0x600000024000:4391437704:错误:100000f7:SSL例程:OPENSSL_internal:WRONG_VERSION_NUMBER:/ BuildRoot / combrary .apple.xbs / Sources / boringssl / boringssl-283.60.3 / ssl / tls_record.cc:242: 2020-02-23 20:52:33.700128-0500 MacNetworkSQL [80612:4731202] [BoringSSL] boringssl_session_handshake_error_print(111)[C1:1] [0x101e003a0] 4391437704:错误:100000f7:SSL例程:OPENSSL_internal:WRONG_VERSION_NUMBER:/ BuildRoot / Li /Caches/com.apple.xbs/Sources/boringssl/boringssl-283.60.3/ssl/tls_record.cc:242: 2020-02-23 20:52:33.700179-0500 MacNetworkSQL [80612:4731202] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726)[C1:1] [0x101e003a0]握手在状态12288下失败 2020-02-23 20:52:33.701183-0500 MacNetworkSQL [80612:4730608]正在等待:-9858:可选(握手失败)

看着客户问候语的wireshk抓取,我看到了:

enter image description here

我查看了成功连接到mysql的Wireshark结果,发现两个地方的版本均为1.2。所以我一定做错了什么,但是呢?

编辑:看来set_min和set_max根本没有做任何事情。我可以将它们都设置为1.3或将其完全删除,但在数据包捕获中仍然得到1.0和1.2。

0 个答案:

没有答案