Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1054 lines
36 KiB

  1. /*******************************************************************************
  2. * Copyright (C) 1997 Gemplus International All Rights Reserved
  3. *
  4. * Name : GPKGUI.C
  5. *
  6. * Description : GUI used by Cryptographic Service Provider for GPK Card.
  7. *
  8. * Author : Laurent CASSIER
  9. *
  10. * Compiler : Microsoft Visual C 6.0
  11. *
  12. * Host : IBM PC and compatible machines under Windows 32 bit
  13. *
  14. * Release : 2.00.000
  15. *
  16. * Last Modif. :
  17. * 19/11/99: V2.xx.000 - Fixed bug #1797
  18. * 30/07/99: V2.xx.000 - Added function DisplayMessage()
  19. * - Added code to compile with UNICODE
  20. * - Renamed some resources ID, FP
  21. * 20/04/99: V2.00.000 - Merged versions of PKCS#11 and CSP, FJ
  22. * 20/04/99: V1.00.005 - Modification on supporting MBCS, JQ
  23. * 23/03/99: V1.00.004 - Replace KeyLen7 and KeyLen8 with KeyLen[], JQ
  24. * 05/01/98: V1.00.003 - Add Unblock PIN management.
  25. * 02/11/97: V1.00.002 - Separate code from GpkCsp Code.
  26. * 27/08/97: V1.00.001 - Begin implementation based on CSP kit.
  27. *
  28. ********************************************************************************
  29. *
  30. * Warning : This Version use the RsaBase CSP for software cryptography.
  31. *
  32. * Remark :
  33. *
  34. *******************************************************************************/
  35. #ifdef _UNICODE
  36. #define UNICODE
  37. #endif
  38. #include "gpkcsp.h"
  39. #define UM_CHANGE_TEXT WM_USER+1
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <tchar.h>
  43. #include "../gpkrsrc/resource.h"
  44. #include "gpkgui.h"
  45. /*-----------------------------------------------------------------------------
  46. Global Variable and Declaration for PIN an Progress DialogBox management
  47. ------------------------------------------------------------------------------*/
  48. HINSTANCE g_hInstMod = 0;
  49. HINSTANCE g_hInstRes = 0;
  50. HWND g_hMainWnd = 0;
  51. /* PIN DialogBox */
  52. char szGpkPin[PIN_MAX+2]; // [JMR 02-04]
  53. TCHAR szGpkPinGUI[PIN_MAX+2];
  54. DWORD dwGpkPinLen;
  55. char szGpkNewPin[PIN_MAX+2]; // [JMR 02-04]
  56. TCHAR szGpkNewPinGUI[PIN_MAX+2];
  57. WORD wGpkNewPinLen;
  58. BOOL bChangePin = FALSE;
  59. BOOL NoDisplay = FALSE;
  60. BOOL bNewPin = FALSE;
  61. BOOL bHideChange = FALSE;//TRUE - Don't display change button
  62. BOOL bUnblockPin = FALSE; // Unblock admin pin
  63. BOOL bUser = TRUE; // User pin
  64. // Dialogue Management: share with gpkgui.c !! it was defined in gpkcsp.c
  65. BYTE KeyLenFile[MAX_REAL_KEY] = {64, 128}; // version 2.00.002
  66. BYTE KeyLenChoice;
  67. TCHAR szKeyType[20];
  68. TCHAR s1[MAX_STRING], s2[MAX_STRING], s3[MAX_STRING];
  69. DWORD CspFlags;
  70. DWORD ContainerStatus;
  71. /* ProgressText DialogBox */
  72. TCHAR szProgTitle[MAX_STRING];
  73. TCHAR szProgText[MAX_STRING];
  74. HWND hProgressDlg = NULL;
  75. FARPROC lpProgressDlg = NULL;
  76. HCURSOR hCursor, hCursor2;
  77. /* Progress DialogBox cancel button, PKCS#11 specific */
  78. TCHAR szProgButton[32];
  79. BOOL IsProgButtoned = FALSE;
  80. BOOL IsProgButtonClick = FALSE;
  81. // not used... [FP]
  82. /*static void wait(DWORD TimeOut)
  83. {
  84. DWORD begin, end, now;
  85. begin = GetTickCount();
  86. end = begin + TimeOut;
  87. do
  88. {
  89. now = GetTickCount();
  90. }
  91. while(now < end);
  92. }*/
  93. // This function is used for cosmetic purpose
  94. // It erase text displayed on DialogBox by strink,
  95. // and display new text with "camera" effect
  96. static void set_effect(HWND hDlg,
  97. DWORD Id,
  98. TCHAR *szText
  99. )
  100. {
  101. #ifdef _CAMERA_EFFECT_
  102. TCHAR Buff[256];
  103. TCHAR Text[256];
  104. long i, j;
  105. GetDlgItemText(hDlg, Id, Buff, sizeof(Buff) / sizeof(TCHAR));
  106. j = _tcslen(Buff);
  107. for (i = 0; i < (long)(_tcsclen(Buff)/2); i++)
  108. {
  109. _tcsset(Text, 0x00);
  110. _tcsncpy(Text, _tcsninc(Buff,i), j);
  111. j = j - 2;
  112. SetDlgItemText(hDlg, Id, Text);
  113. // wait(50);
  114. }
  115. _tcscpy(Buff, szText);
  116. _tcscat(Buff, TEXT(" "));
  117. j = 2;
  118. for (i = _tcsclen(Buff)/2; i >= 0; i--)
  119. {
  120. _tcsset(Text, 0x00);
  121. _tcsncpy(Text, _tcsninc(Buff,i), j);
  122. j = j + 2;
  123. SetDlgItemText(hDlg, Id, Text);
  124. // wait(50);
  125. }
  126. #else
  127. SetDlgItemText(hDlg, Id, szText);
  128. #endif
  129. }
  130. /*******************************************************************************
  131. Function to display a message box with a particular text
  132. *******************************************************************************/
  133. void DisplayMessage( LPTSTR szMsg, LPTSTR szCaption, void* pValue)
  134. {
  135. TCHAR szTmp[MAX_STRING]=TEXT("");
  136. TCHAR szTmp1[MAX_STRING]=TEXT("");
  137. TCHAR szTmp2[MAX_STRING]=TEXT("");
  138. TCHAR szText[MAX_STRING]=TEXT("");
  139. if (_tcscmp(TEXT("locked"), szMsg) == 0)
  140. {
  141. LoadString(g_hInstRes, IDS_GPKUI_CARDLOCKED, szText, sizeof(szText)/sizeof(TCHAR));
  142. }
  143. else if (_tcscmp(TEXT("badpin"), szMsg) == 0)
  144. {
  145. LoadString(g_hInstRes, IDS_GPKUI_BADPINCODE, szTmp1, sizeof(szTmp1)/sizeof(TCHAR));
  146. LoadString(g_hInstRes, IDS_GPKUI_NBRTRYLEFT, szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
  147. _sntprintf(szTmp, (sizeof(szTmp)/sizeof(TCHAR))-1, TEXT("%s\n%s"), szTmp1, szTmp2);
  148. szTmp[(sizeof(szTmp)/sizeof(TCHAR))-1]=0;
  149. _sntprintf(szText, (sizeof(szText)/sizeof(TCHAR))-1, szTmp, *(DWORD *)pValue);
  150. szText[(sizeof(szText)/sizeof(TCHAR))-1]=0;
  151. }
  152. MessageBox(NULL, szText, szCaption, MB_OK | MB_ICONEXCLAMATION);
  153. }
  154. #ifdef UNICODE
  155. //return true if all the wide character in szBuff are in the form 0x00XY, where XY
  156. //is an 8 bits ASCII character.
  157. //len is the number of TCHAR to check from szBuff
  158. int IsTextASCII16( const PTCHAR szBuff, unsigned int len )
  159. {
  160. unsigned int i;
  161. for( i = 0; i < len; i++ )
  162. {
  163. if( szBuff[i] & 0xFF00 )
  164. {
  165. return FALSE;
  166. }
  167. }
  168. return TRUE;
  169. }
  170. #endif
  171. /*------------------------------------------------------------------------------
  172. Functions for PIN Dialog Box Management
  173. ------------------------------------------------------------------------------*/
  174. INT_PTR CALLBACK PinDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  175. {
  176. static TCHAR Buff[PIN_MAX+2]; // [JMR 02-04]
  177. static TCHAR szPinMemo[PIN_MAX+2]; // [JMR 02-04]
  178. static WORD wPinMemoLen;
  179. TCHAR szCaption[MAX_STRING];
  180. #ifdef UNICODE
  181. static TCHAR szPreviousPin[PIN_MAX+2];
  182. static TCHAR szPreviousPin1[PIN_MAX+2];
  183. unsigned int len, CurOffset;
  184. #endif
  185. switch (message)
  186. {
  187. case WM_INITDIALOG:
  188. {
  189. TCHAR szUserPin[MAX_STRING];
  190. TCHAR szSOPin[MAX_STRING];
  191. TCHAR szTitle[MAX_STRING];
  192. // Sets window title
  193. LoadString(g_hInstRes, IDS_GPKUI_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  194. SetWindowText(hDlg,szTitle);
  195. /* Returns the size in bytes */
  196. LoadString(g_hInstRes, IDS_GPKUI_USERPIN, szUserPin, sizeof(szUserPin) / sizeof(TCHAR));
  197. LoadString(g_hInstRes, IDS_GPKUI_SOPIN, szSOPin, sizeof(szSOPin) / sizeof(TCHAR));
  198. set_effect(hDlg, IDC_PINDLGTXT1, TEXT(""));
  199. LoadString (g_hInstRes, IDS_CAPTION_CHANGEPIN, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  200. SetDlgItemText(hDlg, IDB_CHANGE, szCaption);
  201. LoadString (g_hInstRes, IDS_CAPTION_OK, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  202. SetDlgItemText(hDlg, IDOK, szCaption);
  203. LoadString (g_hInstRes, IDS_CAPTION_CANCEL, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  204. SetDlgItemText(hDlg, IDCANCEL, szCaption);
  205. if (bUser)
  206. {
  207. set_effect(hDlg, IDC_PINDLGTXT, szUserPin);
  208. }
  209. else
  210. {
  211. set_effect(hDlg, IDC_PINDLGTXT, szSOPin);
  212. }
  213. if (bHideChange)
  214. {
  215. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  216. }
  217. if (bUnblockPin)
  218. {
  219. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  220. if (bNewPin)
  221. {
  222. TCHAR szNewUserPin[256];
  223. TCHAR szNewSOPin[256];
  224. /* Returns the size in bytes */
  225. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  226. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  227. ShowWindow(GetDlgItem(hDlg, IDC_PIN1), SW_SHOW);
  228. if (bUser)
  229. {
  230. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  231. }
  232. else
  233. {
  234. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  235. }
  236. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  237. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  238. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  239. }
  240. else
  241. {
  242. TCHAR szPinLocked[256];
  243. TCHAR szUnblockCode[256];
  244. /* Returns the size in bytes */
  245. LoadString(g_hInstRes, IDS_GPKUI_PINLOCKED, szPinLocked, sizeof(szPinLocked) / sizeof(TCHAR));
  246. LoadString(g_hInstRes, IDS_GPKUI_UNBLOCKCODE, szUnblockCode, sizeof(szUnblockCode) / sizeof(TCHAR));
  247. set_effect(hDlg, IDC_PINDLGTXT1, szPinLocked);
  248. set_effect(hDlg, IDC_PINDLGTXT, szUnblockCode);
  249. }
  250. }
  251. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  252. return(TRUE);
  253. }
  254. case WM_COMMAND:
  255. {
  256. switch(LOWORD(wParam))
  257. {
  258. case IDC_PIN:
  259. case IDC_PIN1:
  260. {
  261. WORD wPin1, wPin2;
  262. if ( (LOWORD(wParam) == IDC_PIN)
  263. &&(HIWORD(wParam) == EN_SETFOCUS)
  264. &&(bChangePin)
  265. )
  266. {
  267. TCHAR szNewUserPin[MAX_STRING];
  268. TCHAR szNewSOPin[MAX_STRING];
  269. /* Returns the size in bytes */
  270. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  271. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  272. if (bUser)
  273. {
  274. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  275. }
  276. else
  277. {
  278. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  279. }
  280. // + [FP] In the change password case, the confirmation box must be cleared
  281. //SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  282. // - [FP]
  283. break;
  284. }
  285. if ( (LOWORD(wParam) == IDC_PIN1)
  286. &&(HIWORD(wParam) == EN_SETFOCUS)
  287. )
  288. {
  289. wPin1 = (WORD)GetDlgItemText(hDlg,
  290. IDC_PIN,
  291. Buff,
  292. sizeof(Buff)/sizeof(TCHAR)
  293. );
  294. if (wPin1)
  295. {
  296. TCHAR szConfirmNewUserPin[MAX_STRING];
  297. TCHAR szConfirmNewSOPin[MAX_STRING];
  298. memset(Buff, 0, sizeof(Buff));
  299. if(Buff[0]) { MessageBeep(0); } // to prevent compiler from optimization
  300. LoadString(g_hInstRes, IDS_GPKUI_CONFIRMNEWUSERPIN, szConfirmNewUserPin, sizeof(szConfirmNewUserPin) / sizeof(TCHAR));
  301. LoadString(g_hInstRes, IDS_GPKUI_CONFIRMNEWSOPIN, szConfirmNewSOPin, sizeof(szConfirmNewSOPin) / sizeof(TCHAR));
  302. if (bUser)
  303. {
  304. set_effect(hDlg, IDC_PINDLGTXT, szConfirmNewUserPin);
  305. }
  306. else
  307. {
  308. set_effect(hDlg, IDC_PINDLGTXT, szConfirmNewSOPin);
  309. }
  310. // + [FP] This box should never be grayed out
  311. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), FALSE);
  312. // - [FP]
  313. }
  314. // [FP] SCR #50 (MS #310718)
  315. //else
  316. //{
  317. // SetFocus(GetDlgItem(hDlg, IDC_PIN));
  318. //}
  319. break;
  320. }
  321. if (HIWORD(wParam) == EN_CHANGE)
  322. {
  323. wPin1 = (WORD)GetDlgItemText(hDlg,
  324. IDC_PIN,
  325. Buff,
  326. sizeof(Buff)/sizeof(TCHAR)
  327. );
  328. #ifdef UNICODE
  329. len = _tcsclen( Buff );
  330. //get the current offset of the cursor in the entry field
  331. SendDlgItemMessage( hDlg, IDC_PIN, EM_GETSEL, (WPARAM) NULL, (WPARAM)(LPDWORD)&CurOffset);
  332. //verify if there is a character that is not an ASCII 16 bits
  333. if( !IsTextASCII16( Buff, len ) )
  334. {
  335. //replace the new PIN in the dlg with the previous
  336. memcpy( Buff, szPreviousPin, sizeof(szPreviousPin) );
  337. MessageBeep( MB_ICONEXCLAMATION );
  338. set_effect( hDlg, IDC_PIN, Buff );
  339. //adjust the offset of the cursor
  340. CurOffset = CurOffset - (len - _tcsclen(szPreviousPin));
  341. SendDlgItemMessage( hDlg, IDC_PIN, EM_SETSEL, CurOffset, CurOffset );
  342. break;
  343. }
  344. else
  345. {
  346. //replace the previous PIN with the new
  347. memcpy( szPreviousPin, Buff, sizeof(Buff) );
  348. }
  349. #endif
  350. memset(Buff, 0, sizeof(Buff));
  351. if(Buff[0]) { MessageBeep(0); } // to prevent compiler from optimization
  352. if ((bChangePin) || ((bUnblockPin) && (bNewPin)))
  353. {
  354. wPin2 = (WORD)GetDlgItemText(hDlg,
  355. IDC_PIN1,
  356. Buff,
  357. sizeof(Buff)/sizeof(TCHAR)
  358. );
  359. #ifdef UNICODE
  360. //verify if Buff contains a UNICODE character
  361. len = _tcsclen( Buff );
  362. //get the current offset of the cursor in the entry field
  363. SendDlgItemMessage( hDlg, IDC_PIN1, EM_GETSEL, (WPARAM) NULL, (WPARAM)(LPDWORD)&CurOffset);
  364. if( !IsTextASCII16( Buff, len ) )
  365. {
  366. //replace the new PIN in the dlg with the previous
  367. memcpy( Buff, szPreviousPin1, sizeof(szPreviousPin1) );
  368. MessageBeep( MB_ICONEXCLAMATION );
  369. set_effect( hDlg, IDC_PIN1, Buff );
  370. //adjust the offset of the cursor
  371. CurOffset = CurOffset - (len - _tcsclen(szPreviousPin1));
  372. SendDlgItemMessage( hDlg, IDC_PIN1, EM_SETSEL, CurOffset, CurOffset );
  373. break;
  374. }
  375. else
  376. {
  377. //replace the previous PIN with the new
  378. memcpy( szPreviousPin1, Buff, sizeof(Buff) );
  379. }
  380. #endif
  381. memset(Buff, 0, sizeof(Buff));
  382. if(Buff[0]) { MessageBeep(0); } // to prevent compiler from optimization
  383. }
  384. else
  385. {
  386. wPin2 = 4;
  387. }
  388. if ((wPin1 >= 4) && (wPin2 >= 4) && (wPin1 <= 8) && (wPin2 <= 8))
  389. {
  390. EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
  391. EnableWindow(GetDlgItem(hDlg, IDB_CHANGE), TRUE);
  392. }
  393. else
  394. {
  395. EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
  396. EnableWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  397. }
  398. }
  399. break;
  400. }
  401. case IDB_CHANGE:
  402. {
  403. TCHAR szNewUserPin[256];
  404. TCHAR szNewSOPin[256];
  405. /* Returns the size in bytes */
  406. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  407. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  408. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), SW_HIDE);
  409. dwGpkPinLen = (DWORD)GetDlgItemText(hDlg, IDC_PIN, szGpkPinGUI, PIN_MAX+1);
  410. #ifdef UNICODE
  411. wcstombs(szGpkPin, szGpkPinGUI, dwGpkPinLen);
  412. #else
  413. strcpy(szGpkPin, szGpkPinGUI);
  414. #endif
  415. bChangePin = TRUE;
  416. ShowWindow(GetDlgItem(hDlg, IDC_PIN1), SW_SHOW);
  417. if (bUser)
  418. {
  419. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  420. }
  421. else
  422. {
  423. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  424. }
  425. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  426. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  427. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  428. return(TRUE);
  429. }
  430. case IDOK:
  431. {
  432. if ((bChangePin) || ((bUnblockPin) && (bNewPin)))
  433. {
  434. TCHAR szWrongConfirm[MAX_STRING];
  435. TCHAR szChangePin[MAX_STRING];
  436. wPinMemoLen = (WORD)GetDlgItemText(hDlg, IDC_PIN, szPinMemo, PIN_MAX+1);
  437. wGpkNewPinLen = (WORD)GetDlgItemText(hDlg, IDC_PIN1, szGpkNewPinGUI, PIN_MAX+1);
  438. #ifdef UNICODE
  439. wcstombs(szGpkNewPin, szGpkNewPinGUI, wGpkNewPinLen);
  440. #else
  441. strcpy(szGpkNewPin, szGpkNewPinGUI);
  442. #endif
  443. if ( (wPinMemoLen != wGpkNewPinLen)
  444. ||(_tcscmp(szPinMemo, szGpkNewPinGUI))
  445. )
  446. {
  447. /* Returns the size in bytes */
  448. LoadString(g_hInstRes, IDS_GPKUI_WRONGCONFIRM, szWrongConfirm, sizeof(szWrongConfirm) / sizeof(TCHAR));
  449. LoadString(g_hInstRes, IDS_GPKUI_CHANGEPIN, szChangePin, sizeof(szChangePin) / sizeof(TCHAR));
  450. MessageBeep(MB_ICONASTERISK);
  451. MessageBox(hDlg,
  452. szWrongConfirm,
  453. szChangePin,
  454. MB_OK | MB_ICONEXCLAMATION
  455. );
  456. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  457. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  458. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), TRUE);
  459. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  460. break;
  461. }
  462. // [JMR 02-04] begin
  463. else
  464. {
  465. TCHAR szPinWrongLength[MAX_STRING];
  466. //TCHAR szChangePin[MAX_STRING];
  467. TCHAR szText[50];
  468. if ((wPinMemoLen > PIN_MAX) || (wPinMemoLen < PIN_MIN))
  469. {
  470. LoadString (g_hInstRes, IDS_GPKUI_PINWRONGLENGTH, szPinWrongLength, sizeof(szPinWrongLength) / sizeof(TCHAR));
  471. _sntprintf(szText, (sizeof(szText)/sizeof(TCHAR))-1, szPinWrongLength, PIN_MIN, PIN_MAX);
  472. szText[(sizeof(szText)/sizeof(TCHAR))-1]=0;
  473. LoadString (g_hInstRes, IDS_GPKUI_CHANGEPIN, szChangePin, sizeof(szChangePin) / sizeof(TCHAR));
  474. MessageBeep(MB_ICONASTERISK);
  475. MessageBox(hDlg,
  476. szText,
  477. szChangePin,
  478. MB_OK | MB_ICONEXCLAMATION
  479. );
  480. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  481. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  482. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), TRUE);
  483. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  484. break;
  485. }
  486. }
  487. }
  488. // [JMR 02-04] end
  489. else
  490. {
  491. dwGpkPinLen = (DWORD)GetDlgItemText(hDlg, IDC_PIN, szGpkPinGUI, PIN_MAX+1);
  492. #ifdef UNICODE
  493. wcstombs(szGpkPin, szGpkPinGUI, dwGpkPinLen);
  494. #else
  495. strcpy(szGpkPin, szGpkPinGUI);
  496. #endif
  497. }
  498. EndDialog(hDlg, wParam);
  499. return(TRUE);
  500. }
  501. case IDCANCEL:
  502. {
  503. strcpy(szGpkPin, "");
  504. dwGpkPinLen = 0;
  505. strcpy(szGpkNewPin, "");
  506. wGpkNewPinLen = 0;
  507. bChangePin = FALSE;
  508. MessageBeep(MB_ICONASTERISK);
  509. EndDialog(hDlg, wParam);
  510. return(TRUE);
  511. }
  512. }
  513. }
  514. case WM_DESTROY:
  515. {
  516. break;
  517. }
  518. }
  519. return(FALSE);
  520. }
  521. /*------------------------------------------------------------------------------
  522. Functions for Container Dialogue Management
  523. ------------------------------------------------------------------------------*/
  524. INT_PTR CALLBACK ContDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  525. {
  526. TCHAR szContinue[MAX_STRING];
  527. TCHAR szCaption[MAX_STRING];
  528. switch (message)
  529. {
  530. case WM_INITDIALOG:
  531. {
  532. TCHAR szTitle[MAX_STRING];
  533. // Sets window title
  534. LoadString(g_hInstRes, IDS_GPKUI_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  535. SetWindowText(hDlg,szTitle);
  536. LoadString (g_hInstRes, IDS_GPKUI_CONTINUE, szContinue, sizeof(szContinue)/sizeof(TCHAR));
  537. SetDlgItemText(hDlg, IDC_CONTDLGTXT, szContinue);
  538. LoadString (g_hInstRes, IDS_CAPTION_YES, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  539. SetDlgItemText(hDlg, IDYES, szCaption);
  540. LoadString (g_hInstRes, IDS_CAPTION_NO, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  541. SetDlgItemText(hDlg, IDNO, szCaption);
  542. SetFocus(GetDlgItem(hDlg, IDNO));
  543. return(TRUE);
  544. }
  545. case WM_COMMAND:
  546. {
  547. switch(LOWORD(wParam))
  548. {
  549. case IDYES:
  550. {
  551. ContainerStatus = ACCEPT_CONTAINER;
  552. EndDialog(hDlg, wParam);
  553. return(TRUE);
  554. }
  555. case IDNO:
  556. {
  557. ContainerStatus = ABORT_OPERATION;
  558. EndDialog(hDlg, wParam);
  559. return(TRUE);
  560. }
  561. }
  562. }
  563. case WM_DESTROY:
  564. {
  565. break;
  566. }
  567. }
  568. return(FALSE);
  569. }
  570. /*------------------------------------------------------------------------------
  571. Functions for Container Dialogue Management
  572. ------------------------------------------------------------------------------*/
  573. INT_PTR CALLBACK KeyDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  574. {
  575. TCHAR StrLen07[10];
  576. TCHAR StrLen08[10];
  577. TCHAR szMsg[300];
  578. TCHAR szChooseLength[MAX_STRING];
  579. TCHAR szCaption[MAX_STRING];
  580. switch (message)
  581. {
  582. case WM_INITDIALOG:
  583. {
  584. TCHAR szTitle[MAX_STRING];
  585. // Sets window title
  586. LoadString(g_hInstRes, IDS_GPKUI_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  587. SetWindowText(hDlg,szTitle);
  588. LoadString (g_hInstRes, IDS_GPKUI_CHOOSEKEYLENGTH, szChooseLength, sizeof(szChooseLength)/sizeof(TCHAR));
  589. //_tcscpy(szMsg, szChooseLength);
  590. //_tcscat(szMsg, szKeyType);
  591. _sntprintf(szMsg, (sizeof(szMsg)/sizeof(TCHAR))-1, TEXT("%s%s"), szChooseLength, szKeyType);
  592. szMsg[(sizeof(szMsg)/sizeof(TCHAR))-1]=0;
  593. // TT 12/10/99: If we get here, it means that we have 512 and 1024 bits
  594. // keys available. Don't use the length of the first two key files!
  595. //_stprintf(StrLen07, TEXT("%4d"), KeyLenFile[0]*8);
  596. //_stprintf(StrLen08, TEXT("%4d"), KeyLenFile[1]*8);
  597. _sntprintf(StrLen07, (sizeof(StrLen07)/sizeof(TCHAR))-1, TEXT("%4d"), 1024 );
  598. StrLen07[(sizeof(StrLen07)/sizeof(TCHAR))-1]=0;
  599. _sntprintf(StrLen08, (sizeof(StrLen08)/sizeof(TCHAR))-1, TEXT("%4d"), 512 );
  600. StrLen08[(sizeof(StrLen08)/sizeof(TCHAR))-1]=0;
  601. // TT: End
  602. // FP 05/11/99: Write text in the caption of the radio button
  603. //SetDlgItemText(hDlg, IDC_KEYLENGTH, StrLen07);
  604. //SetDlgItemText(hDlg, IDC_KEYLENGTH1, StrLen08);
  605. SetWindowText(GetDlgItem(hDlg, IDB_KEYLENGTH), StrLen07);
  606. SetWindowText(GetDlgItem(hDlg, IDB_KEYLENGTH1), StrLen08);
  607. // FP: End
  608. SetDlgItemText(hDlg, IDC_KEYDLGTXT, szMsg);
  609. KeyLenChoice = 1024/8;//KeyLenFile[0];
  610. CheckDlgButton(hDlg, IDB_KEYLENGTH, BST_CHECKED);
  611. LoadString (g_hInstRes, IDS_CAPTION_OK, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  612. SetDlgItemText(hDlg, IDOK, szCaption);
  613. LoadString (g_hInstRes, IDS_CAPTION_ABORT, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  614. SetDlgItemText(hDlg, IDABORT, szCaption);
  615. SetFocus(GetDlgItem(hDlg, IDOK));
  616. return(TRUE);
  617. }
  618. case WM_COMMAND:
  619. {
  620. switch(LOWORD(wParam))
  621. {
  622. case IDB_KEYLENGTH:
  623. {
  624. ShowWindow(GetDlgItem(hDlg, IDB_KEYLENGTH), SW_SHOW);
  625. KeyLenChoice = 1024/8;//TT 12/10/99 KeyLenFile[0];
  626. break;
  627. }
  628. case IDB_KEYLENGTH1:
  629. {
  630. ShowWindow(GetDlgItem(hDlg, IDB_KEYLENGTH1), SW_SHOW);
  631. KeyLenChoice = 512/8;//KeyLenFile[1];
  632. break;
  633. }
  634. case IDOK:
  635. {
  636. EndDialog(hDlg, wParam);
  637. return(TRUE);
  638. }
  639. case IDABORT:
  640. {
  641. KeyLenChoice = 0;
  642. EndDialog(hDlg, wParam);
  643. return(TRUE);
  644. }
  645. }
  646. }
  647. case WM_DESTROY:
  648. {
  649. break;
  650. }
  651. }
  652. return(FALSE);
  653. }
  654. /*------------------------------------------------------------------------------
  655. Functions for Progress Dialog Box Management
  656. ------------------------------------------------------------------------------*/
  657. /*******************************************************************************
  658. * void Wait (DWORD ulStep,
  659. * DWORD ulMaxStep,
  660. * DWORD ulSecond)
  661. *
  662. * Description : Change Progress Box Text.
  663. *
  664. * Remarks : Nothing.
  665. *
  666. * In : ulStep = Current step number.
  667. * ulMaxStep = Maximum step number.
  668. * ulSecond =
  669. *
  670. * Out : Nothing.
  671. *
  672. * Response : Nothing.
  673. *
  674. *******************************************************************************/
  675. void Wait(DWORD ulStep, DWORD ulMaxStep, DWORD ulSecond)
  676. {
  677. ULONG ulStart, ulEnd, ulBase, ulCur;
  678. TCHAR szTitle[MAX_STRING];
  679. TCHAR szText[MAX_STRING];
  680. TCHAR szTmp[MAX_STRING];
  681. LoadString(g_hInstRes, IDS_GPK4K_KEYGEN, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  682. _sntprintf(szTitle, (sizeof(szTitle)/sizeof(TCHAR))-1, szTmp, ulStep, ulMaxStep);
  683. szTitle[(sizeof(szTitle)/sizeof(TCHAR))-1]=0;
  684. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTITLE, szText, sizeof(szText)/sizeof(TCHAR));
  685. ShowProgress(NULL, szTitle, szText, NULL);
  686. #ifdef _TEST
  687. Sleep(1000); // Allow the tester to see the text displayed in the dialog box
  688. #endif
  689. ulStart = GetTickCount();
  690. ulEnd = ulStart + (ulSecond * 1000);
  691. ulBase = ulSecond * 10;
  692. ulCur = 0;
  693. while (GetTickCount() < ulEnd)
  694. {
  695. Yield();
  696. if (((GetTickCount() - ulStart) / ulBase) > ulCur)
  697. {
  698. ulCur++;
  699. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSPERCENT, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  700. _sntprintf(szText, (sizeof(szText)/sizeof(TCHAR))-1, szTmp, ulCur, (ulEnd-GetTickCount())/1000);
  701. szText[(sizeof(szText)/sizeof(TCHAR))-1]=0;
  702. ChangeProgressText(szText);
  703. }
  704. }
  705. DestroyProgress();
  706. }
  707. /*******************************************************************************/
  708. void ShowProgressWrapper(WORD wKeySize)
  709. {
  710. TCHAR szTmp[MAX_STRING]=TEXT("");
  711. TCHAR szTitle[MAX_STRING];
  712. TCHAR szText[MAX_STRING]=TEXT("");
  713. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTEXT, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  714. _sntprintf(szTitle, (sizeof(szTitle)/sizeof(TCHAR))-1, szTmp, wKeySize);
  715. szTitle[(sizeof(szTitle)/sizeof(TCHAR))-1]=0;
  716. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTITLE, szText, sizeof(szText)/sizeof(TCHAR));
  717. ShowProgress(GetActiveWindow(), szTitle, szText, NULL);
  718. }
  719. /*******************************************************************************/
  720. void ChangeProgressWrapper(DWORD dwTime)
  721. {
  722. TCHAR szTmp[MAX_STRING];
  723. TCHAR szText[MAX_STRING];
  724. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTIME, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  725. _sntprintf(szText, (sizeof(szText)/sizeof(TCHAR))-1, szTmp, dwTime);
  726. szText[(sizeof(szText)/sizeof(TCHAR))-1]=0;
  727. ChangeProgressText(szText);
  728. }
  729. /*******************************************************************************
  730. * void ShowProgress (HWND hWnd,
  731. * LPTSTR lpstrTitle,
  732. * LPTSTR lpstrText,
  733. * LPTSTR lpstrButton
  734. *
  735. * Description : Initialize Progress dialog box CALLBACK.
  736. *
  737. * Remarks : If lpstrButton is null, then don't display cancel button
  738. *
  739. * In : hWnd = Handle of parent window.
  740. * lpstrTitle = Pointer to Title of dialog box.
  741. * lpstrText = Pointer to Text of dialog box.
  742. * lpstrButton = Pointer to Text of button.
  743. *
  744. * Out : Nothing.
  745. *
  746. * Response : Nothing.
  747. *
  748. *******************************************************************************/
  749. void ShowProgress (HWND hWnd,
  750. LPTSTR lpstrTitle,
  751. LPTSTR lpstrText,
  752. LPTSTR lpstrButton
  753. )
  754. {
  755. if (!(CspFlags & CRYPT_SILENT))
  756. {
  757. if ((!hProgressDlg) && (!NoDisplay))
  758. {
  759. _tcscpy(szProgTitle, lpstrTitle);
  760. _tcscpy(szProgText, lpstrText);
  761. _tcscpy(szProgButton, TEXT(""));
  762. if (lpstrButton == NULL)
  763. {
  764. IsProgButtoned = FALSE;
  765. IsProgButtonClick = FALSE;
  766. //lpProgressDlg = MakeProcInstance((FARPROC)ProgressDlgProc, g_hInstRes);
  767. hProgressDlg = CreateDialog(g_hInstRes,
  768. TEXT("PROGDIALOG"),
  769. GetActiveWindow(),
  770. ProgressDlgProc
  771. );
  772. hCursor=SetCursor(LoadCursor(NULL,IDC_WAIT));
  773. }
  774. else
  775. {
  776. IsProgButtoned = TRUE;
  777. IsProgButtonClick = FALSE;
  778. _tcscpy(szProgButton, lpstrButton);
  779. DialogBox(g_hInstRes,
  780. TEXT("PROGDIALOG"),
  781. GetActiveWindow(),
  782. ProgressDlgProc
  783. );
  784. hProgressDlg = NULL;
  785. }
  786. }
  787. }
  788. }
  789. /*******************************************************************************
  790. * void ChangeProgressText (LPTSTR lpstrText)
  791. *
  792. * Description : Change Progress Box Text.
  793. *
  794. * Remarks : Nothing.
  795. *
  796. * In : lpstrText = Pointer to Text of dialog box.
  797. *
  798. * Out : Nothing.
  799. *
  800. * Response : Nothing.
  801. *
  802. *******************************************************************************/
  803. void ChangeProgressText (LPTSTR lpstrText)
  804. {
  805. if (hProgressDlg)
  806. {
  807. _tcscpy(szProgText, lpstrText);
  808. SendMessage(hProgressDlg,UM_CHANGE_TEXT,(WPARAM)NULL,(LPARAM)NULL);
  809. }
  810. }
  811. /*******************************************************************************
  812. * void DestroyProgress (void)
  813. *
  814. * Description : Destroy Progress dialog box CALLBACK.
  815. *
  816. * Remarks : Nothing.
  817. *
  818. * In : Nothing.
  819. *
  820. * Out : Nothing.
  821. *
  822. * Response : Nothing.
  823. *
  824. *******************************************************************************/
  825. void DestroyProgress (void)
  826. {
  827. if (!(CspFlags & CRYPT_SILENT))
  828. {
  829. if ((hProgressDlg) && (!NoDisplay))
  830. {
  831. DestroyWindow(hProgressDlg);
  832. FreeProcInstance(lpProgressDlg);
  833. hProgressDlg = NULL;
  834. SetCursor(hCursor);
  835. }
  836. }
  837. }
  838. /*******************************************************************************
  839. * INT_PTR CALLBACK ProgressDlgProc(HWND hDlg,
  840. * UINT message,
  841. * WPARAM wParam,
  842. * LPARAM lParam
  843. * )
  844. *
  845. * Description : CALLBACK for management of Progess Dialog Box.
  846. *
  847. * Remarks : Nothing.
  848. *
  849. * In : hDlg = Window handle.
  850. * message = Type of message.
  851. * wParam = Word message-specific information.
  852. * lParam = Long message-specific information.
  853. *
  854. * Out : Nothing.
  855. *
  856. * Responses : If everything is OK :
  857. * G_OK
  858. * If an condition error is raised:
  859. *
  860. *******************************************************************************/
  861. INT_PTR CALLBACK ProgressDlgProc(HWND hDlg,
  862. UINT message,
  863. WPARAM wParam,
  864. LPARAM lParam
  865. )
  866. {
  867. #ifdef _DISPLAY
  868. switch (message)
  869. {
  870. /* Initialize Dialog box */
  871. case WM_INITDIALOG:
  872. {
  873. SetWindowText(hDlg,(LPTSTR)szProgTitle);
  874. SetDlgItemText(hDlg,IDC_PROGDLGTXT,(LPCTSTR)szProgText);
  875. if (IsProgButtoned)
  876. {
  877. hProgressDlg = hDlg;
  878. ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
  879. SetWindowText(GetDlgItem(hDlg, IDCANCEL),(LPTSTR)szProgButton);
  880. }
  881. else
  882. {
  883. ShowWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
  884. }
  885. }
  886. return(TRUE);
  887. break;
  888. case UM_CHANGE_TEXT:
  889. {
  890. SetDlgItemText(hDlg,IDC_PROGDLGTXT,(LPTSTR)szProgText);
  891. }
  892. break;
  893. case WM_COMMAND:
  894. {
  895. switch(LOWORD(wParam))
  896. {
  897. case IDCANCEL:
  898. {
  899. IsProgButtonClick = TRUE;
  900. EndDialog(hDlg, wParam);
  901. return(TRUE);
  902. }
  903. }
  904. }
  905. break;
  906. default:
  907. return(FALSE);
  908. }
  909. #endif
  910. return (FALSE);
  911. }
  912. /*******************************************************************************
  913. Functions to set/unset cursor in wait mode
  914. *******************************************************************************/
  915. void BeginWait(void)
  916. {
  917. hCursor2=SetCursor(LoadCursor(NULL,IDC_WAIT));
  918. }
  919. void EndWait(void)
  920. {
  921. SetCursor(hCursor2);
  922. }