Question Question Regarding SSLstream and Certificate Error

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Hopefully someone can explain this to me a little further..

I'm trying to establish a TCP connection using SSLstream, but constantly receive a certificate error:
Authentication failed because the remote party has closed the transport stream

I know the server uses SSL, but I've never really done anything with certificates before. Here is the code I'm using
VB.NET:
Dim DRShost As String = "my.host.net"
Dim client As TcpClient
Dim sslStream As Security.SslStream

Private Sub Thread1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Thread1.DoWork
Dim client As New TcpClient(DRShost, 700)
Dim sslStream As New Security.SslStream(client.GetStream(), True)
sslStream.AuthenticateAsClient(DRShost)

Try
Dim greeting As String = GetResponse(sslStream, System.Text.Encoding.UTF8)

Catch ex As Exception
msgbox(ex.Message)
End Try
End Sub

I've spoken with support at the company whom I'm trying to connect with, and they've told me the following..
In order to investigate this issue please provide us with response of below mentioned command:

openssl s_client -connect separate.hosthere.net:700 -cert cert.pem -key key.pem -CAfile cacert.pem -showcerts -state

Where:
*cert.pem is the public key (registrar's x.509 certificate). It must be obtained from a accepted Certificate Authorty.

*key.pem - registrar's private key. Used to create a digital signature that is verifiable by anyone with the public key.

*cacert.pem - The Root Certificate for the Certificate Authority that signed your certificate.

Also, we have escalated your request regarding the SSL and TLS version confirmation to appropriate team. We will get back to you as soon as more information becomes available to us.

I'm a little confused by their response. I'm not sure how to run the command they are asking for, and I don't have any of the files they are talking about.. Are they saying that I need to be passing these certificates in order to connect with a simple Greeting message like I'm doing above? I'm not that experienced, but I've never heard of that being done before (or seen any examples of it).. Is there any way to ignore or bypass that? Otherwise, could it be that my code is trying to connect using TLS instead of SSL?

Any help or input would be appreciated!
 
Been doing some more research on this and was wondering if I could use some code to try and ignore certificates. I've tried the following options, but still appear to be getting the same error:
Authentication failed because the remote party has closed the transport stream.

VB.NET:
Dim DRShost As String = "my.host.net"
Dim client As TcpClient
Dim sslStream As Security.SslStream

Private Shared Function ValidateRemoteCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal policyErrors As SslPolicyErrors) As Boolean
        Return True
End Function

Private Sub Thread1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Thread1.DoWork
Dim client As New TcpClient(DRShost, 700)
Dim sslStream As New Security.SslStream(client.GetStream(), True)
sslStream.AuthenticateAsClient(DRShost)
System.Net.ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateRemoteCertificate)

Try

Dim greeting As String = GetResponse(sslStream, System.Text.Encoding.UTF8)

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

and also..

VB.NET:
Dim DRShost As String = "my.host.net"
Dim client As TcpClient
Dim sslStream As Security.SslStream

Private Sub Thread1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Thread1.DoWork
Dim client As New TcpClient(DRShost, 700)
Dim sslStream As New Security.SslStream(client.GetStream(), True, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), Nothing)
sslStream.AuthenticateAsClient(DRShost)

Try

Dim greeting As String = GetResponse(sslStream, System.Text.Encoding.UTF8)

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Below are the exception details...
System.IO.IOException was unhandled by user code
HResult=-2146232800
Message=Authentication failed because the remote party has closed the transport stream.
Source=System
StackTrace:
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
at myform.Form1.Thread1_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\Drew\documents\visual studio 2010\Projects\myform\myform\Form1.vb:line 1083
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
InnerException:
 
Back
Top