blob: a94714f91c1acded9ff1bf86cc53c60db6453d81 [file] [log] [blame]
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
A R Karthicka2e53d62016-02-19 17:38:30 -080016import unittest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080017import time
18import os
19from nose.tools import *
A R Karthick22aa0c62016-05-31 11:17:12 -070020from nose.twistedtools import reactor, deferred
21from twisted.internet import defer
A R Karthicka2e53d62016-02-19 17:38:30 -080022from EapTLS import TLSAuthTest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080023from OnosCtrl import OnosCtrl
A R Karthick9313b762016-11-07 13:14:35 -080024from CordLogger import CordLogger
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070025from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070026from scapy_ssl_tls.ssl_tls import *
27from scapy_ssl_tls.ssl_tls_crypto import *
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070028log.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080029
A R Karthick9313b762016-11-07 13:14:35 -080030class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080031
A.R Karthick95d044e2016-06-10 18:44:36 -070032 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070033 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070034 TEST_TIMEOUT = 3600
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070035 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickaa10a202016-08-15 15:06:21 -070036MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
37VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
38ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
39JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx
40ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC
41Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG
42CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl
43cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
44ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo
45qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W
46plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg
47wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0
48ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c
49LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m
50c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga
51v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH
52EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
53D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
54dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
55oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
56hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
57jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
58bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
59opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
60gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
61729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070062-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080063
ChetanGaonker6138fcd2016-08-18 17:56:39 -070064 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
65 'TLS_RSA_WITH_AES_128_CBC_SHA',
66 'TLS_RSA_WITH_AES_128_CBC_SHA256',
67 'TLS_RSA_WITH_AES_256_CBC_SHA256',
68 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
69 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
70 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
71 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
72 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
73 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
74
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070075 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -080076 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070077 self.onos_ctrl = OnosCtrl(self.app)
78 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080079
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070080 def onos_aaa_config(self):
81 aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080082 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070083 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
84 aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip
85 self.onos_ctrl.activate()
86 time.sleep(2)
87 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080088
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070089 def onos_load_config(self, config):
90 status, code = OnosCtrl.config(config)
91 if status is False:
92 log.info('Configure request for AAA returned status %d' %code)
93 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -070094 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -070095
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070096 @deferred(TLS_TIMEOUT)
97 def test_eap_tls(self):
98 df = defer.Deferred()
99 def eap_tls_verify(df):
100 tls = TLSAuthTest()
101 tls.runTest()
102 df.callback(0)
103 reactor.callLater(0, eap_tls_verify, df)
104 return df
105
106 @deferred(TLS_TIMEOUT)
107 def test_eap_tls_with_no_cert(self):
108 df = defer.Deferred()
109 def eap_tls_no_cert(df):
110 def tls_no_cert_cb():
111 log.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700112 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
113 tls.runTest()
114 assert_equal(tls.failTest, True)
115 df.callback(0)
116 reactor.callLater(0, eap_tls_no_cert, df)
117 return df
118
119 @deferred(TLS_TIMEOUT)
120 def test_eap_tls_with_invalid_cert(self):
121 df = defer.Deferred()
122 def eap_tls_invalid_cert(df):
123 def tls_invalid_cert_cb():
124 log.info('TLS authentication failed with invalid certificate')
125
126 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
127 client_cert = self.CLIENT_CERT_INVALID)
128 tls.runTest()
129 assert_equal(tls.failTest, True)
130 df.callback(0)
131 reactor.callLater(0, eap_tls_invalid_cert, df)
132 return df
133
134 @deferred(TLS_TIMEOUT)
135 def test_eap_tls_Nusers_with_same_valid_cert(self):
136 df = defer.Deferred()
137 def eap_tls_Nusers_with_same_valid_cert(df):
138 num_users = 3
139 for i in xrange(num_users):
140 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
141 tls.runTest()
142 df.callback(0)
143 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
144 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800145
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700146 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800147 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700148 df = defer.Deferred()
149 def eap_tls_invalid_session_id(df):
150 def tls_invalid_session_id_cb():
151 log.info('TLS authentication failed with invalid session id')
152 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
153 tls.runTest()
154 assert_equal(tls.failTest, True)
155 df.callback(0)
156 reactor.callLater(0, eap_tls_invalid_session_id, df)
157 return df
158
159 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800160 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700161 df = defer.Deferred()
162 def eap_tls_invalid_gmt_unix_time(df):
163 def eap_tls_invalid_gmt_unix_time_cb():
164 log.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
165 for i in [0,7265,98758,23627238]:
166 log.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
167 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
168 tls.runTest()
169 assert_equal(tls.failTest, True)
170 df.callback(0)
171 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
172 return df
173
174 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800175 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700176 df = defer.Deferred()
177 def eap_tls_invalid_content_type(df):
178 def tls_invalid_content_type_cb():
179 log.info('TLS authentication failed with invalid content type in TLSContentType packet')
180 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
181 tls.runTest()
182 assert_equal(tls.failTest, True)
183 df.callback(0)
184 reactor.callLater(0, eap_tls_invalid_content_type, df)
185 return df
186
187 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800188 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700189 df = defer.Deferred()
190 def eap_tls_invalid_record_fragment_length(df):
191 def eap_tls_invalid_record_fragment_length_cb():
192 log.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
193 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
194 tls.runTest()
195 assert_equal(tls.failTest, True)
196 df.callback(0)
197 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
198 return df
199
200 #invalid id field in identifier response packet
201 @deferred(TLS_TIMEOUT)
202 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
203 df = defer.Deferred()
204 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
205 def tls_with_invalid_id_in_identifier_response_packet_cb():
206 log.info('TLS authentication failed with invalid id in identifier packet')
207 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
208 id_mismatch_in_identifier_response_packet = True)
209 tls.runTest()
210 assert_equal(tls.failTest, True)
211 df.callback(0)
212 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
213 return df
214
215 #invalid id field in client hello packet
216 @deferred(TLS_TIMEOUT)
217 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
218 df = defer.Deferred()
219 def eap_tls_with_invalid_id_in_client_hello_packet(df):
220 def tls_with_invalid_id_in_client_hello_packet_cb():
221 log.info('TLS authentication failed with invalid id in client hello packet')
222 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
223 id_mismatch_in_client_hello_packet = True)
224 tls.runTest()
225 assert_equal(tls.failTest, True)
226 df.callback(0)
227 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
228 return df
229
230 @deferred(TLS_TIMEOUT)
231 def test_eap_tls_without_sending_client_hello(self):
232 df = defer.Deferred()
233 def eap_tls_without_sending_client_hello(df):
234 def tls_without_sending_client_hello_cb():
235 log.info('TLS authentication failed with not sending client hello')
236 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
237 dont_send_client_hello = True)
238 tls.runTest()
239 assert_equal(tls.failTest, True)
240 df.callback(0)
241 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
242 return df
243
244 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800245 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700246 df = defer.Deferred()
247 def eap_tls_aaa_app_deactivate(df):
248 def tls_aaa_app_deactivate_cb():
249 log.info('TLS authentication failed with aaa app deactivated in ONOS')
250 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
251 self.onos_ctrl.deactivate()
252 tls.runTest()
253 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800254 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700255 df.callback(0)
256 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
257 return df
258
259 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
260 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800261 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700262 df = defer.Deferred()
263 def eap_tls_incorrect_cipher_suite_length_field(df):
264 def tls_incorrect_cipher_suite_length_field_cb():
265 log.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
266 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
267 tls.runTest()
268 assert_equal(tls.failTest, True)
269 df.callback(0)
270 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
271 return df
272
273 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
274 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800275 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700276 df = defer.Deferred()
277 def eap_tls_incorrect_compression_methods_length_field(df):
278 def tls_incorrect_compression_methods_length_field_cb():
279 log.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
280 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
281 tls.runTest()
282 assert_equal(tls.failTest, True)
283 df.callback(0)
284 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
285 return df
286
287 #checking with broadcast source mac of EAPOL packet
288 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800289 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700290 df = defer.Deferred()
291 def eap_tls_invalid_source_mac_broadcast(df):
292 def tls_invalid_source_mac_broadcast_cb():
293 log.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
294 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
295 tls.runTest()
296 assert_equal(tls.failTest, True)
297 df.callback(0)
298 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
299 return df
300
301 #checking with multicast source mac of EAPOL packet
302 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800303 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700304 df = defer.Deferred()
305 def eap_tls_invalid_source_mac_multicast(df):
306 def tls_invalid_source_mac_multicast_cb():
307 log.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
308 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
309 tls.runTest()
310 assert_equal(tls.failTest, True)
311 df.callback(0)
312 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
313 return df
314
315 #checking with zero source mac of EAPOL packet
316 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800317 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700318 df = defer.Deferred()
319 def eap_tls_invalid_source_mac_zero(df):
320 def tls_invalid_source_mac_zero_cb():
321 log.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
322 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
323 tls.runTest()
324 assert_equal(tls.failTest, True)
325 df.callback(0)
326 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
327 return df
328
329 #Restarting Radius server after sending client hello
330 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800331 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700332 df = defer.Deferred()
333 def eap_tls_restart_radius_server(df):
334 def tls_restart_radius_server_cb():
335 log.info('TLS authentication failed with radius server down in middle of authentication process')
336 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
337 tls.runTest()
338 assert_equal(tls.failTest, True)
339 df.callback(0)
340 reactor.callLater(0, eap_tls_restart_radius_server, df)
341 return df
342
343 @deferred(TLS_TIMEOUT)
344 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
345 df = defer.Deferred()
346 def eap_tls_incorrect_handshake_type_client_hello(df):
347 def tls_incorrect_handshake_type_client_hello_cb():
348 log.info('TLS authentication failed with incorrect handshake type in client hello packet')
349 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
350 tls.runTest()
351 assert_equal(tls.failTest, True)
352 df.callback(0)
353 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
354 return df
355
356 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
357 @deferred(TLS_TIMEOUT)
358 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
359 df = defer.Deferred()
360 def eap_tls_incorrect_handshake_type_certificate_request(df):
361 def tls_incorrect_handshake_type_certificate_request_cb():
362 log.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
363 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
364 tls.runTest()
365 assert_equal(tls.failTest, True)
366 df.callback(0)
367 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
368 return df
369
370 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
371 @deferred(TLS_TIMEOUT)
372 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
373 df = defer.Deferred()
374 def eap_tls_incorrect_tlsrecord_certificate_request(df):
375 def tls_incorrect_tlsrecord_certificate_request_cb():
376 log.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
377 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
378 tls.runTest()
379 assert_equal(tls.failTest, True)
380 df.callback(0)
381 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
382 return df
383
384 #Sending client hello with zero lenght field in Handshake protocol
385 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800386 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700387 df = defer.Deferred()
388 def eap_tls_invalid_handshake_length_client_hello(df):
389 def tls_invalid_handshake_length_client_hello_cb():
390 log.info('TLS authentication failed with invalid handshake length in client hello packet')
391 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
392 tls.runTest()
393 assert_equal(tls.failTest, True)
394 df.callback(0)
395 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
396 return df
397
398 @deferred(TLS_TIMEOUT)
399 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
400 df = defer.Deferred()
401 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
402 def tls_clientkeyex_replace_with_serverkeyex_cb():
403 log.info('TLS authentication failed with client key exchange replaced with server key exchange')
404 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
405 tls.runTest()
406 assert_equal(tls.failTest, True)
407 df.callback(0)
408 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
409 return df
410
411 #simulating authentication for multiple users, 1K in this test case
412 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800413 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700414 df = defer.Deferred()
415 def eap_tls_1k_with_diff_mac(df):
416 for i in xrange(1000):
417 tls = TLSAuthTest(src_mac = 'random')
418 tls.runTest()
419 log.info('Authentication successfull for user %d'%i)
420 df.callback(0)
421 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
422 return df
423
424 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800425 @deferred(TEST_TIMEOUT+1800)
426 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700427 df = defer.Deferred()
428 def eap_tls_5k_with_diff_mac(df):
429 for i in xrange(5000):
430 tls = TLSAuthTest(src_mac = 'random')
431 tls.runTest()
432 log.info('Authentication successfull for user %d'%i)
433 df.callback(0)
434 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
435 return df
436
A R Karthicka2e53d62016-02-19 17:38:30 -0800437if __name__ == '__main__':
438 t = TLSAuthTest()
439 t.runTest()