SslStream.AuthenticateAsClient 上的异常(消息格式错误) [英] Exception on SslStream.AuthenticateAsClient (The message was badly formatted)

查看:42
本文介绍了SslStream.AuthenticateAsClient 上的异常(消息格式错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了奇怪的问题.我正在尝试通过 TCP/SSL 连接到 Apple 服务器.我正在使用 Apple 提供的客户端证书进行推送通知.我在我的服务器 (Win2k3) 上的本地可信根证书和本地个人证书文件夹中安装了证书.

I have got wierd problem going on. I am trying to connect to Apple server via TCP/SSL. I am using a Client certificate provided by Apple for push notifications. I installed the certificate on my server (Win2k3) in both Local Trusted Root certificates and Local Personal Certificates folder.

现在我有一个处理该连接的类库,当我从从服务器运行的控制台应用程序调用这个类库时,它工作得很好,但是当我从 asp.net 页面或 asmx web 调用该类库时服务我收到以下异常.

Now I have a class library that deals with that connection, when i call this class library from a console application running from the server it works absolutely fine, but when i call that class library from an asp.net page or asmx web service I get the following exception.

对 SSPI 的调用失败,请参阅内部异常.收到的消息意外或格式错误.

A call to SSPI failed, see inner exception. The message received was unexpected or badly formatted.

这是我的代码:

X509Certificate cert = new X509Certificate(certificateLocation, certificatePassword);                       
X509CertificateCollection certCollection = new X509CertificateCollection(new X509Certificate[1] { cert });
// OPEN the new SSL Stream
SslStream ssl = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);                       
ssl.AuthenticateAsClient(ipAddress, certCollection, SslProtocols.Default, false);

ssl.AuthenticateAsClient 是抛出错误的地方.

这让我发疯.如果控制台应用程序可以正常连接,那么 ASP.NET 网络层安全性肯定存在一些问题,导致身份验证失败......不确定,也许需要在 web.config 中添加一些东西或某种安全策略.还要指出的是,我可以在本地开发机器上通过控制台和网站正常连接.

This is driving me nuts. If the console application can connect fine, there must be some problem with asp.net network layer security that is failing the authentication... not sure, perhaps need to add something or some sort of security policy in the web.config. Also just to point out that i can connect fine on my local development machine both with console and website.

有人有什么想法吗?

推荐答案

您是否在系统上安装了证书?如果您运行的是 Windows,它应该位于管理控制台下的本地计算机/个人或受信任文件夹中(运行 -> mmc).

Have you installed the certificate on your system? If you are running windows it should be in Local Computer/Personal or Trusted Folders under Management Console (Run -> mmc).

这篇关于SslStream.AuthenticateAsClient 上的异常(消息格式错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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