4

次のエラーが表示されます。「sspi の呼び出しに失敗しました。内部例外を参照してください。受信したメッセージは予期しないものでしたか、Windows 7 で正しくフォーマットされていませんでした」。考えられるすべての方法を試しましたが、うまくいきませんでした。これをチェックしてください

ここにコードがあります

        int port = 2195;
        String deviceID = "d6c597fcc4e3426993cf29a3a8857efbed3462d5d8e9e32c0f8b387djkdklldk";
        String hostname = "gateway.sandbox.push.apple.com";     // TEST
        //String hostname = "gateway.push.apple.com";           // REAL
        string p12FilePassword = "password";
        //        @"cert.p12";
        String certificatePath = HttpContext.Current.Server.MapPath("~/Certificate.p12");


        X509Certificate2 clientCertificate = string.IsNullOrEmpty(p12FilePassword) ? new X509Certificate2(File.ReadAllBytes(certificatePath)) : new X509Certificate2(File.ReadAllBytes(certificatePath), p12FilePassword, X509KeyStorageFlags.MachineKeySet);

        X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
        TcpClient client = new TcpClient(hostname, port);

        SslStream sslStream = new SslStream(client.GetStream(), false, ValidateServerCertificate, SelectLocalCertificate);
        try
        {
            sslStream.AuthenticateAsClient(hostname, certificatesCollection, System.Security.Authentication.SslProtocols.Tls, false);
        }
        catch (Exception e)
        {
            throw (e);
            //client.Close();
            //return;
        }
4

1 に答える 1

0

これは古い投稿ですが、最近この問題に直面しました。アプリケーションは Windows10 で動作し、Windows サーバー 2008r2 および 2012r2 では失敗しました。解決策は、SslStream を取り除き、TLS 接続に openssl や bouncycastle などのライブラリを使用することです。

于 2018-02-07T09:23:41.570 に答える