1 |
/* wptPINDlg.cpp - PIN callback for smart cards |
2 |
* Copyright (C) 2003, 2004, 2005, 2006 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
*/ |
16 |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
18 |
#endif |
19 |
|
20 |
#include <windows.h> |
21 |
|
22 |
#include "resource.h" |
23 |
#include "wptW32API.h" |
24 |
#include "wptTypes.h" |
25 |
#include "wptGPG.h" |
26 |
#include "wptCommonCtl.h" |
27 |
#include "wptCard.h" |
28 |
#include "wptUTF8.h" |
29 |
|
30 |
|
31 |
/* Dialog procedure to reuqest the PIN from the user. */ |
32 |
BOOL CALLBACK |
33 |
pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
34 |
{ |
35 |
static pin_cb_ctx_s *pin; |
36 |
const char *s; |
37 |
int n, len; |
38 |
|
39 |
switch (msg) { |
40 |
case WM_INITDIALOG: |
41 |
pin = (struct pin_cb_ctx_s *)lparam; |
42 |
if (!pin) |
43 |
BUG (0); |
44 |
if (pin->info_text) |
45 |
s = pin->info_text; |
46 |
else |
47 |
s = _("Please enter the PIN"); |
48 |
CheckDlgButton (dlg, IDC_PIN_HIDE, BST_CHECKED); |
49 |
SetDlgItemText (dlg, IDC_PIN_HIDE, _("&Hide Typing")); |
50 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
51 |
SetDlgItemText (dlg, IDOK, _("&OK")); |
52 |
SetDlgItemText (dlg, IDC_PIN_INFO, s); |
53 |
center_window (dlg, NULL); |
54 |
SetFocus (GetDlgItem (dlg, IDC_PIN_VALUE)); |
55 |
SetForegroundWindow (dlg); |
56 |
return FALSE; |
57 |
|
58 |
case WM_COMMAND: |
59 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_PIN_HIDE) { |
60 |
HWND hwnd = GetDlgItem (dlg, IDC_PIN_VALUE); |
61 |
int hide = IsDlgButtonChecked (dlg, IDC_PIN_HIDE); |
62 |
|
63 |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
64 |
SetFocus (hwnd); |
65 |
} |
66 |
switch (LOWORD (wparam)) { |
67 |
case IDOK: |
68 |
n = SendDlgItemMessage (dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0); |
69 |
if (!n) { |
70 |
msg_box (dlg, _("Please enter a PIN."), _("PIN"), MB_ERR); |
71 |
return FALSE; |
72 |
} |
73 |
if (!pin->which || pin->which == CARD_ADMIN_PIN) { |
74 |
sfree_if_alloc (pin->apin); |
75 |
pin->apin = new char[n+2]; |
76 |
if (!pin->apin) |
77 |
BUG (0); |
78 |
len = GetDlgItemText (dlg, IDC_PIN_VALUE, pin->apin, n+1); |
79 |
if (len < 8) { |
80 |
msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."), |
81 |
_("PIN"), MB_ERR); |
82 |
sfree_if_alloc (pin->apin); |
83 |
return TRUE; |
84 |
} |
85 |
if (is_8bit_string (pin->apin)) { |
86 |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
87 |
_("PIN"), MB_ERR); |
88 |
sfree_if_alloc (pin->apin); |
89 |
return TRUE; |
90 |
} |
91 |
} |
92 |
else if( pin->which == CARD_USER_PIN) { |
93 |
sfree_if_alloc (pin->upin); |
94 |
pin->upin = new char[n+2]; |
95 |
if (!pin->upin) |
96 |
BUG (NULL); |
97 |
len = GetDlgItemText (dlg, IDC_PIN_VALUE, pin->upin, n+1); |
98 |
if (len < 6) { |
99 |
msg_box( dlg, _("'User PIN' must be at least 6 characters long."), |
100 |
_("PIN"), MB_ERR ); |
101 |
sfree_if_alloc (pin->upin); |
102 |
return TRUE; |
103 |
} |
104 |
if (is_8bit_string (pin->upin)) { |
105 |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
106 |
_("PIN"), MB_ERR); |
107 |
sfree_if_alloc (pin->upin); |
108 |
return TRUE; |
109 |
} |
110 |
} |
111 |
EndDialog (dlg, TRUE); |
112 |
break; |
113 |
|
114 |
case IDCANCEL: |
115 |
pin->apin = NULL; |
116 |
pin->upin = NULL; |
117 |
EndDialog (dlg, FALSE); |
118 |
break; |
119 |
} |
120 |
break; |
121 |
} |
122 |
return FALSE; |
123 |
} |