简体   繁体   中英

Server (java) can't receive XML from client (c#) with SSL connection

i'm trying to sending XML from client to server. I using this using System.Security.Cryptography.X509Certificates; and got Exception called in AuthenticateClient . The exception is

AutenticationException was caught, A call to SSPI failed, see inner exception.

this is my code :

public static SslStream OpenSSL(string _IP, int _port)
{
    try
    {
        TcpClient client = new TcpClient(_IP, _port);

        // Create a secure stream
        SslStream sslStream = new SslStream(client.GetStream(), false,
                    new RemoteCertificateValidationCallback(ValidateServerCertificate), null);

        if (sslStream != null)
        {
            sslStream.AuthenticateAsClient(_IP);
        }

        return sslStream;
    }
    catch (Exception _e)
    {
        Util.Log.Track(Config.System.LogMode.UTIL, "Comms.Handler.OpenSSL: exception = " + _e.ToString());
        return null;
    }
}

I can connect to the server, but the server won't receive the XML. I'm stuck here for 2 days, is anyone knows whats wrong with this problem?

note : I use VS2010 (client) and Eclipse Mars for linux (server)

Try to add this C# code

System.Net.ServicePointManager.ServerCertificateValidationCallback =
    ((sender, certificate, chain, sslPolicyErrors) => true);

It ignores the errors of ssl validation

Then try another approach Change it

if (sslStream != null)
{
    sslStream.AuthenticateAsClient(_IP);
}

to this

X509Certificates.X509Certificate2Collection xc = new X509Certificates.X509Certificate2Collection();
sslStream.AuthenticateAsClient(_IP, xc, Security.Authentication.SslProtocols.Tls, false);

Actually,I'm not sure about SslProtocols flags. Maybe SslProtocols.Tls | SslProtocols.Ssl3 SslProtocols.Tls | SslProtocols.Ssl3

If it doesn't help, I don't have any idea :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM