Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2783 - (hide annotations) (download) (as text)
Tue Jan 25 13:38:22 2005 UTC (19 years, 2 months ago) by yutakakn
Original Path: ttssh2/trunk/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 27834 byte(s)
SSH認証ダイアログで、Rhosts/TISがグレーになる前に、Enterキーを押下すると、
アプリケーションエラーとなる現象に対処した。

1 yutakakn 2728 /*
2     Copyright (c) 1998-2001, Robert O'Callahan
3     All rights reserved.
4    
5     Redistribution and use in source and binary forms, with or without modification,
6     are permitted provided that the following conditions are met:
7    
8     Redistributions of source code must retain the above copyright notice, this list of
9     conditions and the following disclaimer.
10    
11     Redistributions in binary form must reproduce the above copyright notice, this list
12     of conditions and the following disclaimer in the documentation and/or other materials
13     provided with the distribution.
14    
15     The name of Robert O'Callahan may not be used to endorse or promote products derived from
16     this software without specific prior written permission.
17    
18     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21     THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    
29     #include "ttxssh.h"
30     #include "util.h"
31    
32     #include <io.h>
33     #include <fcntl.h>
34     #include <stdlib.h>
35     #include <errno.h>
36    
37     #include "resource.h"
38     #include "keyfiles.h"
39    
40     #define AUTH_START_USER_AUTH_ON_ERROR_END 1
41    
42     #define MAX_AUTH_CONTROL IDC_SSHUSETIS
43    
44     static void destroy_malloced_string(char FAR * FAR * str)
45     {
46     if (*str != NULL) {
47     memset(*str, 0, strlen(*str));
48     free(*str);
49     *str = NULL;
50     }
51     }
52    
53     static int auth_types_to_control_IDs[] = {
54     -1, IDC_SSHUSERHOSTS, IDC_SSHUSERSA, IDC_SSHUSEPASSWORD,
55     IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1
56     };
57    
58     static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg,
59     WPARAM wParam, LPARAM lParam)
60     {
61     switch (msg) {
62     case WM_CHAR:
63     if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) {
64     char chars[] = { (char) wParam, 0 };
65    
66     SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE,
67     (LPARAM) (char FAR *) chars);
68     return 0;
69     }
70     }
71    
72     return CallWindowProc((WNDPROC) GetWindowLong(control, GWL_USERDATA),
73     control, msg, wParam, lParam);
74     }
75    
76     static void init_password_control(HWND dlg)
77     {
78     HWND passwordControl = GetDlgItem(dlg, IDC_SSHPASSWORD);
79    
80     SetWindowLong(passwordControl, GWL_USERDATA,
81     SetWindowLong(passwordControl, GWL_WNDPROC,
82     (LONG) password_wnd_proc));
83    
84     SetFocus(passwordControl);
85     }
86    
87     static void set_auth_options_status(HWND dlg, int controlID)
88     {
89     BOOL RSA_enabled = controlID == IDC_SSHUSERSA;
90     BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS;
91     BOOL TIS_enabled = controlID == IDC_SSHUSETIS;
92     int i;
93    
94     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID);
95    
96     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), !TIS_enabled);
97     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), !TIS_enabled);
98    
99     for (i = IDC_CHOOSERSAFILE; i <= IDC_RSAFILENAME; i++) {
100     EnableWindow(GetDlgItem(dlg, i), RSA_enabled);
101     }
102    
103     for (i = IDC_LOCALUSERNAMELABEL; i <= IDC_HOSTRSAFILENAME; i++) {
104     EnableWindow(GetDlgItem(dlg, i), rhosts_enabled);
105     }
106     }
107    
108     static void init_auth_machine_banner(PTInstVar pvar, HWND dlg)
109     {
110     char buf[1024] = "Logging in to ";
111    
112     if (strlen(buf) + strlen(SSH_get_host_name(pvar)) < sizeof(buf) - 2) {
113     strcat(buf, SSH_get_host_name(pvar));
114     }
115     SetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf);
116     }
117    
118     static void update_server_supported_types(PTInstVar pvar, HWND dlg)
119     {
120     int supported_methods = pvar->auth_state.supported_types;
121     int cur_control = -1;
122     int control;
123     HWND focus = GetFocus();
124    
125     if (supported_methods == 0) {
126     return;
127     }
128    
129     for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL;
130     control++) {
131     BOOL enabled = FALSE;
132     int method;
133     HWND item = GetDlgItem(dlg, control);
134    
135     if (item != NULL) {
136     for (method = 0; method <= SSH_AUTH_MAX; method++) {
137     if (auth_types_to_control_IDs[method] == control
138     && (supported_methods & (1 << method)) != 0) {
139     enabled = TRUE;
140     }
141     }
142    
143     EnableWindow(item, enabled);
144    
145     if (IsDlgButtonChecked(dlg, control)) {
146     cur_control = control;
147     }
148     }
149     }
150    
151     if (cur_control >= 0) {
152     if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) {
153     do {
154     cur_control++;
155     if (cur_control > MAX_AUTH_CONTROL) {
156     cur_control = IDC_SSHUSEPASSWORD;
157     }
158     } while (!IsWindowEnabled(GetDlgItem(dlg, cur_control)));
159    
160     set_auth_options_status(dlg, cur_control);
161    
162     if (focus != NULL && !IsWindowEnabled(focus)) {
163     SetFocus(GetDlgItem(dlg, cur_control));
164     }
165     }
166     }
167     }
168    
169     static void init_auth_dlg(PTInstVar pvar, HWND dlg)
170     {
171     int default_method = pvar->session_settings.DefaultAuthMethod;
172    
173     init_auth_machine_banner(pvar, dlg);
174     init_password_control(dlg);
175    
176     if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
177     /* must be retrying a failed attempt */
178     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
179     "Authentication failed. Please retry.");
180     SetWindowText(dlg, "Retrying SSH Authentication");
181     default_method = pvar->auth_state.failed_method;
182     }
183    
184     set_auth_options_status(dlg,
185     auth_types_to_control_IDs[default_method]);
186    
187     if (default_method == SSH_AUTH_TIS) {
188     /* we disabled the password control, so fix the focus */
189     SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
190     }
191    
192     if (pvar->auth_state.user != NULL) {
193     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
194     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
195     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
196     } else if (pvar->session_settings.DefaultUserName[0] != 0) {
197     SetDlgItemText(dlg, IDC_SSHUSERNAME,
198     pvar->session_settings.DefaultUserName);
199     } else {
200     SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
201     }
202    
203     SetDlgItemText(dlg, IDC_RSAFILENAME,
204     pvar->session_settings.DefaultRSAPrivateKeyFile);
205     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
206     pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
207     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
208     pvar->session_settings.DefaultRhostsLocalUserName);
209    
210     update_server_supported_types(pvar, dlg);
211 yutakakn 2739
212     // SSH2 autologin (2004.12.1 yutaka)
213     // ���[�U�A�p�X���[�h�A�F�����\�b�h���������������A������������OK�{�^�������������B
214     if (pvar->ssh2_autologin == 1) {
215     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
216     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
217     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
218    
219     SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
220     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
221     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
222    
223     if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD) {
224     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
225     } else {
226     // TODO
227    
228     }
229     }
230    
231 yutakakn 2728 }
232    
233     static char FAR *alloc_control_text(HWND ctl)
234     {
235     int len = GetWindowTextLength(ctl);
236     char FAR *result = malloc(len + 1);
237    
238     if (result != NULL) {
239     GetWindowText(ctl, result, len + 1);
240     result[len] = 0;
241     }
242    
243     return result;
244     }
245    
246     static int get_key_file_name(HWND parent, char FAR * buf, int bufsize)
247     {
248     #ifdef TERATERM32
249     OPENFILENAME params;
250     char fullname_buf[2048] = "identity";
251    
252 yutakakn 2762 ZeroMemory(&params, sizeof(params));
253 yutakakn 2728 params.lStructSize = sizeof(OPENFILENAME);
254     params.hwndOwner = parent;
255 yutakakn 2762 // �t�B���^������ (2004.12.19 yutaka)
256     params.lpstrFilter = "identity(RSA1)\0identity\0id_rsa(SSH2)\0id_rsa\0id_dsa(SSH2)\0id_dsa\0all(*.*)\0*.*\0\0";
257 yutakakn 2728 params.lpstrCustomFilter = NULL;
258     params.nFilterIndex = 0;
259     buf[0] = 0;
260     params.lpstrFile = fullname_buf;
261     params.nMaxFile = sizeof(fullname_buf);
262     params.lpstrFileTitle = NULL;
263     params.lpstrInitialDir = NULL;
264     params.lpstrTitle = "Choose a file with the RSA private key";
265     params.Flags =
266     OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
267     params.lpstrDefExt = NULL;
268    
269     if (GetOpenFileName(&params) != 0) {
270     copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf);
271     return 1;
272     } else {
273     return 0;
274     }
275     #else
276     return 0;
277     #endif
278     }
279    
280     static void choose_RSA_key_file(HWND dlg)
281     {
282     char buf[1024];
283    
284     if (get_key_file_name(dlg, buf, sizeof(buf))) {
285     SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
286     }
287     }
288    
289     static void choose_host_RSA_key_file(HWND dlg)
290     {
291     char buf[1024];
292    
293     if (get_key_file_name(dlg, buf, sizeof(buf))) {
294     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
295     }
296     }
297    
298     static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
299     {
300     int method = SSH_AUTH_PASSWORD;
301     char FAR *password =
302     alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
303     CRYPTKeyPair FAR *key_pair = NULL;
304    
305     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
306     method = SSH_AUTH_RSA;
307     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
308     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
309     method = SSH_AUTH_RHOSTS_RSA;
310     } else {
311     method = SSH_AUTH_RHOSTS;
312     }
313     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
314     method = SSH_AUTH_TIS;
315     }
316    
317     if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
318     char buf[2048];
319     int file_ctl_ID =
320     method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
321    
322     buf[0] = 0;
323     GetDlgItemText(dlg, file_ctl_ID, buf, sizeof(buf));
324     if (buf[0] == 0) {
325     notify_nonfatal_error(pvar,
326 yutakakn 2762 "You must specify a file containing the RSA/DSA private key.");
327 yutakakn 2728 SetFocus(GetDlgItem(dlg, file_ctl_ID));
328     destroy_malloced_string(&password);
329     return FALSE;
330 yutakakn 2762 }
331    
332     if (SSHv1(pvar)) {
333 yutakakn 2728 BOOL invalid_passphrase = FALSE;
334    
335     key_pair = KEYFILES_read_private_key(pvar, buf, password,
336     &invalid_passphrase,
337     FALSE);
338    
339     if (key_pair == NULL) {
340     if (invalid_passphrase) {
341     HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
342    
343     SetFocus(passwordCtl);
344     SendMessage(passwordCtl, EM_SETSEL, 0, -1);
345     } else {
346     SetFocus(GetDlgItem(dlg, file_ctl_ID));
347     }
348     destroy_malloced_string(&password);
349     return FALSE;
350     }
351 yutakakn 2762
352     } else { // SSH2(yutaka)
353     BOOL invalid_passphrase = FALSE;
354 yutakakn 2769 char errmsg[256];
355 yutakakn 2762
356 yutakakn 2769 memset(errmsg, 0, sizeof(errmsg));
357    
358 yutakakn 2762 key_pair = read_SSH2_private_key(pvar, buf, password,
359     &invalid_passphrase,
360 yutakakn 2769 FALSE,
361     errmsg,
362     sizeof(errmsg)
363     );
364 yutakakn 2762
365     if (key_pair == NULL) { // read error
366 yutakakn 2769 char buf[1024];
367     _snprintf(buf, sizeof(buf), "read error SSH2 private key file\r\n%s", errmsg);
368     notify_nonfatal_error(pvar, buf);
369 yutakakn 2762 destroy_malloced_string(&password);
370     return FALSE;
371     }
372    
373 yutakakn 2728 }
374 yutakakn 2762
375 yutakakn 2728 }
376    
377     /* from here on, we cannot fail, so just munge cur_cred in place */
378     pvar->auth_state.cur_cred.method = method;
379     pvar->auth_state.cur_cred.key_pair = key_pair;
380     /* we can't change the user name once it's set. It may already have
381     been sent to the server, and it can only be sent once. */
382     if (pvar->auth_state.user == NULL) {
383     pvar->auth_state.user =
384     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
385     }
386     if (method == SSH_AUTH_PASSWORD) {
387     pvar->auth_state.cur_cred.password = password;
388     } else {
389     destroy_malloced_string(&password);
390     }
391     if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
392     if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
393     notify_nonfatal_error(pvar,
394     "Rhosts authentication will probably fail because it was not "
395     "the default authentication method.\n"
396     "To use Rhosts authentication "
397     "in TTSSH, you need to set it to be the default by restarting\n"
398     "TTSSH and selecting \"SSH Authentication...\" from the Setup menu"
399     "before connecting.");
400     }
401    
402     pvar->auth_state.cur_cred.rhosts_client_user =
403     alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
404     }
405     pvar->auth_state.auth_dialog = NULL;
406    
407     GetDlgItemText(dlg, IDC_RSAFILENAME,
408     pvar->session_settings.DefaultRSAPrivateKeyFile,
409     sizeof(pvar->session_settings.
410     DefaultRSAPrivateKeyFile));
411     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
412     pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
413     sizeof(pvar->session_settings.
414     DefaultRhostsHostPrivateKeyFile));
415     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
416     pvar->session_settings.DefaultRhostsLocalUserName,
417     sizeof(pvar->session_settings.
418     DefaultRhostsLocalUserName));
419    
420     if (SSHv1(pvar)) {
421     SSH_notify_user_name(pvar);
422     SSH_notify_cred(pvar);
423     } else {
424     // for SSH2(yutaka)
425     do_SSH2_userauth(pvar);
426     }
427    
428     EndDialog(dlg, 1);
429     return TRUE;
430     }
431    
432     static BOOL CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
433     LPARAM lParam)
434     {
435 yutakakn 2739 const int IDC_TIMER1 = 300;
436 yutakakn 2752 const int autologin_timeout = 10; // �~���b
437 yutakakn 2728 PTInstVar pvar;
438    
439     switch (msg) {
440     case WM_INITDIALOG:
441     pvar = (PTInstVar) lParam;
442     pvar->auth_state.auth_dialog = dlg;
443     SetWindowLong(dlg, DWL_USER, lParam);
444    
445     init_auth_dlg(pvar, dlg);
446 yutakakn 2739
447     // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
448     if (pvar->ssh2_autologin == 1) {
449     SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
450     }
451 yutakakn 2728 return FALSE; /* because we set the focus */
452    
453 yutakakn 2739 case WM_TIMER:
454 yutakakn 2752 pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
455     // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
456     if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME)) {
457     KillTimer(dlg, IDC_TIMER1);
458     SendMessage(dlg, WM_COMMAND, IDOK, 0);
459     }
460 yutakakn 2739 return TRUE;
461    
462 yutakakn 2728 case WM_COMMAND:
463     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
464    
465     switch (LOWORD(wParam)) {
466     case IDOK:
467 yutakakn 2783 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
468     if ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME)) {
469     return FALSE;
470     }
471 yutakakn 2728 return end_auth_dlg(pvar, dlg);
472    
473     case IDCANCEL: /* kill the connection */
474     pvar->auth_state.auth_dialog = NULL;
475     notify_closed_connection(pvar);
476     EndDialog(dlg, 0);
477     return TRUE;
478    
479     case IDC_SSHUSEPASSWORD:
480     case IDC_SSHUSERSA:
481     case IDC_SSHUSERHOSTS:
482     case IDC_SSHUSETIS:
483     set_auth_options_status(dlg, LOWORD(wParam));
484     return TRUE;
485    
486     case IDC_CHOOSERSAFILE:
487     choose_RSA_key_file(dlg);
488     return TRUE;
489    
490     case IDC_CHOOSEHOSTRSAFILE:
491     choose_host_RSA_key_file(dlg);
492     return TRUE;
493    
494     default:
495     return FALSE;
496     }
497    
498     default:
499     return FALSE;
500     }
501     }
502    
503     char FAR *AUTH_get_user_name(PTInstVar pvar)
504     {
505     return pvar->auth_state.user;
506     }
507    
508     int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
509     {
510     char buf[1024];
511    
512     _snprintf(buf, sizeof(buf),
513     "Server reports supported authentication method mask = %d",
514     types);
515     buf[sizeof(buf) - 1] = 0;
516     notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
517    
518     if (SSHv1(pvar)) {
519     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
520     | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
521     | (1 << SSH_AUTH_TIS);
522     } else {
523     // for SSH2(yutaka)
524 yutakakn 2762 // types &= (1 << SSH_AUTH_PASSWORD);
525     // ���J���F�����L�������� (2004.12.18 yutaka)
526     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
527     | (1 << SSH_AUTH_DSA);
528 yutakakn 2728 }
529     pvar->auth_state.supported_types = types;
530    
531     if (types == 0) {
532     notify_fatal_error(pvar,
533     "Server does not support any of the authentication options\n"
534     "provided by TTSSH. This connection will now close.");
535     return 0;
536     } else {
537     if (pvar->auth_state.auth_dialog != NULL) {
538     update_server_supported_types(pvar,
539     pvar->auth_state.auth_dialog);
540     }
541    
542     return 1;
543     }
544     }
545    
546     static void start_user_auth(PTInstVar pvar)
547     {
548 yutakakn 2739 // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
549 yutakakn 2728 PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
550     (LPARAM) NULL);
551     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
552     }
553    
554     static void try_default_auth(PTInstVar pvar)
555     {
556     if (pvar->session_settings.TryDefaultAuth) {
557     switch (pvar->session_settings.DefaultAuthMethod) {
558     case SSH_AUTH_RSA:{
559     BOOL invalid_passphrase;
560     char password[] = "";
561    
562     pvar->auth_state.cur_cred.key_pair
563     =
564     KEYFILES_read_private_key(pvar,
565     pvar->session_settings.
566     DefaultRSAPrivateKeyFile,
567     password,
568     &invalid_passphrase, TRUE);
569     if (pvar->auth_state.cur_cred.key_pair == NULL) {
570     return;
571     } else {
572     pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
573     }
574     break;
575     }
576    
577     case SSH_AUTH_RHOSTS:
578     if (pvar->session_settings.
579     DefaultRhostsHostPrivateKeyFile[0] != 0) {
580     BOOL invalid_passphrase;
581     char password[] = "";
582    
583     pvar->auth_state.cur_cred.key_pair
584     =
585     KEYFILES_read_private_key(pvar,
586     pvar->session_settings.
587     DefaultRhostsHostPrivateKeyFile,
588     password,
589     &invalid_passphrase, TRUE);
590     if (pvar->auth_state.cur_cred.key_pair == NULL) {
591     return;
592     } else {
593     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
594     }
595     } else {
596     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
597     }
598    
599     pvar->auth_state.cur_cred.rhosts_client_user =
600     _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
601     break;
602    
603     case SSH_AUTH_PASSWORD:
604     pvar->auth_state.cur_cred.password = _strdup("");
605     pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
606     break;
607    
608     case SSH_AUTH_TIS:
609     default:
610     return;
611     }
612    
613     pvar->auth_state.user =
614     _strdup(pvar->session_settings.DefaultUserName);
615     }
616     }
617    
618     void AUTH_notify_end_error(PTInstVar pvar)
619     {
620     if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
621     start_user_auth(pvar);
622     pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
623     }
624     }
625    
626     void AUTH_advance_to_next_cred(PTInstVar pvar)
627     {
628     pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
629    
630     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
631     try_default_auth(pvar);
632    
633     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
634     if (pvar->err_msg != NULL) {
635     pvar->auth_state.flags |=
636     AUTH_START_USER_AUTH_ON_ERROR_END;
637     } else {
638 yutakakn 2739 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
639     // �R�}���h���C���w������������
640 yutakakn 2728 start_user_auth(pvar);
641     }
642     }
643     } else {
644 yutakakn 2739 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
645     // �R�}���h���C���w������(/auth=xxxx)������
646 yutakakn 2728 start_user_auth(pvar);
647     }
648     }
649    
650     static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
651     {
652     init_auth_machine_banner(pvar, dlg);
653     init_password_control(dlg);
654    
655     if (pvar->auth_state.TIS_prompt != NULL) {
656     if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
657     pvar->auth_state.TIS_prompt[10000] = 0;
658     }
659     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
660     pvar->auth_state.TIS_prompt);
661     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
662     }
663     }
664    
665     static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
666     {
667     char FAR *password =
668     alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
669    
670     pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
671     pvar->auth_state.cur_cred.password = password;
672     pvar->auth_state.auth_dialog = NULL;
673    
674     SSH_notify_cred(pvar);
675    
676     EndDialog(dlg, 1);
677     return TRUE;
678     }
679    
680     static BOOL CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
681     LPARAM lParam)
682     {
683     PTInstVar pvar;
684    
685     switch (msg) {
686     case WM_INITDIALOG:
687     pvar = (PTInstVar) lParam;
688     pvar->auth_state.auth_dialog = dlg;
689     SetWindowLong(dlg, DWL_USER, lParam);
690    
691     init_TIS_dlg(pvar, dlg);
692     return FALSE; /* because we set the focus */
693    
694     case WM_COMMAND:
695     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
696    
697     switch (LOWORD(wParam)) {
698     case IDOK:
699     return end_TIS_dlg(pvar, dlg);
700    
701     case IDCANCEL: /* kill the connection */
702     pvar->auth_state.auth_dialog = NULL;
703     notify_closed_connection(pvar);
704     EndDialog(dlg, 0);
705     return TRUE;
706    
707     default:
708     return FALSE;
709     }
710    
711     default:
712     return FALSE;
713     }
714     }
715    
716     void AUTH_do_cred_dialog(PTInstVar pvar)
717     {
718     if (pvar->auth_state.auth_dialog == NULL) {
719     HWND cur_active = GetActiveWindow();
720     DLGPROC dlg_proc;
721     LPCTSTR dialog_template;
722    
723     switch (pvar->auth_state.mode) {
724     case TIS_AUTH_MODE:
725     dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
726     dlg_proc = TIS_dlg_proc;
727     break;
728     case GENERIC_AUTH_MODE:
729     default:
730     dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
731     dlg_proc = auth_dlg_proc;
732     }
733    
734     if (!DialogBoxParam(hInst, dialog_template,
735     cur_active !=
736     NULL ? cur_active : pvar->NotificationWindow,
737     dlg_proc, (LPARAM) pvar) == -1) {
738     notify_fatal_error(pvar,
739     "Unable to display authentication dialog box.\n"
740     "Connection terminated.");
741     }
742     }
743     }
744    
745     static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
746     {
747     switch (pvar->settings.DefaultAuthMethod) {
748     case SSH_AUTH_RSA:
749     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
750     IDC_SSHUSERSA);
751     break;
752     case SSH_AUTH_RHOSTS:
753     case SSH_AUTH_RHOSTS_RSA:
754     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
755     IDC_SSHUSERHOSTS);
756     break;
757     case SSH_AUTH_TIS:
758     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
759     IDC_SSHUSETIS);
760     break;
761     case SSH_AUTH_PASSWORD:
762     default:
763     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
764     IDC_SSHUSEPASSWORD);
765     }
766    
767     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
768     SetDlgItemText(dlg, IDC_RSAFILENAME,
769     pvar->settings.DefaultRSAPrivateKeyFile);
770     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
771     pvar->settings.DefaultRhostsHostPrivateKeyFile);
772     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
773     pvar->settings.DefaultRhostsLocalUserName);
774     }
775    
776     static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
777     {
778     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
779     pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
780     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
781     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
782     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
783     } else {
784     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
785     }
786     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
787     pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
788     } else {
789     pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
790     }
791    
792     GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
793     sizeof(pvar->settings.DefaultUserName));
794     GetDlgItemText(dlg, IDC_RSAFILENAME,
795     pvar->settings.DefaultRSAPrivateKeyFile,
796     sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
797     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
798     pvar->settings.DefaultRhostsHostPrivateKeyFile,
799     sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
800     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
801     pvar->settings.DefaultRhostsLocalUserName,
802     sizeof(pvar->settings.DefaultRhostsLocalUserName));
803    
804     EndDialog(dlg, 1);
805     return TRUE;
806     }
807    
808     static BOOL CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
809     WPARAM wParam, LPARAM lParam)
810     {
811     PTInstVar pvar;
812    
813     switch (msg) {
814     case WM_INITDIALOG:
815     pvar = (PTInstVar) lParam;
816     SetWindowLong(dlg, DWL_USER, lParam);
817    
818     init_default_auth_dlg(pvar, dlg);
819     return TRUE; /* because we do not set the focus */
820    
821     case WM_COMMAND:
822     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
823    
824     switch (LOWORD(wParam)) {
825     case IDOK:
826     return end_default_auth_dlg(pvar, dlg);
827    
828     case IDCANCEL:
829     EndDialog(dlg, 0);
830     return TRUE;
831    
832     case IDC_CHOOSERSAFILE:
833     choose_RSA_key_file(dlg);
834     return TRUE;
835    
836     case IDC_CHOOSEHOSTRSAFILE:
837     choose_host_RSA_key_file(dlg);
838     return TRUE;
839    
840     default:
841     return FALSE;
842     }
843    
844     default:
845     return FALSE;
846     }
847     }
848    
849     void AUTH_init(PTInstVar pvar)
850     {
851     pvar->auth_state.failed_method = SSH_AUTH_NONE;
852     pvar->auth_state.auth_dialog = NULL;
853     pvar->auth_state.user = NULL;
854     pvar->auth_state.flags = 0;
855     pvar->auth_state.TIS_prompt = NULL;
856     pvar->auth_state.supported_types = 0;
857     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
858     pvar->auth_state.cur_cred.password = NULL;
859     pvar->auth_state.cur_cred.rhosts_client_user = NULL;
860     pvar->auth_state.cur_cred.key_pair = NULL;
861     AUTH_set_generic_mode(pvar);
862     }
863    
864     void AUTH_set_generic_mode(PTInstVar pvar)
865     {
866     pvar->auth_state.mode = GENERIC_AUTH_MODE;
867     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
868     }
869    
870     void AUTH_set_TIS_mode(PTInstVar pvar, char FAR * prompt, int len)
871     {
872     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
873     pvar->auth_state.mode = TIS_AUTH_MODE;
874    
875     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
876     pvar->auth_state.TIS_prompt = malloc(len + 1);
877     memcpy(pvar->auth_state.TIS_prompt, prompt, len);
878     pvar->auth_state.TIS_prompt[len] = 0;
879     } else {
880     AUTH_set_generic_mode(pvar);
881     }
882     }
883    
884     void AUTH_do_default_cred_dialog(PTInstVar pvar)
885     {
886     HWND cur_active = GetActiveWindow();
887    
888     if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
889     cur_active !=
890     NULL ? cur_active : pvar->NotificationWindow,
891     default_auth_dlg_proc, (LPARAM) pvar) == -1) {
892     notify_nonfatal_error(pvar,
893     "Unable to display authentication setup dialog box.");
894     }
895     }
896    
897     void AUTH_destroy_cur_cred(PTInstVar pvar)
898     {
899     destroy_malloced_string(&pvar->auth_state.cur_cred.password);
900     destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
901     if (pvar->auth_state.cur_cred.key_pair != NULL) {
902     CRYPT_free_key_pair(pvar->auth_state.cur_cred.key_pair);
903     pvar->auth_state.cur_cred.key_pair = NULL;
904     }
905     }
906    
907     static char FAR *get_auth_method_name(SSHAuthMethod auth)
908     {
909     switch (auth) {
910     case SSH_AUTH_PASSWORD:
911     return "password";
912     case SSH_AUTH_RSA:
913     return "RSA";
914     case SSH_AUTH_RHOSTS:
915     return "rhosts";
916     case SSH_AUTH_RHOSTS_RSA:
917     return "rhosts with RSA";
918     case SSH_AUTH_TIS:
919     return "challenge/response (TIS)";
920     default:
921     return "unknown method";
922     }
923     }
924    
925     void AUTH_get_auth_info(PTInstVar pvar, char FAR * dest, int len)
926     {
927 yutakakn 2782 char *method = "unknown";
928    
929 yutakakn 2728 if (pvar->auth_state.user == NULL) {
930     strncpy(dest, "None", len);
931     } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
932 yutakakn 2762 if (SSHv1(pvar)) {
933     _snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user,
934     get_auth_method_name(pvar->auth_state.cur_cred.method));
935    
936     } else { // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
937     if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD) {
938 yutakakn 2782 // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
939     if (pvar->keyboard_interactive_done == 1) {
940     method = "keyboard-interactive";
941     } else {
942     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
943     }
944     _snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user, method);
945    
946 yutakakn 2762 } else {
947     if (pvar->auth_state.cur_cred.key_pair->RSA_key != NULL) {
948     method = "RSA";
949     } else if (pvar->auth_state.cur_cred.key_pair->DSA_key != NULL) {
950     method = "DSA";
951     }
952     _snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user, method);
953     }
954    
955     }
956    
957 yutakakn 2728 } else {
958     _snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user,
959     get_auth_method_name(pvar->auth_state.failed_method));
960     }
961    
962     dest[len - 1] = 0;
963     }
964    
965     void AUTH_notify_disconnecting(PTInstVar pvar)
966     {
967     if (pvar->auth_state.auth_dialog != NULL) {
968     PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
969     /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
970     EnableWindow(pvar->NotificationWindow, TRUE);
971     }
972     }
973    
974     void AUTH_end(PTInstVar pvar)
975     {
976     destroy_malloced_string(&pvar->auth_state.user);
977     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
978    
979     AUTH_destroy_cur_cred(pvar);
980     }
981 yutakakn 2739
982     /*
983     * $Log: not supported by cvs2svn $
984 yutakakn 2783 * Revision 1.6 2005/01/24 14:07:07 yutakakn
985     * �Ekeyboard-interactive�F�����T�|�[�g�����B
986     * �@�����������Ateraterm.ini�� "KeyboardInteractive" �G���g�������������B
987     * �E�o�[�W�����_�C�A���O�� OpenSSL�o�[�W���� ������
988     *
989 yutakakn 2782 * Revision 1.5 2004/12/27 14:35:41 yutakakn
990     * SSH2�����������������s�����G���[���b�Z�[�W�����������B
991     *
992 yutakakn 2769 * Revision 1.4 2004/12/22 17:28:14 yutakakn
993     * SSH2���J���F��(RSA/DSA)���T�|�[�g�����B
994     *
995 yutakakn 2762 * Revision 1.3 2004/12/16 13:01:09 yutakakn
996     * SSH�������O�C�����A�v���P�[�V�����G���[�������������C�������B
997     *
998 yutakakn 2752 * Revision 1.2 2004/12/01 15:37:49 yutakakn
999     * SSH2�������O�C���@�\�������B
1000     * �����A�p�X���[�h�F�������������B
1001     * �E�R�}���h���C��
1002     * /ssh /auth=�F�����\�b�h /user=���[�U�� /passwd=�p�X���[�h
1003     *
1004 yutakakn 2739 */

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