I tried to make a ssl connection inside of a COM (dll).
The COM try to 'post' some data to a secureweb server (https).
This work fine in Linux an FreeBSD, but when I tried to use in a Windows

routine, the 'SSL_connect' return "-1".
Some body know the why?

I include the source code of the 'interfase'.

   SSLeay_add_ssl_algorithms();
   SSL_METHOD *meth = SSLv2_client_method();
   SSL_load_error_strings();
   SSL_CTX *ctx = SSL_CTX_new (meth);
 if (ctx == NULL)
  return 0;




 WSADATA wsaData;
 WORD    wVersionRequested = MAKEWORD(1, 1);

 if (WSAStartup(wVersionRequested, &wsaData))
 {
  //printf("Error en WSAStartup()\n");
  return 0;
 }

 SOCKET hSocket = socket(PF_INET, SOCK_STREAM, 0);
 if (hSocket == INVALID_SOCKET)
 {
  //printf("Error en socket()\n");
  return 0;
 }


 /* set the timeout value to TIME_RCV in case that the socket */
 /* waite more TIME_RCV its return an error */
 struct timeval  time_out;
 time_out.tv_usec = 0;
 time_out.tv_sec = TIME_RCV;
 if ( setsockopt(hSocket,SOL_SOCKET,SO_RCVTIMEO,(char *)&time_out,
           sizeof(time_out) ) < 0 )
  {
  closesocket(hSocket);
  return 0;
  }

 int  port = /*80*/ 443;

 SOCKADDR_IN sockAddr;
 memset(&sockAddr,0,sizeof(sockAddr));
 sockAddr.sin_family = AF_INET;
 LPHOSTENT lphost;
 lphost = gethostbyname(m_name_server);
 if (lphost != NULL)
  sockAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
 else
 {
  closesocket(hSocket);
  return 0;
 }
 sockAddr.sin_port = htons(port);
 if (connect(hSocket, (SOCKADDR*)&sockAddr, sizeof(sockAddr)) ==
SOCKET_ERROR)
 {
  //printf("Error en connect()\n");
  closesocket(hSocket);
  return 0;
 }


  /* ----------------------------------------------- */
  /* Now we have TCP conncetion. Start SSL negotiation. */

 SSL *ssl = SSL_new (ctx);
 if (ctx == NULL)
  return 0;
 SSL_set_fd (ssl, hSocket);
 int err = SSL_connect (ssl);
 if (err == -1)
  return 0;

 /* Following two steps are optional and not required for
   data exchange to be successful. */

 /* Get the cipher - opt */

 /* Get server's certificate (note: beware of dynamic allocation) - opt
*/


 X509 *server_cert = SSL_get_peer_certificate (ssl);
 if (server_cert == NULL)
  return 0;

 char *str = X509_NAME_oneline (X509_get_subject_name
(server_cert),0,0);
 if (str == NULL)
  return 0;
 Free (str);

 str = X509_NAME_oneline (X509_get_issuer_name  (server_cert),0,0);
 if (str == NULL)
  return 0;
 Free (str);


  /* We could do all sorts of certificate verification stuff here before

     deallocating the certificate. */

 X509_free (server_cert);


#define POST_LEN 500

 char *post_arg;
 post_arg = new char[POST_LEN];

 
sprintf(post_arg,"step=3911468&direct=TRUE&login=%s&passwd=%s&amount=%s&numfaccli=%s&cardtype=%s&cardnumber=%s&expmonth=%s&expyear=%s&firstname=%s&lastname=%s&addr=%s&zip=%s&email=%s&testmode=%s&tratype=%s&authcode=%s",

     m_login,m_passwrd,m_amount,m_numfaccli,
     m_cardtype,m_cardnumber,m_expmonth,
     m_expyear,m_firstname,m_lastname,
     m_addr,m_zip,m_email,m_testmode,
     m_tratype,m_authcode);

 char buff[4096];

 sprintf(buff,"POST %s HTTP/1.0\r\nAccept: */*\r\nContent-Type:
application/x-www-form-urlencoded\r\nContent-Length: %d\r\nConnection:
Keep-Alive\r\n\r\n%s\r\n",m_server_path,strlen(post_arg),post_arg);

 err = SSL_write (ssl, buff, strlen(buff));
 if (err == -1)
 {
  closesocket(hSocket);
  return 0;
 }

 char rec_buff[4096];
 memset(rec_buff, 0, sizeof(rec_buff));

   err = SSL_read (ssl, rec_buff, 4096 -1);
 if (err == -1)
 {
  closesocket(hSocket);
  return 0;
 }


 SSL_shutdown (ssl);  /* send SSL/TLS close_notify */

 /* Clean up. */

 SSL_free (ssl);
 SSL_CTX_free (ctx);

 closesocket(hSocket);
 WSACleanup();

 return S_OK;


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to