0

SSL/TLSパーソナル チャット サーバーへの接続を確立しようとしています。私のコードスニペットは次のとおりです

public void StartAuthentication(XMPPConnection connection) 
    {
        NetworkStream networkStream = new NetworkStream(connection._sock);
        _sslStream = new SslStream(networkStream, false, new RemoteCertificateValidationCallback(ValidateServerCertificate), new LocalCertificateSelectionCallback(ClientCertificateSelectionCallback));
        X509CertificateCollection collection = new X509CertificateCollection();
        collection.Add(new X509Certificate(@"D:\ca-certs\AddTrust_External_Root.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\America_Online_Root_Certification_Authority_1.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\AOL_Member_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Baltimore_CyberTrust_Root.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\CAcert_Class3.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\CAcert_Root.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Deutsche_Telekom_Root_CA_2.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\DigiCertHighAssuranceCA-3.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\DigiCertHighAssuranceEVRootCA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Entrust.net_2048.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Entrust.net_Secure_Server_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Equifax_Secure_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Equifax_Secure_Global_eBusiness_CA-1.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Go_Daddy_Class_2_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\GTE_CyberTrust_Global_Root.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Microsoft_Internet_Authority_2010.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Microsoft_Secure_Server_Authority_2010.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\StartCom_Certification_Authority.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Thawte_Premium_Server_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Thawte_Primary_Root_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\ValiCert_Class_2_VA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\VeriSign_Class_3_Public_Primary_Certification_Authority_-_G2.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\VeriSign_Class_3_Public_Primary_Certification_Authority_-_G5.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\VeriSign_Class_3_Public_Primary_Certification_Authority_-_G5_2.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\VeriSign_Class3_Extended_Validation_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\Verisign_Class3_Primary_CA.pem"));
        collection.Add(new X509Certificate(@"D:\ca-certs\VeriSign_International_Server_Class_3_CA.pem"));
        try 
        {
            _sslStream.AuthenticateAsClient("lap-020.alumnus.co.in", collection, SslProtocols.Tls, true);

        }
        catch (Exception ex) 
        {
            Console.WriteLine(ex.Message);
        }
    }

プログラムの実行後

_sslStream.AuthenticateAsClient("lap-020.alumnus.co.in", collection, SslProtocols.Tls, true);

メインスレッドブロック。おそらくこれが原因で、ssl ハンドシェイクが開始されません。メインスレッドがブロックされる理由を教えてください。ありがとう

4

2 に答える 2

-1
X509Certificate2Collection certificates = new X509Certificate2Collection();
certificates.Import(**uri**, **CertPass**, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);

ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host);
req.AllowAutoRedirect = true;
req.ClientCertificates = certificates;
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";
WebResponse resp = req.GetResponse();
var html = new StreamReader(resp.GetResponseStream()).ReadToEnd();
于 2017-11-09T11:27:35.750 に答える