I am trying to initialize the tls tunnel with .net SslStream, but after opening the stream, I always get the following error:
"Unable to read data from the transport connection: the established connection was interrupted by the software of your host computer."
After I established the tls connection and after sending the second message.
I have been looking for an answer in the last four days, but there is no useful information on the Internet!
edit: I'm trying to connect to talk.google.com
and I am using sample code from MSDN. The only difference is that I send data before and when it is time to use tls, I do the following:
public void SecureStream() { netStream.Flush(); sslStream = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); sslStream.AuthenticateAsClient("talk.google.com");}
edit: I managed to fix the first error (a small error in the way I handled sending), now I always get
"Unable to read data from the transport connection: the established connection was interrupted by the software of your host computer."
edit2: I did not send any spaces. I rewrote the message transfer part, and I still have the same problem.
I start with
String streamInit = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='google.com' version='1.0'>"; client.Send(streamInit);
Then after receiving I have the following
static void client_MessageReceived(SyncronousClient source, string Result) { if (Regex.IsMatch(Result, "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"><required/></starttls>")) { String startTlS = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"; source.Send(startTlS); } else if (Regex.IsMatch(Result, "<proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>")) { //Do TLS Magic source.SecureStream(); String streamReInit = "<stream:stream xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams'to='google.com'version='1.0'>"; source.Send(streamReInit); } else if (Regex.IsMatch(Result, "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">")) { //String AuthType = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='X-GOOGLE-TOKEN'/>"; String AuthType = "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\"/>"; source.Send(AuthType); }}