1

我能够像这样使用 tls 连接到公共 wss:

let port = 443
let url = URL(string: "wss://echo.websocket.org")!
connection = NWConnection(host: NWEndpoint.Host.name(url.host!, nil), port: NWEndpoint.Port(rawValue: UInt16(port))!, using: .tls)

现在我正在尝试连接到专用网络中的 wss websocket,但我遇到了一些错误。这是我的代码:

let port = 8443
let url = URL(string: "wss://ip_address:8443/gs-guide-websocket/websocket")!
connection = NWConnection(host: NWEndpoint.Host.name(url.host!, nil), port: NWEndpoint.Port(rawValue: UInt16(port))!, using: .tls)

这些是错误:

[BoringSSL] boringssl_context_alert_callback_handler(3747) [C1.1:1][0x7fe945708390] Alert level: fatal, description: certificate unknown
[BoringSSL] boringssl_context_error_print(3699) boringssl ctx 0x600001ec9500: 140639868076392:error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED: /BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/boringssl-109.202.1/ssl/handshake.cc:372:
[BoringSSL]boringssl_context_get_error_code(3519) [C1.1:1][0x7fe945708390] SSL_AD_CERTIFICATE_UNKNOWN

客户端失败并出现错误:-9808:可选(错误的证书格式)

我需要添加特殊选项才能在此处连接吗?

另外,我看到 wss 可以工作,因为我能够连接 SocketRocket,但我想连接 NWConnection

谢谢。

4

1 回答 1

1

解决方案是在服务器上安装我拥有的证书,然后在“设置”>“常规”>“关于”>“证书信任设置”中启用对该证书的完全信任

于 2018-11-14T22:13:16.763 回答