带有Signalr的自签名证书错误-协商请求iOS期间发生错误 [英] self signed certificate error with signalr - Error during negotiation request iOS

查看:96
本文介绍了带有Signalr的自签名证书错误-协商请求iOS期间发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Error: Optional(["message": Error during negotiation request.])

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

I'm getting the error while connection signalr server, I think there is an issue with server side as they used self signed certificate. How I can fix by client side(swift),how to enable in iOS 11 to work with self signed certificate? For the signer library.

下面是我的代码:

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()
}

推荐答案

iOS出于充分的理由不允许使用自签名证书.您应该始终尝试获取服务器的有效证书.从让我们免费加密是非常容易的.

iOS does not allow self signed certificates for good reasons. You should always try to get a valid certificate for your server. It is quite easy to obtain a valid server certificate from Let's Encrypt for free.

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

If you really need to use own certificates, sign them with an own certificate authority (CA) and export the CA certificate to your device. Your device will then accept all certificates signed by this CA.

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

You can use the following OpenSSL calls to create a certificate authority and sign your own certificates with it:

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

这篇关于带有Signalr的自签名证书错误-协商请求iOS期间发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