/
microeval_tests.py
314 lines (226 loc) · 13 KB
/
microeval_tests.py
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
from wxPython.wx import *
import wx
class MicroEvalTests():
class TestData():
def __init__(self):
self.test_id = 0
self.test_name = ""
self.start_func = None
self.results_func = None
self.fail_func = None
self.terminal_results = {} # stores result for each terminal
self.running = False;
def __init__(self, callback):
self.tests = []
self.callback = callback # used for indicating test succeeded
def get_tests(self):
return self.tests
def data_received(self, terminal, c, line):
for test in self.tests:
if not test.results_func == None:
test.results_func(test, terminal, c, line)
def test_failed(self, terminal):
for test in self.tests:
if not test.fail_func == None:
test.fail_func(test, terminal)
def test_notify_succeeded(self, test):
self.callback.test_succeeded(test.test_id)
def test_notify_failed(self, test):
self.callback.test_failed(test.test_id)
def test_started(self, test, selected_terminal, terminals):
test.running = True
for terminal in terminals: test.terminal_results[terminal] = False
if selected_terminal == None:
self.test_results_failed(test, None)
return False
return True
def add_test(self, test_name, start_func=None, results_func=None, fail_func=None):
t = MicroEvalTests.TestData()
t.test_name = test_name
t.test_id = wxNewId()
t.start_func = start_func
t.results_func = results_func
t.fail_func = fail_func;
self.tests.append(t)
""" Add your tests here"""
def add_tests(self):
self.add_test("Latency & Data-Rate (long-running)", self.test_start_latencytest, self.test_results_latencytest)
self.add_test("Data Transfer", self.test_start_datatransfer, self.test_results_datatransfer, self.test_results_failed)
self.add_test("Manual Pairwise Key-Refresh", self.test_start_keyrefresh, self.test_results_keyrefresh)
self.add_test("Global Key-Refresh", self.test_start_global_keyrefresh, self.test_results_global_keyrefresh)
self.add_test("Timed Key-Refresh (long-running)", self.test_start_timed_keyrefresh, self.test_results_timed_keyrefresh)
self.add_test("Local Keep-Alive", self.test_start_local_keepalive, self.test_results_local_keepalive)
self.add_test("Global Keep-Alive (long-running)", self.test_start_global_keepalive, self.test_results_global_keepalive)
# self.add_test("Sensor added to network", self.test_start_sensor_added, self.test_results_sensor_added)
self.add_test("Exclusion list", self.test_start_xlist)
self.add_test("Replay Protection", self.test_start_replay, self.test_results_replay)
self.add_test("Isolation detection", self.test_start_isolation)
self.add_test("Attack detection", self.test_start_attack)
self.add_test("Dynamic Security")
""" Add the functions for your tests here """
def test_start_latencytest(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
selected_terminal.sendKeystrokes("Starting Latency Test", False)
selected_terminal.sendKeystrokes("test_latency", True)
def test_results_latencytest(self, test, terminal, character, line):
if test.running == False:
return
if not line == None:
if line.find('LATENCYTEST:WAYPOINT:') > -1:
print line
print "It took " + line.split(':')[3] + "ms per packet on average to transfer 25 packets of 49 bytes"
time_required_in_secs = float(line.split(':')[3]) / 1000000.0
print "One packet of 49bytes took " + str(time_required_in_secs) + "s"
byte_speed = time_required_in_secs / 49.0
print "The time required for one byte to be sent was " + str(byte_speed) + "s"
if byte_speed == 0:
bytes_in_a_second = 0
else:
bytes_in_a_second = 1.0 / byte_speed
print "The bytes-per-second on average was " + str(bytes_in_a_second)
self.app.Yield()
wx.SafeYield(self.callback, True)
if line.find('LATENCYTEST:DONE') > -1:
self.test_notify_succeeded(test)
""" Tests for data transfer """
def test_start_datatransfer(self, test, selected_terminal, terminals):
# This will send some data from one terminal to the other
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Transfer Test", False)
selected_terminal.sendKeystrokes("ping MICROEVAL_TEST 1 2 3", True)
def test_results_datatransfer(self, test, terminal, character, line):
if test.running == False:
return
if not line == None:
if line.find('PONG:') > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
def test_results_failed(self, test, terminal):
if test.running == False:
return
self.test_notify_failed(test)
test.running = False
""" Tests for key refresh """
def test_start_keyrefresh(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Key Refresh Test", False)
selected_terminal.sendKeystrokes("keyrefresh", True)
def test_results_keyrefresh(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
# print "Received line: " + line
if line.find("Successfully handled KeyRefresh-Packet") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
""" Test for global key exchange """
def test_start_global_keyrefresh(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Global Key Refresh Test", False)
selected_terminal.sendKeystrokes("keyrefreshgk", True)
def test_results_global_keyrefresh(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
print "Received line: " + line
if line.find("received new Global-Key") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
""" Test for timed key exchange """
def test_start_timed_keyrefresh(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
# After this test is started, it just sits and waits for the appropriate
# Messages to arrive
def test_results_timed_keyrefresh(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
print "Received line: " + line
if line.find("Successfully handled KeyRefresh-Packet") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
""" Local Keep-Alive """
def test_start_local_keepalive(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Local Keep-Alive test", False)
selected_terminal.sendKeystrokes("keepalive", True)
def test_results_local_keepalive(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
print "Received line: " + line
if line.find("Received local-keep-alive message") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
""" Global Keep-Alive """
def test_start_global_keepalive(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Global Keep-Alive test", False)
selected_terminal.sendKeystrokes("keepaliveg", True)
def test_results_global_keepalive(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
print "Received line: " + line
if line.find("Successfully received keep-alive packet") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
def test_start_sensor_added(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
wx.MessageBox('Unplug a sensor board, then press OK, then plug it back', 'Info',
wx.OK | wx.ICON_INFORMATION)
def test_results_sensor_added(self, test, terminal, character, line):
if test.running == False: return
def test_start_xlist(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Exclusion List test", False)
selected_terminal.sendKeystrokes("xlist 65530", True)
wx.MessageBox('Sender excluded. Pls test transfer functions individually.', 'Info',
wx.OK | wx.ICON_INFORMATION)
self.test_notify_succeeded(test)
def test_start_replay(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Replay Protection test", False)
selected_terminal.sendKeystrokes("updatecounter 10", True)
# wx.MessageBox('Sender excluded. Pls test transfer functions individually.', 'Info',
# wx.OK | wx.ICON_INFORMATION)
# self.test_notify_succeeded(test)
def test_results_replay(self, test, terminal, character, line):
if test.running == False: return
if not line == None:
print "Received line: " + line
if line.find("[SEC-ERROR-AE]") > -1:
test.terminal_results[terminal] = True
for t, res in test.terminal_results.items():
if res == False:
return # a terminal did not receive results yet
self.test_notify_succeeded(test)
def test_start_isolation(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
wx.MessageBox('Unplug one device', 'Info',
wx.OK | wx.ICON_INFORMATION)
def test_start_attack(self, test, selected_terminal, terminals):
if self.test_started(test, selected_terminal, terminals) == False: return
test.terminal_results[selected_terminal] = True
selected_terminal.sendKeystrokes("Starting Attack test", False)
selected_terminal.sendKeystrokes("wrongmacs 100", True)