2 * wincons.c - various interactive-prompt routines shared between
\r
3 * the Windows console PuTTY tools
\r
11 #include "storage.h"
\r
14 #include "LoginDialog.h"
\r
16 int console_batch_mode = FALSE;
\r
18 static void *console_logctx = NULL;
\r
21 * Clean up and exit.
\r
23 void cleanup_exit(int code)
\r
38 void set_busy_status(void *frontend, int status)
\r
42 void notify_remote_exit(void *frontend)
\r
46 void timer_change_notify(long next)
\r
50 int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
\r
51 char *keystr, char *fingerprint,
\r
52 void (*callback)(void *ctx, int result), void *ctx)
\r
56 static const char absentmsg_batch[] =
\r
57 "The server's host key is not cached in the registry. You\n"
\r
58 "have no guarantee that the server is the computer you\n"
\r
60 "The server's %s key fingerprint is:\n"
\r
62 "Connection abandoned.\n";
\r
63 static const char absentmsg[] =
\r
64 "The server's host key is not cached in the registry. You\n"
\r
65 "have no guarantee that the server is the computer you\n"
\r
67 "The server's %s key fingerprint is:\n"
\r
69 "If you trust this host, enter \"y\" to add the key to\n"
\r
70 "PuTTY's cache and carry on connecting.\n"
\r
71 "If you want to carry on connecting just once, without\n"
\r
72 "adding the key to the cache, enter \"n\".\n"
\r
73 "If you do not trust this host, press Return to abandon the\n"
\r
75 "Store key in cache? (y/n) ";
\r
77 static const char wrongmsg_batch[] =
\r
78 "WARNING - POTENTIAL SECURITY BREACH!\n"
\r
79 "The server's host key does not match the one PuTTY has\n"
\r
80 "cached in the registry. This means that either the\n"
\r
81 "server administrator has changed the host key, or you\n"
\r
82 "have actually connected to another computer pretending\n"
\r
83 "to be the server.\n"
\r
84 "The new %s key fingerprint is:\n"
\r
86 "Connection abandoned.\n";
\r
87 static const char wrongmsg[] =
\r
88 "WARNING - POTENTIAL SECURITY BREACH!\n"
\r
89 "The server's host key does not match the one PuTTY has\n"
\r
90 "cached in the registry. This means that either the\n"
\r
91 "server administrator has changed the host key, or you\n"
\r
92 "have actually connected to another computer pretending\n"
\r
93 "to be the server.\n"
\r
94 "The new %s key fingerprint is:\n"
\r
96 "If you were expecting this change and trust the new key,\n"
\r
97 "enter \"y\" to update PuTTY's cache and continue connecting.\n"
\r
98 "If you want to carry on connecting but without updating\n"
\r
99 "the cache, enter \"n\".\n"
\r
100 "If you want to abandon the connection completely, press\n"
\r
101 "Return to cancel. Pressing Return is the ONLY guaranteed\n"
\r
103 "Update cached key? (y/n, Return cancels connection) ";
\r
105 static const char abandoned[] = "Connection abandoned.\n";
\r
107 static const char mbtitle[] = "%s Security Alert";
\r
110 * Verify the key against the registry.
\r
112 ret = verify_host_key(host, port, keytype, keystr);
\r
114 if (ret == 0) /* success - key matched OK */
\r
117 if (ret == 2) { /* key was different */
\r
119 char *message, *title;
\r
121 message = dupprintf(wrongmsg, keytype, fingerprint, appname);
\r
122 title = dupprintf(mbtitle, appname);
\r
124 mbret = MessageBox(GetParentHwnd(), message, title, MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3);
\r
127 if (mbret == IDYES) {
\r
128 store_host_key(host, port, keytype, keystr);
\r
131 else if (mbret == IDNO)
\r
139 if (ret == 1) { /* key was absent */
\r
141 char *message, *title;
\r
142 message = dupprintf(absentmsg, keytype, fingerprint, appname);
\r
143 title = dupprintf(mbtitle, appname);
\r
144 mbret = MessageBox(GetParentHwnd(), message, title,
\r
145 MB_ICONWARNING | MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON3);
\r
148 if (mbret == IDYES)
\r
150 store_host_key(host, port, keytype, keystr);
\r
153 else if (mbret == IDNO)
\r
163 void update_specials_menu(void *frontend)
\r
168 * Ask whether the selected algorithm is acceptable (since it was
\r
169 * below the configured 'warn' threshold).
\r
171 int askalg(void *frontend, const char *algtype, const char *algname,
\r
172 void (*callback)(void *ctx, int result), void *ctx)
\r
174 static const char msg[] =
\r
175 "The first %s supported by the server is\n"
\r
176 "%s, which is below the configured warning threshold.\n"
\r
177 "Continue with connection? (y/n) ";
\r
179 static const char mbtitle[] = "%s Security Alert";
\r
182 char *message, *title;
\r
184 message = dupprintf(msg, algtype, algname);
\r
185 title = dupprintf(mbtitle, appname);
\r
187 mbret = MessageBox(GetParentHwnd(), message, title, MB_ICONWARNING|MB_YESNO);
\r
190 if (mbret == IDYES)
\r
197 * Ask whether to wipe a session log file before writing to it.
\r
198 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
\r
200 int askappend(void *frontend, Filename filename,
\r
201 void (*callback)(void *ctx, int result), void *ctx)
\r
206 static const char msgtemplate[] =
\r
207 "The session log file \"%.*s\" already exists.\n"
\r
208 "You can overwrite it with a new session log,\n"
\r
209 "append your session log to the end of it,\n"
\r
210 "or disable session logging for this session.\n"
\r
211 "Enter \"y\" to wipe the file, \"n\" to append to it,\n"
\r
212 "or just press Return to disable logging.\n"
\r
213 "Wipe the log file? (y/n, Return cancels logging) ";
\r
215 static const char msgtemplate_batch[] =
\r
216 "The session log file \"%.*s\" already exists.\n"
\r
217 "Logging will not be enabled.\n";
\r
221 if (console_batch_mode) {
\r
222 fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename.path);
\r
226 fprintf(stderr, msgtemplate, FILENAME_MAX, filename.path);
\r
229 hin = GetStdHandle(STD_INPUT_HANDLE);
\r
230 GetConsoleMode(hin, &savemode);
\r
231 SetConsoleMode(hin, (savemode | ENABLE_ECHO_INPUT |
\r
232 ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
\r
233 ReadFile(hin, line, sizeof(line) - 1, &i, NULL);
\r
234 SetConsoleMode(hin, savemode);
\r
236 if (line[0] == 'y' || line[0] == 'Y')
\r
238 else if (line[0] == 'n' || line[0] == 'N')
\r
245 * Warn about the obsolescent key file format.
\r
247 * Uniquely among these functions, this one does _not_ expect a
\r
248 * frontend handle. This means that if PuTTY is ported to a
\r
249 * platform which requires frontend handles, this function will be
\r
250 * an anomaly. Fortunately, the problem it addresses will not have
\r
251 * been present on that platform, so it can plausibly be
\r
252 * implemented as an empty function.
\r
254 void old_keyfile_warning(void)
\r
256 static const char message[] =
\r
257 "You are loading an SSH-2 private key which has an\n"
\r
258 "old version of the file format. This means your key\n"
\r
259 "file is not fully tamperproof. Future versions of\n"
\r
260 "PuTTY may stop supporting this private key format,\n"
\r
261 "so we recommend you convert your key to the new\n"
\r
264 "Once the key is loaded into PuTTYgen, you can perform\n"
\r
265 "this conversion simply by saving it again.\n";
\r
267 fputs(message, stderr);
\r
271 * Display the fingerprints of the PGP Master Keys to the user.
\r
273 void pgp_fingerprints(void)
\r
275 fputs("These are the fingerprints of the PuTTY PGP Master Keys. They can\n"
\r
276 "be used to establish a trust path from this executable to another\n"
\r
277 "one. See the manual for more information.\n"
\r
278 "(Note: these fingerprints have nothing to do with SSH!)\n"
\r
280 "PuTTY Master Key (RSA), 1024-bit:\n"
\r
281 " " PGP_RSA_MASTER_KEY_FP "\n"
\r
282 "PuTTY Master Key (DSA), 1024-bit:\n"
\r
283 " " PGP_DSA_MASTER_KEY_FP "\n", stdout);
\r
286 void console_provide_logctx(void *logctx)
\r
288 console_logctx = logctx;
\r
291 void logevent(void *frontend, const char *string)
\r
293 log_eventlog(console_logctx, string);
\r
296 static void console_data_untrusted(HANDLE hout, const char *data, int len)
\r
299 /* FIXME: control-character filtering */
\r
300 WriteFile(hout, data, len, &dummy, NULL);
\r
303 int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
\r
305 size_t curr_prompt;
\r
308 * Zero all the results, in case we abort half-way through.
\r
312 for (i = 0; i < (int)p->n_prompts; i++)
\r
313 memset(p->prompts[i]->result, 0, p->prompts[i]->result_len);
\r
316 if (console_batch_mode)
\r
320 for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) {
\r
322 prompt_t *pr = p->prompts[curr_prompt];
\r
323 if (!DoLoginDialog(pr->result, pr->result_len-1, pr->prompt))
\r
327 return 1; /* success */
\r
331 void frontend_keypress(void *handle)
\r
334 * This is nothing but a stub, in console code.
\r