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

📄 certdbpage.cpp

📁 MiniCA V2.0版本源码。《小型CA系统V2.1含源码》发表以来
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if (RegSetValueEx(hKey,RegClientP12,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
		{
			AddMsg("创建RegClientP12键错误",M_ERROR);
		}
		memset(encInfo,0,512);
		encLen=0;
	}
	
	if(strClientPwd.IsEmpty())//如果为空,则不进行加密,直接删除Reg
	{
		RegDeleteValue(hKey,RegClientPwd);
	}
	else if(Crypt("idea-cbc",strClientPwd.GetBuffer(0),strClientPwd.GetLength(),encInfo,encLen,
		strRegCode.GetBuffer(0),1,outMsg,NULL))
	{
		if (RegSetValueEx(hKey,RegClientPwd,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
		{
			AddMsg("创建RegClientPwd键错误",M_ERROR);
		}	
		memset(encInfo,0,512);
		encLen=0;
	}

	if(strRootCert.IsEmpty())//如果为空,则不进行加密,直接删除Reg
	{
		RegDeleteValue(hKey,RegRootCert);
	}
	else if(Crypt("idea-cbc",strRootCert.GetBuffer(0),strRootCert.GetLength(),encInfo,encLen,
		strRegCode.GetBuffer(0),1,outMsg,NULL))
	{
		if(RegSetValueEx(hKey,RegRootCert,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
		{
			AddMsg("创建RootCert键错误",M_ERROR);
		}
		memset(encInfo,0,512);
		encLen=0;
	}
	
	::RegCloseKey(hKey); 
	
}
*/

void CCertDbPage::OnRclickTreeSetup(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CPoint point;
	GetCursorPos(&point); // 当前鼠标坐标
	CPoint PointInTree = point;
	m_TreeSetup.ScreenToClient( &PointInTree);
	
	UINT nFlag;
	HTREEITEM hItem = m_TreeSetup.HitTest( PointInTree, &nFlag);
	if(hItem == NULL)
		return;

//	m_TreeSetup.SelectItem(hItem);//设置选中

	
	DWORD dData = m_TreeSetup.GetItemData(hItem);
	CString strName = m_TreeSetup.GetItemText(hItem);
	if(dData < 100 || dData %100 !=0 || strName == MiniCT_1803)
		return;
	
	
	if(nFlag&TVHT_ONITEMLABEL) //查看菜单
	{
		BCMenu menu;
		menu.LoadMenu(IDR_MENU_CERTDB);
		menu.LoadToolbar(IDR_MINICAMENU);
		
		CLanguage::TranslateMenu(&menu, MAKEINTRESOURCE(IDR_MENU_SETUP));
		
		CMenu* pPopup = menu.GetSubMenu(0);
		ASSERT(pPopup);
		UINT nSelection = pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL|
			TPM_NONOTIFY|TPM_RETURNCMD,point.x, point.y, this, NULL);
		menu.DestroyMenu();
		//返回菜单id
		CString m_CdbPath = ((CMiniCaApp *)AfxGetApp())->GetAppPath() + "\\CertDB.CDB";
		CFile file;
		char buf[100] = {0};
		if(!file.Open(m_CdbPath,CFile::modeRead))
			return;
		for(;;)
		{
			stuCertDB CertDB;
			int len = file.Read(&CertDB,sizeof(stuCertDB));
			if(len==0)
				break;
			if(CertDB._uID != dData)
				continue;
			{
				if(nSelection == ID_MENUITEM_CERTVIEW)
				{
					((CMiniMainDlg *)GetParent())->ViewCertInfo(CertDB._chINFO,CertDB._uLENGTH,0);
				}
				else if(nSelection == ID_MENUITEM_CERTIMPORT)
				{
					CMiniCaApp::AddRootToStore(CertDB._chINFO, CertDB._uLENGTH); //加入der格式根证书
				}
			}
			break;
		}
		file.Close();
	}
	*pResult = 0;
}

void CCertDbPage::OnBSavecdb()
{
	m_TreeSetup.Savecdb();
}

void CCertDbPage::OnBResertdb() //证书库还原
{
	// TODO: Add your control notification handler code here
	UINT uCrc = 0;
	CString strCrc;
	if(::MessageBox(this->m_hWnd, MiniCT_1810, MiniCT_0010,MB_ICONQUESTION | MB_YESNO)!=IDYES)
		return;
	/*得到配置*/
	HRSRC hRsrc=FindResource(NULL,MAKEINTRESOURCE(IDR_CERTDB_INI),"INI");
	DWORD lenCert = SizeofResource(NULL, hRsrc); 
	HGLOBAL hgCert=LoadResource(NULL,hRsrc);
	LPSTR lpCert=(LPSTR)LockResource(hgCert);

	CString m_IniPathName = ((CMiniCaApp *)AfxGetApp())->GetAppPath() +  "\\CertDB.CDB";
	CFile file;
	file.Open(m_IniPathName,CFile::modeCreate|CFile::modeWrite);	//存文件
	{
		file.Write(lpCert,lenCert);
	}
	file.Close();
	m_TreeSetup.LoadCdb();

}

void CCertDbPage::AddMsg(CString info, DWORD type)
{
	((CMiniMainDlg *)GetParent())->AddMsg(MiniCT_0007, info, type);
}

BOOL CCertDbPage::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.
}

UINT CCertDbPage::GetNameType()
{
	UINT uSelect ;
	if(((CButton*)GetDlgItem(IDC_DB_RADIO1))->GetCheck())
		uSelect = 0;
	else if(((CButton*)GetDlgItem(IDC_DB_RADIO2))->GetCheck())
		uSelect = 1;
	else if(((CButton*)GetDlgItem(IDC_DB_RADIO3))->GetCheck())
		uSelect = 2;
	else if(((CButton*)GetDlgItem(IDC_DB_RADIO4))->GetCheck())
		uSelect = 3;
	return uSelect;
}

void CCertDbPage::OnBSelect() 
{
	// TODO: Add your control notification handler code here
	LPITEMIDLIST pidlRoot = NULL; 
	LPMALLOC pMalloc;   
	if(NOERROR == SHGetSpecialFolderLocation(m_hWnd,CSIDL_DRIVES ,&pidlRoot))	//leak
	{
		BROWSEINFO bi;   //必须传入的参数,下面就是这个结构的参数的初始化 
		CString strDisplayName;// = CMiniCaApp::NormalCode("选择文件夹");;   //用来得到,你选择的活页夹路径,相当于提供一个缓冲区 
		bi.hwndOwner = GetSafeHwnd();   //得到父窗口Handle值 
		bi.pidlRoot=0;   //这个变量就是我们在上面得到的. 
		bi.pszDisplayName = strDisplayName.GetBuffer(MAX_PATH+1);   //得到缓冲区指针, 
		CString strTitle = MiniCT_1811;
		bi.lpszTitle = strTitle;  //设置标题 
		bi.ulFlags = BIF_RETURNONLYFSDIRS  | BIF_DONTGOBELOWDOMAIN  ;   //设置标志 
		bi.lpfn=NULL; 
		bi.lParam=0; 
		bi.iImage=0;   //上面这个是一些无关的参数的设置,最好设置起来, 
		ITEMIDLIST * pidl;  
		pidl = SHBrowseForFolder(&bi);   //打开对话框 
		if(!pidl)
			return;
		SHGetPathFromIDList(pidl,bi.pszDisplayName);	
		strDisplayName.ReleaseBuffer();   //和上面的GetBuffer()相对应 
		SetCaPath(strDisplayName);
	
		if(SUCCEEDED( SHGetMalloc ( &pMalloc ))) // leak
		{ 
			pMalloc->Free(pidlRoot); 
			pMalloc->Release(); 
		} 
	}
}

void CCertDbPage::SetCaPath(CString strPath)
{

	//创建目录
	//结构
	//MiniCA.exe attrib desktop.ini +h +s
	//	strPath + MiniCACert																
	//					+		 CaCert				//CA中心证书存放位置			
	//                  +		WizardCert          //数证向导						

	SetDlgItemText(IDC_EDIT_SAVE, strPath);
	//得到证书命名选项

	WritePrivateProfileString("PATH", "Cert",strPath.GetBuffer(256), m_IniPathName);

//	SetPathInfo(strPath, "%SystemRoot%\\system32\\SHELL32.dll", "150", "MiniCA V2.0");  利用系统图标

	TCHAR	szProgPath[MAX_PATH * 2];
	::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));

	CString sMiniCA;
	sMiniCA.Format("%s", szProgPath);

	SetPathInfo(strPath, szProgPath, "12", MiniCT_1812);  //利用minica图标

	//首先建立 strPath + MiniCACert
	DWORD dErrCode = 0;
	BOOL b = CreateDirectory(strPath + "\\MiniCACert", NULL);
	if(!b)
		dErrCode = GetLastError();

//	HTREEITEM hPathItem = m_PathTree.InsertItem(strPath + "\\MiniCACert",0,0);

//	SetPathInfo(strPath + "\\MiniCACert", "%SystemRoot%\\system32\\SHELL32.dll", "47", 
//		CMiniCaApp::NormalCode("MiniCA 证书中心"));
	//设置文件夹属性

	//建立 strPath + MiniCACert + CaCert
	b = CreateDirectory(strPath + "\\MiniCACert\\CaCert", NULL);
	if(!b)
		dErrCode = GetLastError();

//	HTREEITEM hPathSecond = m_PathTree.InsertItem(strPath + "\\MiniCACert\\CaCert",hPathItem,0);

	CMiniMainDlg * pMain = (CMiniMainDlg *)AfxGetMainWnd();
	CCaCenterPage * pCa = (CCaCenterPage *)(pMain->GetPage("CCaCenterPage"));

	//strPath可能带有\\比如c:\\时候就带有,这时候要去掉这个
	if(strPath.Right(1) == "\\")
	{
		strPath.Delete(strPath.GetLength() -1);
	}

	if(pCa)
	{
		pCa->SetNamePath(strPath + "\\MiniCACert\\CaCert");
	}


	//建立 strPath + MiniCACert + CaCert + MiniCACert
//	b = CreateDirectory(strPath + "\\MiniCACert\\CaCert\\Cert", NULL);
//	if(!b)
//		dErrCode = GetLastError();
//	m_PathTree.InsertItem(strPath + "\\MiniCACert\\CaCert\\Cert",hPathSecond,0);
//	m_PathStrArray.Add(strPath + "\\MiniCACert\\CaCert\\Cert");


	//建立 strPath + MiniCACert + CaCert + Crl
//	b = CreateDirectory(strPath + "\\MiniCACert\\CaCert\\Crl", NULL);
//	if(!b)
///		dErrCode = GetLastError();
//	m_PathTree.InsertItem(strPath + "\\MiniCACert\\CaCert\\Crl",hPathSecond,0);
//	m_PathStrArray.Add(strPath + "\\MiniCACert\\CaCert\\Crl");


	//建立 strPath + MiniCACert + WizardCert
	b = CreateDirectory(strPath + "\\MiniCACert\\WizardCert", NULL);
	if(!b)
		dErrCode = GetLastError();

//	hPathSecond = m_PathTree.InsertItem(strPath + "\\MiniCACert\\WizardCert",hPathItem,0);
	CCaCertWizardSheet * pWizard = (CCaCertWizardSheet *)(pMain->GetPage("CCaCertWizardSheet"));
	if(pWizard)
	{
		CCaCertInfoPage * pCaInfo = (CCaCertInfoPage *)(pWizard->GetPage("CCaCertInfoPage"));
		CCaCertManPage * pCaMan = (CCaCertManPage *)(pWizard->GetPage("CCaCertManPage"));
		
		if(pCaInfo) 
		{
			pCaInfo->SetNamePath(strPath + "\\MiniCACert\\WizardCert");
		}
		if(pCaMan) 
		{
			pCaMan->SetNamePath(strPath + "\\MiniCACert\\WizardCert");
		}
	}


	//建立 strPath + MiniCACert + WizardCert + Cert
//	b = CreateDirectory(strPath + "\\MiniCACert\\WizardCert\\Cert", NULL);
//	if(!b)
//		dErrCode = GetLastError();

//	m_PathTree.InsertItem(strPath + "\\MiniCACert\\WizardCert\\Cert",hPathSecond,0);
//	m_PathStrArray.Add(strPath + "\\MiniCACert\\WizardCert\\Cert");


	//建立 strPath + MiniCACert + WizardCert + Crl
//	b = CreateDirectory(strPath + "\\MiniCACert\\WizardCert\\Crl", NULL);
//	if(!b)
//		dErrCode = GetLastError();

//	m_PathTree.InsertItem(strPath + "\\MiniCACert\\WizardCert\\Crl",hPathSecond,0);
	//建立 strPath + MiniCACert + WizardCert + Man
//	b = CreateDirectory(strPath + "\\MiniCACert\\WizardCert\\Man", NULL);
//	if(!b)
//		dErrCode = GetLastError();

//	m_PathTree.InsertItem(strPath + "\\MiniCACert\\WizardCert\\Man",hPathSecond,0);
//	m_PathStrArray.Add(strPath + "\\MiniCACert\\WizardCert\\Man");
}

