Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ttssh2/ttxssh/auth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9255 - (show annotations) (download) (as text)
Wed May 19 14:11:26 2021 UTC (2 years, 9 months ago) by nmaya
File MIME type: text/x-csrc
File size: 60238 byte(s)
SSH2 暗号化方式 chacha20-poly1305@openssh.com をサポート

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

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