EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Visual C++/MFC sample using CElSecureAsyncSocket

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#24206
Posted: 03/20/2013 15:47:56
by Dmytro Bogatskyy (EldoS Corp.)

As for the sample please install .Net edition and take a look of C#\SSLBlackbox\Client\SSLClientDemo This sample illustrates use of TElSecureClient component to secure socket connection.

A code below is a skeleton of this sample for C++
Code
#include <cstring>
#include <stdio.h>
#include <stdlib.h>

#include "sbmisc.h"
#include "sbsslclient.h"
#include "sbx509.h"
#include "sbutils.h"

using namespace SecureBlackbox;

void SB_CALLBACK SecureClient_OnSend(void * _ObjectData, TObjectHandle Sender, void * Buffer, int32_t Size)
{
   try
   {
      // send data to socket
   }
   catch (...)
   {
      std::cout << "Unexpected error in SecureClient_OnSend event handler" << std::endl;
   }
}

void SB_CALLBACK SecureClient_OnReceive(void * _ObjectData, TObjectHandle Sender, void * Buffer, int32_t MaxSize, int32_t * Written)
{
   try
   {
         // receive data from socket
   }
   catch (...)
   {
      std::cout << "Unexpected error in SecureClient_OnReceive event handler" << std::endl;
   }
}

void SB_CALLBACK SecureClient_OnData(void * _ObjectData, TObjectHandle Sender, void * Buffer, int32_t Size)
{
   // print data
}

void SB_CALLBACK SecureClient_OnOpenConnection(void * _ObjectData, TObjectHandle Sender)
{
   std::cout << "SSL connection established" << std::endl;
}

void SB_CALLBACK SecureClient_OnCloseConnection(void * _ObjectData, TObjectHandle Sender, TSBCloseReasonRaw CloseReason)
{
   std::cout << "SSL connection closed" << std::endl;
}

void SB_CALLBACK SecureClient_OnCertificateValidate(void * _ObjectData, TObjectHandle Sender, TElX509CertificateHandle X509Certificate, int8_t * Validate)
{
   std::cout << "Certificate received" << std::endl;
   *Validate = true;
}

int main(int argc, char **argv)
{
   try
   {
      SetLicenseKey("ACA0...D240");
   }
   catch (SBException E)
   {
      std::cout << "Failed to set license key:" << std::endl;
      std::cout << E.what() << std::endl;
   }

   // open a socket

   TElSSLClient SecureClient (NULL);
   SecureClient.set_Enabled(true);
        SecureClient.set_OnSend(&SecureClient_OnSend, NULL);
        SecureClient.set_OnReceive(&SecureClient_OnReceive, NULL);
        SecureClient.set_OnData(&SecureClient_OnData, NULL);
   SecureClient.set_OnCertificateValidate(&SecureClient_OnCertificateValidate, NULL);
   SecureClient.set_OnOpenConnection(&SecureClient_OnOpenConnection, NULL);
   SecureClient.set_OnCloseConnection(&SecureClient_OnCloseConnection, NULL);
   try
   {
      SecureClient.Open();
                // start socket receiver thread
                // ...
   }
   catch (SBException E)
   {
                std::cout << "Connection failed due to exception:" << std::endl;
      std::cout << E.what() << std::endl;
      std::cout << "Stack trace: " << E.getErrorStackTrace().c_str() << std::endl;
   }

   return 0;
}

Reply

Statistics

Topic viewed 4338 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!