资源简介

OpenSSL+VC6.0 实现的安全Web Server,客户端和服务器都有当然OpenSSL库在VC中的配置,要自己配置好,也就是include file 和library file路径自己配置好

资源截图

代码片段和文件信息

// SSLServer.cpp: implementation of the CSSLServer class.
//
//////////////////////////////////////////////////////////////////////

#include “SSLServer.h“
#include 
using namespace std;

#define BUFSIZZ 1024
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
char CSSLServer::pass[1024] = {0};
// 格林威治时间的星期转换
char *week[] = {
“Sun“  
“Mon“
“Tue“
“Wed“
“Thu“
“Fri“
“Sat“
};

// 格林威治时间的月份转换
char *month[] = 
{
“Jan“  
“Feb“
“Mar“
“Apr“
“May“
“Jun“
“Jul“
“Aug“
“Sep“
“Oct“
“Nov“
“Dec“
};

CSSLServer::CSSLServer()
{
m_bRunning = false;
m_socket = NULL;
m_TmpSocket = NULL;
m_nPort = 8000;
m_keyfile = ““;
m_dhfile = ““;
m_ca_list = ““;
m_ctx = NULL;
m_ListenThread = NULL;
m_RootDir = “F:\\code\\VC6.0\\SSL\\Web Server Root Directory“;
CreateTypeMap();
}

CSSLServer::~CSSLServer()
{
if (m_socket != NULL)
{
closesocket(m_socket);
m_socket = NULL;
}

if (m_ctx != NULL)
{
SSL_CTX_free(m_ctx);
m_ctx = NULL;
}
}

DWORD WINAPI CSSLServer::ListenThread(LPVOID lpParameter)
{
CSSLServer *pInfo = (CSSLServer*)lpParameter;
SOCKET SocketClient;
SOCKADDR_IN SockAddr;
int nLen = sizeof(SOCKADDR_IN);

for (;;)
{
SocketClient = accept(pInfo->m_socket (LPSOCKADDR)&SockAddr &nLen);
if (INVALID_SOCKET == SocketClient)
{
cout << “ERROR: accepted a invalid socket“ < break;
}

//print the Client connect information
cout << inet_ntoa(SockAddr.sin_addr) << “ connected Socket=“ << (int)SocketClient << endl;
pInfo->m_TmpSocket = SocketClient;

HANDLE ThreadHandle;
ThreadHandle = ::CreateThread(NULL 0 ClientThread (LPVOID)pInfo 0 NULL);
::CloseHandle(ThreadHandle);
}

return 0;
}

DWORD WINAPI CSSLServer::ClientThread(LPVOID lpParameter)
{
SSL *ssl;
BIO *sbio;
CSSLServer *pClientInfo = (CSSLServer*)lpParameter;
SOCKET sock = pClientInfo->m_TmpSocket;
sbio = BIO_new_socket(sock BIO_NOCLOSE);
ssl = SSL_new(pClientInfo->m_ctx);
SSL_set_bio(ssl sbio sbio);
if (SSL_accept(ssl) <= 0)
{
cout << “SSL accept error“ << endl;
}
else
{
pClientInfo->http_serve(sslsock);
}

cout << “Socket=“ << (int)sock << “ exit the server“ << endl;
return 0;
}

int CSSLServer::http_serve(SSL *ssl SOCKET s)
{
char buf[BUFSIZZ] = {0};
    int rlen;
    BIO *io*ssl_bio;
ULONG errocode = 0;
    
    io=BIO_new(BIO_f_buffer());
    ssl_bio=BIO_new(BIO_f_ssl());
    BIO_set_ssl(ssl_biosslBIO_CLOSE);
    BIO_push(iossl_bio);
    
    while(1)
{
      r=BIO_gets(iobufBUFSIZZ-1);

  int nR = SSL_get_error(sslr);
      switch(nR)
  {
  case SSL_ERROR_NONE:
          len=r;
          break;
  default:
          cout << “SSL read problem“ << endl;
  errocode = ERR_peek_last_error(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1257  2010-04-29 10:40  SSL\ca.crt

     文件        963  2010-04-29 09:20  SSL\ca.key

     文件        245  2002-01-11 00:08  SSL\dh1024.pem

     文件        802  2002-01-11 00:08  SSL\root.pem

     文件       3200  2010-04-29 10:45  SSL\server.crt

     文件        688  2010-04-29 09:16  SSL\server.csr

     文件        963  2010-04-29 10:41  SSL\server.key

     文件       1749  2002-01-11 00:08  SSL\server.pem

     文件       2171  2010-04-29 10:48  SSL\SSL.CPP

     文件       4372  2010-04-25 19:37  SSL\SSL.dsp

     文件        529  2010-04-24 23:30  SSL\SSL.dsw

     文件      58368  2010-04-29 14:20  SSL\SSL.ncb

     文件      54784  2010-04-29 14:20  SSL\SSL.opt

     文件      20248  2010-04-29 10:48  SSL\SSL.plg

     文件      14400  2010-04-29 09:42  SSL\SSLServer.cpp

     文件       2466  2010-04-29 09:42  SSL\SSLServer.h

     文件       4216  2007-06-27 15:23  SSL\Web Server Root Directory\index.files\airpcap.gif

     文件       5431  2007-06-27 15:23  SSL\Web Server Root Directory\index.files\cace_logo.gif

     文件        904  2007-06-27 15:23  SSL\Web Server Root Directory\index.files\curve.gif

     文件        905  2007-06-27 15:24  SSL\Web Server Root Directory\index.files\curvedown.gif

     文件        435  2007-06-27 15:23  SSL\Web Server Root Directory\index.files\New.gif

     文件       1919  2007-06-27 16:07  SSL\Web Server Root Directory\index.files\winpcap.css

     文件      12225  2007-06-27 16:07  SSL\Web Server Root Directory\index.html

     文件       1745  2002-01-11 00:08  SSLClient\client.pem

     文件        245  2002-01-11 00:08  SSLClient\dh1024.pem

     文件        802  2002-01-11 00:08  SSLClient\root.pem

     文件       1749  2002-01-11 00:08  SSLClient\server.pem

     文件       6476  2010-04-28 23:27  SSLClient\SSLClient.cpp

     文件       4320  2010-04-23 20:27  SSLClient\SSLClient.dsp

     文件        541  2010-04-23 20:20  SSLClient\SSLClient.dsw

............此处省略11个文件信息

评论

共有 条评论