blob: 3fd72f5342dc3463c86c355b3f5ee91e70ac69cb [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
A R Karthick76a497a2017-04-12 10:59:39 -070025from CordTestUtils import log_test
A R Karthickbf1e4b02017-07-11 20:17:14 -070026from CordTestConfig import setup_module
27from VolthaCtrl import VolthaCtrl, voltha_setup, voltha_teardown
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070028from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070029from scapy_ssl_tls.ssl_tls import *
30from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070031log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080032
A R Karthick9313b762016-11-07 13:14:35 -080033class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080034
A.R Karthick95d044e2016-06-10 18:44:36 -070035 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070036 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070037 TEST_TIMEOUT = 3600
A R Karthickbf1e4b02017-07-11 20:17:14 -070038 VOLTHA_HOST = None
39 VOLTHA_REST_PORT = 8881
40 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
41 VOLTHA_OLT_TYPE = 'simulated_olt'
42 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
43 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
44 voltha_device = None
45 voltha_ctrl = None
46 voltha_switch_map = None
A R Karthickeeac7e12017-03-10 17:35:39 -080047 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070048 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080049MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
50VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
51CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
52JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
53MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
54Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
55CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070056cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080057ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
581zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
59QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
6046DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
61of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
62CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
63zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
64b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
65DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
66D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
67dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070068oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080069hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
70QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
71iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
72+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
73dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
747cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070075-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080076
ChetanGaonker6138fcd2016-08-18 17:56:39 -070077 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
78 'TLS_RSA_WITH_AES_128_CBC_SHA',
79 'TLS_RSA_WITH_AES_128_CBC_SHA256',
80 'TLS_RSA_WITH_AES_256_CBC_SHA256',
81 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
82 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
83 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
84 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
85 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
86 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
87
A R Karthickbf1e4b02017-07-11 20:17:14 -070088
89 @classmethod
90 def setUpClass(cls):
91 #activate the device if voltha was enabled
92 if cls.VOLTHA_ENABLED is False or cls.VOLTHA_HOST is None:
93 return
94 ret = voltha_setup(host = cls.VOLTHA_HOST,
95 rest_port = cls.VOLTHA_REST_PORT,
96 olt_type = cls.VOLTHA_OLT_TYPE,
97 olt_mac = cls.VOLTHA_OLT_MAC,
98 uplink_vlan_map = cls.VOLTHA_UPLINK_VLAN_MAP)
99 if ret is not None:
100 cls.voltha_ctrl, cls.voltha_device, cls.voltha_switch_map = ret[0], ret[1], ret[2]
101
102 @classmethod
103 def tearDownClass(cls):
104 if cls.voltha_ctrl and cls.voltha_device:
105 voltha_teardown(cls.voltha_ctrl, cls.voltha_device, cls.voltha_switch_map)
106
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700107 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -0800108 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700109 self.onos_ctrl = OnosCtrl(self.app)
110 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800111
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700112 def onos_aaa_config(self):
A R Karthicka652c4a2017-03-10 17:47:08 -0800113 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
114 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700115 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A R Karthicka652c4a2017-03-10 17:47:08 -0800116 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700117 self.onos_ctrl.activate()
118 time.sleep(2)
119 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800120
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700121 def onos_load_config(self, config):
122 status, code = OnosCtrl.config(config)
123 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700124 log_test.info('Configure request for AAA returned status %d' %code)
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700125 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -0700126 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -0700127
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700128 @deferred(TLS_TIMEOUT)
129 def test_eap_tls(self):
130 df = defer.Deferred()
131 def eap_tls_verify(df):
132 tls = TLSAuthTest()
133 tls.runTest()
134 df.callback(0)
135 reactor.callLater(0, eap_tls_verify, df)
136 return df
137
138 @deferred(TLS_TIMEOUT)
139 def test_eap_tls_with_no_cert(self):
140 df = defer.Deferred()
141 def eap_tls_no_cert(df):
142 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700143 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700144 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
145 tls.runTest()
146 assert_equal(tls.failTest, True)
147 df.callback(0)
148 reactor.callLater(0, eap_tls_no_cert, df)
149 return df
150
151 @deferred(TLS_TIMEOUT)
152 def test_eap_tls_with_invalid_cert(self):
153 df = defer.Deferred()
154 def eap_tls_invalid_cert(df):
155 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700156 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700157
158 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
159 client_cert = self.CLIENT_CERT_INVALID)
160 tls.runTest()
161 assert_equal(tls.failTest, True)
162 df.callback(0)
163 reactor.callLater(0, eap_tls_invalid_cert, df)
164 return df
165
166 @deferred(TLS_TIMEOUT)
167 def test_eap_tls_Nusers_with_same_valid_cert(self):
168 df = defer.Deferred()
169 def eap_tls_Nusers_with_same_valid_cert(df):
170 num_users = 3
171 for i in xrange(num_users):
172 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
173 tls.runTest()
174 df.callback(0)
175 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
176 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800177
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700178 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800179 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700180 df = defer.Deferred()
181 def eap_tls_invalid_session_id(df):
182 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700183 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700184 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
185 tls.runTest()
186 assert_equal(tls.failTest, True)
187 df.callback(0)
188 reactor.callLater(0, eap_tls_invalid_session_id, df)
189 return df
190
191 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800192 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700193 df = defer.Deferred()
194 def eap_tls_invalid_gmt_unix_time(df):
195 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700196 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700197 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700198 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700199 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
200 tls.runTest()
201 assert_equal(tls.failTest, True)
202 df.callback(0)
203 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
204 return df
205
206 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800207 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700208 df = defer.Deferred()
209 def eap_tls_invalid_content_type(df):
210 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700211 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700212 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
213 tls.runTest()
214 assert_equal(tls.failTest, True)
215 df.callback(0)
216 reactor.callLater(0, eap_tls_invalid_content_type, df)
217 return df
218
219 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800220 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700221 df = defer.Deferred()
222 def eap_tls_invalid_record_fragment_length(df):
223 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700224 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700225 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
226 tls.runTest()
227 assert_equal(tls.failTest, True)
228 df.callback(0)
229 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
230 return df
231
232 #invalid id field in identifier response packet
233 @deferred(TLS_TIMEOUT)
234 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
235 df = defer.Deferred()
236 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
237 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700238 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700239 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
240 id_mismatch_in_identifier_response_packet = True)
241 tls.runTest()
242 assert_equal(tls.failTest, True)
243 df.callback(0)
244 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
245 return df
246
247 #invalid id field in client hello packet
248 @deferred(TLS_TIMEOUT)
249 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
250 df = defer.Deferred()
251 def eap_tls_with_invalid_id_in_client_hello_packet(df):
252 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700253 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700254 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
255 id_mismatch_in_client_hello_packet = True)
256 tls.runTest()
257 assert_equal(tls.failTest, True)
258 df.callback(0)
259 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
260 return df
261
262 @deferred(TLS_TIMEOUT)
263 def test_eap_tls_without_sending_client_hello(self):
264 df = defer.Deferred()
265 def eap_tls_without_sending_client_hello(df):
266 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700267 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700268 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
269 dont_send_client_hello = True)
270 tls.runTest()
271 assert_equal(tls.failTest, True)
272 df.callback(0)
273 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
274 return df
275
276 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800277 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700278 df = defer.Deferred()
279 def eap_tls_aaa_app_deactivate(df):
280 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700281 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700282 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
283 self.onos_ctrl.deactivate()
284 tls.runTest()
285 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800286 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700287 df.callback(0)
288 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
289 return df
290
291 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
292 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800293 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700294 df = defer.Deferred()
295 def eap_tls_incorrect_cipher_suite_length_field(df):
296 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700297 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700298 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
299 tls.runTest()
300 assert_equal(tls.failTest, True)
301 df.callback(0)
302 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
303 return df
304
305 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
306 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800307 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700308 df = defer.Deferred()
309 def eap_tls_incorrect_compression_methods_length_field(df):
310 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700311 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700312 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
313 tls.runTest()
314 assert_equal(tls.failTest, True)
315 df.callback(0)
316 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
317 return df
318
319 #checking with broadcast source mac of EAPOL packet
320 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800321 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700322 df = defer.Deferred()
323 def eap_tls_invalid_source_mac_broadcast(df):
324 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700325 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700326 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
327 tls.runTest()
328 assert_equal(tls.failTest, True)
329 df.callback(0)
330 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
331 return df
332
333 #checking with multicast source mac of EAPOL packet
334 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800335 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700336 df = defer.Deferred()
337 def eap_tls_invalid_source_mac_multicast(df):
338 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700339 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700340 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
341 tls.runTest()
342 assert_equal(tls.failTest, True)
343 df.callback(0)
344 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
345 return df
346
347 #checking with zero source mac of EAPOL packet
348 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800349 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700350 df = defer.Deferred()
351 def eap_tls_invalid_source_mac_zero(df):
352 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700353 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700354 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
355 tls.runTest()
356 assert_equal(tls.failTest, True)
357 df.callback(0)
358 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
359 return df
360
361 #Restarting Radius server after sending client hello
362 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800363 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700364 df = defer.Deferred()
365 def eap_tls_restart_radius_server(df):
366 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700367 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700368 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
369 tls.runTest()
370 assert_equal(tls.failTest, True)
371 df.callback(0)
372 reactor.callLater(0, eap_tls_restart_radius_server, df)
373 return df
374
375 @deferred(TLS_TIMEOUT)
376 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
377 df = defer.Deferred()
378 def eap_tls_incorrect_handshake_type_client_hello(df):
379 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700380 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700381 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
382 tls.runTest()
383 assert_equal(tls.failTest, True)
384 df.callback(0)
385 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
386 return df
387
388 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
389 @deferred(TLS_TIMEOUT)
390 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
391 df = defer.Deferred()
392 def eap_tls_incorrect_handshake_type_certificate_request(df):
393 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700394 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700395 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
396 tls.runTest()
397 assert_equal(tls.failTest, True)
398 df.callback(0)
399 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
400 return df
401
402 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
403 @deferred(TLS_TIMEOUT)
404 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
405 df = defer.Deferred()
406 def eap_tls_incorrect_tlsrecord_certificate_request(df):
407 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700408 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700409 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
410 tls.runTest()
411 assert_equal(tls.failTest, True)
412 df.callback(0)
413 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
414 return df
415
416 #Sending client hello with zero lenght field in Handshake protocol
417 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800418 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700419 df = defer.Deferred()
420 def eap_tls_invalid_handshake_length_client_hello(df):
421 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700422 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700423 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
424 tls.runTest()
425 assert_equal(tls.failTest, True)
426 df.callback(0)
427 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
428 return df
429
430 @deferred(TLS_TIMEOUT)
431 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
432 df = defer.Deferred()
433 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
434 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700435 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700436 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
437 tls.runTest()
438 assert_equal(tls.failTest, True)
439 df.callback(0)
440 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
441 return df
442
443 #simulating authentication for multiple users, 1K in this test case
444 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800445 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700446 df = defer.Deferred()
447 def eap_tls_1k_with_diff_mac(df):
448 for i in xrange(1000):
449 tls = TLSAuthTest(src_mac = 'random')
450 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700451 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700452 df.callback(0)
453 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
454 return df
455
456 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800457 @deferred(TEST_TIMEOUT+1800)
458 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700459 df = defer.Deferred()
460 def eap_tls_5k_with_diff_mac(df):
461 for i in xrange(5000):
462 tls = TLSAuthTest(src_mac = 'random')
463 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700464 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700465 df.callback(0)
466 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
467 return df
468
A R Karthick8f930292017-07-07 12:36:22 -0700469 def tls_scale(self, num_sessions):
470 '''Called from scale test'''
471 def tls_session_fail_cb():
472 pass
473 for i in xrange(num_sessions):
474 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
475 tls.runTest()
476 if tls.failTest is False:
477 log_test.info('Authentication successful for user %d'%i)
478 else:
479 log_test.info('Authentication failed for user %d' %i)
480
A R Karthicka2e53d62016-02-19 17:38:30 -0800481if __name__ == '__main__':
482 t = TLSAuthTest()
483 t.runTest()