【问题标题】:self signed certificate error with signalr - Error during negotiation request iOS信号器的自签名证书错误 - 协商请求 iOS 期间出错
【发布时间】:2018-01-28 07:27:47
【问题描述】:
Error: Optional(["message": Error during negotiation request.])

我在连接信号器服务器时遇到错误,我认为服务器端存在问题,因为他们使用了自签名证书。如何通过客户端(swift)修复,如何在 iOS 11 中启用自签名证书?对于签名者库。

下面是我的代码:

func test() {

    let persistentConnection = SignalR("http://services.test.com/signalr", connectionType: .persistent)

     let simpleHub1 = Hub("testHub")

    persistentConnection.useWKWebView = false

    persistentConnection.addHub(simpleHub1)

    persistentConnection.received = { data in
        print(data)
    }

    persistentConnection.connected = { [weak self] in

        print("Connected. Connection ID: \(String(describing: self!.hubConnection.connectionID))")
    }

    persistentConnection.starting = { [weak self] in
        print("Starting...")

    }

    persistentConnection.reconnecting = { [weak self] in
        print("Reconnecting...")
    }

    persistentConnection.connected = { [weak self] in
        print("Connected. Connection ID: \(String(describing: self!.hubConnection.connectionID))")
    }

    persistentConnection.reconnected = { [weak self] in
        print("Reconnected. Connection ID: \(String(describing: self!.hubConnection.connectionID))")
    }

    persistentConnection.disconnected = { [weak self] in
        print("Disconnected.")
    }

    persistentConnection.connectionSlow = { print("Connection slow...") }

    persistentConnection.error = { [weak self] error in

            print("Connection timed out. Restarting...")
            persistentConnection.start()
        }
    }
    persistentConnection.start()
}

【问题讨论】:

  • 我认为您应该详细说明...请尝试向审阅者提供更多有用的信息,以便他们帮助您解决问题。
  • 但是我看到你的网址是 http 不是 https?
  • 那么这个错误的原因是什么?协商请求期间出错。]

标签: ios swift signalr ssl-certificate ios11


【解决方案1】:

iOS 不允许使用自签名证书是有充分理由的。您应该始终尝试为您的服务器获取有效证书。从Let's Encrypt免费获取有效的服务器证书非常容易。

如果您确实需要使用自己的证书,请使用自己的证书颁发机构 (CA) 对其进行签名,然后将 CA 证书导出到您的设备。然后,您的设备将接受该 CA 签署的所有证书。

您可以使用以下 OpenSSL 调用来创建证书颁发机构并使用它签署您自己的证书:

openssl genrsa -out ca.key.pem 2048
openssl req -x509 -new -days 365 -sha256 -nodes -subj '/C=Country/ST=State/L=Location/CN=CommonName' -key ca.key.pem -out ca.crt.pem
openssl genrsa -out server.key.pem 2048
openssl req -new -sha256 -subj '/C=Country/ST=State/L=Location/CN=CommonName' -key 
server.key.pem -out server.csr.pem
openssl x509 -req -days 365 -in server.csr.pem -CA ca.crt.pem -CAkey ca.key.pem -CAcreateserial -out server.crt.pem -sha256
openssl x509 -in server.crt.pem -text -noout
openssl verify -CAfile ca.crt.pem server.crt.pem

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多