0

I have created a java server with self-signed certificate and I can connect to it with openssl and communicate with it. But the c# client I wrote keeps getting a System.InvalidOperationException (This operation can only be used with authenticated environment (mirror translated to english)) during WriteAsync.

The server says: "javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake".

c# client:

TcpClient tcpClient = new TcpClient("127.0.0.1", 40);
using (SslStream sslStream = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(this.ValidateServerCertificate))) {
    sslStream.AuthenticateAsClientAsync("127.0.0.1");

    byte[] request = Encoding.ASCII.GetBytes(prepareRequest(email, password));
    sslStream.WriteAsync(request, 0, request.Length); //this is where I get exception

}
tcpClient.Close();

The server does not require client certificate. What should I do to make it happen?

Edit:

Here is the openssl output when I connect with openssl s_client -connect 127.0.0.1:40:

CONNECTED(00000003)
depth=0 C = .., ST = .., L = .., O = Unknown, OU = Unknown, CN = ..
verify error:num=18:self signed certificate
verify return:1
depth=0 C = .., ST = .., L = .., O = Unknown, OU = Unknown, CN = ..
verify return:1
---
Certificate chain
 0 s:/C=../ST=../L=../O=Unknown/OU=Unknown/CN=..
   i:/C=../ST=../L=../O=Unknown/OU=Unknown/CN=..
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDcTCCAlmgAwIBAgIEKrrdADANBgkqhkiG9w0BAQsFADBpMQswCQYDVQQGEwJI
VTENMAsGA1UECBMEUGVzdDERMA8GA1UEBxMIQnVkYXBlc3QxEDAOBgNVBAoTB1Vu
a25vd24xEDAOBgNVBAsTB1Vua25vd24xFDASBgNVBAMTC0RhdmlkIE9yY3NrMB4X
DTE3MDgxNDEyMDU1MFoXDTE4MDgwOTEyMDU1MFowaTELMAkGA1UEBhMCSFUxDTAL
BgNVBAgTBFBlc3QxETAPBgNVBAcTCEJ1ZGFwZXN0MRAwDgYDVQQKEwdVbmtub3du
MRAwDgYDVQQLEwdVbmtub3duMRQwEgYDVQQDEwtEYXZpZCBPcmNzazCCASIwDQYJ
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAJToS08AGHt74oSP2jL1rkfnTlcBBKXZ
nrJCmn/S4LHATh9xwsvM8dHuN+CPR6ZJAhLUPnFW5jP8DNExsUShvEFXSKZUw43W
VDQNctvuZ4KAdgh878QQv94XN4k0pZkohrReCmLNU6cDOsL8Mv75gSmjWqN/SUml
CGCKADhgeS9rUwHeIqEfxFjLdnDHq1vmdmGDgtO/VQnTv2KG8xkUtRIOn/sTPtc/
dFcmTN7wIaq5q7I6Ujrp2oTVdDdlL6xODy2TGuRoD+1cbFhWqNgHbZzKdeChGDrl
73+znrJnbqkRvPzb5zPzVQUAHILFvAAN5/ef8D1ss0BkhF71ySt7bzUCAwEAAaMh
MB8wHQYDVR0OBBYEFE0ApKA3xeiPt1qcwXBSmKPxi+Y1MA0GCSqGSIb3DQEBCwUA
A4IBAQACkxJOcxnacXIPugZY9aL0cfgV3FKCWs3ZxKfMksQ2v9xLl8Z0QC5DBhoT
zAJ5f9eE9f/DRIaqjzL9nbD/3sx3W6CFdXPYsX6jWyWbvzzT+8tGEmof4Dmi3RAr
98e7wFFPYYIMMptea/MmeF/pM2O0EVAc3W+HTXdEg/DFYHQOgFBlQUYWAcAQfXCX
uaza/3uQYAjBLGRvVyR2akwLSulxee7wdbQX5TfiDMeL10DGuaelAUQswhOzxaiZ
X3bKlcGxoS5QLHIDVHHaFxya3MFoejrGxXLn0SyaVcJ/DVDByrWjeu7zf964vw86
hHMOzi4KwRlBrUn9oz2LAPIYmBIs
-----END CERTIFICATE-----
subject=/C=../ST=../L=../O=Unknown/OU=Unknown/CN=..
issuer=/C=../ST=../L=../O=Unknown/OU=Unknown/CN=..
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1369 bytes and written 431 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 5995A92B659904ED327561C58121A90D1C3D1B538F190E32E552D575DACB7C9E
    Session-ID-ctx:
    Master-Key: F0190CF037F957E64A2B8E307D4FDC71EFF81881A091677D0DA6790B8100601330D50086F12AB330EE264B49D0053D84
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1502980395
    Timeout   : 300 (sec)
    Verify return code: 18 (self signed certificate)
---
Message from server...
  • Is the IP address correct? 127.0.0.1 is you local machine, so if the java server is on another machine it won't get to it. – Eric Yeoman Aug 17 '17 at 12:42
  • It is correct it's running on the same pc for now. –  Aug 17 '17 at 12:47
  • Oh well, but at least thats the obvious out of the way:). Have you had a look through this thread https://stackoverflow.com/questions/21245796/javax-net-ssl-sslhandshakeexception-remote-host-closed-connection-during-handsh – Eric Yeoman Aug 17 '17 at 12:57
  • Not until now, but unfortunately none of them were relevant or solved the problem :( but thans for the recommendation :) –  Aug 17 '17 at 13:18
  • What is you server's ciphersuite configuration? I think GCM ciphersuites were added to windows with special update. BTW can you connect to 127.0.0.1:40 using internet explorer? – savageBum Aug 23 '17 at 14:02

0 Answers0