C#: SSL with SocketAsyncEventArgs?
Asked Answered
D

3

7

I'm developing a socket server using C# .NET. I'm using the async model provided by the SocketAsyncEventArgs class, because it must be a high performance server to support many connections in short periods of time. Next, I want to secure the communication between clients and server, and I think I could use SSL.

Is there any way of using SSL with the SocketAsyncEventArgs model? I know .NET has the SslStream class for SSL securing, but I need to use SocketAsyncEventArgs for high performance.

Is it possible to use SSL in an upper level, without implementing it in the server code?

Thanks in advance.

Doi answered 7/10, 2010 at 11:37 Comment(1)
John did you get any more info about this?Mill
F
8

Not sure if anyone cares anymore since this is so old but I needed to do just that this week and could not find anything on the internet that met my needs. Maybe there is something new in the framework that does this that I was unable find... Regardless, I would post source code but since I wrote it for my company and they tend to frown on that, I'll just outline the approach I took:

Since SslStream takes a stream in the constructor, I implemented my own Stream subtype with an underlying MemoryStream for reads and another for writes. I also pass in the TcpClient to this object as well.

I used the TcpClient to do the handshake for setting up the SSL connection. After authenticating the server or client depending on how I am using it, I then use my two MemoryStreams for the SslStream read/writes.

So for Async writes, I first write my payload to the SslStream which populates my MemoryStream for writing with encrypted data. With the encrypted data from the MemoryStream, I populate the SocketAsyncEventArgs buffer and call the TcpClient SendAsync method. For reads, it's pretty much the opposite.

I can't say it particular excites me to move the data like that but as long as you don't let your MemoryBuffer objects get reallocated constantly, it's not a performance issue. At least this way, I can use just the framework and my own code without relying on third party software.

Flemings answered 18/12, 2014 at 19:34 Comment(0)
H
0

You can take third-party implementation of SSL/TLS protocol, such as our SecureBlackbox, and use it with any transport, including .NET Sockets in asynchronous mode. SSL server component of SecureBlackbox doesn't have it's own socket, instead it fires events, in whose handlers you write your socket-related code. This way you an plug any transport, even non-socket one.

Huddleston answered 7/10, 2010 at 14:29 Comment(0)
R
0

I think I may have found a project that provides this.

https://sourceforge.net/projects/socketservers/

I'm still playing with it and am bumping into an issue loading the server certificate, however, looking through the source code it looks promising.

One aspect I'm unsure about is that it p/invokes to secur32.dll rather than being a pure c# implementation, so I'm not sure what the memory/performance impact of that is.

The details on the sourceforge project page are sparse as to what the goal of the project is.

Rumba answered 4/12, 2010 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.