|
Forums -> Security Library Forum
SecureSockets and Streams? |
|
|
by Paul Grebenc [mentalis_alias at blinkenlights dot org] posted on 2004/05/26 |
|
Okay... I figured out I should probably be using SecureTcpClient instead. I can call GetStream() to get a Stream from that object.
When I call Connect, a connection is made (verified with ethereal capture). I then try to create a StreamWriter with which I write to the socket:
oSW = new StreamWriter(oSecureTcpClient.GetStream());
So far so good.. until I try to write through the StreamWriter:
oSW.WriteLine(sRequest);
...(more writes)...
oSW.Flush();
The WriteLine calls succeed, although I can see from my capture that no data is transmitted over the wire. A Flush should do the job, I think, but when Flush is called, the program hangs for a bit, then throws an exception:
System.IO.IOException: An I/O exception occurred. ---> System.ObjectDisposedException: Cannot access a disposed object named "Org.Mentalis.Security.Ssl.Shared.SocketController".
Object name: "Org.Mentalis.Security.Ssl.Shared.SocketController".
at Org.Mentalis.Security.Ssl.Shared.SocketController.BeginSend(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at Org.Mentalis.Security.Ssl.SecureSocket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
at Org.Mentalis.Security.Ssl.SecureSocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Org.Mentalis.Security.Ssl.SecureNetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
Am I using the stream from this object incorrectly (it works with a regular Socket)? Or is something else wrong?
Paul
|
by Pieter Philippaerts [Pieter at mentalis dot org] posted on 2004/05/26 |
|
It's possible that the SSL handshake with the server failed. Could you also post how you create the oSecureTcpClient? |
by Paul Grebenc [mentalis_alias at blinkenlights dot org] posted on 2004/05/26 |
|
Here is basically a summary of what my code is doing. The socket does open, and it stays open, until I flush the StreamWriter, at which the previous exception is thrown.
SecurityOptions oSecurityOptions = new SecurityOptions(SecureProtocol.Ssl3, null, ConnectionEnd.Client);
oSecurityOptions.Verifier = new CertVerifyEventHandler(Verifier);
IPEndPoint oIPEndPoint = new IPEndPoint(oIPAddress, iPort);
SecureTcpClient oSTC = new SecureTcpClient(oSecurityOptions);
oSTC.Connect(oIPEndPoint);
StreamWriter oSW = new StreamWriter(oSTC.GetStream());
oSW.WriteLine("Hello");
oSW.Flush();
Verifier is the following do-nothing method:
protected void Verifier(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
{
}
Regards,
Paul
|
by Paul Grebenc [mentalis_alias at blinkenlights dot org] posted on 2004/05/26 |
|
By the way, I am attempting to connect to a secure web server, which I can successfully access using a browser. I've tried connecting to two different servers, actually, so a problem on the remote server side is (I think) probably not likely.
Paul
|
by Pieter Philippaerts [Pieter at mentalis dot org] posted on 2004/06/01 |
|
I think the reason of the error is because the server certificate verification fails.
The SecurityOptions structure you're using has the VerificationType property set to 'CredentialVerification.Auto'. This is the default verification method. When setting this option, the SecureSocket will check the common name of the server for you, and if the verification fails it will abort the connection.
However, you've set the common server name to 'null' which means the verification will never succeed.
Try setting the VerificationType property to 'CredentialVerification.None'. Hopefully it will work then.
If it does, you know what the problem is and you can deal with it accordingly.
If this doesn't solve your problem, let us know here on the forum. |
by Paul Grebenc [mentalis_alias at blinkenlights dot org] posted on 2004/06/14 |
|
Hello, sorry for the delay.
I tried setting the credential requirements to CredentialVerification.None in my SecurityOptions object. A connection is still being made, but then closed on my end. I get the following exception.
System.IO.IOException: An I/O exception occurred. ---> Org.Mentalis.Security.SecurityException: An error occurs while communicating with the remote host. ---> System.Security.Cryptography.CryptographicException: Couldn't acquire crypto service provider context.
at Org.Mentalis.Security.Cryptography.CAPIProvider.CreateHandle()
at Org.Mentalis.Security.Cryptography.CAPIProvider.get_Handle()
at Org.Mentalis.Security.Certificates.Certificate.get_PublicKey()
at Org.Mentalis.Security.Ssl.Shared.ClientHandshakeLayer.ProcessServerHelloDone(HandshakeMessage message)
at Org.Mentalis.Security.Ssl.Shared.ClientHandshakeLayer.ProcessMessage(HandshakeMessage message)
at Org.Mentalis.Security.Ssl.Shared.HandshakeLayer.ProcessMessages(RecordMessage message)
at Org.Mentalis.Security.Ssl.Shared.RecordLayer.ProcessBytes(Byte[] buffer, Int32 offset, Int32 size)
at Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessServerHello(Byte[] bytes, Int32 offset, Int32 size)
at Org.Mentalis.Security.Ssl.Shared.CompatibilityLayer.ProcessHello(Byte[] bytes, Int32 offset, Int32 size)
at Org.Mentalis.Security.Ssl.Shared.SocketController.OnReceive(IAsyncResult ar)
--- End of inner exception stack trace ---
at Org.Mentalis.Security.Ssl.SecureSocket.EndSend(IAsyncResult asyncResult)
at Org.Mentalis.Security.Ssl.SecureSocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Org.Mentalis.Security.Ssl.SecureNetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
|
|
|