1

I'm using a TCP Client Server Library called Lacewing.

http://lacewing-project.org/docs/

What I noticed is that messages I send and receive are in plain text. Is there a way to encrypt / decrypt the messages easily given that I use TCP? How could I add something like TLS en.wikipedia.org/wiki/Transport_Layer_Security or similar?

Thanks

The library is pretty high level but here is client server in a nutshell:

#include <string>
#include <iostream>  
#define  LacewingFunction
#include "Lacewing.h"

void onReceive (Lacewing::Server &Server, Lacewing::Server::Client &Client,
                char * Data, int Size) {
                    /* callback body */
                    std::cout << Data << "\n";
}

void onConnect (Lacewing::Server &Server, Lacewing::Server::Client &Client)
{
    std::cout << "Connected!" << "\n";
    Client.Send("TestingS");
}



void onReceiveC (Lacewing::Client &Client, char * Data, int Size)
{
    std::cout << Data << "\n";
    Client.Send("TesingC");
}


int main(int argc, char* argv[])  
{  
    std::string s;
    std::cin >> s;
    if(s == "server")
    {
        Lacewing::EventPump pump;
        Lacewing::Server* server = new Lacewing::Server(pump);
        server->onReceive(onReceive);
        server->onConnect(onConnect);
        server->Host(1234);
        pump.StartEventLoop();
    }
    else
    {
        Lacewing::EventPump pump;
        Lacewing::Client* server = new Lacewing::Client(pump);
        server->onReceive(onReceiveC);
        server->Connect("192.168.2.12",1234);
        pump.StartEventLoop();
    }

    return 0;  
}  
James M
  • 18,506
  • 3
  • 48
  • 56
jmasterx
  • 52,639
  • 96
  • 311
  • 557
  • You could try using another library that is commonly used called Boost::Asio which is a nice library that has built-in SSL support. If you want to code in C, OpenSSL has a nice library that is simple to use. – user99545 May 14 '12 at 05:52

1 Answers1

0

In a word: yes. Your two basic options are SSL/TLS and IPsec. SSL would be implemented in your application; IPsec would be outside of your control.

See this answer to a related question.

You'd have to post some of your networking code if you want help on how to adapt it to SSL/TLS.


Edit: If you don't want to modify the source code to Lacewing, it seems to me that the easiest solution for you might be to use something like stunnel to protect your traffic.

Community
  • 1
  • 1
mpontillo
  • 13,559
  • 7
  • 62
  • 90
  • After you accept the connection, you'd need to do the TLS negotiation, certificate checking, etc, before proceeding to the point where you allow your client/server code to send/receive data. Basically everything stunnel does. ;-) You'd probably want to add a new API to Lacewing; something like `SSLServer`/`SSLClient`; the server would need the ability to specify its certificate. – mpontillo May 14 '12 at 01:06
  • Where would be a tutorial that might show how to do this sort of thing? – jmasterx May 14 '12 at 01:09
  • Lacewing has something about certificates but Im not sure that's it http://lacewing-project.org/docs/server/CertificateLoaded.html – jmasterx May 14 '12 at 01:12
  • Oh, what am I thinking?! Looks like it might have some level of SSL/TLS support already. Try loading a certificate! – mpontillo May 14 '12 at 01:16
  • I'm having trouble loading one. – jmasterx May 14 '12 at 01:35
  • With OpenSSL, connecting to the server yields result 21, self signed certificate, but, with my client it always says secure handshake failed. – jmasterx May 15 '12 at 16:35
  • Maybe there is an API to allow the client to trust the self-signed cert? I guess you need to determine how to configure the chain of trust on the client. – mpontillo May 15 '12 at 16:53