📄 pgppassphrasedialog.cpp
字号:
case WM_COMMAND:
{
gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);
options = (CPGPSigningPassphraseDialogOptions *)
gpp->options;
switch (LOWORD (wParam))
{
case IDOK:
{
int ComboSelection;
FreePassphrases(gpp);
ComboSelection = SendDlgItemMessage (hDlg, IDC_SIGNKEYCOMBO,
CB_GETCURSEL, 0, 0);
if (ComboSelection == CB_ERR)
{
PGPsdkUIMessageBox (hDlg,
IDS_PGPERROR, IDS_NOSIGNKEY,
MB_OK | MB_ICONEXCLAMATION);
break;
}
i = SendDlgItemMessage (hDlg, IDC_PHRASE1,
WM_GETTEXTLENGTH, 0, 0) +1;
gpp->szDummy = (char *)secAlloc (gpp->context, i);
if(gpp->szDummy)
{
gpp->pszPassPhrase = (char *)secAlloc (gpp->context, i);
if (gpp->pszPassPhrase)
{
PGPKeyRef key;
PGPError err;
PGPBoolean bShared;
GetDlgItemText (hDlg, IDC_PHRASE1, gpp->szDummy, i);
key = (PGPKeyRef)SendDlgItemMessage (hDlg,
IDC_SIGNKEYCOMBO, CB_GETITEMDATA, ComboSelection, 0);
err=PGPGetKeyBoolean( key, kPGPKeyPropIsSecretShared, &bShared);
if(IsntPGPError(err) && bShared)
{
// So, they want to do a shared key....
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
*(options->mPassphraseKeyPtr) = key;
EndDialog (hDlg, kPGPError_KeyUnusableForSignature);
break;
}
if(PassphraseLengthAndQualityOK(hDlg,options,gpp->pszPassPhrase))
{
if (!options->mVerifyPassphrase)
{
ClearPassphrases(hDlg,gpp);
SaveOptionSettings(gpp->hwndOptionsControl);
EndDialog (hDlg, kPGPError_NoErr);
break;
}
err=ValidateSigningPhrase(hDlg,gpp,gpp->pszPassPhrase,key);
if(IsntPGPError(err))
{
ClearPassphrases(hDlg,gpp);
SaveOptionSettings(gpp->hwndOptionsControl);
EndDialog (hDlg, kPGPError_NoErr);
break;
}
}
// Bad passphrase/quality
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
break;
}
}
// Couldn't allocate passphrases
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
EndDialog (hDlg, kPGPError_OutOfMemory);
break;
}
case IDC_SIGNKEYCOMBO :
{
if(HIWORD(wParam)==CBN_SELCHANGE)
EnablePassPhraseControl (hDlg);
break;
}
}
}
break;
}
return FALSE;
}
// Signer combo box
PGPError
pgpSigningPassphraseDialogPlatform(
PGPContextRef context,
CPGPSigningPassphraseDialogOptions *options)
{
// check for UI option if not set the assume Graphical
// else use command line UI
if (options->mTextUI) {
return pgpSigningPassphraseCL(context, options);
} else {
PGPError err;
GPP gpp;
memset(&gpp,0x00,sizeof(GPP));
gpp.context=context;
gpp.options=options;
InitRandomKeyHook(&hhookKeyboard, &hhookMouse);
InstallSecurityHooks();
err = DialogBoxParam(gPGPsdkUILibInst,
MAKEINTRESOURCE (IDD_PASSPHRASEOPTIONS),
options->mHwndParent,
(DLGPROC)pgpSigningPassphraseDlgProc,
(LPARAM)&gpp);
*(options->mPassphrasePtr)=gpp.pszPassPhrase;
UninstallSecurityHooks();
UninitRandomKeyHook(hhookKeyboard, hhookMouse);
return(err);
}
}
// ________________________
//
// Dialog Message procedure
BOOL CALLBACK
pgpConfirmationDlgProc (
HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
CPGPConfirmationPassphraseDialogOptions *options;
GPP *gpp;
INT i;
DWORD Common;
Common=DoCommonCalls (hDlg,uMsg,wParam,lParam);
if(Common)
return Common;
switch (uMsg)
{
case WM_INITDIALOG:
{
gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);
options = (CPGPConfirmationPassphraseDialogOptions *)
gpp->options;
gpp->iNextTabControl = IDC_PHRASE2;
gpp->hwndQuality = GetDlgItem (hDlg, IDC_PHRASEQUALITY);
gpp->hwndMinQuality = GetDlgItem (hDlg, IDC_MINQUALITY);
gpp->wpOrigPhrase1Proc = (WNDPROC) SetWindowLong (
GetDlgItem (hDlg, IDC_PHRASE1),
GWL_WNDPROC,
(LONG) PhraseSubclassProc);
gpp->wpOrigPhrase2Proc = (WNDPROC) SetWindowLong (
GetDlgItem (hDlg, IDC_PHRASE2),
GWL_WNDPROC,
(LONG) PhraseConfirmSubclassProc);
gpp->hwndOptionsControl=DisplayOptions(hDlg,options->mDialogOptions,215);
// If we aren't showing quality, don't show either bar
if(!options->mShowPassphraseQuality)
{
EnableWindow (GetDlgItem (hDlg, IDC_STATICPASSQUAL), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_STATICPASSQUAL), SW_HIDE);
EnableWindow (GetDlgItem (hDlg, IDC_STATICMINQUAL), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_STATICMINQUAL), SW_HIDE);
EnableWindow (GetDlgItem (hDlg, IDC_MINQUALITY), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_MINQUALITY), SW_HIDE);
EnableWindow (GetDlgItem (hDlg, IDC_PHRASEQUALITY), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_PHRASEQUALITY), SW_HIDE);
}
// If we don't give a min quality, don't show bar
if(options->mMinPassphraseQuality==0)
{
EnableWindow (GetDlgItem (hDlg, IDC_STATICMINQUAL), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_STATICMINQUAL), SW_HIDE);
EnableWindow (GetDlgItem (hDlg, IDC_MINQUALITY), FALSE);
ShowWindow (GetDlgItem (hDlg, IDC_MINQUALITY), SW_HIDE);
}
// Set our min quality benchmark
SendMessage (gpp->hwndMinQuality, PBM_SETPOS,
options->mMinPassphraseQuality, 0);
// Disable OK till we get a good passphrase if mins are active
if(options->mMinPassphraseQuality!=0)
// (options->mMinPassphraseLength!=0))
EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
return FALSE;
}
case WM_COMMAND:
{
gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);
options = (CPGPConfirmationPassphraseDialogOptions *)
gpp->options;
switch(LOWORD (wParam))
{
case IDOK:
{
FreePassphrases(gpp);
// get passphrase
i = SendDlgItemMessage (hDlg, IDC_PHRASE1,
WM_GETTEXTLENGTH, 0, 0) +1;
gpp->szDummy = (char *)secAlloc (gpp->context, i);
if(gpp->szDummy)
{
gpp->pszPassPhrase = (char *)secAlloc (gpp->context, i);
if (gpp->pszPassPhrase)
{
GetDlgItemText (hDlg, IDC_PHRASE1, gpp->szDummy, i);
// get passphrase confirmation
i = SendDlgItemMessage (hDlg, IDC_PHRASE2,
WM_GETTEXTLENGTH, 0, 0) +1;
gpp->pszPassPhraseConf = (char *)secAlloc (gpp->context, i);
if (gpp->pszPassPhraseConf)
{
GetDlgItemText (hDlg, IDC_PHRASE2, gpp->szDummy, i);
if(PassphraseLengthAndQualityOK(hDlg,options,gpp->pszPassPhrase))
{
if (!lstrcmp (gpp->pszPassPhrase, gpp->pszPassPhraseConf))
{
ClearPassphrases(hDlg,gpp);
if(gpp->pszPassPhraseConf)
{
secFree(gpp->pszPassPhraseConf);
gpp->pszPassPhraseConf=NULL;
}
SaveOptionSettings(gpp->hwndOptionsControl);
EndDialog (hDlg, kPGPError_NoErr);
break;
}
else
{
PGPsdkUIMessageBox (hDlg, IDS_PGPERROR,
IDS_PHRASEMISMATCH, MB_OK|MB_ICONEXCLAMATION);
}
}
// Badpassphrase/quality
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
SendMessage (gpp->hwndQuality, PBM_SETPOS, 0, 0);
if(options->mMinPassphraseQuality!=0)
EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
break;
}
}
}
// Couldn't allocate passphrases
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
EndDialog (hDlg, kPGPError_OutOfMemory);
break;
}
}
break;
}
}
return FALSE;
}
// Double edit window
PGPError
pgpConfirmationPassphraseDialogPlatform(
PGPContextRef context,
CPGPConfirmationPassphraseDialogOptions *options)
{
PGPError err;
GPP gpp;
memset(&gpp,0x00,sizeof(GPP));
gpp.context=context;
gpp.options=options;
InitRandomKeyHook(&hhookKeyboard, &hhookMouse);
InstallSecurityHooks();
err = DialogBoxParam (gPGPsdkUILibInst,
MAKEINTRESOURCE (IDD_PASSPHRASEENCRYPT),
options->mHwndParent,
(DLGPROC)pgpConfirmationDlgProc, (LPARAM)&gpp);
*(options->mPassphrasePtr)=gpp.pszPassPhrase;
UninstallSecurityHooks();
UninitRandomKeyHook(hhookKeyboard, hhookMouse);
return(err);
}
// _________________________________________________________
//
// Dialog Message procedure - get passphrase and signing key
BOOL CALLBACK
pgpKeyPassphraseDlgProc (
HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
CPGPKeyPassphraseDialogOptions *options;
GPP *gpp;
INT i;
DWORD Common;
Common=DoCommonCalls (hDlg,uMsg,wParam,lParam);
if(Common)
return Common;
switch (uMsg)
{
case WM_INITDIALOG:
{
RECT rc;
int iTextWidth;
HDC hdc;
char szNameFinal[kPGPMaxUserIDSize];
gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);
options = (CPGPKeyPassphraseDialogOptions *)
gpp->options;
gpp->iNextTabControl = IDOK;
gpp->wpOrigPhrase1Proc = (WNDPROC) SetWindowLong(
GetDlgItem(hDlg, IDC_PHRASE1),
GWL_WNDPROC,
(LONG) PhraseSubclassProc);
GetClientRect(GetDlgItem(hDlg,IDC_KEYNAME), &rc);
iTextWidth = rc.right-rc.left;
hdc = GetDC (GetDlgItem(hDlg,IDC_KEYNAME));
GetKeyString(hdc,iTextWidth,options->mDefaultKey,szNameFinal);
SetWindowText(GetDlgItem(hDlg,IDC_KEYNAME),szNameFinal);
ReleaseDC (GetDlgItem (hDlg, IDC_KEYNAME), hdc);
gpp->hwndOptionsControl=DisplayOptions(hDlg,options->mDialogOptions,130);
return FALSE;
}
case WM_COMMAND:
{
gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);
options = (CPGPKeyPassphraseDialogOptions *)
gpp->options;
switch (LOWORD (wParam))
{
case IDOK:
{
PGPBoolean PassValid;
FreePassphrases(gpp);
i = SendDlgItemMessage (hDlg, IDC_PHRASE1,
WM_GETTEXTLENGTH, 0, 0) +1;
gpp->szDummy = (char *)secAlloc (gpp->context, i);
if(gpp->szDummy)
{
gpp->pszPassPhrase = (char *)secAlloc (gpp->context, i);
if (gpp->pszPassPhrase)
{
GetDlgItemText (hDlg, IDC_PHRASE1, gpp->szDummy, i);
if(PassphraseLengthAndQualityOK(hDlg,options,gpp->pszPassPhrase))
{
if(!options->mVerifyPassphrase)
{
ClearPassphrases(hDlg,gpp);
SaveOptionSettings(gpp->hwndOptionsControl);
EndDialog (hDlg, kPGPError_NoErr);
break;
}
PassValid=PGPPassphraseIsValid (options->mDefaultKey,
PGPOPassphrase (gpp->context, gpp->pszPassPhrase),
PGPOLastOption (gpp->context));
if(PassValid)
{
ClearPassphrases(hDlg,gpp);
SaveOptionSettings(gpp->hwndOptionsControl);
EndDialog (hDlg, kPGPError_NoErr);
break;
}
else
{
PGPsdkUIMessageBox (hDlg,
IDS_PGPERROR,IDS_BADPASSREENTER,
MB_OK|MB_ICONSTOP);
}
}
// Bad passphrase/quality
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
break;
}
}
// Couldn't allocate passphrases
ClearPassphrases(hDlg,gpp);
FreePassphrases(gpp);
EndDialog (hDlg, kPGPError_OutOfMemory);
break;
}
}
}
break;
}
return FALSE;
}
PGPError
pgpKeyPassphraseDialogPlatform(
PGPContextRef context,
CPGPKeyPassphraseDialogOptions *options)
{
PGPError err;
PGPBoolean bShared,bNeedsPhrase;
err=PGPGetKeyBoolean( options->mDefaultKey,
kPGPKeyPropIsSecretShared,
&bShared);
if(IsntPGPError(err) && bShared)
{
// So, they want to do a shared key....
return(kPGPError_KeyUnusableForSignature);
}
err=PGPGetKeyBoolean (options->mDefaultKey,
kPGPKeyPropNeedsPassphrase,
&bNeedsPhrase);
if(IsntPGPError(err) && !bNeedsPhrase)
{
*(options->mPassphrasePtr)=(char *)secAlloc (context, 1);
if(*(options->mPassphrasePtr)==0)
return(kPGPError_OutOfMemory);
// Doesn't need a passphrase
strcpy(*(options->mPassphrasePtr),"");
return(kPGPError_NoErr);
}
if (options->mTextUI) {
return pgpKeyPassphraseCL(context, options);
} else {
GPP gpp;
memset(&gpp,0x00,sizeof(GPP));
gpp.context=context;
gpp.options=options;
InitRandomKeyHook(&hhookKeyboard, &hhookMouse);
InstallSecurityHooks();
err = DialogBoxParam (gPGPsdkUILibInst,
MAKEINTRESOURCE (IDD_KEYPASSPHRASE),
options->mHwndParent,
(DLGPROC)pgpKeyPassphraseDlgProc, (LPARAM)&gpp);
*(options->mPassphrasePtr)=gpp.pszPassPhrase;
UninstallSecurityHooks();
UninitRandomKeyHook(hhookKeyboard, hhookMouse);
return(err);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -