【问题标题】:NWConnection using TLS fails in Swift使用 TLS 的 NWConnection 在 Swift 中失败
【发布时间】:2018-11-12 01:43:39
【问题描述】:

我能够像这样使用 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] 警报级别:致命,描述:证书未知
[BoringSSL]boringssl_context_error_print(3699)boringssl ctx 0x600001ec9500: 140639868076392:error:1000007d:SSL 例程:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED:/BuildRoot/Library/Caches/com.apple.xbs1/Sources/boringssl-1/09.202. ssl/handshake.cc:372:
[BoringSSL]boringssl_context_get_error_code(3519) [C1.1:1][0x7fe945708390] SSL_AD_CERTIFICATE_UNKNOWN

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

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

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

谢谢。

【问题讨论】:

    标签: ios swift ssl wss network.framework


    【解决方案1】:

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

    【讨论】:

    • 你能描述一下你是怎么做到的吗?
    猜你喜欢
    • 1970-01-01
    • 2020-02-14
    • 2019-12-16
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多