Thread: Secure socket

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Post Secure socket

    hello everyone, am a novice at programming, i was told to code a client/server interaction, i came up with this but i need to secure it so that when a client connects, instead of showing "YourMessage", it is suppose to show something elseMain.cppclnt.hmain.cppwind.h

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    you could look into something like openssl or gnutls. otherwise, you could roll your own security with encryption and hashing, using something like cryptopp.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    secure server

    Thank you, though what am looking for is a small code to insert into this code:
    Code:
    server:
    
    #include "wind.h"
    
    using namespace std;
    
    //begi
    void main()
    {
    
        long answer ;
        WSAData wsaData;
        WORD DLLVERSION;
        DLLVERSION = MAKEWORD(2,1);
    
        answer = WSAStartup(DLLVERSION, &wsaData);
    
        SOCKADDR_IN addr;
        int addrlen = sizeof(addr);
    
     SOCKET slisten;
     SOCKET  sConnect;
    
     sConnect = socket(AF_INET,SOCK_STREAM,NULL);
    
     addr.sin_addr.s_addr = inet_addr("127.0.0.1");
     addr.sin_family = AF_INET;
    
     addr.sin_port = htons(1234);
    
     slisten = socket(AF_INET,SOCK_STREAM,NULL);
    
     bind(slisten, (SOCKADDR*)&addr, sizeof(addr));
     // unlimited clients
     listen(slisten, SOMAXCONN);
    
     //conditions
     for(;;)
    
    
    
          {
    cout <<"waiting for client" <<endl;
    if (sConnect = accept(slisten,(SOCKADDR*)&addr, &addrlen))
          {
              cout<<" A connection was found" <<endl;
    
               answer = send(sConnect,       "YourMessage", 12 ,NULL);
    
          }
    
     }
    }
    
    client:
    
    #include "clnt.h"
    
    using namespace std;
    
    void main ()
    {
     string confirm;
     char message[200];
      string strmessage;
    
    long answer;
    WSAData wsaData;
    WORD DLLVersion;
    DLLVersion = MAKEWORD(2,1);
    answer = WSAStartup(DLLVersion, &wsaData);
    
    
    
    SOCKADDR_IN addr;
     int addrlen = sizeof(addr);
    
      SOCKET sconnect;
    
      sconnect = socket(AF_INET,      SOCK_STREAM,NULL);
    
      addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    
      addr.sin_family = AF_INET;
    
      addr.sin_port = htons(1234);
    
    
    cout <<" Do you want to connect to your server?[Y/N]" <<endl;
    cin>> confirm;
    if(confirm == "N")
    {
          exit(1);
        }
           else
        {
            if(confirm == "Y")
            {
               connect(sconnect,     (SOCKADDR*)&addr, sizeof(addr));
              answer = recv(sconnect, message, sizeof(message), NULL);
              strmessage = message;
              cout << strmessage <<endl;
              getchar();
            }
    
         }
    
    getchar();
    }

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    it's not that simple. there is no standard, OS-integrated method for security of low level sockets. your best bet is to use openssl or one of the wrappers that exist for it, like boost::asio. you will need to do this on both the server and the client.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by danny1 View Post
    Thank you, though what am looking for is a small code to insert into this code:
    That's what I'd like a lot of the time too. "I'd like some small code to insert to create a GUI front-end for my database", "I'd like some small code to insert to facilitate concurrency for various aspects of this process", etc. Guess what? I usually don't get what I'd like

    If you go with SSL, you'll also have to create a self-signed SSL certificate for the server.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MK27 View Post
    If you go with SSL, you'll also have to create a self-signed SSL certificate for the server.
    or get one from a registered certification authority for free from here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Secure?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-08-2009, 11:17 AM
  2. secure use of scanf
    By belhifet in forum C Programming
    Replies: 5
    Last Post: 11-26-2006, 06:07 PM
  3. Secure Instant Messaging
    By newbie29 in forum C++ Programming
    Replies: 2
    Last Post: 05-06-2005, 02:36 AM
  4. Secure Network Programming with C
    By zahid in forum C Programming
    Replies: 1
    Last Post: 05-19-2003, 10:10 AM
  5. Ctrl+Alt+Del: Secure?
    By RoD in forum Tech Board
    Replies: 6
    Last Post: 01-24-2003, 05:53 PM

Tags for this Thread