Simple client / server, TCP / IP, encrypted message flow, SSL (C ++)

Basically my question is the same:

Simple client / server, TCP / IP, encrypted message flow, SSL

The difference is that I need this for pure C ++, not .NET. I cannot use third-party libraries, so if it is not a Windows system component (for example, above), I need something with the source code so that I can get the general idea and create it myself.

Thanks:)

Quote from another question for reference:

β€œWriting a small client server is a TCP / IP application. It basically creates a server, and then you can create several different clients and a little chat session. I wonder if there is any way to enable using standard .net libraries. Encryption?

m_mainSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

Is there any way speficying tcp using rsa?

Or do you (me) need to write some user libraries to make an exchange key and then encrypt subsequent chat messages? I did what before for uni, but it was in java, but I know that it would be difficult to convert them. Just try not to have reinvent the wheel ...

Or how about using ssl?

Thanks, Ron.

+4
source share
3 answers

Writing your own encryption code is "not recommended." It’s easy enough to make a simple mistake when using one of these libraries, not to mention when you try to write it yourself.

What you really want to use is OpenSSL with Boost.ASIO on top of it. If you cannot do this, your next best alternative is to use the Internet Explorer COM object. It's not that flexible, but it can work just fine, depending on your specific needs. You can also learn the Win32 API. Recently, I looked that cryptographic APIs are not enough for this. The last way to handle this is to wrap the .NET API so that you can use them from your own C ++.

Only if none of this works for you, you should even think about it. You will make mistakes, and as a result, your application will be less secure. So, before you start writing your own cryptocode, you can also try to look at SOCKS tunneling through SSH and use some kind of SSH implementation. The next thing I would look at is to buy the code, and not write it yourself. The code will not be as good as the open source suggestions, because it will be less used, so it will have more security problems, but it will still be better than anything you write when you first work.

Only if you have exhausted all of these options, consider writing it yourself. After you think about it, you should try all the other options again to make sure that you have not missed, so that one of them works for you for the first time.

If you are still writing your own implementation, discard it and use one of the other options before putting it into production, as there will be errors that jeopardize security to the extent that you probably couldn't worry too .

I apologize for all this, but the correct implementation of these rules is very difficult, and not what you can do just by looking at the implementation of someone else.

0
source

Have you considered using the ASIO library? think-async dot com / Asio /

There is an example specifically for SSL-based client / server. http://think-async.com/Asio/asio-1.4.1/doc/asio/examples.html#asio.examples.ssl

Its like "pure c ++" as you can get.

+2
source

You can always look at OpenSSL , which is open source, but it will be similar to an SSL implementation on its own. I would suggest wrapping OpenSSL and using it. Or use the SSL tunnel application available in OpenSSL.

+1
source

All Articles