CertDbPage.cpp
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:27k
源码类别:

CA认证

开发平台:

Visual C++

  1. // CertDbPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "minica.h"
  5. #include "CertDbPage.h"
  6. #include "MiniMainDlg.h"
  7. #include ".GenericClassLanguage.h"
  8. #include "minict.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CCertDbPage property page
  16. IMPLEMENT_DYNCREATE(CCertDbPage, CPropertyPage)
  17. CCertDbPage::CCertDbPage() : CPropertyPage(CCertDbPage::IDD)
  18. {
  19. //{{AFX_DATA_INIT(CCertDbPage)
  20. //}}AFX_DATA_INIT
  21. m_IniPathName = ((CMiniCaApp *)AfxGetApp())->GetAppPath() +  "\MiniCA.ini";
  22. }
  23. CCertDbPage::~CCertDbPage()
  24. {
  25. }
  26. void CCertDbPage::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CPropertyPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CCertDbPage)
  30. DDX_Control(pDX, IDC_DB_SAVECDB, m_Bsavecdb);
  31. DDX_Control(pDX, IDC_DB_RESERTDB, m_Bresertdb);
  32. DDX_Control(pDX, IDC_TREE_SETUP, m_TreeSetup);
  33. // DDX_Control(pDX, IDC_EDIT_SAVE, m_CertSave);
  34. DDX_Control(pDX, IDC_DB_SELECT, m_Bselect);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(CCertDbPage, CPropertyPage)
  38. //{{AFX_MSG_MAP(CCertDbPage)
  39. ON_BN_CLICKED(IDC_DB_RESERTDB, OnBResertdb)
  40. ON_BN_CLICKED(IDC_DB_SAVECDB, OnBSavecdb)
  41. ON_NOTIFY(NM_RCLICK, IDC_TREE_SETUP, OnRclickTreeSetup)
  42. ON_BN_CLICKED(IDC_DB_SELECT, OnBSelect)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CCertDbPage message handlers
  47. BOOL CCertDbPage::OnInitDialog() 
  48. {
  49. CPropertyPage::OnInitDialog();
  50. CXPStyleButtonST::SetAllThemeHelper(this, ((CMiniCaApp *)AfxGetApp())->GetThemeHelperST());
  51. m_Bsavecdb.SetIcon(IDI_ICON11);
  52. m_Bsavecdb.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
  53. m_Bresertdb.SetIcon(IDI_ICON12);
  54. m_Bresertdb.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
  55. // TODO: Add extra initialization here
  56. CImageList * pImgList = ((CMiniCaApp *)AfxGetApp())->GetImgList();
  57. m_TreeSetup.SetImageList(pImgList,TVSIL_NORMAL);//9 - 15
  58. //24:每个图片的宽度为24
  59. //24:每个图片的高度为24
  60. //TRUE  该图以透明方式显示
  61. //ILC_COLOR24,  颜色数为24位(其他可选常量祥见有关API)
  62. //16:    创建时容量为3个图片
  63. //1:    图片数量超出当前容量时,自动扩容,每次扩容1个图片的容量
  64. /* m_DbList.SetImageList(pImgList, LVSIL_SMALL);
  65. m_DbList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);
  66. m_DbList.InsertColumn(0, CMiniCaApp::NormalCode("证书分类"), LVCFMT_LEFT, 130);
  67. m_DbList.InsertColumn(1, CMiniCaApp::NormalCode("序号"), LVCFMT_LEFT, 40);
  68. m_DbList.InsertColumn(2, CMiniCaApp::NormalCode("密钥"), LVCFMT_LEFT, 40);
  69. m_DbList.InsertColumn(3, CMiniCaApp::NormalCode("用户信息"), LVCFMT_LEFT, 135);
  70. m_DbList.InsertColumn(4, CMiniCaApp::NormalCode("起始时间"), LVCFMT_LEFT, 70);
  71. m_DbList.InsertColumn(5, CMiniCaApp::NormalCode("有效期"), LVCFMT_LEFT, 50);
  72. */
  73. // m_TreeSetup.m_HtreeList.RemoveAll();//清除列表
  74. m_hItem[0] = m_TreeSetup.InsertItem(MiniCT_1800, 0, 0); //证书库 m_hItem[0]
  75. m_TreeSetup.SetItemImage(m_hItem[0],0,0);
  76. m_TreeSetup.SetItemData(m_hItem[0],0);//根为0
  77. HTREEITEM hItemSecond = TVI_ROOT;//二级
  78. HTREEITEM hItemThird = TVI_ROOT;//三级
  79. HTREEITEM hItemFour = TVI_ROOT;//四级
  80. m_hItem[1] = m_TreeSetup.InsertItem(MiniCT_1801, 0, 0, m_hItem[0]); //根证书(Highest) hItemSecond
  81. m_TreeSetup.SetItemImage(m_hItem[1],0,0);
  82. m_TreeSetup.SetItemData(m_hItem[1],1);//根证书为1
  83. m_hItem[2] = m_TreeSetup.InsertItem(MiniCT_1802, 0, 0,m_hItem[1]); //根证书公钥 hItemThird
  84. m_TreeSetup.SetItemImage(m_hItem[2],0,0);
  85. m_TreeSetup.SetItemData(m_hItem[2],10);//根证书公钥10
  86. m_hItem[3] = m_TreeSetup.InsertItem(MiniCT_1803, 0, 0,m_hItem[2]); //公钥文件 hItemFour
  87. m_TreeSetup.SetItemImage(m_hItem[3],3,3);
  88. m_TreeSetup.SetItemData(m_hItem[3],100);//根证书公钥文件为100
  89. m_TreeSetup.m_HtreeList.AddTail(m_hItem[3]);
  90. m_hItem[4] = m_TreeSetup.InsertItem(MiniCT_1804, 0, 0,m_hItem[1]); //根证书私钥 hItemThird
  91. m_TreeSetup.SetItemImage(m_hItem[4],0,0); 
  92. m_TreeSetup.SetItemData(m_hItem[4],11);//根证书私钥为11
  93. m_hItem[5] = m_TreeSetup.InsertItem(MiniCT_1805, 0, 0,m_hItem[4]); //私钥文件 hItemFour
  94. m_TreeSetup.SetItemImage(m_hItem[5],3,3);
  95. m_TreeSetup.SetItemData(m_hItem[5],110);//根证书私钥文件为110
  96. m_TreeSetup.m_HtreeList.AddTail(m_hItem[5]);
  97. m_hItem[6] = m_TreeSetup.InsertItem("********", 0, 0,m_hItem[4]); //hItemFour
  98. m_TreeSetup.SetItemImage(m_hItem[6],5,5);
  99. m_TreeSetup.SetItemData(m_hItem[6],111);//根证书私钥密钥111
  100. m_hItem[7] = m_TreeSetup.InsertItem(MiniCT_1806, 0, 0,m_hItem[0]); //根证书(Higher) hItemSecond
  101. m_TreeSetup.SetItemImage(m_hItem[7],0,0);
  102. m_TreeSetup.SetItemData(m_hItem[7],2);//服务器证书为2
  103. m_hItem[8] = m_TreeSetup.InsertItem(MiniCT_1802, 0, 0,m_hItem[7]); //hItemThird
  104. m_TreeSetup.SetItemImage(m_hItem[8],0,0);
  105. m_TreeSetup.SetItemData(m_hItem[8],20);//服务器公钥20
  106. m_hItem[9] = m_TreeSetup.InsertItem(MiniCT_1803, 0, 0,m_hItem[8]); //hItemFour
  107. m_TreeSetup.SetItemImage(m_hItem[9],3,3);
  108. m_TreeSetup.SetItemData(m_hItem[9],200);//公钥文件200
  109. m_TreeSetup.m_HtreeList.AddTail(m_hItem[9]);
  110. m_hItem[10] = m_TreeSetup.InsertItem(MiniCT_1804, 0, 0,m_hItem[7]); //hItemThird
  111. m_TreeSetup.SetItemImage(m_hItem[10],0,0);
  112. m_TreeSetup.SetItemData(m_hItem[10],21);//服务器私钥为21
  113. m_hItem[11] = m_TreeSetup.InsertItem(MiniCT_1805, 0, 0,m_hItem[10]); //hItemFour
  114. m_TreeSetup.SetItemImage(m_hItem[11],3,3);
  115. m_TreeSetup.SetItemData(m_hItem[11],210);//私钥文件为210
  116. m_TreeSetup.m_HtreeList.AddTail(m_hItem[11]);
  117. m_hItem[12] = m_TreeSetup.InsertItem("********", 0, 0,m_hItem[10]); //hItemFour
  118. m_TreeSetup.SetItemImage(m_hItem[12],5,5);
  119. m_TreeSetup.SetItemData(m_hItem[12],211);//私钥密钥211
  120. m_hItem[13] = m_TreeSetup.InsertItem(MiniCT_1807, 0, 0,m_hItem[0]); //根证书(High) hItemSecond
  121. m_TreeSetup.SetItemImage(m_hItem[13],0,0);
  122. m_TreeSetup.SetItemData(m_hItem[13],3);//客户端证书为3
  123. m_hItem[14] = m_TreeSetup.InsertItem(MiniCT_1802, 0, 0,m_hItem[13]); //hItemThird
  124. m_TreeSetup.SetItemImage(m_hItem[14],0,0);
  125. m_TreeSetup.SetItemData(m_hItem[14],30);//客户端公钥为30
  126. m_hItem[15] = m_TreeSetup.InsertItem(MiniCT_1803, 0, 0,m_hItem[14]); //hItemFour
  127. m_TreeSetup.SetItemImage(m_hItem[15],3,3);
  128. m_TreeSetup.SetItemData(m_hItem[15],300);//客户端公钥文件为300
  129. m_TreeSetup.m_HtreeList.AddTail(m_hItem[15]);
  130. m_hItem[16] = m_TreeSetup.InsertItem(MiniCT_1804, 0, 0,m_hItem[13]); //hItemThird
  131. m_TreeSetup.SetItemImage(m_hItem[16],0,0);
  132. m_TreeSetup.SetItemData(m_hItem[16],31);//客户端私钥为31
  133. m_hItem[17] = m_TreeSetup.InsertItem(MiniCT_1805, 0, 0,m_hItem[16]); //hItemFour
  134. m_TreeSetup.SetItemImage(m_hItem[17],3,3);
  135. m_TreeSetup.SetItemData(m_hItem[17],310);//私钥文件为310
  136. m_TreeSetup.m_HtreeList.AddTail(m_hItem[17]);
  137. m_hItem[18] = m_TreeSetup.InsertItem("********", 0, 0,m_hItem[16]); //hItemFour
  138. m_TreeSetup.SetItemImage(m_hItem[18],5,5);
  139. m_TreeSetup.SetItemData(m_hItem[18],311);//私钥密钥为311
  140. m_hItem[19] = m_TreeSetup.InsertItem(MiniCT_1808, 0, 0,m_hItem[0]); //根证书(Low) hItemSecond
  141. m_TreeSetup.SetItemImage(m_hItem[19],0,0);
  142. m_TreeSetup.SetItemData(m_hItem[19],4);//加密证书4
  143. m_hItem[20] = m_TreeSetup.InsertItem(MiniCT_1802, 0, 0,m_hItem[19]); //hItemThird
  144. m_TreeSetup.SetItemImage(m_hItem[20],0,0);
  145. m_TreeSetup.SetItemData(m_hItem[20],40);//公钥为40
  146. m_hItem[21] = m_TreeSetup.InsertItem(MiniCT_1803, 0, 0,m_hItem[20]); //hItemFour
  147. m_TreeSetup.SetItemImage(m_hItem[21],3,3);
  148. m_TreeSetup.SetItemData(m_hItem[21],400);//公钥文件400
  149. m_TreeSetup.m_HtreeList.AddTail(m_hItem[21]);
  150. m_hItem[22] = m_TreeSetup.InsertItem(MiniCT_1804, 0, 0,m_hItem[19]); //hItemThird
  151. m_TreeSetup.SetItemImage(m_hItem[22],0,0);
  152. m_TreeSetup.SetItemData(m_hItem[22],41);//私钥为41
  153. m_hItem[23] = m_TreeSetup.InsertItem(MiniCT_1805, 0, 0,m_hItem[22]); //hItemFour
  154. m_TreeSetup.SetItemImage(m_hItem[23],3,3);
  155. m_TreeSetup.SetItemData(m_hItem[23],410);//私钥文件为410
  156. m_TreeSetup.m_HtreeList.AddTail(m_hItem[23]);
  157. m_hItem[24] = m_TreeSetup.InsertItem("********", 0, 0,m_hItem[22]); //hItemFour
  158. m_TreeSetup.SetItemImage(m_hItem[24],5,5);
  159. m_TreeSetup.SetItemData(m_hItem[24],411);//私钥密钥为411
  160. m_hItem[25] = m_TreeSetup.InsertItem(MiniCT_1809, 0, 0,m_hItem[0]); //hItemSecond
  161. m_TreeSetup.SetItemImage(m_hItem[25],0,0);
  162. m_TreeSetup.SetItemData(m_hItem[25],5);//签名为5
  163. m_hItem[26] = m_TreeSetup.InsertItem(MiniCT_1802, 0, 0,m_hItem[25]); //hItemThird
  164. m_TreeSetup.SetItemImage(m_hItem[26],0,0);
  165. m_TreeSetup.SetItemData(m_hItem[26],50);//验证公钥50
  166. m_hItem[27] = m_TreeSetup.InsertItem(MiniCT_1803, 0, 0,m_hItem[26]); //hItemFour
  167. m_TreeSetup.SetItemImage(m_hItem[27],3,3);
  168. m_TreeSetup.SetItemData(m_hItem[27],500);//公钥文件为500
  169. m_TreeSetup.m_HtreeList.AddTail(m_hItem[27]);
  170. m_hItem[28] = m_TreeSetup.InsertItem(MiniCT_1804, 0, 0,m_hItem[25]); //hItemThird
  171. m_TreeSetup.SetItemImage(m_hItem[28],0,0);
  172. m_TreeSetup.SetItemData(m_hItem[28],51);//签名私钥为51
  173. m_hItem[29] = m_TreeSetup.InsertItem(MiniCT_1805, 0, 0,m_hItem[28]); //hItemFour
  174. m_TreeSetup.SetItemImage(m_hItem[29],3,3);
  175. m_TreeSetup.SetItemData(m_hItem[29],510);//私钥文件510
  176. m_TreeSetup.m_HtreeList.AddTail(m_hItem[29]);
  177. m_hItem[30] = m_TreeSetup.InsertItem("********", 0, 0,m_hItem[28]); //hItemFour
  178. m_TreeSetup.SetItemImage(m_hItem[30],5,5);
  179. m_TreeSetup.SetItemData(m_hItem[30],511);//私钥密钥511
  180. // hItemFour = m_TreeSetup.InsertItem(_T("Your First Name (Example of edit box)"), 10, 10);
  181.  //  m_TreeSetup.AddEditBox(hItemFour, RUNTIME_CLASS(CDemoEdit));
  182. m_TreeSetup.EnsureVisible(m_hItem[0]);
  183. // m_TreeSetup.Expand(m_TreeSetup.GetRootItem(),TVE_EXPAND);
  184. // CG: The following block was added by the ToolTips component. { // Create the ToolTip control. m_toolTip.Create(this); m_toolTip.AddTool(GetDlgItem(IDC_TREE_SETUP), "根证书库r可设置五个不同级别的根证书");
  185. m_toolTip.AddTool(GetDlgItem(IDC_DB_RESERTDB), "重置证书库r操作不可恢复");
  186. m_toolTip.AddTool(GetDlgItem(IDC_DB_SAVECDB), "保存证书库r保存后新配置生效");
  187. m_toolTip.AddTool(GetDlgItem(IDC_DB_SELECT), "选择全局证书存储路径");
  188. m_toolTip.AddTool(GetDlgItem(IDC_EDIT_SAVE), "全局证书存储路径r默认情况下的证书存储路径");
  189. m_toolTip.AddTool(GetDlgItem(IDC_DB_RADIO1), "全局证书命名方式r行如:hpxs.Cer");
  190. m_toolTip.AddTool(GetDlgItem(IDC_DB_RADIO2), "全局证书命名方式r行如:hpxs100.Cer");
  191. m_toolTip.AddTool(GetDlgItem(IDC_DB_RADIO3), "全局证书命名方式r行如:100hpxs.Cer");
  192. m_toolTip.AddTool(GetDlgItem(IDC_DB_RADIO4), "全局证书命名方式r行如:100.Cer");
  193. // TODO: Use one of the following forms to add controls: }
  194. ((CButton*)GetDlgItem(IDC_DB_RADIO2))->SetCheck(true);
  195. if(!((CMiniCaApp *)AfxGetApp())->IsXpStyle())
  196. {
  197. ClassXP(GetDlgItem(IDC_DB_RADIO1)->m_hWnd,TRUE);
  198. ClassXP(GetDlgItem(IDC_DB_RADIO2)->m_hWnd,TRUE);
  199. ClassXP(GetDlgItem(IDC_DB_RADIO3)->m_hWnd,TRUE);
  200. ClassXP(GetDlgItem(IDC_DB_RADIO4)->m_hWnd,TRUE);
  201. ClassXP(GetDlgItem(IDC_EDIT_SAVE)->m_hWnd,TRUE);
  202. }
  203. CXPStyleButtonST::SetAllThemeHelper(this, 
  204. ((CMiniCaApp *)AfxGetApp())->GetThemeHelperST());
  205. m_Bselect.SetIcon(IDI_ICON12);
  206. m_Bselect.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
  207. CString strRoot = ((CMiniCaApp *)AfxGetApp())->GetAppPath();
  208. CString strPath;
  209. GetPrivateProfileString("PATH", "Cert","",strPath.GetBuffer(256),255, m_IniPathName);
  210. strPath.ReleaseBuffer();//在 GetBuffer 和 ReleaseBuffer 之间这个范围,一定不能使用你要操作的这个缓冲的 CString 对象的任何方法
  211. if(strPath.IsEmpty())
  212. SetCaPath(strRoot);
  213. else
  214. SetCaPath(strPath);
  215. return TRUE;  // return TRUE unless you set the focus to a control
  216. // EXCEPTION: OCX Property Pages should return FALSE
  217. }
  218. /*void CCertDbPage::OnBSave() //写入注册表
  219. {
  220. // TODO: Add your control notification handler code here
  221. CString strRegCode,strRootCert,strRootP12,strRootPwd,strServerP12,strServerPwd,strClientP12,strClientPwd;
  222. GetDlgItemText(IDC_EDIT2,strRootP12);
  223. GetDlgItemText(IDC_EDIT5,strRootPwd);
  224. GetDlgItemText(IDC_EDIT3,strServerP12);
  225. GetDlgItemText(IDC_EDIT6,strServerPwd);
  226. GetDlgItemText(IDC_EDIT4,strClientP12);
  227. GetDlgItemText(IDC_EDIT7,strClientPwd);
  228. GetDlgItemText(IDC_EDIT_REGCODE,strRegCode);
  229. CString RegMiniCA,RegRootCert,RegRootP12,RegRootPwd,RegServerP12,RegServerPwd,RegClientP12,
  230. RegClientPwd;//注册表项
  231. RegMiniCA.LoadString(IDS_REG_KEY);
  232. RegRootCert.LoadString(IDS_ROOT_CERT);
  233. RegRootP12.LoadString(IDS_ROOT_P12);
  234. RegRootPwd.LoadString(IDS_ROOT_PWD);
  235. RegServerP12.LoadString(IDS_SERVER_P12);
  236. RegServerPwd.LoadString(IDS_SERVER_PWD);
  237. RegClientP12.LoadString(IDS_CLIENT_P12);
  238. RegClientPwd.LoadString(IDS_CLIENT_PWD);
  239. HKEY hKey = NULL; 
  240. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegMiniCA, 0, KEY_SET_VALUE, &hKey)!=ERROR_SUCCESS) //打开错误
  241. {
  242. return;
  243. }
  244. //加密各信息 注册码作为pwd
  245. char encInfo[512]={0};
  246. UINT encLen=0;
  247. char outMsg[100]={0};
  248. if(strRootP12.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  249. {
  250. RegDeleteValue(hKey,RegRootP12);
  251. }
  252. else if(Crypt("idea-cbc",strRootP12.GetBuffer(0),strRootP12.GetLength(),encInfo,encLen,
  253. strRegCode.GetBuffer(0),1,outMsg,NULL))
  254. {
  255. if (RegSetValueEx(hKey,RegRootP12,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  256. {
  257. AddMsg("创建RootP12键错误",M_ERROR);
  258. }
  259. memset(encInfo,0,512);
  260. encLen=0;
  261. }
  262. if(strRootPwd.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  263. {
  264. RegDeleteValue(hKey,RegRootPwd);
  265. }
  266. else if(Crypt("idea-cbc",strRootPwd.GetBuffer(0),strRootPwd.GetLength(),encInfo,encLen,
  267. strRegCode.GetBuffer(0),1,outMsg,NULL))
  268. {
  269. if (RegSetValueEx(hKey,RegRootPwd,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  270. {
  271. AddMsg("创建RegRootPwd键错误",M_ERROR);
  272. }
  273. memset(encInfo,0,512);
  274. encLen=0;
  275. }
  276. if(strServerP12.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  277. {
  278. RegDeleteValue(hKey,RegServerP12);
  279. }
  280. else if(Crypt("idea-cbc",strServerP12.GetBuffer(0),strServerP12.GetLength(),encInfo,encLen,
  281. strRegCode.GetBuffer(0),1,outMsg,NULL))
  282. {
  283. if (RegSetValueEx(hKey,RegServerP12,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  284. {
  285. AddMsg("创建RegServerP12键错误",M_ERROR);
  286. }
  287. memset(encInfo,0,512);
  288. encLen=0;
  289. }
  290. if(strServerPwd.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  291. {
  292. RegDeleteValue(hKey,RegServerPwd);
  293. }
  294. else if(Crypt("idea-cbc",strServerPwd.GetBuffer(0),strServerPwd.GetLength(),encInfo,encLen,
  295. strRegCode.GetBuffer(0),1,outMsg,NULL))
  296. {
  297. if(RegSetValueEx(hKey,RegServerPwd,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  298. {
  299. AddMsg("创建RegServerPwd键错误",M_ERROR);
  300. }
  301. memset(encInfo,0,512);
  302. encLen=0;
  303. }
  304. if(strClientP12.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  305. {
  306. RegDeleteValue(hKey,RegClientP12);
  307. }
  308. else if(Crypt("idea-cbc",strClientP12.GetBuffer(0),strClientP12.GetLength(),encInfo,encLen,
  309. strRegCode.GetBuffer(0),1,outMsg,NULL))
  310. {
  311. if (RegSetValueEx(hKey,RegClientP12,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  312. {
  313. AddMsg("创建RegClientP12键错误",M_ERROR);
  314. }
  315. memset(encInfo,0,512);
  316. encLen=0;
  317. }
  318. if(strClientPwd.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  319. {
  320. RegDeleteValue(hKey,RegClientPwd);
  321. }
  322. else if(Crypt("idea-cbc",strClientPwd.GetBuffer(0),strClientPwd.GetLength(),encInfo,encLen,
  323. strRegCode.GetBuffer(0),1,outMsg,NULL))
  324. {
  325. if (RegSetValueEx(hKey,RegClientPwd,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  326. {
  327. AddMsg("创建RegClientPwd键错误",M_ERROR);
  328. }
  329. memset(encInfo,0,512);
  330. encLen=0;
  331. }
  332. if(strRootCert.IsEmpty())//如果为空,则不进行加密,直接删除Reg
  333. {
  334. RegDeleteValue(hKey,RegRootCert);
  335. }
  336. else if(Crypt("idea-cbc",strRootCert.GetBuffer(0),strRootCert.GetLength(),encInfo,encLen,
  337. strRegCode.GetBuffer(0),1,outMsg,NULL))
  338. {
  339. if(RegSetValueEx(hKey,RegRootCert,0,REG_BINARY,(UCHAR *)encInfo,encLen)!=ERROR_SUCCESS)
  340. {
  341. AddMsg("创建RootCert键错误",M_ERROR);
  342. }
  343. memset(encInfo,0,512);
  344. encLen=0;
  345. }
  346. ::RegCloseKey(hKey); 
  347. }
  348. */
  349. void CCertDbPage::OnRclickTreeSetup(NMHDR* pNMHDR, LRESULT* pResult) 
  350. {
  351. // TODO: Add your control notification handler code here
  352. CPoint point;
  353. GetCursorPos(&point); // 当前鼠标坐标
  354. CPoint PointInTree = point;
  355. m_TreeSetup.ScreenToClient( &PointInTree);
  356. UINT nFlag;
  357. HTREEITEM hItem = m_TreeSetup.HitTest( PointInTree, &nFlag);
  358. if(hItem == NULL)
  359. return;
  360. // m_TreeSetup.SelectItem(hItem);//设置选中
  361. DWORD dData = m_TreeSetup.GetItemData(hItem);
  362. CString strName = m_TreeSetup.GetItemText(hItem);
  363. if(dData < 100 || dData %100 !=0 || strName == MiniCT_1803)
  364. return;
  365. if(nFlag&TVHT_ONITEMLABEL) //查看菜单
  366. {
  367. BCMenu menu;
  368. menu.LoadMenu(IDR_MENU_CERTDB);
  369. menu.LoadToolbar(IDR_MINICAMENU);
  370. CLanguage::TranslateMenu(&menu, MAKEINTRESOURCE(IDR_MENU_SETUP));
  371. CMenu* pPopup = menu.GetSubMenu(0);
  372. ASSERT(pPopup);
  373. UINT nSelection = pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL|
  374. TPM_NONOTIFY|TPM_RETURNCMD,point.x, point.y, this, NULL);
  375. menu.DestroyMenu();
  376. //返回菜单id
  377. CString m_CdbPath = ((CMiniCaApp *)AfxGetApp())->GetAppPath() + "\CertDB.CDB";
  378. CFile file;
  379. char buf[100] = {0};
  380. if(!file.Open(m_CdbPath,CFile::modeRead))
  381. return;
  382. for(;;)
  383. {
  384. stuCertDB CertDB;
  385. int len = file.Read(&CertDB,sizeof(stuCertDB));
  386. if(len==0)
  387. break;
  388. if(CertDB._uID != dData)
  389. continue;
  390. {
  391. if(nSelection == ID_MENUITEM_CERTVIEW)
  392. {
  393. ((CMiniMainDlg *)GetParent())->ViewCertInfo(CertDB._chINFO,CertDB._uLENGTH,0);
  394. }
  395. else if(nSelection == ID_MENUITEM_CERTIMPORT)
  396. {
  397. CMiniCaApp::AddRootToStore(CertDB._chINFO, CertDB._uLENGTH); //加入der格式根证书
  398. }
  399. }
  400. break;
  401. }
  402. file.Close();
  403. }
  404. *pResult = 0;
  405. }
  406. void CCertDbPage::OnBSavecdb()
  407. {
  408. m_TreeSetup.Savecdb();
  409. }
  410. void CCertDbPage::OnBResertdb() //证书库还原
  411. {
  412. // TODO: Add your control notification handler code here
  413. UINT uCrc = 0;
  414. CString strCrc;
  415. if(::MessageBox(this->m_hWnd, MiniCT_1810, MiniCT_0010,MB_ICONQUESTION | MB_YESNO)!=IDYES)
  416. return;
  417. /*得到配置*/
  418. HRSRC hRsrc=FindResource(NULL,MAKEINTRESOURCE(IDR_CERTDB_INI),"INI");
  419. DWORD lenCert = SizeofResource(NULL, hRsrc); 
  420. HGLOBAL hgCert=LoadResource(NULL,hRsrc);
  421. LPSTR lpCert=(LPSTR)LockResource(hgCert);
  422. CString m_IniPathName = ((CMiniCaApp *)AfxGetApp())->GetAppPath() +  "\CertDB.CDB";
  423. CFile file;
  424. file.Open(m_IniPathName,CFile::modeCreate|CFile::modeWrite); //存文件
  425. {
  426. file.Write(lpCert,lenCert);
  427. }
  428. file.Close();
  429. m_TreeSetup.LoadCdb();
  430. }
  431. void CCertDbPage::AddMsg(CString info, DWORD type)
  432. {
  433. ((CMiniMainDlg *)GetParent())->AddMsg(MiniCT_0007, info, type);
  434. }
  435. BOOL CCertDbPage::PreTranslateMessage(MSG* pMsg)
  436. {
  437. // 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.
  438. }
  439. UINT CCertDbPage::GetNameType()
  440. {
  441. UINT uSelect ;
  442. if(((CButton*)GetDlgItem(IDC_DB_RADIO1))->GetCheck())
  443. uSelect = 0;
  444. else if(((CButton*)GetDlgItem(IDC_DB_RADIO2))->GetCheck())
  445. uSelect = 1;
  446. else if(((CButton*)GetDlgItem(IDC_DB_RADIO3))->GetCheck())
  447. uSelect = 2;
  448. else if(((CButton*)GetDlgItem(IDC_DB_RADIO4))->GetCheck())
  449. uSelect = 3;
  450. return uSelect;
  451. }
  452. void CCertDbPage::OnBSelect() 
  453. {
  454. // TODO: Add your control notification handler code here
  455. LPITEMIDLIST pidlRoot = NULL; 
  456. LPMALLOC pMalloc;   
  457. if(NOERROR == SHGetSpecialFolderLocation(m_hWnd,CSIDL_DRIVES ,&pidlRoot)) //leak
  458. {
  459. BROWSEINFO bi;   //必须传入的参数,下面就是这个结构的参数的初始化 
  460. CString strDisplayName;// = CMiniCaApp::NormalCode("选择文件夹");;   //用来得到,你选择的活页夹路径,相当于提供一个缓冲区 
  461. bi.hwndOwner = GetSafeHwnd();   //得到父窗口Handle值 
  462. bi.pidlRoot=0;   //这个变量就是我们在上面得到的. 
  463. bi.pszDisplayName = strDisplayName.GetBuffer(MAX_PATH+1);   //得到缓冲区指针, 
  464. CString strTitle = MiniCT_1811;
  465. bi.lpszTitle = strTitle;  //设置标题 
  466. bi.ulFlags = BIF_RETURNONLYFSDIRS  | BIF_DONTGOBELOWDOMAIN  ;   //设置标志 
  467. bi.lpfn=NULL; 
  468. bi.lParam=0; 
  469. bi.iImage=0;   //上面这个是一些无关的参数的设置,最好设置起来, 
  470. ITEMIDLIST * pidl;  
  471. pidl = SHBrowseForFolder(&bi);   //打开对话框 
  472. if(!pidl)
  473. return;
  474. SHGetPathFromIDList(pidl,bi.pszDisplayName);
  475. strDisplayName.ReleaseBuffer();   //和上面的GetBuffer()相对应 
  476. SetCaPath(strDisplayName);
  477. if(SUCCEEDED( SHGetMalloc ( &pMalloc ))) // leak
  478. pMalloc->Free(pidlRoot); 
  479. pMalloc->Release(); 
  480. }
  481. }
  482. void CCertDbPage::SetCaPath(CString strPath)
  483. {
  484. //创建目录
  485. //结构
  486. //MiniCA.exe attrib desktop.ini +h +s
  487. // strPath + MiniCACert
  488. // +  CaCert //CA中心证书存放位置
  489. //                  + WizardCert          //数证向导
  490. SetDlgItemText(IDC_EDIT_SAVE, strPath);
  491. //得到证书命名选项
  492. WritePrivateProfileString("PATH", "Cert",strPath.GetBuffer(256), m_IniPathName);
  493. // SetPathInfo(strPath, "%SystemRoot%\system32\SHELL32.dll", "150", "MiniCA V2.0");  利用系统图标
  494. TCHAR szProgPath[MAX_PATH * 2];
  495. ::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));
  496. CString sMiniCA;
  497. sMiniCA.Format("%s", szProgPath);
  498. SetPathInfo(strPath, szProgPath, "12", MiniCT_1812);  //利用minica图标
  499. //首先建立 strPath + MiniCACert
  500. DWORD dErrCode = 0;
  501. BOOL b = CreateDirectory(strPath + "\MiniCACert", NULL);
  502. if(!b)
  503. dErrCode = GetLastError();
  504. // HTREEITEM hPathItem = m_PathTree.InsertItem(strPath + "\MiniCACert",0,0);
  505. // SetPathInfo(strPath + "\MiniCACert", "%SystemRoot%\system32\SHELL32.dll", "47", 
  506. // CMiniCaApp::NormalCode("MiniCA 证书中心"));
  507. //设置文件夹属性
  508. //建立 strPath + MiniCACert + CaCert
  509. b = CreateDirectory(strPath + "\MiniCACert\CaCert", NULL);
  510. if(!b)
  511. dErrCode = GetLastError();
  512. // HTREEITEM hPathSecond = m_PathTree.InsertItem(strPath + "\MiniCACert\CaCert",hPathItem,0);
  513. CMiniMainDlg * pMain = (CMiniMainDlg *)AfxGetMainWnd();
  514. CCaCenterPage * pCa = (CCaCenterPage *)(pMain->GetPage("CCaCenterPage"));
  515. //strPath可能带有\比如c:\时候就带有,这时候要去掉这个
  516. if(strPath.Right(1) == "\")
  517. {
  518. strPath.Delete(strPath.GetLength() -1);
  519. }
  520. if(pCa)
  521. {
  522. pCa->SetNamePath(strPath + "\MiniCACert\CaCert");
  523. }
  524. //建立 strPath + MiniCACert + CaCert + MiniCACert
  525. // b = CreateDirectory(strPath + "\MiniCACert\CaCert\Cert", NULL);
  526. // if(!b)
  527. // dErrCode = GetLastError();
  528. // m_PathTree.InsertItem(strPath + "\MiniCACert\CaCert\Cert",hPathSecond,0);
  529. // m_PathStrArray.Add(strPath + "\MiniCACert\CaCert\Cert");
  530. //建立 strPath + MiniCACert + CaCert + Crl
  531. // b = CreateDirectory(strPath + "\MiniCACert\CaCert\Crl", NULL);
  532. // if(!b)
  533. /// dErrCode = GetLastError();
  534. // m_PathTree.InsertItem(strPath + "\MiniCACert\CaCert\Crl",hPathSecond,0);
  535. // m_PathStrArray.Add(strPath + "\MiniCACert\CaCert\Crl");
  536. //建立 strPath + MiniCACert + WizardCert
  537. b = CreateDirectory(strPath + "\MiniCACert\WizardCert", NULL);
  538. if(!b)
  539. dErrCode = GetLastError();
  540. // hPathSecond = m_PathTree.InsertItem(strPath + "\MiniCACert\WizardCert",hPathItem,0);
  541. CCaCertWizardSheet * pWizard = (CCaCertWizardSheet *)(pMain->GetPage("CCaCertWizardSheet"));
  542. if(pWizard)
  543. {
  544. CCaCertInfoPage * pCaInfo = (CCaCertInfoPage *)(pWizard->GetPage("CCaCertInfoPage"));
  545. CCaCertManPage * pCaMan = (CCaCertManPage *)(pWizard->GetPage("CCaCertManPage"));
  546. if(pCaInfo) 
  547. {
  548. pCaInfo->SetNamePath(strPath + "\MiniCACert\WizardCert");
  549. }
  550. if(pCaMan) 
  551. {
  552. pCaMan->SetNamePath(strPath + "\MiniCACert\WizardCert");
  553. }
  554. }
  555. //建立 strPath + MiniCACert + WizardCert + Cert
  556. // b = CreateDirectory(strPath + "\MiniCACert\WizardCert\Cert", NULL);
  557. // if(!b)
  558. // dErrCode = GetLastError();
  559. // m_PathTree.InsertItem(strPath + "\MiniCACert\WizardCert\Cert",hPathSecond,0);
  560. // m_PathStrArray.Add(strPath + "\MiniCACert\WizardCert\Cert");
  561. //建立 strPath + MiniCACert + WizardCert + Crl
  562. // b = CreateDirectory(strPath + "\MiniCACert\WizardCert\Crl", NULL);
  563. // if(!b)
  564. // dErrCode = GetLastError();
  565. // m_PathTree.InsertItem(strPath + "\MiniCACert\WizardCert\Crl",hPathSecond,0);
  566. //建立 strPath + MiniCACert + WizardCert + Man
  567. // b = CreateDirectory(strPath + "\MiniCACert\WizardCert\Man", NULL);
  568. // if(!b)
  569. // dErrCode = GetLastError();
  570. // m_PathTree.InsertItem(strPath + "\MiniCACert\WizardCert\Man",hPathSecond,0);
  571. // m_PathStrArray.Add(strPath + "\MiniCACert\WizardCert\Man");
  572. }
  573. void CCertDbPage::SetPathInfo(CString strPath, CString strIconFile, CString strIconIndex, 
  574.  CString strInfoTip) //设置文件夹图标
  575. {
  576. //目录属性 %SystemRoot%system32SHELL32.dll
  577. // [.ShellClassInfo]
  578. // IconFile=.MiniCA.exe
  579. // IconIndex=0
  580. //除了给desktop.ini增加属性外,还要给当前要设置的路径增加 S 属性
  581. SetFileAttributes(strPath + "\desktop.ini", FILE_ATTRIBUTE_NORMAL); 
  582. WritePrivateProfileString(".ShellClassInfo", "ConfirmFileOp", "0", strPath + "\desktop.ini");
  583. WritePrivateProfileString(".ShellClassInfo", "IconFile", strIconFile, strPath + "\desktop.ini");
  584. WritePrivateProfileString(".ShellClassInfo", "InfoTip", strInfoTip, strPath + "\desktop.ini");
  585. WritePrivateProfileString(".ShellClassInfo", "IconIndex", strIconIndex, strPath + "\desktop.ini");
  586. SetFileAttributes(strPath + "\desktop.ini", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 
  587. SetFileAttributes(strPath , FILE_ATTRIBUTE_SYSTEM);
  588. }
  589. void CCertDbPage::TranslateCT()
  590. {
  591. //更新树控件
  592. m_TreeSetup.SetItemText(m_hItem[0], MiniCT_1800);
  593. m_TreeSetup.SetItemText(m_hItem[1], MiniCT_1801);
  594. m_TreeSetup.SetItemText(m_hItem[2], MiniCT_1802);
  595. m_TreeSetup.SetItemText(m_hItem[3], MiniCT_1803);
  596. m_TreeSetup.SetItemText(m_hItem[4], MiniCT_1804);
  597. m_TreeSetup.SetItemText(m_hItem[5], MiniCT_1805);
  598. m_TreeSetup.SetItemText(m_hItem[7], MiniCT_1806);
  599. m_TreeSetup.SetItemText(m_hItem[8], MiniCT_1802);
  600. m_TreeSetup.SetItemText(m_hItem[9], MiniCT_1803);
  601. m_TreeSetup.SetItemText(m_hItem[10], MiniCT_1804);
  602. m_TreeSetup.SetItemText(m_hItem[11], MiniCT_1805);
  603. m_TreeSetup.SetItemText(m_hItem[13], MiniCT_1807);
  604. m_TreeSetup.SetItemText(m_hItem[14], MiniCT_1802);
  605. m_TreeSetup.SetItemText(m_hItem[15], MiniCT_1803);
  606. m_TreeSetup.SetItemText(m_hItem[16], MiniCT_1804);
  607. m_TreeSetup.SetItemText(m_hItem[17], MiniCT_1805);
  608. m_TreeSetup.SetItemText(m_hItem[19], MiniCT_1808);
  609. m_TreeSetup.SetItemText(m_hItem[20], MiniCT_1802);
  610. m_TreeSetup.SetItemText(m_hItem[21], MiniCT_1803);
  611. m_TreeSetup.SetItemText(m_hItem[22], MiniCT_1804);
  612. m_TreeSetup.SetItemText(m_hItem[23], MiniCT_1805);
  613. m_TreeSetup.SetItemText(m_hItem[25], MiniCT_1809);
  614. m_TreeSetup.SetItemText(m_hItem[26], MiniCT_1802);
  615. m_TreeSetup.SetItemText(m_hItem[27], MiniCT_1803);
  616. m_TreeSetup.SetItemText(m_hItem[28], MiniCT_1804);
  617. m_TreeSetup.SetItemText(m_hItem[29], MiniCT_1805);
  618. m_TreeSetup.LoadCdb();
  619. //更新static控件
  620. SetDlgItemText(IDC_STATIC_SETUP2, MiniCT_11001);
  621. SetDlgItemText(IDC_STATIC_SETUP3, MiniCT_11002);
  622. SetDlgItemText(IDC_STATIC_SETUP4, MiniCT_11003);
  623. SetDlgItemText(IDC_STATIC_SETUP5, MiniCT_11004);
  624. SetDlgItemText(IDC_DB_RADIO1, MiniCT_11005);
  625. SetDlgItemText(IDC_DB_RADIO2, MiniCT_11006);
  626. SetDlgItemText(IDC_DB_RADIO3, MiniCT_11007);
  627. SetDlgItemText(IDC_DB_RADIO4, MiniCT_11008);
  628. SetDlgItemText(IDC_DB_SAVECDB, MiniCT_11009);
  629. SetDlgItemText(IDC_DB_RESERTDB, MiniCT_11010);
  630. SetDlgItemText(IDC_DB_SELECT, MiniCT_11011);
  631. }