📄 keygen.c
字号:
LoadString(g_hInstance, IDS_TITLE, szTitle, 254);
LoadString(g_hInstance, IDS_E_MINEXPIRE, szErrMsg, 254);
SetWindowText(GetDlgItem(hwndDlg, IDC_EXPIREDAYS), "1");
MessageBox(hwndDlg, szErrMsg, szTitle, MB_ICONEXCLAMATION);
}
else
pConfig->keyExpiration = nValue;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
case IDC_RADIO_1024:
case IDC_RADIO_1536:
case IDC_RADIO_2048:
case IDC_RADIO_3072:
case IDC_RADIO_CUSTOM:
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_1024) == BST_CHECKED)
pConfig->nKeySize = 1024;
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_1536) == BST_CHECKED)
pConfig->nKeySize = 1536;
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_2048) == BST_CHECKED)
pConfig->nKeySize = 2048;
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_3072) == BST_CHECKED)
pConfig->nKeySize = 3072;
if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_CUSTOM) == BST_CHECKED)
{
GetWindowText(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS),
szKeySize, 10);
pConfig->nKeySize = atoi(szKeySize) - 1;
if (pConfig->nKeySize < 1024)
pConfig->nKeySize = 1025;
}
sInitGUI(hwndDlg, pConfig);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_CUSTOM_BITS:
GetWindowText(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), szKeySize,
10);
pConfig->nKeySize = atoi(szKeySize);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_KEYGENCERTREQ:
if (IsDlgButtonChecked(hwndDlg, IDC_KEYGENCERTREQ) == BST_CHECKED)
pConfig->bKeyGenCertRequest = TRUE;
else
pConfig->bKeyGenCertRequest = FALSE;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_ALLOWMANREQ:
if (IsDlgButtonChecked(hwndDlg, IDC_ALLOWMANREQ) == BST_CHECKED)
pConfig->bAllowManualCertRequest = TRUE;
else
pConfig->bAllowManualCertRequest = FALSE;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_AUTOSIGNCA:
if (IsDlgButtonChecked(hwndDlg, IDC_AUTOSIGNCA) == BST_CHECKED)
pConfig->bAutoSignRootCAKey = TRUE;
else
pConfig->bAutoSignRootCAKey = FALSE;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_ALWAYSSEND:
if (IsDlgButtonChecked(hwndDlg, IDC_ALWAYSSEND) == BST_CHECKED)
pConfig->bAlwaysSendKeys = TRUE;
else
pConfig->bAlwaysSendKeys = FALSE;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_AUTORECON:
if (IsDlgButtonChecked(hwndDlg, IDC_AUTORECON) == BST_CHECKED)
pConfig->bAutoKeyReconstruction = TRUE;
else
pConfig->bAutoKeyReconstruction = FALSE;
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_CATYPE:
switch (HIWORD(wParam))
{
case CBN_SELENDOK:
sSaveSelection(hwndDlg, pConfig);
sInitGUI(hwndDlg, pConfig);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
break;
case IDC_ADDATTRIBUTES:
sSaveSelection(hwndDlg, pConfig);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_RECONSERVER:
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
break;
default:
bReturnCode = CommonDlgProc(hwndDlg, uMsg, wParam, lParam);
break;
}
return(bReturnCode);
}
static void sInitGUI(HWND hwndDlg, pgpConfigInfo *pConfig)
{
char sz1536[255];
char sz2048[255];
char sz3072[255];
char szCustom[255];
if (pConfig->bAllowKeyGen)
CheckDlgButton(hwndDlg, IDC_ALLOW_KEYGEN, BST_CHECKED);
else
{
CheckDlgButton(hwndDlg, IDC_ALLOW_KEYGEN, BST_UNCHECKED);
pConfig->bSetKeyGen = FALSE;
}
EnableWindow(GetDlgItem(hwndDlg, IDC_SETKEYGEN), pConfig->bAllowKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_MISCGROUP), pConfig->bAllowKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_ALWAYSSEND), pConfig->bAllowKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_AUTORECON), pConfig->bAllowKeyGen);
if (pConfig->bSetKeyGen)
CheckDlgButton(hwndDlg, IDC_SETKEYGEN, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_SETKEYGEN, BST_UNCHECKED);
if (pConfig->bUseSmartCard)
CheckDlgButton(hwndDlg, IDC_SMARTCARD, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_SMARTCARD, BST_UNCHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_SMARTCARD), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_KEYTYPEGROUP), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_KEYEXPIREGROUP), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_KEYSIZEGROUP), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_ELGAMAL), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_RSA), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_RSALEGACY), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_NEVER), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_EXPIRES), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_EXPIRATIONDATE), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_1024), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_1536), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_2048), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_3072), pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_CUSTOM), pConfig->bSetKeyGen);
switch (pConfig->keyType)
{
case kPGPPublicKeyAlgorithm_DSA:
CheckDlgButton(hwndDlg, IDC_RADIO_ELGAMAL, BST_CHECKED);
ShowWindow(GetDlgItem(hwndDlg, IDC_RADIO_3072), SW_SHOW);
LoadString(g_hInstance, IDS_KG_DH1536, sz1536, 254);
LoadString(g_hInstance, IDS_KG_DH2048, sz2048, 254);
LoadString(g_hInstance, IDS_KG_DH3072, sz3072, 254);
LoadString(g_hInstance, IDS_KG_DHCUSTOM, szCustom, 254);
break;
case kPGPPublicKeyAlgorithm_RSASignOnly:
CheckDlgButton(hwndDlg, IDC_RADIO_RSA, BST_CHECKED);
ShowWindow(GetDlgItem(hwndDlg, IDC_RADIO_3072), SW_SHOW);
LoadString(g_hInstance, IDS_KG_RSA1536, sz1536, 254);
LoadString(g_hInstance, IDS_KG_RSA2048, sz2048, 254);
LoadString(g_hInstance, IDS_KG_RSA3072, sz3072, 254);
LoadString(g_hInstance, IDS_KG_DHCUSTOM, szCustom, 254);
break;
case kPGPPublicKeyAlgorithm_RSA:
CheckDlgButton(hwndDlg, IDC_RADIO_RSALEGACY, BST_CHECKED);
ShowWindow(GetDlgItem(hwndDlg, IDC_RADIO_3072), SW_HIDE);
LoadString(g_hInstance, IDS_KG_RSA1536, sz1536, 254);
LoadString(g_hInstance, IDS_KG_RSA2048, sz2048, 254);
LoadString(g_hInstance, IDS_KG_RSACUSTOM, szCustom, 254);
break;
}
SetWindowText(GetDlgItem(hwndDlg, IDC_RADIO_1536), sz1536);
SetWindowText(GetDlgItem(hwndDlg, IDC_RADIO_2048), sz2048);
SetWindowText(GetDlgItem(hwndDlg, IDC_RADIO_3072), sz3072);
SetWindowText(GetDlgItem(hwndDlg, IDC_RADIO_CUSTOM), szCustom);
if (pConfig->keyExpiration)
{
char szExpireDays[4];
wsprintf(szExpireDays, "%d", pConfig->keyExpiration / SECONDS_PER_DAY);
CheckDlgButton(hwndDlg, IDC_RADIO_EXPIRES, BST_CHECKED);
SetWindowText(GetDlgItem(hwndDlg, IDC_EXPIREDAYS), szExpireDays);
EnableWindow(GetDlgItem(hwndDlg, IDC_EXPIREDAYS),
pConfig->bSetKeyGen);
EnableWindow(GetDlgItem(hwndDlg, IDC_EXPIRESPIN),
pConfig->bSetKeyGen);
}
else
{
CheckDlgButton(hwndDlg, IDC_RADIO_NEVER, BST_CHECKED);
SetWindowText(GetDlgItem(hwndDlg, IDC_EXPIREDAYS), "0");
EnableWindow(GetDlgItem(hwndDlg, IDC_EXPIREDAYS), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EXPIRESPIN), FALSE);
}
CheckDlgButton(hwndDlg, IDC_RADIO_1024, BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_RADIO_1536, BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_RADIO_2048, BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_RADIO_3072, BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_RADIO_CUSTOM, BST_UNCHECKED);
switch (pConfig->nKeySize)
{
case 1024:
CheckDlgButton(hwndDlg, IDC_RADIO_1024, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), FALSE);
break;
case 1536:
CheckDlgButton(hwndDlg, IDC_RADIO_1536, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), FALSE);
break;
case 2048:
CheckDlgButton(hwndDlg, IDC_RADIO_2048, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), FALSE);
break;
case 3072:
CheckDlgButton(hwndDlg, IDC_RADIO_3072, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), FALSE);
break;
default:
CheckDlgButton(hwndDlg, IDC_RADIO_CUSTOM, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS),
pConfig->bSetKeyGen);
break;
}
wsprintf(szCustom, "%d", pConfig->nKeySize);
SetWindowText(GetDlgItem(hwndDlg, IDC_CUSTOM_BITS), szCustom);
if (pConfig->bKeyGenCertRequest)
CheckDlgButton(hwndDlg, IDC_KEYGENCERTREQ, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_KEYGENCERTREQ, BST_UNCHECKED);
if (pConfig->bAllowManualCertRequest)
CheckDlgButton(hwndDlg, IDC_ALLOWMANREQ, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_ALLOWMANREQ, BST_UNCHECKED);
if (pConfig->bAutoSignRootCAKey)
CheckDlgButton(hwndDlg, IDC_AUTOSIGNCA, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_AUTOSIGNCA, BST_UNCHECKED);
if (pConfig->bAlwaysSendKeys)
CheckDlgButton(hwndDlg, IDC_ALWAYSSEND, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_ALWAYSSEND, BST_UNCHECKED);
if (pConfig->bAutoKeyReconstruction)
CheckDlgButton(hwndDlg, IDC_AUTORECON, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_AUTORECON, BST_UNCHECKED);
if (pConfig->nCAType == kPGPKeyServerClass_Invalid)
EnableWindow(GetDlgItem(hwndDlg, IDC_ADDATTRIBUTES), FALSE);
else
EnableWindow(GetDlgItem(hwndDlg, IDC_ADDATTRIBUTES), TRUE);
if (pConfig->szReconServer != NULL)
SetWindowText(GetDlgItem(hwndDlg, IDC_RECONSERVER),
pConfig->szReconServer);
else
SetWindowText(GetDlgItem(hwndDlg, IDC_RECONSERVER), "");
return;
}
static void sSaveSelection(HWND hwndDlg, pgpConfigInfo *pConfig)
{
int nIndex;
PGPAttributeValue *pAVList = NULL;
PGPUInt32 nNumAVs = 0;
PGPError err = kPGPError_NoErr;
nIndex = SendDlgItemMessage(hwndDlg, IDC_CATYPE, CB_GETCURSEL, 0, 0);
pConfig->nOldCAType = pConfig->nCAType;
pConfig->nCAType = (PGPKeyServerClass) SendDlgItemMessage(hwndDlg,
IDC_CATYPE, CB_GETITEMDATA,
nIndex, 0);
if ((pConfig->nOldCAType == pConfig->nCAType) &&
(pConfig->avData != NULL))
PGPclDataToAVPairs(pConfig->memoryMgr, pConfig->avData,
pConfig->avDataSize, &pAVList, &nNumAVs);
if (pConfig->nCAType != kPGPKeyServerClass_Invalid)
err = PGPclGetCACertRequestAVList(hwndDlg, pConfig->pgpContext, TRUE,
NULL, pConfig->nCAType, &(pConfig->nCertRequestType),
&pAVList, &nNumAVs);
if (IsntPGPError(err))
{
if (pConfig->avData != NULL)
{
PGPFreeData(pConfig->avData);
pConfig->avData = NULL;
pConfig->avDataSize = 0;
}
if (pAVList != NULL)
{
PGPclAVPairsToData(pConfig->memoryMgr, pAVList, nNumAVs,
&(pConfig->avData), &(pConfig->avDataSize));
PGPclFreeCACertRequestAVList(pAVList, nNumAVs);
}
}
else if (pAVList != NULL)
PGPFreeData(pAVList);
pConfig->bCopyClientPrefs = TRUE;
return;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -