⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssl.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/Ssl.cpp,v $
 * $Date: 2003/05/31 12:20:44 $
 *
 Description:

\*____________________________________________________________________________*/
/* $SourceTop:$ */

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <stdio.h>

#include "PICompat.h"
#include "PIString.h"

#include "resrc1.h"
#include "Common.h"
#include "Dialogs.h"

/*____________________________________________________________________________*\
 *
 Description:
	Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndPort = 0;
static HWND hWndURL = 0;
static HWND hWndSsl = 0;
static HWND hWndSsl2 = 0;
static HWND hWndSsl3 = 0;
static HWND hWndTls1 = 0;
static HWND hWndDebug = 0;
static HWND hWndPkFile = 0;
static HWND hWndCertFile = 0;
static HWND hWndVal0 = 0;
static HWND hWndVal1 = 0;
static HWND hWndVal2 = 0;
static HWND hWndDepth = 0;
static HWND hWndBug = 0;
static HWND hWndHack = 0;
static HWND hWndCaCertPath = 0;
static HWND hWndCaCertFile = 0;
static HWND hWndCiphers = 0;
static HWND hWndKeygen = 0;
static int __iValidation = 0;

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_updateSSL( int iSSL )
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	*szBuf = '\0';
	SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );

	if ( iSSL )
		{
		AD_replaceValue( __pConfig, "Internal", "URLProtocol", "https://" );
		AD_replaceValue( __pConfig, "Internal", "DefaultPort", "443" );
		if (!stricmp(szBuf, "80")) {
			SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"443");
			};
		EnableWindow( hWndSsl2, TRUE ); EnableWindow( hWndSsl3, TRUE );
		EnableWindow( hWndTls1, TRUE ); EnableWindow( hWndDebug, TRUE );
		EnableWindow( hWndPkFile, TRUE ); EnableWindow( hWndCertFile, TRUE );
		EnableWindow( hWndVal0, TRUE ); EnableWindow( hWndVal1, TRUE );
		EnableWindow( hWndVal2, TRUE ); EnableWindow( hWndDepth, TRUE );
		EnableWindow( hWndCaCertPath, TRUE ); EnableWindow( hWndCaCertFile, TRUE );
		EnableWindow( hWndBug, TRUE ); EnableWindow( hWndHack, TRUE );
		EnableWindow( hWndCiphers, TRUE );
		EnableWindow( hWndKeygen,
			::SendMessage( hWndPkFile, EM_LINELENGTH, 0, 0 ) &&
			::SendMessage( hWndCertFile, EM_LINELENGTH, 0, 0 )
			);
		}
	else
		{
		AD_replaceValue( __pConfig, "Internal", "URLProtocol", "http://" );
		AD_replaceValue( __pConfig, "Internal", "DefaultPort", "80" );
		if (!stricmp(szBuf, "443")) {
			SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"80");
			};
		EnableWindow( hWndSsl2, FALSE ); EnableWindow( hWndSsl3, FALSE );
		EnableWindow( hWndTls1, FALSE ); EnableWindow( hWndDebug, FALSE );
		EnableWindow( hWndPkFile, FALSE ); EnableWindow( hWndCertFile, FALSE );
		EnableWindow( hWndVal0, FALSE ); EnableWindow( hWndVal1, FALSE );
		EnableWindow( hWndVal2, FALSE ); EnableWindow( hWndDepth, FALSE );
		EnableWindow( hWndCaCertPath, FALSE ); EnableWindow( hWndCaCertFile, FALSE );
		EnableWindow( hWndBug, FALSE ); EnableWindow( hWndHack, FALSE );
		EnableWindow( hWndCiphers, FALSE ); EnableWindow( hWndKeygen, FALSE );
		};
}


/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_updateURL( HWND hDlg )
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	/* --- Get current value --- */
	assert( AD_lookupValue( __pConfig, "Internal", "URLProtocol" ) );
	strcpy( szBuf, AD_lookupValue( __pConfig, "Internal", "URLProtocol" ) );
	int iLen = strlen( szBuf );
	assert( AD_lookupValue( __pConfig, "General", "Host" ) );
	strcpy( &szBuf[iLen], AD_lookupValue( __pConfig, "General", "Host" ) );
	iLen = strlen( szBuf );
	szBuf[iLen++] = ':';
	SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE-iLen, (LPARAM)&(szBuf[iLen]) );
	assert( AD_lookupValue( __pConfig, "Internal", "DefaultPort" ) );
	if ( atoi( &(szBuf[iLen]) )==atoi(AD_lookupValue( __pConfig, "Internal", 
			"DefaultPort" )) )
		{ szBuf[--iLen] = '\0'; };

	/* --- now update the URL --- */
	SendMessage( hWndURL, WM_SETTEXT, 0, (LPARAM)szBuf );
	
	/* --- mark property sheet as modified --- */
	AD_Changed( hDlg );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
	LPARAM lParam)
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	switch (uMsg)
		{
		case WM_INITDIALOG:
			{
			hWndPort = GetDlgItem( hDlg, IDC_PORT );
			hWndURL = GetDlgItem( hDlg, IDC_URL );
			hWndSsl = GetDlgItem( hDlg, IDC_SSL );
			hWndSsl2 = GetDlgItem( hDlg, IDC_SSL2 );
			hWndSsl3 = GetDlgItem( hDlg, IDC_SSL3 );
			hWndTls1 = GetDlgItem( hDlg, IDC_TLS1 );
			hWndDebug = GetDlgItem( hDlg, IDC_DEBUG );
			hWndPkFile = GetDlgItem( hDlg, IDC_PKEYFILE );
			hWndCertFile = GetDlgItem( hDlg, IDC_CERTFILE );
			hWndVal0 = GetDlgItem( hDlg, IDC_NONE );
			hWndVal1 = GetDlgItem( hDlg, IDC_OPTIONAL );
			hWndVal2 = GetDlgItem( hDlg, IDC_MANDATORY );
			hWndDepth = GetDlgItem( hDlg, IDC_DEPTH );
			hWndBug = GetDlgItem( hDlg, IDC_MSIEBUG );
			hWndHack = GetDlgItem( hDlg, IDC_HACK );
			hWndCaCertPath = GetDlgItem( hDlg, IDC_CAPATH );
			hWndCaCertFile = GetDlgItem( hDlg, IDC_CAFILE );
			hWndCiphers = GetDlgItem( hDlg, IDC_CIPHERS );
			hWndKeygen = GetDlgItem( hDlg, IDC_NEW );

			assert( hWndPort && hWndSsl && hWndURL );
			assert( hWndSsl2 && hWndSsl3 && hWndTls1 );
			assert( hWndDebug && hWndPkFile && hWndCertFile );
			assert( hWndDepth && hWndVal0 && hWndVal1 && hWndVal2 );
			assert( hWndCaCertPath && hWndCaCertFile && hWndCiphers );
			assert( hWndBug && hWndHack && hWndKeygen );

			::SendMessage( hWndSsl, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndSsl2, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndSsl3, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndTls1, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndDebug, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndBug, BM_SETCHECK, BST_UNCHECKED, 0 );
			::SendMessage( hWndHack, BM_SETCHECK, BST_UNCHECKED, 0 );

			/* --- just for sanity --- */
			::SendMessage( hWndPort, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndPkFile, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndCertFile, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndDepth, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndCaCertPath, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndCaCertFile, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndCiphers, EM_SETLIMITTEXT, 256, 0 );

			/* --- SSL, Port and URL --- */
			// are set in PSN_SETACTIVE handler

			/* --- SSL version and options --- */
			int i = atoi(AD_lookupValue( __pConfig, "SSL", "Options" ));
			::SendMessage( hWndSsl2, BM_SETCHECK, (WPARAM)(i & 1), 0 );
			::SendMessage( hWndSsl3, BM_SETCHECK, (WPARAM)(i & 2), 0 );
			::SendMessage( hWndTls1, BM_SETCHECK, (WPARAM)(i & 4), 0 );
			::SendMessage( hWndDebug, BM_SETCHECK, (WPARAM)(i & 8), 0 );
			::SendMessage( hWndBug, BM_SETCHECK, (WPARAM)(i & 16), 0 );
			::SendMessage( hWndHack, BM_SETCHECK, (WPARAM)(i & 32), 0 );

			/* server Private Key and Certificate file path --- */
			const char *pVal = AD_lookupValue( __pConfig, "SSL", "PKeyFile" );
			::SendMessage( hWndPkFile, WM_SETTEXT, 0, (LPARAM)pVal );
			pVal = AD_lookupValue( __pConfig, "SSL", "CertFile" );
			::SendMessage( hWndCertFile, WM_SETTEXT, 0, (LPARAM)pVal );

			/* --- User cert validation --- */
			__iValidation = atoi(AD_lookupValue( __pConfig, "SSL", "Validation" ));
			::SendMessage( hWndVal0, BM_SETCHECK, (WPARAM)(__iValidation==0), 0 );
			::SendMessage( hWndVal1, BM_SETCHECK, (WPARAM)(__iValidation==1), 0 );
			::SendMessage( hWndVal2, BM_SETCHECK, (WPARAM)(__iValidation==2), 0 );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -