1 |
/* wptPINDlg.cpp - PIN callback for smart cards |
/* wptPINDlg.cpp - PIN callback for smart cards |
2 |
* Copyright (C) 2003, 2004 Timo Schulz |
* Copyright (C) 2003, 2004, 2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#include <windows.h> |
#include <windows.h> |
21 |
|
|
22 |
#include "../resource.h" |
#include "../resource.h" |
28 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
29 |
|
|
30 |
|
|
31 |
|
/* Dialog procedure to reuqest the PIN from the user. */ |
32 |
BOOL CALLBACK |
BOOL CALLBACK |
33 |
pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
34 |
{ |
{ |
35 |
|
static int hide = 1; |
36 |
static pin_cb_ctx_s * pin; |
static pin_cb_ctx_s * pin; |
37 |
const char * s; |
const char * s; |
38 |
int n, len; |
int n, len; |
39 |
|
|
40 |
switch( msg ) { |
switch (msg) { |
41 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
42 |
|
hide = 1; |
43 |
pin = (struct pin_cb_ctx_s *)lparam; |
pin = (struct pin_cb_ctx_s *)lparam; |
44 |
if (!pin) |
if (!pin) |
45 |
BUG (0); |
BUG (0); |
47 |
s = pin->info_text; |
s = pin->info_text; |
48 |
else |
else |
49 |
s = _("Please enter the PIN"); |
s = _("Please enter the PIN"); |
50 |
SetDlgItemText( dlg, IDC_PIN_INFO, s ); |
CheckDlgButton (dlg, IDC_PIN_HIDE, BST_CHECKED); |
51 |
center_window( dlg ); |
SetDlgItemText (dlg, IDC_PIN_INFO, s); |
52 |
SetFocus( GetDlgItem( dlg, IDC_PIN_VALUE ) ); |
center_window (dlg, NULL); |
53 |
SetForegroundWindow( dlg ); |
SetFocus( GetDlgItem (dlg, IDC_PIN_VALUE )); |
54 |
|
SetForegroundWindow (dlg); |
55 |
return FALSE; |
return FALSE; |
56 |
|
|
57 |
case WM_COMMAND: |
case WM_COMMAND: |
58 |
|
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_PIN_HIDE) { |
59 |
|
HWND hwnd = GetDlgItem (dlg, IDC_PIN_VALUE); |
60 |
|
hide ^= 1; |
61 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
62 |
|
SetFocus (hwnd); |
63 |
|
} |
64 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
65 |
case IDOK: |
case IDOK: |
66 |
n = SendDlgItemMessage( dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0 ); |
n = SendDlgItemMessage( dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0 ); |
68 |
msg_box( dlg, _("Please enter a PIN."), _("PIN"), MB_ERR ); |
msg_box( dlg, _("Please enter a PIN."), _("PIN"), MB_ERR ); |
69 |
return FALSE; |
return FALSE; |
70 |
} |
} |
71 |
if (!pin->which || pin->which == GPGME_EDITCARD_CHAPIN) { |
if (!pin->which || pin->which == CARD_ADMIN_PIN) { |
72 |
free_if_alloc (pin->apin); |
sfree_if_alloc (pin->apin); |
73 |
pin->apin = new char[n+2]; |
pin->apin = new char[n+2]; |
74 |
if (!pin->apin) |
if (!pin->apin) |
75 |
BUG (0); |
BUG (0); |
77 |
if (len < 8) { |
if (len < 8) { |
78 |
msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."), |
msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."), |
79 |
_("PIN"), MB_ERR); |
_("PIN"), MB_ERR); |
80 |
free_if_alloc (pin->apin); |
sfree_if_alloc (pin->apin); |
81 |
return FALSE; |
return FALSE; |
82 |
} |
} |
83 |
if (is_8bit_string (pin->apin)) { |
if (is_8bit_string (pin->apin)) { |
84 |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
85 |
_("PIN"), MB_ERR); |
_("PIN"), MB_ERR); |
86 |
free_if_alloc (pin->apin); |
sfree_if_alloc (pin->apin); |
87 |
return FALSE; |
return FALSE; |
88 |
} |
} |
89 |
} |
} |
90 |
else if( pin->which == GPGME_EDITCARD_CHUPIN) { |
else if( pin->which == CARD_USER_PIN) { |
91 |
free_if_alloc (pin->upin); |
sfree_if_alloc (pin->upin); |
92 |
pin->upin = new char[n+2]; |
pin->upin = new char[n+2]; |
93 |
if (!pin->upin) |
if (!pin->upin) |
94 |
BUG( NULL ); |
BUG( NULL ); |
96 |
if (len < 6) { |
if (len < 6) { |
97 |
msg_box( dlg, _("'User PIN' must be at least 6 characters long."), |
msg_box( dlg, _("'User PIN' must be at least 6 characters long."), |
98 |
_("PIN"), MB_ERR ); |
_("PIN"), MB_ERR ); |
99 |
free_if_alloc( pin->upin ); |
sfree_if_alloc (pin->upin); |
100 |
return FALSE; |
return FALSE; |
101 |
} |
} |
102 |
if (is_8bit_string (pin->upin)) { |
if (is_8bit_string (pin->upin)) { |
103 |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
msg_box (dlg, _("PIN's are currently limited to US-ASCII"), |
104 |
_("PIN"), MB_ERR); |
_("PIN"), MB_ERR); |
105 |
free_if_alloc (pin->upin); |
sfree_if_alloc (pin->upin); |
106 |
return FALSE; |
return FALSE; |
107 |
} |
} |
108 |
} |
} |
118 |
break; |
break; |
119 |
} |
} |
120 |
return FALSE; |
return FALSE; |
|
} /* pin_cb_dlg_proc */ |
|
121 |
|
} |