Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/auth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7635 - (show annotations) (download) (as text)
Mon Apr 29 16:22:21 2019 UTC (4 years, 11 months ago) by zmatsuo
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 63925 byte(s)
Visual Studio 2005でビルドできるよう修正
1 /*
2 * Copyright (c) 1998-2001, Robert O'Callahan
3 * (C) 2004-2019 TeraTerm Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "ttxssh.h"
31 #include "util.h"
32 #include "ssh.h"
33 #include "key.h"
34 #include "ttlib.h"
35 #include "dlglib.h"
36
37 #include <io.h>
38 #include <fcntl.h>
39 #include <stdlib.h>
40 #include <errno.h>
41 #include <Lmcons.h> // for UNLEN
42 #include <crtdbg.h>
43
44 #include "resource.h"
45 #include "keyfiles.h"
46 #include "libputty.h"
47 #include "tipwin.h"
48 #include "auth.h"
49
50 #if defined(_DEBUG)
51 #define malloc(l) _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
52 #define free(p) _free_dbg((p), _NORMAL_BLOCK)
53 #endif
54
55 #define AUTH_START_USER_AUTH_ON_ERROR_END 1
56
57 #define MAX_AUTH_CONTROL IDC_SSHUSEPAGEANT
58
59 #undef DialogBoxParam
60 #define DialogBoxParam(p1,p2,p3,p4,p5) \
61 TTDialogBoxParam(p1,p2,p3,p4,p5)
62 #undef EndDialog
63 #define EndDialog(p1,p2) \
64 TTEndDialog(p1, p2)
65
66 //static HFONT DlgAuthFont;
67 //static HFONT DlgTisFont;
68 //static HFONT DlgAuthSetupFont;
69
70 void destroy_malloced_string(char **str)
71 {
72 if (*str != NULL) {
73 SecureZeroMemory(*str, strlen(*str));
74 free(*str);
75 *str = NULL;
76 }
77 }
78
79 static int auth_types_to_control_IDs[] = {
80 -1, IDC_SSHUSERHOSTS, IDC_SSHUSERSA, IDC_SSHUSEPASSWORD,
81 IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1,
82 -1, -1, -1, -1, -1, -1, -1, -1, -1, IDC_SSHUSEPAGEANT, -1
83 };
84
85 typedef struct {
86 WNDPROC ProcOrg;
87 PTInstVar pvar;
88 TipWin *tipwin;
89 BOOL *UseControlChar;
90 } TPasswordControlData;
91
92 static void password_wnd_proc_close_tooltip(TPasswordControlData *data)
93 {
94 if (data->tipwin != NULL) {
95 TipWinDestroy(data->tipwin);
96 data->tipwin = NULL;
97 }
98 }
99
100 static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg,
101 WPARAM wParam, LPARAM lParam)
102 {
103 LRESULT result;
104 TPasswordControlData *data = (TPasswordControlData *)GetWindowLongPtr(control, GWLP_USERDATA);
105 switch (msg) {
106 case WM_CHAR:
107 if ((data->UseControlChar == NULL || *data->UseControlChar == TRUE) &&
108 (GetKeyState(VK_CONTROL) & 0x8000) != 0)
109 { // �����������g�p���� && CTRL�L�[��������������
110 TCHAR chars[] = { (TCHAR) wParam, 0 };
111
112 SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE,
113 (LPARAM) (TCHAR *) chars);
114
115 if (data->tipwin == NULL) {
116 TCHAR uimsg[MAX_UIMSG];
117 RECT rect;
118 PTInstVar pvar = data->pvar;
119 UTIL_get_lang_msg("DLG_AUTH_TIP_CONTROL_CODE", pvar, "control character is entered");
120 _tcscpy_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
121 if (wParam == 'V' - 'A' + 1) {
122 // CTRL + V
123 _tcscat_s(uimsg, _countof(uimsg), _T("\n"));
124 UTIL_get_lang_msg("DLG_AUTH_TIP_PASTE_KEY", pvar, "Use Shift + Insert to paste from clipboard");
125 _tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
126 }
127 GetWindowRect(control, &rect);
128 data->tipwin = TipWinCreate(control, rect.left, rect.bottom, uimsg);
129 }
130
131 return 0;
132 } else {
133 password_wnd_proc_close_tooltip(data);
134 }
135 break;
136 case WM_KILLFOCUS:
137 password_wnd_proc_close_tooltip(data);
138 break;
139 }
140
141 result = CallWindowProc((WNDPROC)data->ProcOrg,
142 control, msg, wParam, lParam);
143
144 if (msg == WM_NCDESTROY) {
145 SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)data->ProcOrg);
146 password_wnd_proc_close_tooltip(data);
147 free(data);
148 }
149
150 return result;
151 }
152
153 void init_password_control(PTInstVar pvar, HWND dlg, int item, BOOL *UseControlChar)
154 {
155 HWND passwordControl = GetDlgItem(dlg, item);
156 TPasswordControlData *data = (TPasswordControlData *)malloc(sizeof(TPasswordControlData));
157 data->ProcOrg = (WNDPROC)GetWindowLongPtr(passwordControl, GWLP_WNDPROC);
158 data->pvar = pvar;
159 data->tipwin = NULL;
160 data->UseControlChar = UseControlChar;
161 SetWindowLongPtr(passwordControl, GWLP_WNDPROC, (LONG_PTR)password_wnd_proc);
162 SetWindowLongPtr(passwordControl, GWLP_USERDATA, (LONG_PTR)data);
163 SetFocus(passwordControl);
164 }
165
166 static void set_auth_options_status(HWND dlg, int controlID)
167 {
168 BOOL RSA_enabled = controlID == IDC_SSHUSERSA;
169 BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS;
170 BOOL TIS_enabled = controlID == IDC_SSHUSETIS;
171 BOOL PAGEANT_enabled = controlID == IDC_SSHUSEPAGEANT;
172 int i;
173
174 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID);
175
176 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), (!TIS_enabled && !PAGEANT_enabled));
177 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), (!TIS_enabled && !PAGEANT_enabled));
178 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), (!TIS_enabled && !PAGEANT_enabled));
179
180 for (i = IDC_CHOOSERSAFILE; i <= IDC_RSAFILENAME; i++) {
181 EnableWindow(GetDlgItem(dlg, i), RSA_enabled);
182 }
183
184 for (i = IDC_LOCALUSERNAMELABEL; i <= IDC_HOSTRSAFILENAME; i++) {
185 EnableWindow(GetDlgItem(dlg, i), rhosts_enabled);
186 }
187 }
188
189 static void init_auth_machine_banner(PTInstVar pvar, HWND dlg)
190 {
191 char buf[1024], buf2[1024];
192
193 GetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf2, sizeof(buf2));
194 _snprintf_s(buf, sizeof(buf), _TRUNCATE, buf2, SSH_get_host_name(pvar));
195 SetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf);
196 }
197
198 static void update_server_supported_types(PTInstVar pvar, HWND dlg)
199 {
200 int supported_methods = pvar->auth_state.supported_types;
201 int cur_control = -1;
202 int control;
203 HWND focus = GetFocus();
204
205 if (supported_methods == 0) {
206 return;
207 }
208
209 for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL;
210 control++) {
211 BOOL enabled = FALSE;
212 int method;
213 HWND item = GetDlgItem(dlg, control);
214
215 if (item != NULL) {
216 for (method = 0; method <= SSH_AUTH_MAX; method++) {
217 if (auth_types_to_control_IDs[method] == control
218 && (supported_methods & (1 << method)) != 0) {
219 enabled = TRUE;
220 }
221 }
222
223 EnableWindow(item, enabled);
224
225 if (IsDlgButtonChecked(dlg, control)) {
226 cur_control = control;
227 }
228 }
229 }
230
231 if (cur_control >= 0) {
232 if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) {
233 do {
234 cur_control++;
235 if (cur_control > MAX_AUTH_CONTROL) {
236 cur_control = IDC_SSHUSEPASSWORD;
237 }
238 } while (!IsWindowEnabled(GetDlgItem(dlg, cur_control)));
239
240 set_auth_options_status(dlg, cur_control);
241
242 if (focus != NULL && !IsWindowEnabled(focus)) {
243 SetFocus(GetDlgItem(dlg, cur_control));
244 }
245 }
246 }
247 }
248
249 static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
250 {
251 const static DlgTextInfo text_info[] = {
252 { 0, "DLG_AUTH_TITLE" },
253 { IDC_SSHAUTHBANNER, "DLG_AUTH_BANNER" },
254 { IDC_SSHAUTHBANNER2, "DLG_AUTH_BANNER2" },
255 { IDC_SSHUSERNAMELABEL, "DLG_AUTH_USERNAME" },
256 { IDC_SSHPASSWORDCAPTION, "DLG_AUTH_PASSWORD" },
257 { IDC_REMEMBER_PASSWORD, "DLG_AUTH_REMEMBER_PASSWORD" },
258 { IDC_FORWARD_AGENT, "DLG_AUTH_FWDAGENT" },
259 { IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
260 { IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
261 { IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
262 { IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
263 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
264 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
265 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
266 { IDOK, "BTN_OK" },
267 { IDCANCEL, "BTN_DISCONNECT" },
268 };
269 int default_method = pvar->session_settings.DefaultAuthMethod;
270
271 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
272
273 init_auth_machine_banner(pvar, dlg);
274 init_password_control(pvar, dlg, IDC_SSHPASSWORD, UseControlChar);
275
276 // �F�����s�������x������������
277 if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
278 /* must be retrying a failed attempt */
279 UTIL_get_lang_msg("DLG_AUTH_BANNER2_FAILED", pvar, "Authentication failed. Please retry.");
280 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, pvar->ts->UIMsg);
281 UTIL_get_lang_msg("DLG_AUTH_TITLE_FAILED", pvar, "Retrying SSH Authentication");
282 SetWindowText(dlg, pvar->ts->UIMsg);
283 default_method = pvar->auth_state.failed_method;
284 }
285
286 // �p�X���[�h���o���������`�F�b�N�{�b�N�X�����f�t�H���g���L�������� (2006.8.3 yutaka)
287 if (pvar->ts_SSH->remember_password) {
288 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_CHECKED, 0);
289 } else {
290 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_UNCHECKED, 0);
291 }
292
293 // ForwardAgent �����������f���� (2008.12.4 maya)
294 CheckDlgButton(dlg, IDC_FORWARD_AGENT, pvar->settings.ForwardAgent);
295
296 // SSH �o�[�W������������ TIS �����x������������
297 if (pvar->settings.ssh_protocol_version == 1) {
298 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE1", pvar,
299 "Use challenge/response(&TIS) to log in");
300 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
301 } else {
302 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE2", pvar,
303 "Use keyboard-&interactive to log in");
304 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
305 }
306
307 if (pvar->auth_state.user != NULL) {
308 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
309 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
310 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
311 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
312 }
313 else if (strlen(pvar->ssh2_username) > 0) {
314 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
315 if (pvar->ssh2_autologin == 1) {
316 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
317 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
318 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
319 }
320 }
321 else {
322 switch(pvar->session_settings.DefaultUserType) {
323 case 0:
324 // ����������
325 break;
326 case 1:
327 // use DefaultUserName
328 if (pvar->session_settings.DefaultUserName[0] == 0) {
329 // �u�����������v����������
330 pvar->session_settings.DefaultUserType = 0;
331 } else {
332 SetDlgItemText(dlg, IDC_SSHUSERNAME,
333 pvar->session_settings.DefaultUserName);
334 }
335 break;
336 case 2: {
337 TCHAR user_name[UNLEN+1];
338 DWORD len = _countof(user_name);
339 BOOL r = GetUserName(user_name, &len);
340 if (r != 0) {
341 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
342 }
343 break;
344 }
345 default:
346 // ��������������������
347 pvar->session_settings.DefaultUserType = 0;
348 }
349 }
350
351 if (strlen(pvar->ssh2_password) > 0) {
352 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
353 if (pvar->ssh2_autologin == 1) {
354 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
355 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
356 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
357 }
358 }
359
360 SetDlgItemText(dlg, IDC_RSAFILENAME,
361 pvar->session_settings.DefaultRSAPrivateKeyFile);
362 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
363 pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
364 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
365 pvar->session_settings.DefaultRhostsLocalUserName);
366
367 if (pvar->ssh2_authmethod == SSH_AUTH_PASSWORD) {
368 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
369
370 } else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
371 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);
372
373 SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
374 if (pvar->ssh2_autologin == 1) {
375 EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
376 EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
377 }
378
379 // /auth=challenge ������ (2007.10.5 maya)
380 } else if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
381 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSETIS);
382 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
383 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
384 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
385
386 // /auth=pageant ������
387 } else if (pvar->ssh2_authmethod == SSH_AUTH_PAGEANT) {
388 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPAGEANT);
389 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
390 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
391 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
392
393 } else {
394 // �f�t�H���g���F�����\�b�h���_�C�A���O�����f
395 set_auth_options_status(dlg, auth_types_to_control_IDs[default_method]);
396
397 update_server_supported_types(pvar, dlg);
398
399 // �z�X�g�m�F�_�C�A���O��������������=�E�B���h�E���A�N�e�B�u������������
400 // �� SetFocus �����s�����A�R�}���h���C�����n�������F��������������������
401 // �����������A�������O�C���L������ SetFocus ������ (2009.1.31 maya)
402 if (default_method == SSH_AUTH_TIS) {
403 /* we disabled the password control, so fix the focus */
404 SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
405 }
406 else if (default_method == SSH_AUTH_PAGEANT) {
407 SetFocus(GetDlgItem(dlg, IDC_SSHUSEPAGEANT));
408 }
409
410 }
411
412 if (GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) == 0) {
413 SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
414 }
415 else if (pvar->ask4passwd == 1) {
416 SetFocus(GetDlgItem(dlg, IDC_SSHPASSWORD));
417 }
418
419 // '/I' �w�������������������������� (2005.9.5 yutaka)
420 if (pvar->ts->Minimize) {
421 //20050822���� start T.Takahashi
422 ShowWindow(dlg,SW_MINIMIZE);
423 //20050822���� end T.Takahashi
424 }
425 }
426
427 static char *alloc_control_text(HWND ctl)
428 {
429 int len = GetWindowTextLength(ctl);
430 char *result = malloc(len + 1);
431
432 if (result != NULL) {
433 GetWindowText(ctl, result, len + 1);
434 result[len] = 0;
435 }
436
437 return result;
438 }
439
440 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
441 {
442 OPENFILENAME params;
443 char fullname_buf[2048] = "identity";
444 char filter[MAX_UIMSG];
445
446 ZeroMemory(&params, sizeof(params));
447 params.lStructSize = get_OPENFILENAME_SIZE();
448 params.hwndOwner = parent;
449 // �t�B���^������ (2004.12.19 yutaka)
450 // 3�t�@�C���t�B���^������ (2005.4.26 yutaka)
451 UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_FILTER", pvar,
452 "identity files\\0identity;id_rsa;id_dsa;id_ecdsa;id_ed25519;*.ppk;*.pem\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0id_ecdsa(SSH2)\\0id_ecdsa\\0id_ed25519(SSH2)\\0id_ed25519\\0PuTTY(*.ppk)\\0*.ppk\\0PEM files(*.pem)\\0*.pem\\0all(*.*)\\0*.*\\0\\0");
453 memcpy(filter, pvar->ts->UIMsg, sizeof(filter));
454 params.lpstrFilter = filter;
455 params.lpstrCustomFilter = NULL;
456 params.nFilterIndex = 0;
457 buf[0] = 0;
458 params.lpstrFile = fullname_buf;
459 params.nMaxFile = sizeof(fullname_buf);
460 params.lpstrFileTitle = NULL;
461 params.lpstrInitialDir = NULL;
462 UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_TITLE", pvar,
463 "Choose a file with the RSA/DSA/ECDSA/ED25519 private key");
464 params.lpstrTitle = pvar->ts->UIMsg;
465 params.Flags =
466 OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
467 params.lpstrDefExt = NULL;
468
469 if (GetOpenFileName(&params) != 0) {
470 copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf);
471 return 1;
472 } else {
473 return 0;
474 }
475 }
476
477 static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
478 {
479 char buf[1024];
480
481 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
482 SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
483 }
484 }
485
486 static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
487 {
488 char buf[1024];
489
490 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
491 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
492 }
493 }
494
495 static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
496 {
497 int method = SSH_AUTH_PASSWORD;
498 char *password =
499 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
500 Key *key_pair = NULL;
501
502 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
503 method = SSH_AUTH_RSA;
504 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
505 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
506 method = SSH_AUTH_RHOSTS_RSA;
507 } else {
508 method = SSH_AUTH_RHOSTS;
509 }
510 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
511 method = SSH_AUTH_TIS;
512 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
513 method = SSH_AUTH_PAGEANT;
514 }
515
516 if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
517 char keyfile[2048];
518 int file_ctl_ID =
519 method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
520
521 keyfile[0] = 0;
522 GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
523 if (keyfile[0] == 0) {
524 UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
525 "You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
526 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
527 SetFocus(GetDlgItem(dlg, file_ctl_ID));
528 destroy_malloced_string(&password);
529 return FALSE;
530 }
531
532 if (SSHv1(pvar)) {
533 BOOL invalid_passphrase = FALSE;
534
535 key_pair = KEYFILES_read_private_key(pvar, keyfile, password,
536 &invalid_passphrase,
537 FALSE);
538
539 if (key_pair == NULL) {
540 if (invalid_passphrase) {
541 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
542
543 SetFocus(passwordCtl);
544 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
545 } else {
546 SetFocus(GetDlgItem(dlg, file_ctl_ID));
547 }
548 destroy_malloced_string(&password);
549 return FALSE;
550 }
551
552 } else { // SSH2(yutaka)
553 BOOL invalid_passphrase = FALSE;
554 char errmsg[256];
555 FILE *fp = NULL;
556 ssh2_keyfile_type keyfile_type;
557
558 memset(errmsg, 0, sizeof(errmsg));
559
560 keyfile_type = get_ssh2_keytype(keyfile, &fp, errmsg, sizeof(errmsg));
561 switch (keyfile_type) {
562 case SSH2_KEYFILE_TYPE_OPENSSH:
563 {
564 key_pair = read_SSH2_private_key(pvar, fp, password,
565 &invalid_passphrase,
566 FALSE,
567 errmsg,
568 sizeof(errmsg)
569 );
570 break;
571 }
572 case SSH2_KEYFILE_TYPE_PUTTY:
573 {
574 key_pair = read_SSH2_PuTTY_private_key(pvar, fp, password,
575 &invalid_passphrase,
576 FALSE,
577 errmsg,
578 sizeof(errmsg)
579 );
580 break;
581 }
582 case SSH2_KEYFILE_TYPE_SECSH:
583 {
584 key_pair = read_SSH2_SECSH_private_key(pvar, fp, password,
585 &invalid_passphrase,
586 FALSE,
587 errmsg,
588 sizeof(errmsg)
589 );
590 break;
591 }
592 default:
593 {
594 char buf[1024];
595
596 // �t�@�C�����J�����������t�@�C���`�����s��������������������
597 if (fp != NULL) {
598 key_pair = read_SSH2_private_key(pvar, fp, password,
599 &invalid_passphrase,
600 FALSE,
601 errmsg,
602 sizeof(errmsg)
603 );
604 break;
605 }
606
607 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
608 "read error SSH2 private key file\r\n%s");
609 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
610 notify_nonfatal_error(pvar, buf);
611 // ���������������������� SSH2 �������t�@�C�����J����������
612 // ���t�@�C�����I���{�^�����t�H�[�J�X������
613 SetFocus(GetDlgItem(dlg, IDC_CHOOSERSAFILE));
614 destroy_malloced_string(&password);
615 return FALSE;
616 }
617 }
618
619 if (key_pair == NULL) { // read error
620 char buf[1024];
621 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
622 "read error SSH2 private key file\r\n%s");
623 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
624 notify_nonfatal_error(pvar, buf);
625 // �p�X�t���[�Y���������v����������������IDC_SSHPASSWORD���t�H�[�J�X������ (2006.10.29 yasuhide)
626 if (invalid_passphrase) {
627 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
628
629 SetFocus(passwordCtl);
630 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
631 } else {
632 SetFocus(GetDlgItem(dlg, file_ctl_ID));
633 }
634 destroy_malloced_string(&password);
635 return FALSE;
636 }
637
638 }
639
640 }
641 else if (method == SSH_AUTH_PAGEANT) {
642 pvar->pageant_key = NULL;
643 pvar->pageant_curkey = NULL;
644 pvar->pageant_keylistlen = 0;
645 pvar->pageant_keycount = 0;
646 pvar->pageant_keycurrent = 0;
647 pvar->pageant_keyfinal=FALSE;
648
649 // Pageant �����M
650 if (SSHv1(pvar)) {
651 pvar->pageant_keylistlen = putty_get_ssh1_keylist(&pvar->pageant_key);
652 }
653 else {
654 pvar->pageant_keylistlen = putty_get_ssh2_keylist(&pvar->pageant_key);
655 }
656 if (pvar->pageant_keylistlen == 0) {
657 UTIL_get_lang_msg("MSG_PAGEANT_NOTFOUND", pvar,
658 "Can't find Pageant.");
659 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
660
661 return FALSE;
662 }
663 pvar->pageant_curkey = pvar->pageant_key;
664
665 // ������
666 pvar->pageant_keycount = get_uint32_MSBfirst(pvar->pageant_curkey);
667 if (pvar->pageant_keycount == 0) {
668 UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
669 "Pageant has no valid key.");
670 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
671
672 return FALSE;
673 }
674 pvar->pageant_curkey += 4;
675 }
676
677 /* from here on, we cannot fail, so just munge cur_cred in place */
678 pvar->auth_state.cur_cred.method = method;
679 pvar->auth_state.cur_cred.key_pair = key_pair;
680 /* we can't change the user name once it's set. It may already have
681 been sent to the server, and it can only be sent once. */
682 if (pvar->auth_state.user == NULL) {
683 pvar->auth_state.user =
684 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
685 }
686
687 // �p�X���[�h���������������������������� (2006.8.3 yutaka)
688 if (SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_GETCHECK, 0,0) == BST_CHECKED) {
689 pvar->settings.remember_password = 1; // �o��������
690 pvar->ts_SSH->remember_password = 1;
691 } else {
692 pvar->settings.remember_password = 0; // ���������������Y����
693 pvar->ts_SSH->remember_password = 0;
694 }
695
696 // ���J���F���������A�Z�b�V�������������p�X���[�h���g�����������������������������������B
697 // (2005.4.8 yutaka)
698 if (method == SSH_AUTH_PASSWORD || method == SSH_AUTH_RSA) {
699 pvar->auth_state.cur_cred.password = password;
700 } else {
701 destroy_malloced_string(&password);
702 }
703 if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
704 if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
705 UTIL_get_lang_msg("MSG_RHOSTS_NOTDEFAULT_ERROR", pvar,
706 "Rhosts authentication will probably fail because it was not "
707 "the default authentication method.\n"
708 "To use Rhosts authentication "
709 "in TTSSH, you need to set it to be the default by restarting\n"
710 "TTSSH and selecting \"SSH Authentication...\" from the Setup menu "
711 "before connecting.");
712 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
713 }
714
715 pvar->auth_state.cur_cred.rhosts_client_user =
716 alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
717 }
718 pvar->auth_state.auth_dialog = NULL;
719
720 GetDlgItemText(dlg, IDC_RSAFILENAME,
721 pvar->session_settings.DefaultRSAPrivateKeyFile,
722 sizeof(pvar->session_settings.
723 DefaultRSAPrivateKeyFile));
724 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
725 pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
726 sizeof(pvar->session_settings.
727 DefaultRhostsHostPrivateKeyFile));
728 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
729 pvar->session_settings.DefaultRhostsLocalUserName,
730 sizeof(pvar->session_settings.
731 DefaultRhostsLocalUserName));
732
733 if (SSHv1(pvar)) {
734 SSH_notify_user_name(pvar);
735 SSH_notify_cred(pvar);
736 } else {
737 // for SSH2(yutaka)
738 do_SSH2_userauth(pvar);
739 }
740
741 EndDialog(dlg, 1);
742 #if 0
743 if (DlgAuthFont != NULL) {
744 DeleteObject(DlgAuthFont);
745 }
746 #endif
747
748 return TRUE;
749 }
750
751 /**
752 * �N���b�v�{�[�h����ANSI����������������
753 * �����������K�v��������strlen()��������
754 * @param hWnd
755 * @param emtpy TRUE�������N���b�v�{�[�h����������
756 * @retval �����������|�C���^ �g�p��free()��������
757 * ����������(�������G���[��)��NULL
758 */
759 char *GetClipboardTextA(HWND hWnd, BOOL empty)
760 {
761 HGLOBAL hGlobal;
762 const char *lpStr;
763 size_t length;
764 char *pool;
765
766 OpenClipboard(hWnd);
767 hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
768 if (hGlobal == NULL) {
769 CloseClipboard();
770 return NULL;
771 }
772 lpStr = (const char *)GlobalLock(hGlobal);
773 length = GlobalSize(hGlobal);
774 if (length == 0) {
775 pool = NULL;
776 } else {
777 pool = (char *)malloc(length + 1); // +1 for terminator
778 memcpy(pool, lpStr, length);
779 pool[length] = '\0';
780 }
781 GlobalUnlock(hGlobal);
782 if (empty) {
783 EmptyClipboard();
784 }
785 CloseClipboard();
786
787 return pool;
788 }
789
790
791 BOOL autologin_sent_none;
792 static BOOL CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
793 LPARAM lParam)
794 {
795 const int IDC_TIMER1 = 300; // �������O�C�����L��������
796 const int IDC_TIMER2 = 301; // �T�|�[�g�������������\�b�h�������`�F�b�N(CheckAuthListFirst)
797 const int IDC_TIMER3 = 302; // challenge �� ask4passwd ��CheckAuthListFirst �� FALSE ������
798 const int autologin_timeout = 10; // �~���b
799 PTInstVar pvar;
800 // LOGFONT logfont;
801 // HFONT font;
802 static BOOL UseControlChar;
803 static BOOL ShowPassPhrase;
804 static HICON hIconDropdown;
805
806 switch (msg) {
807 case WM_INITDIALOG:
808 pvar = (PTInstVar) lParam;
809 pvar->auth_state.auth_dialog = dlg;
810 SetWindowLong(dlg, DWL_USER, lParam);
811
812 UseControlChar = TRUE;
813 ShowPassPhrase = FALSE;
814 init_auth_dlg(pvar, dlg, &UseControlChar);
815 #if 0
816 font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
817 GetObject(font, sizeof(LOGFONT), &logfont);
818 if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgAuthFont, pvar)) {
819 SendDlgItemMessage(dlg, IDC_SSHAUTHBANNER, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
820 SendDlgItemMessage(dlg, IDC_SSHAUTHBANNER2, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
821 SendDlgItemMessage(dlg, IDC_SSHUSERNAMELABEL, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
822 SendDlgItemMessage(dlg, IDC_SSHUSERNAME, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
823 SendDlgItemMessage(dlg, IDC_SSHPASSWORDCAPTION, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
824 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
825 SendDlgItemMessage(dlg, IDC_REMEMBER_PASSWORD, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
826 SendDlgItemMessage(dlg, IDC_FORWARD_AGENT, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
827 SendDlgItemMessage(dlg, IDC_SSHUSEPASSWORD, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
828 SendDlgItemMessage(dlg, IDC_SSHUSERSA, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
829 SendDlgItemMessage(dlg, IDC_CHOOSERSAFILE, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
830 SendDlgItemMessage(dlg, IDC_RSAFILENAME, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
831 SendDlgItemMessage(dlg, IDC_SSHUSERHOSTS, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
832 SendDlgItemMessage(dlg, IDC_LOCALUSERNAMELABEL, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
833 SendDlgItemMessage(dlg, IDC_LOCALUSERNAME, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
834 SendDlgItemMessage(dlg, IDC_CHOOSEHOSTRSAFILE, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
835 SendDlgItemMessage(dlg, IDC_HOSTRSAFILENAME, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
836 SendDlgItemMessage(dlg, IDC_SSHUSETIS, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
837 SendDlgItemMessage(dlg, IDC_SSHUSEPAGEANT, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
838 SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
839 SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgAuthFont, MAKELPARAM(TRUE,0));
840 }
841 else {
842 DlgAuthFont = NULL;
843 }
844 #endif
845 hIconDropdown = LoadImage(hInst, MAKEINTRESOURCE(IDI_DROPDOWN),
846 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
847 SendMessage(GetDlgItem(dlg, IDC_USERNAME_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
848 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
849
850 // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
851 if (pvar->ssh2_autologin == 1) {
852 autologin_sent_none = FALSE;
853 SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
854 }
855 else {
856 // �T�|�[�g�������������\�b�h���`�F�b�N�����B(2007.9.24 maya)
857 // �������L�����A�����������s�����������A���[�U�����m����������
858 if (pvar->session_settings.CheckAuthListFirst &&
859 !pvar->tryed_ssh2_authlist &&
860 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
861 SetTimer(dlg, IDC_TIMER2, autologin_timeout, 0);
862 }
863 // /auth=challenge �� /ask4passwd ���w���������������[�U�����m����������
864 // �������AOK �{�^���������� TIS auth �_�C�A���O���o��
865 else if (pvar->ssh2_authmethod == SSH_AUTH_TIS &&
866 pvar->ask4passwd &&
867 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
868 SetTimer(dlg, IDC_TIMER3, autologin_timeout, 0);
869 }
870 }
871 CenterWindow(dlg, GetParent(dlg));
872 return FALSE; /* because we set the focus */
873
874 case WM_TIMER:
875 pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
876 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
877 if (wParam == IDC_TIMER1) {
878 // �������O�C��������
879 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
880 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
881 if (SSHv2(pvar) &&
882 pvar->session_settings.CheckAuthListFirst &&
883 !pvar->tryed_ssh2_authlist) {
884 if (!autologin_sent_none) {
885 autologin_sent_none = TRUE;
886
887 // �_�C�A���O�����[�U������������
888 if (pvar->auth_state.user == NULL) {
889 pvar->auth_state.user =
890 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
891 }
892
893 // CheckAuthListFirst �� TRUE �������� AuthList ���A����������������
894 // IDOK �����������i�����������A�F�����\�b�h none ������ (2008.10.12 maya)
895 do_SSH2_userauth(pvar);
896 }
897 //else {
898 // none �������������A����������������
899 //}
900 }
901 else {
902 // SSH1 ������
903 // ������ CheckAuthListFirst �� FALSE ������
904 // ������ CheckAuthListFirst TRUE ���Aauthlist ���A������������
905 KillTimer(dlg, IDC_TIMER1);
906
907 // �_�C�A���O�����[�U������������
908 if (pvar->auth_state.user == NULL) {
909 pvar->auth_state.user =
910 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
911 }
912
913 SendMessage(dlg, WM_COMMAND, IDOK, 0);
914 }
915 }
916 }
917 else if (wParam == IDC_TIMER2) {
918 // authlist ����������
919 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
920 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
921 if (SSHv2(pvar)) {
922 KillTimer(dlg, IDC_TIMER2);
923
924 // �_�C�A���O�����[�U������������
925 if (pvar->auth_state.user == NULL) {
926 pvar->auth_state.user =
927 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
928 }
929
930 // ���[�U�������X��������
931 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
932 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
933
934 // �F�����\�b�h none ������
935 do_SSH2_userauth(pvar);
936
937 // TIS �p�� OK �����������F�������s������������������
938 // Unexpected SSH2 message �������B
939 }
940 else if (SSHv1(pvar)) {
941 KillTimer(dlg, IDC_TIMER2);
942
943 // TIS �p�� OK ������
944 if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
945 SendMessage(dlg, WM_COMMAND, IDOK, 0);
946 }
947 // SSH1 �����F�����\�b�h none ����������
948 }
949 // �v���g�R���o�[�W�����m���O������������
950 }
951 }
952 else if (wParam == IDC_TIMER3) {
953 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
954 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
955 if (SSHv2(pvar) || SSHv1(pvar)) {
956 KillTimer(dlg, IDC_TIMER3);
957
958 // TIS �p�� OK ������
959 SendMessage(dlg, WM_COMMAND, IDOK, 0);
960 }
961 // �v���g�R���o�[�W�����m���O������������
962 }
963 }
964 return FALSE;
965
966 case WM_COMMAND:
967 pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
968
969 switch (LOWORD(wParam)) {
970 case IDOK:
971 // �F�������T�[�o�������f�������������A�L�����Z�������������B(2014.3.31 yutaka)
972 if (!pvar->cv->Ready) {
973 goto canceled;
974 }
975
976 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
977 if (pvar->userauth_retry_count == 0 &&
978 ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) ||
979 !(pvar->ssh_state.status_flags & STATUS_HOST_OK))) {
980 return FALSE;
981 }
982 else if (SSHv2(pvar) &&
983 pvar->session_settings.CheckAuthListFirst &&
984 !pvar->tryed_ssh2_authlist) {
985 // CheckAuthListFirst ���L�����F������������������������
986 // OK �������������������� (2008.10.4 maya)
987 return FALSE;
988 }
989
990 return end_auth_dlg(pvar, dlg);
991
992 case IDCANCEL: /* kill the connection */
993 canceled:
994 pvar->auth_state.auth_dialog = NULL;
995 notify_closed_connection(pvar, "authentication cancelled");
996 EndDialog(dlg, 0);
997 #if 0
998 if (DlgAuthFont != NULL) {
999 DeleteObject(DlgAuthFont);
1000 }
1001 #endif
1002 return TRUE;
1003
1004 case IDC_SSHUSERNAME:
1005 // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
1006 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
1007 (pvar->ssh_state.status_flags & STATUS_HOST_OK) &&
1008 HIWORD(wParam) == EN_KILLFOCUS) {
1009 // �������L���������������s��������������
1010 if (SSHv2(pvar) &&
1011 pvar->session_settings.CheckAuthListFirst &&
1012 !pvar->tryed_ssh2_authlist) {
1013 // �_�C�A���O�����[�U�������f
1014 if (pvar->auth_state.user == NULL) {
1015 pvar->auth_state.user =
1016 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
1017 }
1018
1019 // ���[�U���������������������`�F�b�N����
1020 if (strlen(pvar->auth_state.user) == 0) {
1021 return FALSE;
1022 }
1023
1024 // ���[�U�������X��������
1025 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
1026 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
1027
1028 // �F�����\�b�h none ������
1029 do_SSH2_userauth(pvar);
1030 return TRUE;
1031 }
1032 }
1033
1034 return FALSE;
1035
1036 case IDC_SSHUSEPASSWORD:
1037 case IDC_SSHUSERSA:
1038 case IDC_SSHUSERHOSTS:
1039 case IDC_SSHUSETIS:
1040 case IDC_SSHUSEPAGEANT:
1041 set_auth_options_status(dlg, LOWORD(wParam));
1042 return TRUE;
1043
1044 case IDC_CHOOSERSAFILE:
1045 choose_RSA_key_file(dlg, pvar);
1046 return TRUE;
1047
1048 case IDC_CHOOSEHOSTRSAFILE:
1049 choose_host_RSA_key_file(dlg, pvar);
1050 return TRUE;
1051
1052 case IDC_FORWARD_AGENT:
1053 // �����Z�b�V�������������f������ (2008.12.4 maya)
1054 pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1055 return TRUE;
1056
1057 case IDC_SSHPASSWORD_OPTION: {
1058 TCHAR uimsg[MAX_UIMSG];
1059 RECT rect;
1060 HWND hWndButton;
1061 int result;
1062 HMENU hMenu= CreatePopupMenu();
1063 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1064 uimsg, _countof(uimsg),
1065 "Paste from &clipboard",
1066 pvar->ts->UILanguageFile);
1067 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 1, uimsg);
1068 GetI18nStrT("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1069 uimsg, _countof(uimsg),
1070 "Paste from &clipboard and cl&ear clipboard",
1071 pvar->ts->UILanguageFile);
1072 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1073 GetI18nStrT("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1074 uimsg, _countof(uimsg),
1075 "Use control charac&ters",
1076 pvar->ts->UILanguageFile);
1077 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1078 GetI18nStrT("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1079 uimsg, _countof(uimsg),
1080 "&Show passphrase",
1081 pvar->ts->UILanguageFile);
1082 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1083 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1084 GetWindowRect(hWndButton, &rect);
1085 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1086 DestroyMenu(hMenu);
1087 switch(result) {
1088 case 1:
1089 case 2: {
1090 // �N���b�v�{�[�h�����y�[�X�g
1091 BOOL clear_clipboard = result == 2;
1092 char *clipboard = GetClipboardTextA(dlg, clear_clipboard);
1093 if (clipboard != NULL) {
1094 SetDlgItemTextA(dlg, IDC_SSHPASSWORD, clipboard);
1095 free(clipboard);
1096 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1097 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1098 return FALSE;
1099 }
1100 return TRUE;
1101 }
1102 case 3:
1103 // �����R�[�h�g�p/���g�p
1104 UseControlChar = !UseControlChar;
1105 break;
1106 case 4:
1107 // �p�X�t���[�Y�\��/���\��
1108 ShowPassPhrase = !ShowPassPhrase;
1109 {
1110 // ������ on/off ������������
1111 HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1112 static wchar_t password_char;
1113 if (password_char == 0) {
1114 wchar_t c = (wchar_t)SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1115 password_char = c;
1116 }
1117 if (ShowPassPhrase) {
1118 SendMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1119 } else {
1120 #if !defined(UNICODE)
1121 if (password_char < 0x100) {
1122 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1123 } else {
1124 // TODO W�n������ ����������������
1125 //SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1126 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1127 }
1128 #else
1129 SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1130 #endif
1131 }
1132 //InvalidateRect(hWnd, NULL, TRUE);
1133 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1134 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1135 return TRUE;
1136 }
1137 break;
1138 }
1139 break;
1140 }
1141
1142 case IDC_USERNAME_OPTION: {
1143 TCHAR uimsg[MAX_UIMSG];
1144 RECT rect;
1145 HWND hWndButton;
1146 HMENU hMenu= CreatePopupMenu();
1147 int result;
1148 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_WINDOWS_USERNAME",
1149 uimsg, _countof(uimsg),
1150 "Paste &Windows username",
1151 pvar->ts->UILanguageFile);
1152 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 1, uimsg);
1153 hWndButton = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1154 GetWindowRect(hWndButton, &rect);
1155 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1156 DestroyMenu(hMenu);
1157 switch (result) {
1158 case 1: {
1159 TCHAR user_name[UNLEN+1];
1160 DWORD len = _countof(user_name);
1161 BOOL r = GetUserName(user_name, &len);
1162 if (r != 0) {
1163 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
1164 SendDlgItemMessage(dlg, IDC_SSHUSERNAME, EM_SETSEL, 0, -1);
1165 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHUSERNAME), TRUE);
1166 }
1167 break;
1168 }
1169 }
1170 return TRUE;
1171 }
1172
1173 default:
1174 return FALSE;
1175 }
1176
1177 case WM_DESTROY:
1178 if (hIconDropdown != NULL) {
1179 DeleteObject(hIconDropdown);
1180 }
1181 return FALSE;
1182
1183 default:
1184 return FALSE;
1185 }
1186 }
1187
1188 char *AUTH_get_user_name(PTInstVar pvar)
1189 {
1190 return pvar->auth_state.user;
1191 }
1192
1193 int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
1194 {
1195 logprintf(LOG_LEVEL_VERBOSE, "Server reports supported authentication method mask = %d", types);
1196
1197 if (SSHv1(pvar)) {
1198 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1199 | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
1200 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1201 } else {
1202 // for SSH2(yutaka)
1203 // types &= (1 << SSH_AUTH_PASSWORD);
1204 // ���J���F�����L�������� (2004.12.18 yutaka)
1205 // TIS�������BSSH2����keyboard-interactive�����������B(2005.3.12 yutaka)
1206 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1207 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1208 }
1209 pvar->auth_state.supported_types = types;
1210
1211 if (types == 0) {
1212 UTIL_get_lang_msg("MSG_NOAUTHMETHOD_ERROR", pvar,
1213 "Server does not support any of the authentication options\n"
1214 "provided by TTSSH. This connection will now close.");
1215 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1216 return 0;
1217 } else {
1218 if (pvar->auth_state.auth_dialog != NULL) {
1219 update_server_supported_types(pvar, pvar->auth_state.auth_dialog);
1220 }
1221
1222 return 1;
1223 }
1224 }
1225
1226 static void start_user_auth(PTInstVar pvar)
1227 {
1228 // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
1229 PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
1230 (LPARAM) NULL);
1231 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1232 }
1233
1234 static void try_default_auth(PTInstVar pvar)
1235 {
1236 if (pvar->session_settings.TryDefaultAuth) {
1237 switch (pvar->session_settings.DefaultAuthMethod) {
1238 case SSH_AUTH_RSA:{
1239 BOOL invalid_passphrase;
1240 char password[] = "";
1241
1242 pvar->auth_state.cur_cred.key_pair
1243 =
1244 KEYFILES_read_private_key(pvar,
1245 pvar->session_settings.
1246 DefaultRSAPrivateKeyFile,
1247 password,
1248 &invalid_passphrase, TRUE);
1249 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1250 return;
1251 } else {
1252 pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1253 }
1254 break;
1255 }
1256
1257 case SSH_AUTH_RHOSTS:
1258 if (pvar->session_settings.
1259 DefaultRhostsHostPrivateKeyFile[0] != 0) {
1260 BOOL invalid_passphrase;
1261 char password[] = "";
1262
1263 pvar->auth_state.cur_cred.key_pair
1264 =
1265 KEYFILES_read_private_key(pvar,
1266 pvar->session_settings.
1267 DefaultRhostsHostPrivateKeyFile,
1268 password,
1269 &invalid_passphrase, TRUE);
1270 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1271 return;
1272 } else {
1273 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
1274 }
1275 } else {
1276 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
1277 }
1278
1279 pvar->auth_state.cur_cred.rhosts_client_user =
1280 _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
1281 break;
1282
1283 case SSH_AUTH_PAGEANT:
1284 pvar->auth_state.cur_cred.method = SSH_AUTH_PAGEANT;
1285 break;
1286
1287 case SSH_AUTH_PASSWORD:
1288 pvar->auth_state.cur_cred.password = _strdup("");
1289 pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1290 break;
1291
1292 case SSH_AUTH_TIS:
1293 default:
1294 return;
1295 }
1296
1297 pvar->auth_state.user =
1298 _strdup(pvar->session_settings.DefaultUserName);
1299 }
1300 }
1301
1302 void AUTH_notify_end_error(PTInstVar pvar)
1303 {
1304 if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
1305 start_user_auth(pvar);
1306 pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
1307 }
1308 }
1309
1310 void AUTH_advance_to_next_cred(PTInstVar pvar)
1311 {
1312 pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
1313
1314 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1315 try_default_auth(pvar);
1316
1317 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1318 if (pvar->err_msg != NULL) {
1319 pvar->auth_state.flags |=
1320 AUTH_START_USER_AUTH_ON_ERROR_END;
1321 } else {
1322 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1323 // �R�}���h���C���w������������
1324 start_user_auth(pvar);
1325 }
1326 }
1327 } else {
1328 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1329 // �R�}���h���C���w������(/auth=xxxx)������
1330 start_user_auth(pvar);
1331 }
1332 }
1333
1334 static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
1335 {
1336 char uimsg[MAX_UIMSG];
1337
1338 GetWindowText(dlg, uimsg, sizeof(uimsg));
1339 UTIL_get_lang_msg("DLG_TIS_TITLE", pvar, uimsg);
1340 SetWindowText(dlg, pvar->ts->UIMsg);
1341 GetDlgItemText(dlg, IDC_SSHAUTHBANNER, uimsg, sizeof(uimsg));
1342 UTIL_get_lang_msg("DLG_TIS_BANNER", pvar, uimsg);
1343 SetDlgItemText(dlg, IDC_SSHAUTHBANNER, pvar->ts->UIMsg);
1344 GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1345 UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1346 SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1347 GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1348 UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
1349 SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1350
1351 init_auth_machine_banner(pvar, dlg);
1352 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1353
1354 if (pvar->auth_state.TIS_prompt != NULL) {
1355 if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1356 pvar->auth_state.TIS_prompt[10000] = 0;
1357 }
1358 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1359 pvar->auth_state.TIS_prompt);
1360 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1361 }
1362
1363 if (pvar->auth_state.echo) {
1364 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1365 }
1366 }
1367
1368 static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1369 {
1370 char *password =
1371 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1372
1373 pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1374 pvar->auth_state.cur_cred.password = password;
1375 pvar->auth_state.auth_dialog = NULL;
1376
1377 // add
1378 if (SSHv2(pvar)) {
1379 pvar->keyboard_interactive_password_input = 1;
1380 handle_SSH2_userauth_inforeq(pvar);
1381 }
1382
1383 SSH_notify_cred(pvar);
1384
1385 EndDialog(dlg, 1);
1386 return TRUE;
1387 }
1388
1389 static BOOL CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1390 LPARAM lParam)
1391 {
1392 PTInstVar pvar;
1393 // LOGFONT logfont;
1394 // HFONT font;
1395
1396 switch (msg) {
1397 case WM_INITDIALOG:
1398 pvar = (PTInstVar) lParam;
1399 pvar->auth_state.auth_dialog = dlg;
1400 SetWindowLong(dlg, DWL_USER, lParam);
1401
1402 init_TIS_dlg(pvar, dlg);
1403 #if 0
1404 font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
1405 GetObject(font, sizeof(LOGFONT), &logfont);
1406 if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgTisFont, pvar)) {
1407 SendDlgItemMessage(dlg, IDC_SSHAUTHBANNER, WM_SETFONT, (WPARAM)DlgTisFont, MAKELPARAM(TRUE,0));
1408 SendDlgItemMessage(dlg, IDC_SSHAUTHBANNER2, WM_SETFONT, (WPARAM)DlgTisFont, MAKELPARAM(TRUE,0));
1409 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, WM_SETFONT, (WPARAM)DlgTisFont, MAKELPARAM(TRUE,0));
1410 SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgTisFont, MAKELPARAM(TRUE,0));
1411 SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgTisFont, MAKELPARAM(TRUE,0));
1412 }
1413 else {
1414 DlgTisFont = NULL;
1415 }
1416 #endif
1417 // /auth=challenge ������ (2007.10.5 maya)
1418 if (pvar->ssh2_autologin == 1) {
1419 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1420 SendMessage(dlg, WM_COMMAND, IDOK, 0);
1421 }
1422
1423 CenterWindow(dlg, GetParent(dlg));
1424 return FALSE; /* because we set the focus */
1425
1426 case WM_COMMAND:
1427 pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
1428
1429 switch (LOWORD(wParam)) {
1430 case IDOK:
1431 #if 0
1432 if (DlgTisFont != NULL) {
1433 DeleteObject(DlgTisFont);
1434 }
1435 #endif
1436 return end_TIS_dlg(pvar, dlg);
1437
1438 case IDCANCEL: /* kill the connection */
1439 pvar->auth_state.auth_dialog = NULL;
1440 notify_closed_connection(pvar, "authentication cancelled");
1441 EndDialog(dlg, 0);
1442 #if 0
1443 if (DlgTisFont != NULL) {
1444 DeleteObject(DlgTisFont);
1445 }
1446 #endif
1447 return TRUE;
1448
1449 default:
1450 return FALSE;
1451 }
1452
1453 default:
1454 return FALSE;
1455 }
1456 }
1457
1458 void AUTH_do_cred_dialog(PTInstVar pvar)
1459 {
1460 if (pvar->auth_state.auth_dialog == NULL) {
1461 HWND cur_active = GetActiveWindow();
1462 DLGPROC dlg_proc;
1463 LPCTSTR dialog_template;
1464
1465 switch (pvar->auth_state.mode) {
1466 case TIS_AUTH_MODE:
1467 dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
1468 dlg_proc = TIS_dlg_proc;
1469 break;
1470 case GENERIC_AUTH_MODE:
1471 default:
1472 dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
1473 dlg_proc = auth_dlg_proc;
1474 }
1475
1476 if (!DialogBoxParam(hInst, dialog_template,
1477 cur_active !=
1478 NULL ? cur_active : pvar->NotificationWindow,
1479 dlg_proc, (LPARAM) pvar) == -1) {
1480 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1481 "Unable to display authentication dialog box.\n"
1482 "Connection terminated.");
1483 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1484 }
1485 }
1486 }
1487
1488 static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1489 {
1490 int id;
1491 TCHAR user_name[UNLEN+1];
1492 DWORD len;
1493 TCHAR uimsg[MAX_UIMSG];
1494 TCHAR uimsg2[MAX_UIMSG];
1495 const static DlgTextInfo text_info[] = {
1496 { 0, "DLG_AUTHSETUP_TITLE" },
1497 { IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
1498 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1499 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_USERNAME" },
1500 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_SYSTEM_USERNAME" },
1501 { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_SYSTEM_USERNAME_TEXT" },
1502 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1503 { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1504 { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1505 { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1506 { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1507 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1508 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1509 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1510 { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1511 { IDOK, "BTN_OK" },
1512 { IDCANCEL, "BTN_CANCEL" },
1513 };
1514
1515 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1516
1517 switch (pvar->settings.DefaultAuthMethod) {
1518 case SSH_AUTH_RSA:
1519 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1520 IDC_SSHUSERSA);
1521 break;
1522 case SSH_AUTH_RHOSTS:
1523 case SSH_AUTH_RHOSTS_RSA:
1524 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1525 IDC_SSHUSERHOSTS);
1526 break;
1527 case SSH_AUTH_TIS:
1528 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1529 IDC_SSHUSETIS);
1530 break;
1531 case SSH_AUTH_PAGEANT:
1532 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1533 IDC_SSHUSEPAGEANT);
1534 break;
1535 case SSH_AUTH_PASSWORD:
1536 default:
1537 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1538 IDC_SSHUSEPASSWORD);
1539 }
1540
1541 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1542 SetDlgItemText(dlg, IDC_RSAFILENAME,
1543 pvar->settings.DefaultRSAPrivateKeyFile);
1544 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1545 pvar->settings.DefaultRhostsHostPrivateKeyFile);
1546 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1547 pvar->settings.DefaultRhostsLocalUserName);
1548
1549 if (pvar->settings.CheckAuthListFirst) {
1550 CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1551 }
1552
1553 if (pvar->session_settings.DefaultUserName[0] == 0) {
1554 // ���������u�����������v����������
1555 pvar->session_settings.DefaultUserType = 0;
1556 }
1557 id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1558 pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1559 IDC_SSH_NO_USERNAME;
1560 CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1561
1562 len = _countof(user_name);
1563 GetUserName(user_name, &len);
1564
1565 GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1566 _stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1567 SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1568 }
1569
1570 static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1571 {
1572 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1573 pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1574 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1575 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1576 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1577 } else {
1578 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1579 }
1580 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1581 pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1582 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1583 pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1584 } else {
1585 pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1586 }
1587
1588 GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1589 sizeof(pvar->settings.DefaultUserName));
1590 GetDlgItemText(dlg, IDC_RSAFILENAME,
1591 pvar->settings.DefaultRSAPrivateKeyFile,
1592 sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1593 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1594 pvar->settings.DefaultRhostsHostPrivateKeyFile,
1595 sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1596 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1597 pvar->settings.DefaultRhostsLocalUserName,
1598 sizeof(pvar->settings.DefaultRhostsLocalUserName));
1599 pvar->settings.DefaultUserType =
1600 IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1601 IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1602
1603 if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1604 pvar->settings.CheckAuthListFirst = TRUE;
1605 }
1606 else {
1607 pvar->settings.CheckAuthListFirst = FALSE;
1608 }
1609
1610 EndDialog(dlg, 1);
1611 return TRUE;
1612 }
1613
1614 static BOOL CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1615 WPARAM wParam, LPARAM lParam)
1616 {
1617 PTInstVar pvar;
1618 // LOGFONT logfont;
1619 // HFONT font;
1620
1621 switch (msg) {
1622 case WM_INITDIALOG:
1623 pvar = (PTInstVar) lParam;
1624 SetWindowLong(dlg, DWL_USER, lParam);
1625
1626 init_default_auth_dlg(pvar, dlg);
1627 #if 0
1628 font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
1629 GetObject(font, sizeof(LOGFONT), &logfont);
1630 if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgAuthSetupFont, pvar)) {
1631 SendDlgItemMessage(dlg, IDC_SSHAUTHBANNER, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1632 SendDlgItemMessage(dlg, IDC_SSHUSERNAMELABEL, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1633 SendDlgItemMessage(dlg, IDC_SSHUSERNAME, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1634 SendDlgItemMessage(dlg, IDC_SSHUSEPASSWORD, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1635 SendDlgItemMessage(dlg, IDC_SSHUSERSA, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1636 SendDlgItemMessage(dlg, IDC_CHOOSERSAFILE, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1637 SendDlgItemMessage(dlg, IDC_RSAFILENAME, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1638 SendDlgItemMessage(dlg, IDC_SSHUSERHOSTS, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1639 SendDlgItemMessage(dlg, IDC_LOCALUSERNAMELABEL, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1640 SendDlgItemMessage(dlg, IDC_LOCALUSERNAME, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1641 SendDlgItemMessage(dlg, IDC_CHOOSEHOSTRSAFILE, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1642 SendDlgItemMessage(dlg, IDC_HOSTRSAFILENAME, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1643 SendDlgItemMessage(dlg, IDC_SSHUSETIS, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1644 SendDlgItemMessage(dlg, IDC_SSHUSEPAGEANT, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1645 SendDlgItemMessage(dlg, IDC_CHECKAUTH, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1646 SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1647 SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgAuthSetupFont, MAKELPARAM(TRUE,0));
1648 }
1649 else {
1650 DlgAuthSetupFont = NULL;
1651 }
1652 #endif
1653 CenterWindow(dlg, GetParent(dlg));
1654 return TRUE; /* because we do not set the focus */
1655
1656 case WM_COMMAND:
1657 pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
1658
1659 switch (LOWORD(wParam)) {
1660 case IDOK:
1661 #if 0
1662 if (DlgAuthSetupFont != NULL) {
1663 DeleteObject(DlgAuthSetupFont);
1664 }
1665 #endif
1666 return end_default_auth_dlg(pvar, dlg);
1667
1668 case IDCANCEL:
1669 EndDialog(dlg, 0);
1670 #if 0
1671 if (DlgAuthSetupFont != NULL) {
1672 DeleteObject(DlgAuthSetupFont);
1673 }
1674 #endif
1675 return TRUE;
1676
1677 case IDC_CHOOSERSAFILE:
1678 choose_RSA_key_file(dlg, pvar);
1679 return TRUE;
1680
1681 case IDC_CHOOSEHOSTRSAFILE:
1682 choose_host_RSA_key_file(dlg, pvar);
1683 return TRUE;
1684
1685 default:
1686 return FALSE;
1687 }
1688
1689 default:
1690 return FALSE;
1691 }
1692 }
1693
1694 void AUTH_init(PTInstVar pvar)
1695 {
1696 pvar->auth_state.failed_method = SSH_AUTH_NONE;
1697 pvar->auth_state.auth_dialog = NULL;
1698 pvar->auth_state.user = NULL;
1699 pvar->auth_state.flags = 0;
1700 pvar->auth_state.TIS_prompt = NULL;
1701 pvar->auth_state.echo = 0;
1702 pvar->auth_state.supported_types = 0;
1703 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1704 pvar->auth_state.cur_cred.password = NULL;
1705 pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1706 pvar->auth_state.cur_cred.key_pair = NULL;
1707 AUTH_set_generic_mode(pvar);
1708 }
1709
1710 void AUTH_set_generic_mode(PTInstVar pvar)
1711 {
1712 pvar->auth_state.mode = GENERIC_AUTH_MODE;
1713 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1714 }
1715
1716 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1717 {
1718 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1719 pvar->auth_state.mode = TIS_AUTH_MODE;
1720
1721 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1722 pvar->auth_state.TIS_prompt = malloc(len + 1);
1723 memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1724 pvar->auth_state.TIS_prompt[len] = 0;
1725 pvar->auth_state.echo = echo;
1726 } else {
1727 AUTH_set_generic_mode(pvar);
1728 }
1729 }
1730
1731 void AUTH_do_default_cred_dialog(PTInstVar pvar)
1732 {
1733 HWND cur_active = GetActiveWindow();
1734
1735 if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1736 cur_active != NULL ? cur_active
1737 : pvar->NotificationWindow,
1738 default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1739 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1740 "Unable to display authentication setup dialog box.");
1741 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1742 }
1743 }
1744
1745 void AUTH_destroy_cur_cred(PTInstVar pvar)
1746 {
1747 destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1748 destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1749 if (pvar->auth_state.cur_cred.key_pair != NULL) {
1750 key_free(pvar->auth_state.cur_cred.key_pair);
1751 pvar->auth_state.cur_cred.key_pair = NULL;
1752 }
1753 }
1754
1755 static const char *get_auth_method_name(SSHAuthMethod auth)
1756 {
1757 switch (auth) {
1758 case SSH_AUTH_PASSWORD:
1759 return "password";
1760 case SSH_AUTH_RSA:
1761 return "publickey";
1762 case SSH_AUTH_PAGEANT:
1763 return "publickey";
1764 case SSH_AUTH_RHOSTS:
1765 return "rhosts";
1766 case SSH_AUTH_RHOSTS_RSA:
1767 return "rhosts with RSA";
1768 case SSH_AUTH_TIS:
1769 return "challenge/response (TIS)";
1770 default:
1771 return "unknown method";
1772 }
1773 }
1774
1775 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1776 {
1777 const char *method = "unknown";
1778 char buf[256];
1779
1780 if (pvar->auth_state.user == NULL) {
1781 strncpy_s(dest, len, "None", _TRUNCATE);
1782 } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1783 if (SSHv1(pvar)) {
1784 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1785 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1786 pvar->auth_state.user,
1787 get_auth_method_name(pvar->auth_state.cur_cred.method));
1788
1789 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1790 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1791 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1792 "RSA");
1793 strncat_s(dest, len, buf, _TRUNCATE);
1794 }
1795 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1796 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1797 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1798 "RSA");
1799 strncat_s(dest, len, buf, _TRUNCATE);
1800 }
1801 } else {
1802 // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1803 // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1804 if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1805 pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1806 // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1807 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1808 method = "keyboard-interactive";
1809 } else {
1810 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1811 }
1812 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1813 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1814 pvar->auth_state.user, method);
1815 }
1816 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1817 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1818 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1819 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1820 pvar->auth_state.user,
1821 get_auth_method_name(pvar->auth_state.cur_cred.method));
1822
1823 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1824 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1825 ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1826 strncat_s(dest, len, buf, _TRUNCATE);
1827 }
1828 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1829 int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1830 char *s = (char *)malloc(key_len+1);
1831
1832 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1833 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1834 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1835 pvar->auth_state.user,
1836 get_auth_method_name(pvar->auth_state.cur_cred.method));
1837
1838 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1839 s[key_len] = '\0';
1840 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1841 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1842 ssh_key_type(get_keytype_from_name(s)));
1843 strncat_s(dest, len, buf, _TRUNCATE);
1844
1845 free(s);
1846 }
1847 }
1848
1849 } else {
1850 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1851 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, pvar->auth_state.user,
1852 get_auth_method_name(pvar->auth_state.failed_method));
1853 }
1854
1855 dest[len - 1] = 0;
1856 }
1857
1858 void AUTH_notify_disconnecting(PTInstVar pvar)
1859 {
1860 if (pvar->auth_state.auth_dialog != NULL) {
1861 PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1862 /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1863 EnableWindow(pvar->NotificationWindow, TRUE);
1864 }
1865 }
1866
1867 void AUTH_end(PTInstVar pvar)
1868 {
1869 destroy_malloced_string(&pvar->auth_state.user);
1870 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1871
1872 AUTH_destroy_cur_cred(pvar);
1873 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26