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