📄 ssl.cpp
字号:
iLen = strlen( szBuf );
szBuf[iLen++] = ':';
SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE-iLen, (LPARAM)&(szBuf[iLen]) );
assert( M_LookupValue( pConfig, "Internal", "DefaultPort" ) );
if ( atoi( &(szBuf[iLen]) )==atoi(M_LookupValue( pConfig, "Internal",
"DefaultPort" )) )
{ szBuf[--iLen] = '\0'; };
/* --- now update the URL --- */
SendMessage( hWndURL, WM_SETTEXT, 0, (LPARAM)szBuf );
/* --- mark property sheet as modified --- */
Changed( hDlg );
}
BOOL 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 );
assert( hWndPort && hWndSsl && hWndURL );
assert( hWndSsl2 && hWndSsl3 && hWndTls1 );
assert( hWndDebug && hWndPkFile && hWndCertFile );
assert( hWndDepth && hWndVal0 && hWndVal1 && hWndVal2 );
assert( hWndCaCertPath && hWndCaCertFile && hWndCiphers );
assert( hWndBug && hWndHack );
::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(M_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 = M_LookupValue( pConfig, "SSL", "PKeyFile" );
::SendMessage( hWndPkFile, WM_SETTEXT, 0, (LPARAM)pVal );
pVal = M_LookupValue( pConfig, "SSL", "CertFile" );
::SendMessage( hWndCertFile, WM_SETTEXT, 0, (LPARAM)pVal );
/* --- User cert validation --- */
__iValidation = atoi(M_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 );
/* --- validation depth, CA Certificate path and filename --- */
pVal = M_LookupValue( pConfig, "SSL", "Depth" );
::SendMessage( hWndDepth, WM_SETTEXT, 0, (LPARAM)pVal );
pVal = M_LookupValue( pConfig, "SSL", "CaCertPath" );
::SendMessage( hWndCaCertPath, WM_SETTEXT, 0, (LPARAM)pVal );
pVal = M_LookupValue( pConfig, "SSL", "CaCertFile" );
::SendMessage( hWndCaCertFile, WM_SETTEXT, 0, (LPARAM)pVal );
/* --- List of ciphers --- */
pVal = M_LookupValue( pConfig, "SSL", "Ciphers" );
::SendMessage( hWndCiphers, WM_SETTEXT, 0, (LPARAM)pVal );
Unchanged( hDlg );
};
break;
case WM_COMMAND:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
{
switch( GET_WM_COMMAND_ID( wParam, lParam) )
{
case IDC_SSL:
Internal_updateSSL( ::SendMessage( hWndSsl, BM_GETCHECK,
0, 0 ) == BST_CHECKED );
Internal_updateURL( hDlg );
break;
case IDC_SSL2:
case IDC_SSL3:
::SendMessage( hWndTls1, BM_SETCHECK, (FALSE), 0 );
break;
case IDC_TLS1:
::SendMessage( hWndSsl2, BM_SETCHECK, (FALSE), 0 );
::SendMessage( hWndSsl3, BM_SETCHECK, (FALSE), 0 );
break;
case IDC_NONE:
__iValidation = 0; break;
case IDC_OPTIONAL:
__iValidation = 1; break;
case IDC_MANDATORY:
__iValidation = 2; break;
default:;
};
/* --- mark property sheet as modified --- */
Changed( hDlg );
}
else if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
{
switch( GET_WM_COMMAND_ID( wParam, lParam) )
{
case IDC_PORT:
Internal_updateURL( hDlg );
break;
default:;
/* --- mark property sheet as modified --- */
Changed( hDlg );
};
};
break;
case WM_DESTROY:
break;
case WM_NOTIFY:
switch( ((NMHDR *)lParam)->code )
{
case PSN_SETACTIVE:
{
int iSaveChanged = IsChanged();
SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)
M_LookupValue( pConfig, "General", "Port" ) );
const char *pTest = M_LookupValue( pConfig, "Internal", \
"ServerIOObjectLine" );
SendMessage( hWndSsl, BM_SETCHECK, (WPARAM)strstr( pTest, "SSLIO" ), 0 );
Internal_updateSSL( ::SendMessage( hWndSsl, BM_GETCHECK,
0, 0 ) == BST_CHECKED );
Internal_updateURL( hDlg );
if ( !iSaveChanged ) { Unchanged( hDlg ); };
SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
return (TRUE);
}
case PSN_QUERYCANCEL:
return SHEET->Cancel(pInterface, hDlg);
case PSN_KILLACTIVE:
if ( IsChanged() )
{
*szBuf = 0;
SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
int iPort = atoi( szBuf );
if ( iPort<0 || iPort>65535 )
{
/*
** Give message and abort change
*/
MessageBox( hDlg, "Port must be in the range [0..65536]",
"Port Field Error", MB_OK );
SetFocus( hWndPort );
SendMessage( hWndPort, EM_SETSEL, 0, -1 );
SetWindowLong( hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
return (TRUE);
};
M_ReplaceValue( pConfig, "General", "Port", szBuf );
SendMessage( hWndURL, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "Identity", "URL", szBuf );
if ( ::SendMessage( hWndSsl, BM_GETCHECK, 0, 0 )==BST_CHECKED )
{
M_ReplaceValue( pConfig, "Internal", "ServerIOObjectLine", \
"\tIOObject SSLIOObject" );
}
else
{
M_ReplaceValue( pConfig, "Internal", "ServerIOObjectLine", \
"\tIOObject ServerIOObject" );
}
/* --- SSL version and options --- */
int iIdx = 0;
if ( ::SendMessage( hWndSsl2, BM_GETCHECK, 0, 0 )) { iIdx += 1; };
if ( ::SendMessage( hWndSsl3, BM_GETCHECK, 0, 0 )) { iIdx += 2; };
if ( ::SendMessage( hWndTls1, BM_GETCHECK, 0, 0 )) { iIdx += 4; };
if ( ::SendMessage( hWndDebug, BM_GETCHECK, 0, 0 )) { iIdx += 8; };
if ( ::SendMessage( hWndBug, BM_GETCHECK, 0, 0 )) { iIdx += 16; };
if ( ::SendMessage( hWndHack, BM_GETCHECK, 0, 0 )) { iIdx += 32; };
M_ReplaceValue( pConfig, "SSL", "Options", itoa( iIdx,szBuf,10 ));
/* server Private Key and Certificate file path --- */
*szBuf = 0;
::SendMessage( hWndPkFile, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "PKeyFile", szBuf );
*szBuf = 0;
::SendMessage( hWndCertFile, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "CertFile", szBuf );
/* --- User cert validation --- */
M_ReplaceValue( pConfig, "SSL", "Validation",
itoa( __iValidation,szBuf,10 ));
/* --- validation depth, CA Certificate path and filename --- */
*szBuf = 0;
::SendMessage( hWndDepth, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "Depth", szBuf );
*szBuf = 0;
::SendMessage( hWndCaCertPath, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "CaCertPath", szBuf );
*szBuf = 0;
::SendMessage( hWndCaCertFile, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "CaCertFile", szBuf );
/* --- List of ciphers --- */
*szBuf = 0;
::SendMessage( hWndCiphers, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
M_ReplaceValue( pConfig, "SSL", "Ciphers", szBuf );
}
SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
return (TRUE);
default:
return (FALSE);
};
break;
default:
return (FALSE);
};
return (TRUE);
}
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
if ( uMsg==WM_INITDIALOG )
{
::SetWindowLong( hDlg, DWL_USER, ((LPPROPSHEETPAGE)lParam)->lParam );
};
SslPage *pPage = (SslPage *)::GetWindowLong( hDlg, DWL_USER );
return pPage ? pPage->DialogProc( hDlg, uMsg, wParam, lParam ) : FALSE;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int SslPage_constructor( PIObject *pObj,
int iArgc, const char *ppArgv[] )
{
return IFaceBase_constructor( pObj, PI_NEW( SslPage( pObj,
iArgc, ppArgv ) ) );
}
#if 0
/*___+++CNF_BEGIN+++___*/
<Class>
Name SslPageClass
Type LogicExtension
Library IntrFace
OnClassLoad IFaceBase_onClassLoad
Constructor SslPage_constructor
CopyConstructor IFaceBase_copyConstructor
Destructor IFaceBase_destructor
Execute IFaceBase_execute
</Class>
<Object>
Name SslPage
Class SslPageClass
</Object>
/*___+++CNF_END+++___*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -