Exception on SslStream.AuthenticateAsClient (The message was badly formatted)
Posted
by Noms
on Stack Overflow
See other posts from Stack Overflow
or by Noms
Published on 2009-12-10T23:50:29Z
Indexed on
2010/05/06
10:48 UTC
Read the original article
Hit count: 1432
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.
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.
A call to SSPI failed, see inner exception. The message received was unexpected or badly formatted.
This is my code:
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
is where the error gets thrown.
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.
Anyone has got any ideas?
© Stack Overflow or respective owner