A call to SSPI failed, The message received was unexpected or badly formatted

Dec 2, 2011 at 9:11 AM

Hi :

Getting above exception on the   sslStream.AuthenticateAsClient(hostname, clientCertColl, SslProtocols.Default, sslCheckCertRevocation)  step.

I have used a windows tool to verify that the connection works and the certificate is valid. The only setting that I can't replicate is "Accept any certificate" which needs to be true.

Any ideas?

Thanks - Simon 

static string ftpServer = "xxx.co.uk";
static int ftpPort = 2121;
static string ftpDir = "/sw/xxxxx/";
static string ftpCert = @"C:\code\cert-prod.p12";
static string ftpUser = "s6456346";
static string ftpPass = "????";
static string ftpCertPass = @"???";

        private SslStream CreateSSlStream(Stream s, bool leaveInnerStreamOpen)
            SslStream sslStream = new SslStream(s, leaveInnerStreamOpen,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null //new LocalCertificateSelectionCallback(ValidateClientCertificate)

            sslStream.ReadTimeout = timeout;
            sslStream.WriteTimeout = timeout;

            X509Certificate2Collection clientCertColl = new X509Certificate2Collection();
            if (sslClientCert != null)
                sslStream.AuthenticateAsClient(hostname, clientCertColl, SslProtocols.Default, sslCheckCertRevocation);
            catch (Exception ex) {
                if (ex.InnerException != null)
                    Console.WriteLine("Inner exception: " + ex.InnerException.Message);

            return sslStream;