void CCertDbPage::SetPathInfo(CString strPath, CString strIconFile, CString strIconIndex, 
							 CString strInfoTip)		//设置文件夹图标
{
	//目录属性 %SystemRoot%\system32\SHELL32.dll
	//	[.ShellClassInfo]
	//	IconFile=.\MiniCA.exe
	//	IconIndex=0

	//除了给desktop.ini增加属性外,还要给当前要设置的路径增加 S 属性

	SetFileAttributes(strPath + "\\desktop.ini", FILE_ATTRIBUTE_NORMAL); 
	WritePrivateProfileString(".ShellClassInfo", "ConfirmFileOp", "0", strPath + "\\desktop.ini");
	WritePrivateProfileString(".ShellClassInfo", "IconFile", strIconFile, strPath + "\\desktop.ini");
	WritePrivateProfileString(".ShellClassInfo", "InfoTip", strInfoTip, strPath + "\\desktop.ini");
	WritePrivateProfileString(".ShellClassInfo", "IconIndex", strIconIndex, strPath + "\\desktop.ini");
	SetFileAttributes(strPath + "\\desktop.ini", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 
	SetFileAttributes(strPath , FILE_ATTRIBUTE_SYSTEM);
}

void CCertDbPage::TranslateCT()
{
	//更新树控件

	m_TreeSetup.SetItemText(m_hItem[0], MiniCT_1800);

	m_TreeSetup.SetItemText(m_hItem[1], MiniCT_1801);
	m_TreeSetup.SetItemText(m_hItem[2], MiniCT_1802);
	m_TreeSetup.SetItemText(m_hItem[3], MiniCT_1803);
	m_TreeSetup.SetItemText(m_hItem[4], MiniCT_1804);
	m_TreeSetup.SetItemText(m_hItem[5], MiniCT_1805);

	m_TreeSetup.SetItemText(m_hItem[7], MiniCT_1806);
	m_TreeSetup.SetItemText(m_hItem[8], MiniCT_1802);
	m_TreeSetup.SetItemText(m_hItem[9], MiniCT_1803);
	m_TreeSetup.SetItemText(m_hItem[10], MiniCT_1804);
	m_TreeSetup.SetItemText(m_hItem[11], MiniCT_1805);

	m_TreeSetup.SetItemText(m_hItem[13], MiniCT_1807);
	m_TreeSetup.SetItemText(m_hItem[14], MiniCT_1802);
	m_TreeSetup.SetItemText(m_hItem[15], MiniCT_1803);
	m_TreeSetup.SetItemText(m_hItem[16], MiniCT_1804);
	m_TreeSetup.SetItemText(m_hItem[17], MiniCT_1805);

	m_TreeSetup.SetItemText(m_hItem[19], MiniCT_1808);
	m_TreeSetup.SetItemText(m_hItem[20], MiniCT_1802);
	m_TreeSetup.SetItemText(m_hItem[21], MiniCT_1803);
	m_TreeSetup.SetItemText(m_hItem[22], MiniCT_1804);
	m_TreeSetup.SetItemText(m_hItem[23], MiniCT_1805);

	m_TreeSetup.SetItemText(m_hItem[25], MiniCT_1809);
	m_TreeSetup.SetItemText(m_hItem[26], MiniCT_1802);
	m_TreeSetup.SetItemText(m_hItem[27], MiniCT_1803);
	m_TreeSetup.SetItemText(m_hItem[28], MiniCT_1804);
	m_TreeSetup.SetItemText(m_hItem[29], MiniCT_1805);

	m_TreeSetup.LoadCdb();



	//更新static控件
	SetDlgItemText(IDC_STATIC_SETUP2, MiniCT_11001);
	SetDlgItemText(IDC_STATIC_SETUP3, MiniCT_11002);
	SetDlgItemText(IDC_STATIC_SETUP4, MiniCT_11003);
	SetDlgItemText(IDC_STATIC_SETUP5, MiniCT_11004);
	SetDlgItemText(IDC_DB_RADIO1, MiniCT_11005);
	SetDlgItemText(IDC_DB_RADIO2, MiniCT_11006);
	SetDlgItemText(IDC_DB_RADIO3, MiniCT_11007);
	SetDlgItemText(IDC_DB_RADIO4, MiniCT_11008);
	SetDlgItemText(IDC_DB_SAVECDB, MiniCT_11009);
	SetDlgItemText(IDC_DB_RESERTDB, MiniCT_11010);
	SetDlgItemText(IDC_DB_SELECT, MiniCT_11011);
}

⌨️ 快捷键说明

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