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

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