📄 cacertinfopage.cpp
字号:
// Get the default provider name.
if (CryptGetDefaultProvider(
PROV_RSA_FULL,
NULL,
CRYPT_MACHINE_DEFAULT,
pbProvName,
&cbProvName))
{
str = pbProvName;
}
else
{
str = "";
}
// Free resouces when done.
LocalFree(pbProvName);
return str;
}
BOOL CCaCertInfoPage::GetCertInfo(CStaticTreeCtrl * p_WizardTree,
HTREENODE & hInfoBase,
HTREENODE & hInfoHold,
HTREENODE & hInfoSave)
{
BOOL bFull = FALSE;//信息是否完整,是否可以制作数证
CString info,name,matter,temp,pkcs,error,format;
CString sInfoBase;
HTREENODE hTemp;
COLORREF colError = RGB(255,0,0);
//数证基本信息
CString str;
int nCount = m_CheckList.GetItemCount();
DWORD dData = 0;
for(int i = nCount -1; i >= 0; i--)
{
//检查状态
if(ListView_GetCheckState(m_CheckList.m_hWnd,i))//此项选中
{
name = m_CheckList.GetItemText(i,0);
matter = m_CheckList.GetItemText(i,1);
if(name.IsEmpty() || matter.IsEmpty())
continue;
sInfoBase.Format("%s: %s",name, matter);
hTemp = p_WizardTree->InsertChild( hInfoBase, sInfoBase);
/* if(name == "CN" || name == "commonName" && matter.IsEmpty())
{
p_WizardTree->SetNodeColor(hTemp, colError);
}*/
bFull = TRUE;
}
}
if(!bFull)
{
p_WizardTree->SetNodeColor(hInfoBase, colError);
}
//数证约束信息
//密钥长度,
//证书有效期
//私鈅保护
GetDlgItemText(IDC_EDIT_PWD, matter);
name = MiniCT_0302; //MiniCT_0302 "私钥保护:"
CString strTemp;
if(matter.IsEmpty())
{
strTemp = MiniCT_0303; //MiniCT_0303 "未保护"
temp.Format("%s%s",name, strTemp);
}
else
{
strTemp = MiniCT_0304; //MiniCT_0304 "保护"
temp.Format("%s%s",name, strTemp);
}
p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(temp));
GetDlgItemText(IDC_STATIC_CAINFO15, name);
GetDlgItemText(IDC_EDIT_DAY, matter); // 10 -
sInfoBase.Format("%s %s",name,matter);
hTemp = p_WizardTree->InsertChild( hInfoHold, sInfoBase);
if(matter.IsEmpty())
{
p_WizardTree->SetNodeColor(hTemp, colError);
bFull = FALSE;
}
GetDlgItemText(IDC_STATIC_CAINFO16, name);
GetDlgItemText(IDC_COMBO_L, matter); // 10 -
sInfoBase.Format("%s %s",name,matter);
hTemp = p_WizardTree->InsertChild( hInfoHold, sInfoBase);
if(matter.IsEmpty())
{
p_WizardTree->SetNodeColor(hTemp, colError);
bFull = FALSE;
}
//约束信息
//数证格式
if(((CButton*)GetDlgItem(IDC_CAINFO_RADIODER))->GetCheck())//选中,DER格式
{
format.Format("%s: DER", MiniCT_0305); //MiniCT_0305 证书格式
m_CertFormat = DER;
}
else
{
format.Format("%s: PEM", MiniCT_0305); //MiniCT_0305
m_CertFormat = PEM;
}
p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(format));
if(((CButton*)GetDlgItem(IDC_STATIC_CAINFO21))->GetCheck())//选中
{
pkcs.Format("Pkcs#12%s", MiniCT_0306); //MiniCT_0306 "包: 附带"
}
else
{
pkcs.Format("Pkcs#12%s", MiniCT_0307); //MiniCT_0307 "包: 不附带"
}
p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(pkcs));
//存储信息
if(((CButton*)GetDlgItem(IDC_RADIO_DISK))->GetCheck())//磁盘文件
{
CString str;
GetDlgItemText(IDC_EDIT_PATH,temp);
//尝试建立目录
//测试路径是否存在
BOOL bDir = FALSE;
// if(_mkdir(temp) == -1 && errno != EEXIST)
temp += "\\";
if(!CMiniCaApp::MakeSureDirectoryPathExists(temp))
{
str.Format("%s %s", MiniCT_0308, temp); //MiniCT_0308 存储路径无效
bFull = FALSE;
}
else
{
str.Format("%s %s",MiniCT_0309, temp); //MiniCT_0309 存储路径:
bDir = TRUE;
}
str.Replace("\\", "\\ ");
HTREENODE hTemp = p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(str));
if(!bDir)
p_WizardTree->SetNodeColor(hTemp, RGB(255,0,0));
}
else if(((CButton*)GetDlgItem(IDC_R_CSP))->GetCheck())//CSP
{
BOOL bDir = FALSE;
CString str;
GetDlgItemText(IDC_COMBO_CSP,str);
temp.Format("%s %s", MiniCT_0310, str); //MiniCT_0310 CSP名称:
p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(temp));
GetDlgItemText(IDC_EDIT_CONT,temp);
if(temp.IsEmpty())
{
str.Format(MiniCT_0311); ////MiniCT_0311 "密钥容器无效"
bFull = FALSE;
bDir = FALSE;
}
else
{
str.Format("%s %s\n", MiniCT_0312, temp); //MiniCT_0312 密钥容器:
bDir = TRUE;
}
HTREENODE hTemp = p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(str));
if(!bDir)
p_WizardTree->SetNodeColor(hTemp, RGB(255,0,0));
}
return bFull;
}
void CCaCertInfoPage::GetCert(stuSUBJECT *& pCERT, stuCERTINFO & certInfo)
{
CString str;
int nCount = m_CheckList.GetItemCount();
CString strName;
DWORD dData = 0;
for(int i = 0;i<nCount;i++)
{
//检查状态
if(ListView_GetCheckState(m_CheckList.m_hWnd,i))//此项选中
{
strName = m_CheckList.GetItemText(i,1);
pCERT->Add(pCERT,m_ArrayInside[i], strName);
}
}
certInfo.uCertLen = GetDlgItemInt(IDC_COMBO_L);
certInfo.uCertDay = GetDlgItemInt(IDC_EDIT_DAY);
certInfo.uCertFormat = m_CertFormat;
certInfo.bCertP12 = ((CButton*)GetDlgItem(IDC_STATIC_CAINFO21))->GetCheck();
GetDlgItemText(IDC_EDIT_PWD,str);
strncpy(certInfo.cCertPwd,str.GetBuffer(0),sizeof(certInfo.cCertPwd));
str.ReleaseBuffer();
if(((CButton*)GetDlgItem(IDC_RADIO_DISK))->GetCheck())//选中磁盘
{
GetDlgItemText(IDC_EDIT_PATH,str);
strncpy(certInfo.cCertDir,str.GetBuffer(0),sizeof(certInfo.cCertDir));
str.ReleaseBuffer();
}
else
{
GetDlgItemText(IDC_COMBO_CSP,str);
strncpy(certInfo.cCertCsp,str.GetBuffer(0),sizeof(certInfo.cCertCsp));
str.ReleaseBuffer();
GetDlgItemText(IDC_EDIT_CONT,str);
strncpy(certInfo.cCertCon,str.GetBuffer(0),sizeof(certInfo.cCertCon));
str.ReleaseBuffer();
}
}
BOOL CCaCertInfoPage::PreTranslateMessage(MSG* pMsg)
{
// CG: The following block was added by the ToolTips component. { // Let the ToolTip process this message. m_toolTip.RelayEvent(pMsg); } return CPropertyPage::PreTranslateMessage(pMsg); // CG: This was added by the ToolTips component.
}
void CCaCertInfoPage::SetNamePath(const CString &strPath)
{
if(!strPath.IsEmpty())
{
SetDlgItemText(IDC_EDIT_PATH,strPath);
//更新报告信息
CMiniMainDlg * pMain = (CMiniMainDlg *)AfxGetMainWnd();
CCaCertWizardSheet * pWizard = (CCaCertWizardSheet *)(pMain->GetPage("CCaCertWizardSheet"));
if(pWizard)
{
CCaCertReportPage * pReportPage = (CCaCertReportPage *)(pWizard->GetPage("CCaCertReportPage"));
if(pReportPage)
pReportPage->ViewWizardInfo();
}
}
}
void CCaCertInfoPage::SetLVCheck (WPARAM ItemIndex, BOOL bCheck)
{
ListView_SetItemState(m_CheckList.m_hWnd, ItemIndex,
UINT((int(bCheck) + 1) << 12), LVIS_STATEIMAGEMASK);
}
void CCaCertInfoPage::GetIniInfo(CString strIniPath)
{
//删除原来内容
m_CheckList.DeleteAllItems();
//清除链表内容
m_ArrayInside.RemoveAll();
char buf[255] = {0};
char info[255] = {0};
char inside[255] = {0};
GetPrivateProfileString("TOTAL", "ToTal","0",buf,50, m_IniPathName);
CString strIndex;
int uMax = atoi(buf);
for(int i = 0, j = 0; i<uMax; i++)
{
strIndex.Format("INFO%d",i+1);
//首先读取是否显示标志
GetPrivateProfileString(strIndex, "IsDisp","0",buf,50, m_IniPathName);
if(atoi(buf) <= 0)
continue;
GetPrivateProfileString(strIndex, "InsideName","0",inside,254, m_IniPathName);//内部名称
if(strlen(inside) == 0)
continue;
else
m_ArrayInside.Add(inside);
GetPrivateProfileString(strIndex, "DispName","0",buf,254, m_IniPathName);
if(strlen(buf) == 0)
continue;
GetPrivateProfileString(strIndex, "Info","0",info,254, m_IniPathName);
if(strlen(info) == 0)
continue;
m_CheckList.InsertItem(j, buf, 7);
m_CheckList.SetItemText(j, 1, info);
GetPrivateProfileString(strIndex, "IsCheck","78",buf,50, m_IniPathName);//是否选中
SetLVCheck (j, atoi(buf));
j++;
}
}
void CCaCertInfoPage::TranslateCT()
{
CHeaderCtrl * pHeader = m_CheckList.GetHeaderCtrl();
if (pHeader)
{
CString str = MiniCT_0300;
HDITEM hdi;
hdi.mask = HDI_TEXT;
hdi.pszText = (LPTSTR)((LPCTSTR)str);
pHeader->SetItem(0, &hdi);
str = MiniCT_0301;
hdi.pszText = (LPTSTR)((LPCTSTR)str);
pHeader->SetItem(1, &hdi);
}
//翻译STATIC
SetDlgItemText(IDC_STATIC_CAINFO1, MiniCT_10301);
SetDlgItemText(IDC_STATIC_CAINFO12, MiniCT_10302);
SetDlgItemText(IDC_STATIC_CAINFO13, MiniCT_10303);
SetDlgItemText(IDC_STATIC_CAINFO14, MiniCT_10304);
SetDlgItemText(IDC_STATIC_CAINFO15, MiniCT_10305);
SetDlgItemText(IDC_STATIC_CAINFO16, MiniCT_10306);
SetDlgItemText(IDC_STATIC_CAINFO17, MiniCT_10307);
SetDlgItemText(IDC_STATIC_CAINFO18, MiniCT_10308);
SetDlgItemText(IDC_STATIC_CAINFO19, MiniCT_10309);
SetDlgItemText(IDC_STATIC_CAINFO20, MiniCT_10310);
SetDlgItemText(IDC_STATIC_CAINFO21, MiniCT_10311);
SetDlgItemText(IDC_STATIC_CAINFO22, MiniCT_10312);
SetDlgItemText(IDC_STATIC_CAINFO23, MiniCT_10313);
SetDlgItemText(IDC_CAINFO_RADIODER, MiniCT_10314);
SetDlgItemText(IDC_CAINFO_RADIOPEM, MiniCT_10315);
SetDlgItemText(IDC_RADIO_DISK, MiniCT_10316);
SetDlgItemText(IDC_R_CSP, MiniCT_10317);
}
void CCaCertInfoPage::OnCainfoRadioder()
{
// TODO: Add your control notification handler code here
m_CertFormat = DER;
}
void CCaCertInfoPage::OnCainfoRadiopem()
{
// TODO: Add your control notification handler code here
m_CertFormat = PEM;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -