-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQtDlg.cpp
208 lines (193 loc) · 8.09 KB
/
QtDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (C) 2012 Rajendran Thirupugalsamy
* See LICENSE for full copyright and license information.
* See COPYING for distribution information.
*/
extern "C" {
#include "putty.h"
#include "ssh.h"
}
#include "GuiMainWindow.h"
#include "GuiTerminalWindow.h"
#include <QMessageBox>
#include <QtConfig.h>
/*
* Ask whether the selected algorithm is acceptable (since it was
* below the configured 'warn' threshold).
*/
int askalg(void *frontend, const char *algtype, const char *algname,
void (*/*callback*/)(void *ctx, int result), void * /*ctx*/) {
assert(frontend);
GuiTerminalWindow *f = static_cast<GuiTerminalWindow *>(frontend);
QString msg = QString("The first " + QString(algtype) +
" supported by the server\n"
"is " +
QString(algname) +
", which is below the configured\n"
"warning threshold.\n"
"Do you want to continue with this connection?\n");
switch (QMessageBox::warning(f->getMainWindow(), QString(APPNAME " Security Alert"), msg,
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) {
case QMessageBox::Yes:
return 2;
case QMessageBox::No:
return 1;
default:
return 0;
}
}
/*
* Ask whether to wipe a session log file before writing to it.
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
*/
int askappend(void * /*frontend*/, Filename filename, void (*/*callback*/)(void *ctx, int result),
void * /*ctx*/) {
// assert(frontend);
QString msg = QString("The session log file \"") + QString(filename.path) +
QString(
"\" already exists.\n"
"You can overwrite it with a new session log,\n"
"append your session log to the end of it,\n"
"or disable session logging for this session.\n"
"Hit Yes to wipe the file, No to append to it,\n"
"or Cancel to disable logging.");
switch (QMessageBox::warning(NULL, QString(APPNAME " Log to File"), msg,
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Cancel)) {
case QMessageBox::Yes:
return 2;
case QMessageBox::No:
return 1;
default:
return 0;
}
}
int get_userpass_input_v2(void *frontend, prompts_t *p, unsigned char *in, int inlen) {
GuiTerminalWindow *f = static_cast<GuiTerminalWindow *>(frontend);
int ret = -1;
// ret = cmdline_get_passwd_input(p, in, inlen);
if (ret == -1) ret = term_get_userpass_input(f->term, p, in, inlen);
return ret;
}
static void hostkey_regname(char *buffer, int buffer_sz, const char *hostname, int port,
const char *keytype) {
snprintf(buffer, buffer_sz, "%s@%d:%s", keytype, port, hostname);
}
void store_host_key(const char *hostname, int port, const char *keytype, const char *key) {
char buf[200];
hostkey_regname(buf, sizeof(buf), hostname, port, keytype);
qutty_config.ssh_host_keys[buf] = key;
qutty_config.saveConfig();
}
int verify_host_key(const char *hostname, int port, const char *keytype, const char *key) {
char buf[200];
hostkey_regname(buf, sizeof(buf), hostname, port, keytype);
if (qutty_config.ssh_host_keys.find(buf) == qutty_config.ssh_host_keys.end()) return 1;
if (strcmp(key, qutty_config.ssh_host_keys[buf].c_str())) return 2;
return 0;
}
int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, char *keystr,
char *fingerprint, void (*/*callback*/)(void *ctx, int result),
void * /*ctx*/) {
assert(frontend);
GuiTerminalWindow *f = static_cast<GuiTerminalWindow *>(frontend);
int ret = 1;
QString absentmsg = QString(
"The server's host key is not cached in the registry. You\n"
"have no guarantee that the server is the computer you\n"
"think it is.\n"
"The server's " +
QString(keytype) + " key fingerprint is:\n") +
QString(fingerprint) +
QString(
"\n"
"If you trust this host, hit Yes to add the key to\n" APPNAME
"'s cache and carry on connecting.\n"
"If you want to carry on connecting just once, without\n"
"adding the key to the cache, hit No.\n"
"If you do not trust this host, hit Cancel to abandon the\n"
"connection.\n");
QString wrongmsg = QString(
"WARNING - POTENTIAL SECURITY BREACH!\n"
"\n"
"The server's host key does not match the one " APPNAME
" has\n"
"cached in the registry. This means that either the\n"
"server administrator has changed the host key, or you\n"
"have actually connected to another computer pretending\n"
"to be the server.\n"
"The new " +
QString(keytype) + " key fingerprint is:\n" + QString(fingerprint) +
"\n"
"If you were expecting this change and trust the new key,\n"
"hit Yes to update " APPNAME
"'s cache and continue connecting.\n"
"If you want to carry on connecting but without updating\n"
"the cache, hit No.\n"
"If you want to abandon the connection completely, hit\n"
"Cancel. Hitting Cancel is the ONLY guaranteed safe\n"
"choice.\n");
/*
* Verify the key against the registry.
*/
ret = verify_host_key(host, port, keytype, keystr);
if (ret == 0) /* success - key matched OK */
return 1;
else if (ret == 2) { /* key was different */
switch (QMessageBox::critical(f->getMainWindow(), QString(APPNAME " Security Alert"), wrongmsg,
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Cancel)) {
case QMessageBox::Yes:
store_host_key(host, port, keytype, keystr);
return 2;
case QMessageBox::No:
return 1;
default:
return 0;
}
} else if (ret == 1) { /* key was absent */
switch (QMessageBox::warning(f->getMainWindow(), QString(APPNAME " Security Alert"), absentmsg,
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Cancel)) {
case QMessageBox::Yes:
store_host_key(host, port, keytype, keystr);
return 2;
case QMessageBox::No:
return 1;
default:
return 0;
}
}
return 0; /* abandon the connection */
}
void old_keyfile_warning(void) {
QMessageBox::warning(NULL, QString(APPNAME "%s Key File Warning"),
QString(
"You are loading an SSH-2 private key which has an\n"
"old version of the file format. This means your key\n"
"file is not fully tamperproof. Future versions of\n" APPNAME
" may stop supporting this private key format,\n"
"so we recommend you convert your key to the new\n"
"format.\n"
"\n"
"You can perform this conversion by loading the key\n"
"into PuTTYgen and then saving it again."),
QMessageBox::Ok);
}
void qt_message_box_no_frontend(const char *title, const char *fmt, ...) {
QString msg;
va_list args;
va_start(args, fmt);
QMessageBox::critical(NULL, QString(title), msg.vsprintf(fmt, args), QMessageBox::Ok);
va_end(args);
}
void qt_message_box(void *frontend, const char *title, const char *fmt, ...) {
QString msg;
va_list args;
assert(frontend);
GuiTerminalWindow *f = static_cast<GuiTerminalWindow *>(frontend);
va_start(args, fmt);
QMessageBox::critical(f, QString(title), msg.vsprintf(fmt, args), QMessageBox::Ok);
va_end(args);
}
void logevent(void *frontend, const char *string) { qDebug() << frontend << string; }