Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/key.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5857 by yutakapon, Sun May 10 15:41:48 2015 UTC revision 5931 by yutakapon, Sat Aug 8 17:42:07 2015 UTC
# Line 27  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI Line 27  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
27  */  */
28  #include "key.h"  #include "key.h"
29  #include "kex.h"  #include "kex.h"
30    #include "resource.h"
31    
32  #include <openssl/rsa.h>  #include <openssl/rsa.h>
33  #include <openssl/dsa.h>  #include <openssl/dsa.h>
# Line 1912  error: Line 1913  error:
1913          return (ret);          return (ret);
1914  }  }
1915    
1916  static void update_known_hosts(PTInstVar pvar, struct hostkeys_update_ctx *ctx)  static BOOL CALLBACK hosts_updatekey_dlg_proc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
1917  {  {
1918          size_t i;          static HFONT DlgHostsAddFont;
1919          int dlgresult;          PTInstVar pvar;
1920          char msg[1024], tmp[128];          LOGFONT logfont;
1921          char *fp;          HFONT font;
1922            char buf[1024];
1923          char *host;          char *host;
1924            struct hostkeys_update_ctx *ctx;
1925            char *fp;
1926            size_t i;
1927    
1928          host = pvar->ssh_state.hostname;          switch (msg) {
1929            case WM_INITDIALOG:
1930                    pvar = (PTInstVar)lParam;
1931                    SetWindowLong(dlg, DWL_USER, lParam);
1932    
1933          // "/nosecuritywarning"が指定されている場合、更新は一切行わない。                  host = pvar->ssh_state.hostname;
1934          if (pvar->nocheck_known_hosts) {                  ctx = pvar->hostkey_ctx;
                 _snprintf_s(msg, sizeof(msg), _TRUNCATE, "Hostkey was not updated because `/nosecuritywarning' option was specified.");  
                 notify_verbose_message(pvar, msg, LOG_LEVEL_VERBOSE);  
                 goto error;  
         }  
1935    
1936          // known_hostsファイルの更新を行うため、ユーザに問い合わせを行う。                  UTIL_get_lang_msg("DLG_HOSTKEY_ROTATION_WARNING", pvar,
         if (pvar->settings.UpdateHostkeys == SSH_UPDATE_HOSTKEYS_ASK) {  
                 UTIL_get_lang_msg("DLG_HOSTKEY_ROTATION_WARNING", pvar,  
1937                          "Remote server \"%s\" sent the set of host keys which are absent in your list of known hosts. \n"                          "Remote server \"%s\" sent the set of host keys which are absent in your list of known hosts. \n"
1938                          "The machine you have contacted may be a hostile machine pretending to be the server, or legitimate server supporting host key rotation. \n\n"                          "The machine you have contacted may be a hostile machine pretending to be the server, or legitimate server supporting host key rotation. \n\n"
1939                          "If you choose to add %u latest key(s) and remove %u obsolete key(s) from this machine to the known hosts list and continue, then you will not receive this warning again.\n\n"                          "If you choose to add %u latest key(s) and remove %u obsolete key(s) from this machine to the known hosts list and continue, then you will not receive this warning again.\n\n"
1940                          "Do you want to update known hosts file with new key(s)?\n\n"                          "Do you want to update known hosts file with new key(s)?\n\n"
1941                          );                          );
1942                  _snprintf_s(msg, sizeof(msg), _TRUNCATE,                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,
1943                          pvar->ts->UIMsg, host, ctx->nnew, ctx->nold                          pvar->ts->UIMsg, host, ctx->nnew, ctx->nold
1944                          );                          );
1945                    SetDlgItemText(dlg, IDC_HOSTKEY_MESSAGE, buf);
1946    
1947                    _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%u latest key(s):\n", ctx->nnew);
1948                    SetDlgItemText(dlg, IDC_ADDKEY_TEXT, buf);
1949                    for (i = 0; i < ctx->nkeys; i++) {
1950                            if (ctx->keys_seen[i])
1951                                    continue;
1952                            fp = key_fingerprint(ctx->keys[i], SSH_FP_HEX);
1953                            buf[0] = 0;
1954                            strcat_s(buf, sizeof(buf), get_sshname_from_key(ctx->keys[i]));
1955                            strcat_s(buf, sizeof(buf), " ");
1956                            strcat_s(buf, sizeof(buf), fp);
1957                            SendDlgItemMessage(dlg, IDC_ADDKEY_EDIT, EM_REPLACESEL, 0, (LPARAM)buf);
1958                            SendDlgItemMessage(dlg, IDC_ADDKEY_EDIT, EM_REPLACESEL, 0, (LPARAM)"\r\n");
1959                            free(fp);
1960                    }
1961    
1962                    _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%u obsolete key(s):\n", ctx->nold);
1963                    SetDlgItemText(dlg, IDC_REMOVEKEY_TEXT, buf);
1964                    for (i = 0; i < ctx->nold; i++) {
1965                            fp = key_fingerprint(ctx->old_keys[i], SSH_FP_HEX);
1966                            buf[0] = 0;
1967                            strcat_s(buf, sizeof(buf), get_sshname_from_key(ctx->old_keys[i]));
1968                            strcat_s(buf, sizeof(buf), " ");
1969                            strcat_s(buf, sizeof(buf), fp);
1970                            SendDlgItemMessage(dlg, IDC_REMOVEKEY_EDIT, EM_REPLACESEL, 0, (LPARAM)buf);
1971                            SendDlgItemMessage(dlg, IDC_REMOVEKEY_EDIT, EM_REPLACESEL, 0, (LPARAM)"\r\n");
1972                            free(fp);
1973                    }
1974    
1975                    font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
1976                    GetObject(font, sizeof(LOGFONT), &logfont);
1977                    if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgHostsAddFont, pvar)) {
1978                            SendDlgItemMessage(dlg, IDC_HOSTKEY_MESSAGE, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1979                            SendDlgItemMessage(dlg, IDC_ADDKEY_TEXT, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1980                            SendDlgItemMessage(dlg, IDC_ADDKEY_EDIT, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1981                            SendDlgItemMessage(dlg, IDC_REMOVEKEY_TEXT, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1982                            SendDlgItemMessage(dlg, IDC_REMOVEKEY_EDIT, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1983                            //SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1984                            //SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgHostsAddFont, MAKELPARAM(TRUE, 0));
1985                    }
1986                    else {
1987                            DlgHostsAddFont = NULL;
1988                    }
1989    
1990                    return TRUE;                    /* because we do not set the focus */
1991    
1992            case WM_COMMAND:
1993                    pvar = (PTInstVar)GetWindowLong(dlg, DWL_USER);
1994    
1995                    switch (LOWORD(wParam)) {
1996                    case IDOK:
1997    
1998                            EndDialog(dlg, 1);
1999    
2000                  if (ctx->nnew > 0) {                          if (DlgHostsAddFont != NULL) {
2001                          _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%u latest key(s):\n", ctx->nnew);                                  DeleteObject(DlgHostsAddFont);
                         strcat_s(msg, sizeof(msg), tmp);  
                         for (i = 0; i < ctx->nkeys; i++) {  
                                 if (ctx->keys_seen[i])  
                                         continue;  
                                 fp = key_fingerprint(ctx->keys[i], SSH_FP_HEX);  
                                 strcat_s(msg, sizeof(msg), get_sshname_from_key(ctx->keys[i]));  
                                 strcat_s(msg, sizeof(msg), " ");  
                                 strcat_s(msg, sizeof(msg), fp);  
                                 strcat_s(msg, sizeof(msg), "\n");  
                                 free(fp);  
2002                          }                          }
                 }  
2003    
2004                  if (ctx->nold > 0) {                          return TRUE;
2005                          strcat_s(msg, sizeof(msg), "\n");  
2006                    case IDCANCEL:                  /* kill the connection */
2007                            EndDialog(dlg, 0);
2008    
2009                          _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%u obsolete key(s):\n", ctx->nold);                          if (DlgHostsAddFont != NULL) {
2010                          strcat_s(msg, sizeof(msg), tmp);                                  DeleteObject(DlgHostsAddFont);
                         for (i = 0; i < ctx->nold; i++) {  
                                 fp = key_fingerprint(ctx->old_keys[i], SSH_FP_HEX);  
                                 strcat_s(msg, sizeof(msg), get_sshname_from_key(ctx->old_keys[i]));  
                                 strcat_s(msg, sizeof(msg), " ");  
                                 strcat_s(msg, sizeof(msg), fp);  
                                 strcat_s(msg, sizeof(msg), "\n");  
                                 free(fp);  
2011                          }                          }
2012    
2013                            return TRUE;
2014    
2015                    default:
2016                            return FALSE;
2017                  }                  }
2018    
2019                  dlgresult = MessageBox(NULL, msg, "TTSSH: SECURITY WARNING", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2);          default:
2020                  if (dlgresult != IDYES) {                  return FALSE;
2021            }
2022    }
2023    
2024    static void update_known_hosts(PTInstVar pvar, struct hostkeys_update_ctx *ctx)
2025    {
2026            size_t i;
2027            int dlgresult;
2028            char msg[1024];
2029            char *host;
2030    
2031            host = pvar->ssh_state.hostname;
2032    
2033            // "/nosecuritywarning"が指定されている場合、更新は一切行わない。
2034            if (pvar->nocheck_known_hosts) {
2035                    _snprintf_s(msg, sizeof(msg), _TRUNCATE, "Hostkey was not updated because `/nosecuritywarning' option was specified.");
2036                    notify_verbose_message(pvar, msg, LOG_LEVEL_VERBOSE);
2037                    goto error;
2038            }
2039    
2040            // known_hostsファイルの更新を行うため、ユーザに問い合わせを行う。
2041            if (pvar->settings.UpdateHostkeys == SSH_UPDATE_HOSTKEYS_ASK) {
2042                    HWND cur_active = GetActiveWindow();
2043    
2044                    pvar->hostkey_ctx = ctx;
2045                    dlgresult = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHUPDATE_HOSTKEY),
2046                            cur_active != NULL ? cur_active : pvar->NotificationWindow,
2047                            hosts_updatekey_dlg_proc, (LPARAM)pvar);
2048                    if (dlgresult != 1) {
2049                          _snprintf_s(msg, sizeof(msg), _TRUNCATE, "Hostkey was not updated because a user cancelled.");                          _snprintf_s(msg, sizeof(msg), _TRUNCATE, "Hostkey was not updated because a user cancelled.");
2050                          notify_verbose_message(pvar, msg, LOG_LEVEL_VERBOSE);                          notify_verbose_message(pvar, msg, LOG_LEVEL_VERBOSE);
2051                          goto error;                          goto error;

Legend:
Removed from v.5857  
changed lines
  Added in v.5931

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