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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Author: Werner Dittmann <Werner.Dittmann@t-online.de>, (C) 2006
// Michel de Boer <michel@twinklephone.com>
#include "twinkle_zrtp_ui.h"
#ifdef HAVE_ZRTP
#include "phone.h"
#include "line.h"
#include "log.h"
#include "util.h"
using namespace std;
using namespace GnuZrtpCodes;
extern t_phone *phone;
// Initialize static data
map<int32, std::string>TwinkleZrtpUI::infoMap;
map<int32, std::string>TwinkleZrtpUI::warningMap;
map<int32, std::string>TwinkleZrtpUI::severeMap;
map<int32, std::string>TwinkleZrtpUI::zrtpMap;
bool TwinkleZrtpUI::mapsDone = false;
std::string TwinkleZrtpUI::unknownCode = "Unknown error code";
TwinkleZrtpUI::TwinkleZrtpUI(t_audio_session* session) :
audioSession(session)
{
if (mapsDone) {
return;
}
// Initialize error mapping
infoMap.insert(pair<int32, std::string>(InfoHelloReceived,
string("Hello received, preparing a Commit")));
infoMap.insert(pair<int32, std::string>(InfoCommitDHGenerated,
string("Commit: Generated a public DH key")));
infoMap.insert(pair<int32, std::string>(InfoRespCommitReceived,
string("Responder: Commit received, preparing DHPart1")));
infoMap.insert(pair<int32, std::string>(InfoDH1DHGenerated,
string("DH1Part: Generated a public DH key")));
infoMap.insert(pair<int32, std::string>(InfoInitDH1Received,
string("Initiator: DHPart1 received, preparing DHPart2")));
infoMap.insert(pair<int32, std::string>(InfoRespDH2Received,
string("Responder: DHPart2 received, preparing Confirm1")));
infoMap.insert(pair<int32, std::string>(InfoInitConf1Received,
string("Initiator: Confirm1 received, preparing Confirm2")));
infoMap.insert(pair<int32, std::string>(InfoRespConf2Received,
string("Responder: Confirm2 received, preparing Conf2Ack")));
infoMap.insert(pair<int32, std::string>(InfoRSMatchFound,
string("At least one retained secrets matches - security OK")));
infoMap.insert(pair<int32, std::string>(InfoSecureStateOn,
string("Entered secure state")));
infoMap.insert(pair<int32, std::string>(InfoSecureStateOff,
string("No more security for this session")));
warningMap.insert(pair<int32, std::string>(WarningDHAESmismatch,
string("Commit contains an AES256 cipher but does not offer a Diffie-Helman 4096")));
warningMap.insert(pair<int32, std::string>(WarningGoClearReceived,
string("Received a GoClear message")));
warningMap.insert(pair<int32, std::string>(WarningDHShort,
string("Hello offers an AES256 cipher but does not offer a Diffie-Helman 4096")));
warningMap.insert(pair<int32, std::string>(WarningNoRSMatch,
string("No retained shared secrets available - must verify SAS")));
warningMap.insert(pair<int32, std::string>(WarningCRCmismatch,
string("Internal ZRTP packet checksum mismatch - packet dropped")));
warningMap.insert(pair<int32, std::string>(WarningSRTPauthError,
string("Dropping packet because SRTP authentication failed!")));
warningMap.insert(pair<int32, std::string>(WarningSRTPreplayError,
string("Dropping packet because SRTP replay check failed!")));
warningMap.insert(pair<int32, std::string>(WarningNoExpectedRSMatch,
string("Valid retained shared secrets availabe but no matches found - must verify SAS")));
severeMap.insert(pair<int32, std::string>(SevereHelloHMACFailed,
string("Hash HMAC check of Hello failed!")));
severeMap.insert(pair<int32, std::string>(SevereCommitHMACFailed,
string("Hash HMAC check of Commit failed!")));
severeMap.insert(pair<int32, std::string>(SevereDH1HMACFailed,
string("Hash HMAC check of DHPart1 failed!")));
severeMap.insert(pair<int32, std::string>(SevereDH2HMACFailed,
string("Hash HMAC check of DHPart2 failed!")));
severeMap.insert(pair<int32, std::string>(SevereCannotSend,
string("Cannot send data - connection or peer down?")));
severeMap.insert(pair<int32, std::string>(SevereProtocolError,
string("Internal protocol error occured!")));
severeMap.insert(pair<int32, std::string>(SevereNoTimer,
string("Cannot start a timer - internal resources exhausted?")));
severeMap.insert(pair<int32, std::string>(SevereTooMuchRetries,
string("Too much retries during ZRTP negotiation - connection or peer down?")));
zrtpMap.insert(pair<int32, std::string>(MalformedPacket,
string("Malformed packet (CRC OK, but wrong structure)")));
zrtpMap.insert(pair<int32, std::string>(CriticalSWError,
string("Critical software error")));
zrtpMap.insert(pair<int32, std::string>(UnsuppZRTPVersion,
string("Unsupported ZRTP version")));
zrtpMap.insert(pair<int32, std::string>(HelloCompMismatch,
string("Hello components mismatch")));
zrtpMap.insert(pair<int32, std::string>(UnsuppHashType,
string("Hash type not supported")));
zrtpMap.insert(pair<int32, std::string>(UnsuppCiphertype,
string("Cipher type not supported")));
zrtpMap.insert(pair<int32, std::string>(UnsuppPKExchange,
string("Public key exchange not supported")));
zrtpMap.insert(pair<int32, std::string>(UnsuppSRTPAuthTag,
string("SRTP auth. tag not supported")));
zrtpMap.insert(pair<int32, std::string>(UnsuppSASScheme,
string("SAS scheme not supported")));
zrtpMap.insert(pair<int32, std::string>(NoSharedSecret,
string("No shared secret available, DH mode required")));
zrtpMap.insert(pair<int32, std::string>(DHErrorWrongPV,
string("DH Error: bad pvi or pvr ( == 1, 0, or p-1)")));
zrtpMap.insert(pair<int32, std::string>(DHErrorWrongHVI,
string("DH Error: hvi != hashed data")));
zrtpMap.insert(pair<int32, std::string>(SASuntrustedMiTM,
string("Received relayed SAS from untrusted MiTM")));
zrtpMap.insert(pair<int32, std::string>(ConfirmHMACWrong,
string("Auth. Error: Bad Confirm pkt HMAC")));
zrtpMap.insert(pair<int32, std::string>(NonceReused,
string("Nonce reuse")));
zrtpMap.insert(pair<int32, std::string>(EqualZIDHello,
string("Equal ZIDs in Hello")));
zrtpMap.insert(pair<int32, std::string>(GoCleatNotAllowed,
string("GoClear packet received, but not allowed")));
mapsDone = true;
}
void TwinkleZrtpUI::secureOn(std::string cipher) {
audioSession->set_is_encrypted(true);
audioSession->set_srtp_cipher_mode(cipher);
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
log_file->write_header("TwinkleZrtpUI::secureOn");
log_file->write_raw("Line ");
log_file->write_raw(lineno + 1);
log_file->write_raw(": audio encryption enabled: ");
log_file->write_raw(cipher);
log_file->write_endl();
log_file->write_footer();
ui->cb_async_line_encrypted(lineno, true);
ui->cb_async_line_state_changed();
}
void TwinkleZrtpUI::secureOff() {
audioSession->set_is_encrypted(false);
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
log_file->write_header("TwinkleZrtpUI::secureOff");
log_file->write_raw("Line ");
log_file->write_raw(lineno + 1);
log_file->write_raw(": audio encryption disabled.\n");
log_file->write_footer();
ui->cb_async_line_encrypted(lineno, false);
ui->cb_async_line_state_changed();
}
void TwinkleZrtpUI::showSAS(std::string sas, bool verified) {
audioSession->set_zrtp_sas(sas);
audioSession->set_zrtp_sas_confirmed(verified);
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
log_file->write_header("TwinkleZrtpUI::showSAS");
log_file->write_raw("Line ");
log_file->write_raw(lineno + 1);
log_file->write_raw(": SAS =");
log_file->write_raw(sas);
log_file->write_endl();
log_file->write_footer();
if (!verified) {
ui->cb_async_show_zrtp_sas(lineno, sas);
}
ui->cb_async_line_state_changed();
}
void TwinkleZrtpUI::confirmGoClear() {
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
ui->cb_async_zrtp_confirm_go_clear(lineno);
}
void TwinkleZrtpUI::showMessage(MessageSeverity sev, int subCode) {
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
string msg = "Line ";
msg += int2str(lineno + 1);
msg += ": ";
msg += *mapCodesToString(sev, subCode);
switch (sev) {
case Info:
log_file->write_report(msg, "TwinkleZrtpUI::showMessage", LOG_NORMAL,
LOG_INFO);
break;
case Warning:
log_file->write_report(msg, "TwinkleZrtpUI::showMessage", LOG_NORMAL,
LOG_WARNING);
break;
default:
log_file->write_report(msg, "TwinkleZrtpUI::showMessage", LOG_NORMAL,
LOG_CRITICAL);
}
}
void TwinkleZrtpUI::zrtpNegotiationFailed(MessageSeverity severity, int subCode) {
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
string m = "Line ";
m += int2str(lineno + 1);
m += ": ZRTP negotiation failed.\n";
m += *mapCodesToString(severity, subCode);
switch (severity) {
case Info:
log_file->write_report(m, "TwinkleZrtpUI::zrtpNegotiationFailed", LOG_NORMAL,
LOG_INFO);
break;
case Warning:
log_file->write_report(m, "TwinkleZrtpUI::zrtpNegotiationFailed", LOG_NORMAL,
LOG_WARNING);
break;
default:
log_file->write_report(m, "TwinkleZrtpUI::zrtpNegotiationFailed", LOG_NORMAL,
LOG_CRITICAL);
}
}
void TwinkleZrtpUI::zrtpNotSuppOther() {
t_line *line = audioSession->get_line();
int lineno = line->get_line_number();
string msg = "Line ";
msg += int2str(lineno + 1);
msg += ": remote party does not support ZRTP.";
log_file->write_report(msg, "TwinkleZrtpUI::zrtpNotSuppOther");
}
const string *const TwinkleZrtpUI::mapCodesToString(MessageSeverity severity, int subCode) {
string *m = &unknownCode;
switch (severity) {
case Info:
m = &infoMap[subCode];
break;
case Warning:
m = &warningMap[subCode];
break;
case Severe:
m = &severeMap[subCode];
break;
case ZrtpError:
if (subCode < 0) {
subCode *= -1;
}
m = &zrtpMap[subCode];
break;
default:
break;
}
return m;
}
#endif
|