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

CA认证

开发平台:

Visual C++

  1. // SafeDataCdbPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "minica.h"
  5. #include "SafeDataCdbPage.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. // CSafeDataCdbPage property page
  16. IMPLEMENT_DYNCREATE(CSafeDataCdbPage, CPropertyPage)
  17. CSafeDataCdbPage::CSafeDataCdbPage() : CPropertyPage(CSafeDataCdbPage::IDD)
  18. {
  19. //{{AFX_DATA_INIT(CSafeDataCdbPage)
  20. //}}AFX_DATA_INIT
  21. }
  22. CSafeDataCdbPage::~CSafeDataCdbPage()
  23. {
  24. }
  25. void CSafeDataCdbPage::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CPropertyPage::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CSafeDataCdbPage)
  29. // DDX_Control(pDX, IDC_EDIT9, m_XpEdit9);
  30. // DDX_Control(pDX, IDC_EDIT6, m_XpEdit6);
  31. // DDX_Control(pDX, IDC_EDIT3, m_XpEdit3);
  32. //}}AFX_DATA_MAP
  33.     DDX_FileEditCtrl(pDX, IDC_EDIT8, m_Edit8, FEC_FILEOPEN);
  34.     DDX_FileEditCtrl(pDX, IDC_EDIT7, m_Edit7, FEC_FILEOPEN);
  35.     DDX_FileEditCtrl(pDX, IDC_EDIT5, m_Edit5, FEC_FILEOPEN);
  36.     DDX_FileEditCtrl(pDX, IDC_EDIT4, m_Edit4, FEC_FILEOPEN);
  37.     DDX_FileEditCtrl(pDX, IDC_EDIT2, m_Edit2, FEC_FILEOPEN);
  38.     DDX_FileEditCtrl(pDX, IDC_EDIT1, m_Edit1, FEC_FILEOPEN);
  39. }
  40. BEGIN_MESSAGE_MAP(CSafeDataCdbPage, CPropertyPage)
  41. //{{AFX_MSG_MAP(CSafeDataCdbPage)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CSafeDataCdbPage message handlers
  46. BOOL CSafeDataCdbPage::OnInitDialog() 
  47. {
  48. CPropertyPage::OnInitDialog();
  49. // TODO: Add extra initialization here
  50.     HANDLE handle = ::LoadImage(AfxGetInstanceHandle(),
  51.                                 MAKEINTRESOURCE(IDI_ICON_DIR),
  52.                                 IMAGE_ICON,
  53.                                 0,
  54.                                 0,
  55.                                 LR_DEFAULTCOLOR);
  56.     m_Edit8.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  57. m_Edit8.SetButtonWidth(18);
  58. m_Edit8.SetCaption(MiniCT_0714); //私鈅
  59. m_Edit8.SetFilter(MiniCT_0715);
  60.     m_Edit7.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  61. m_Edit7.SetButtonWidth(18);
  62. m_Edit7.SetCaption(MiniCT_0720); //公鈅
  63. m_Edit7.SetFilter(MiniCT_0721);
  64.     m_Edit5.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  65. m_Edit5.SetButtonWidth(18);
  66. m_Edit5.SetCaption(MiniCT_0714);
  67. m_Edit5.SetFilter(MiniCT_0715);
  68.     m_Edit4.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  69. m_Edit4.SetButtonWidth(18);
  70. m_Edit4.SetCaption(MiniCT_0720);
  71. m_Edit4.SetFilter(MiniCT_0721);
  72.     m_Edit2.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  73. m_Edit2.SetButtonWidth(18);
  74. m_Edit2.SetCaption(MiniCT_0714);
  75. m_Edit2.SetFilter(MiniCT_0715);
  76.     m_Edit1.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  77. m_Edit1.SetButtonWidth(18);
  78. m_Edit1.SetCaption(MiniCT_0734); //选择公钥证书文件(可多选)
  79. m_Edit1.SetFilter(MiniCT_0721);
  80. m_Edit1.ModifyFlags(0, FEC_MULTIPLE);
  81. if(!((CMiniCaApp *)AfxGetApp())->IsXpStyle())
  82. {
  83. ClassXP(GetDlgItem(IDC_EDIT3)->m_hWnd,TRUE);
  84. ClassXP(GetDlgItem(IDC_EDIT6)->m_hWnd,TRUE);
  85. ClassXP(GetDlgItem(IDC_EDIT9)->m_hWnd,TRUE);
  86. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK1)->m_hWnd,TRUE);
  87. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK2)->m_hWnd,TRUE);
  88. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK3)->m_hWnd,TRUE);
  89. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK4)->m_hWnd,TRUE);
  90. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK5)->m_hWnd,TRUE);
  91. ClassXP(GetDlgItem(IDC_SAFEDS_CHECK6)->m_hWnd,TRUE);
  92. }
  93. return TRUE;  // return TRUE unless you set the focus to a control
  94.               // EXCEPTION: OCX Property Pages should return FALSE
  95. }
  96. BOOL CSafeDataCdbPage::GetCertPair(EncType eType, BOOL bKeyType, 
  97.    char * sCert, DWORD & dLen,
  98.    CString & strPwd, CColorListBox * pList)
  99. {
  100. CColorListBox * p_List = NULL;
  101. if(!pList)
  102. {
  103. p_List = &((CMiniMainDlg *)AfxGetMainWnd())->m_ListBox;
  104. }
  105. else
  106. p_List = pList;
  107. BOOL bSucceed = TRUE;
  108. CString strPath;
  109. dLen = 0;
  110. switch(eType)
  111. {
  112. case SEAL:
  113. if(bKeyType)//公钥
  114. {
  115. GetDlgItemText(IDC_EDIT1, strPath);
  116. if(strPath.IsEmpty()) //调用内部证书
  117. {
  118. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(300, sCert, dLen, strPwd, TRUE, p_List);
  119. }
  120. else
  121. {
  122. strcpy(sCert, strPath.GetBuffer(0));
  123. if(IsWindow(p_List->m_hWnd))
  124. p_List->AddMsg(MiniCT_1400, M_WARING); //MiniCT_1400 加载外部证书...
  125. }
  126. }
  127. else//私钥
  128. {
  129. GetDlgItemText(IDC_EDIT2, strPath);
  130. GetDlgItemText(IDC_EDIT3, strPwd);
  131. if(strPath.IsEmpty()) //调用内部证书
  132. {
  133. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(310, sCert, dLen, strPwd, TRUE, p_List);
  134. }
  135. else
  136. {
  137. strcpy(sCert, strPath.GetBuffer(0));
  138. if(IsWindow(p_List->m_hWnd))
  139. p_List->AddMsg(MiniCT_1400, M_WARING);
  140. }
  141. }
  142. break;
  143. case SIGN:
  144. if(bKeyType)//公钥
  145. {
  146. GetDlgItemText(IDC_EDIT4, strPath);
  147. if(strPath.IsEmpty()) //调用内部证书
  148. {
  149. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(500, sCert, dLen, strPwd, TRUE, p_List);
  150. }
  151. else
  152. {
  153. strcpy(sCert, strPath.GetBuffer(0));
  154. if(IsWindow(p_List->m_hWnd))
  155. p_List->AddMsg(MiniCT_1400, M_WARING);
  156. }
  157. }
  158. else//私钥
  159. {
  160. GetDlgItemText(IDC_EDIT5, strPath);
  161. GetDlgItemText(IDC_EDIT6, strPwd);
  162. if(strPath.IsEmpty()) //调用内部证书
  163. {
  164. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(510, sCert, dLen, strPwd, TRUE, p_List);
  165. }
  166. else
  167. {
  168. strcpy(sCert, strPath.GetBuffer(0));
  169. if(IsWindow(p_List->m_hWnd))
  170. p_List->AddMsg(MiniCT_1400, M_WARING);
  171. }
  172. }
  173. break;
  174. case PubEnc:
  175. case PrivEnc:
  176. if(bKeyType)//公钥
  177. {
  178. GetDlgItemText(IDC_EDIT7, strPath);
  179. if(strPath.IsEmpty()) //调用内部证书
  180. {
  181. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(400, sCert, dLen, strPwd, TRUE, p_List);
  182. }
  183. else
  184. {
  185. strcpy(sCert, strPath.GetBuffer(0));
  186. if(IsWindow(p_List->m_hWnd))
  187. p_List->AddMsg(MiniCT_1400, M_WARING);
  188. }
  189. }
  190. else//私钥
  191. {
  192. GetDlgItemText(IDC_EDIT8, strPath);
  193. GetDlgItemText(IDC_EDIT9, strPwd);
  194. if(strPath.IsEmpty()) //调用内部证书
  195. {
  196. bSucceed =  ((CMiniCaApp *)AfxGetApp())->GetCertPair(410, sCert, dLen, strPwd, TRUE, p_List);
  197. }
  198. else
  199. {
  200. strcpy(sCert, strPath.GetBuffer(0));
  201. if(IsWindow(p_List->m_hWnd))
  202. p_List->AddMsg(MiniCT_1400, M_WARING);
  203. }
  204. }
  205. break;
  206. }
  207. return bSucceed;
  208. }
  209. void CSafeDataCdbPage::TranslateCT()
  210. {
  211. SetDlgItemText(IDC_SAFEDS_STATIC1, MiniCT_11501);
  212. SetDlgItemText(IDC_SAFEDS_STATIC2, MiniCT_11502);
  213. SetDlgItemText(IDC_SAFEDS_STATIC3, MiniCT_11503);
  214. SetDlgItemText(IDC_SAFEDS_STATIC4, MiniCT_11504);
  215. SetDlgItemText(IDC_SAFEDS_STATIC5, MiniCT_11505);
  216. SetDlgItemText(IDC_SAFEDS_STATIC6, MiniCT_11506);
  217. SetDlgItemText(IDC_SAFEDS_CHECK1, MiniCT_11507);
  218. SetDlgItemText(IDC_SAFEDS_CHECK2, MiniCT_11508);
  219. SetDlgItemText(IDC_SAFEDS_CHECK3, MiniCT_11509);
  220. SetDlgItemText(IDC_SAFEDS_CHECK4, MiniCT_11510);
  221. SetDlgItemText(IDC_SAFEDS_CHECK5, MiniCT_11511);
  222. SetDlgItemText(IDC_SAFEDS_CHECK6, MiniCT_11512);
  223. SetDlgItemText(IDC_SAFEDS_SAVE, MiniCT_11513);
  224. }