blob: 6e5991a43026bf2597eacb73d18a35b3739c1189 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# 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
16
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
A R Karthicka2e53d62016-02-19 17:38:30 -080032import unittest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080033import time
34import os
35from nose.tools import *
A R Karthick22aa0c62016-05-31 11:17:12 -070036from nose.twistedtools import reactor, deferred
37from twisted.internet import defer
A R Karthicka2e53d62016-02-19 17:38:30 -080038from EapTLS import TLSAuthTest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080039from OnosCtrl import OnosCtrl
A R Karthick9313b762016-11-07 13:14:35 -080040from CordLogger import CordLogger
A R Karthick76a497a2017-04-12 10:59:39 -070041from CordTestUtils import log_test
A R Karthickdd064632017-07-12 13:02:17 -070042from CordTestConfig import setup_module, teardown_module
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070043from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070044from scapy_ssl_tls.ssl_tls import *
45from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070046log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080047
A R Karthick9313b762016-11-07 13:14:35 -080048class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080049
A.R Karthick95d044e2016-06-10 18:44:36 -070050 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070051 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070052 TEST_TIMEOUT = 3600
A R Karthickbf1e4b02017-07-11 20:17:14 -070053 VOLTHA_HOST = None
54 VOLTHA_REST_PORT = 8881
55 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
56 VOLTHA_OLT_TYPE = 'simulated_olt'
57 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
58 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthickeeac7e12017-03-10 17:35:39 -080059 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070060 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080061MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
62VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
63CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
64JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
65MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
66Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
67CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070068cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080069ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
701zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
71QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
7246DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
73of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
74CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
75zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
76b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
77DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
78D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
79dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070080oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080081hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
82QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
83iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
84+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
85dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
867cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070087-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080088
ChetanGaonker6138fcd2016-08-18 17:56:39 -070089 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
90 'TLS_RSA_WITH_AES_128_CBC_SHA',
91 'TLS_RSA_WITH_AES_128_CBC_SHA256',
92 'TLS_RSA_WITH_AES_256_CBC_SHA256',
93 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
94 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
95 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
96 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
97 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
98 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
99
A R Karthickbf1e4b02017-07-11 20:17:14 -0700100
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700101 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -0800102 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700103 self.onos_ctrl = OnosCtrl(self.app)
104 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800105
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700106 def onos_aaa_config(self):
A R Karthicka652c4a2017-03-10 17:47:08 -0800107 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
108 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700109 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A R Karthicka652c4a2017-03-10 17:47:08 -0800110 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700111 self.onos_ctrl.activate()
112 time.sleep(2)
113 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800114
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700115 def onos_load_config(self, config):
116 status, code = OnosCtrl.config(config)
117 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700118 log_test.info('Configure request for AAA returned status %d' %code)
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700119 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -0700120 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -0700121
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700122 @deferred(TLS_TIMEOUT)
123 def test_eap_tls(self):
124 df = defer.Deferred()
125 def eap_tls_verify(df):
126 tls = TLSAuthTest()
127 tls.runTest()
128 df.callback(0)
129 reactor.callLater(0, eap_tls_verify, df)
130 return df
131
132 @deferred(TLS_TIMEOUT)
133 def test_eap_tls_with_no_cert(self):
134 df = defer.Deferred()
135 def eap_tls_no_cert(df):
136 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700137 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700138 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
139 tls.runTest()
140 assert_equal(tls.failTest, True)
141 df.callback(0)
142 reactor.callLater(0, eap_tls_no_cert, df)
143 return df
144
145 @deferred(TLS_TIMEOUT)
146 def test_eap_tls_with_invalid_cert(self):
147 df = defer.Deferred()
148 def eap_tls_invalid_cert(df):
149 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700150 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700151
152 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
153 client_cert = self.CLIENT_CERT_INVALID)
154 tls.runTest()
155 assert_equal(tls.failTest, True)
156 df.callback(0)
157 reactor.callLater(0, eap_tls_invalid_cert, df)
158 return df
159
160 @deferred(TLS_TIMEOUT)
161 def test_eap_tls_Nusers_with_same_valid_cert(self):
162 df = defer.Deferred()
163 def eap_tls_Nusers_with_same_valid_cert(df):
164 num_users = 3
165 for i in xrange(num_users):
166 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
167 tls.runTest()
168 df.callback(0)
169 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
170 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800171
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700172 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800173 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700174 df = defer.Deferred()
175 def eap_tls_invalid_session_id(df):
176 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700177 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700178 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
179 tls.runTest()
180 assert_equal(tls.failTest, True)
181 df.callback(0)
182 reactor.callLater(0, eap_tls_invalid_session_id, df)
183 return df
184
185 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800186 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700187 df = defer.Deferred()
188 def eap_tls_invalid_gmt_unix_time(df):
189 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700190 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700191 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700192 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700193 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
194 tls.runTest()
195 assert_equal(tls.failTest, True)
196 df.callback(0)
197 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
198 return df
199
200 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800201 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700202 df = defer.Deferred()
203 def eap_tls_invalid_content_type(df):
204 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700205 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700206 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
207 tls.runTest()
208 assert_equal(tls.failTest, True)
209 df.callback(0)
210 reactor.callLater(0, eap_tls_invalid_content_type, df)
211 return df
212
213 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800214 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700215 df = defer.Deferred()
216 def eap_tls_invalid_record_fragment_length(df):
217 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700218 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700219 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
220 tls.runTest()
221 assert_equal(tls.failTest, True)
222 df.callback(0)
223 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
224 return df
225
226 #invalid id field in identifier response packet
227 @deferred(TLS_TIMEOUT)
228 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
229 df = defer.Deferred()
230 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
231 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700232 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700233 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
234 id_mismatch_in_identifier_response_packet = True)
235 tls.runTest()
236 assert_equal(tls.failTest, True)
237 df.callback(0)
238 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
239 return df
240
241 #invalid id field in client hello packet
242 @deferred(TLS_TIMEOUT)
243 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
244 df = defer.Deferred()
245 def eap_tls_with_invalid_id_in_client_hello_packet(df):
246 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700247 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700248 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
249 id_mismatch_in_client_hello_packet = True)
250 tls.runTest()
251 assert_equal(tls.failTest, True)
252 df.callback(0)
253 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
254 return df
255
256 @deferred(TLS_TIMEOUT)
257 def test_eap_tls_without_sending_client_hello(self):
258 df = defer.Deferred()
259 def eap_tls_without_sending_client_hello(df):
260 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700261 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700262 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
263 dont_send_client_hello = True)
264 tls.runTest()
265 assert_equal(tls.failTest, True)
266 df.callback(0)
267 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
268 return df
269
270 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800271 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700272 df = defer.Deferred()
273 def eap_tls_aaa_app_deactivate(df):
274 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700275 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700276 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
277 self.onos_ctrl.deactivate()
278 tls.runTest()
279 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800280 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700281 df.callback(0)
282 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
283 return df
284
285 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
286 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800287 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700288 df = defer.Deferred()
289 def eap_tls_incorrect_cipher_suite_length_field(df):
290 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700291 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700292 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
293 tls.runTest()
294 assert_equal(tls.failTest, True)
295 df.callback(0)
296 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
297 return df
298
299 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
300 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800301 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700302 df = defer.Deferred()
303 def eap_tls_incorrect_compression_methods_length_field(df):
304 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700305 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700306 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
307 tls.runTest()
308 assert_equal(tls.failTest, True)
309 df.callback(0)
310 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
311 return df
312
313 #checking with broadcast source mac of EAPOL packet
314 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800315 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700316 df = defer.Deferred()
317 def eap_tls_invalid_source_mac_broadcast(df):
318 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700319 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700320 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
321 tls.runTest()
322 assert_equal(tls.failTest, True)
323 df.callback(0)
324 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
325 return df
326
327 #checking with multicast source mac of EAPOL packet
328 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800329 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700330 df = defer.Deferred()
331 def eap_tls_invalid_source_mac_multicast(df):
332 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700333 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700334 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
335 tls.runTest()
336 assert_equal(tls.failTest, True)
337 df.callback(0)
338 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
339 return df
340
341 #checking with zero source mac of EAPOL packet
342 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800343 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700344 df = defer.Deferred()
345 def eap_tls_invalid_source_mac_zero(df):
346 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700347 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700348 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
349 tls.runTest()
350 assert_equal(tls.failTest, True)
351 df.callback(0)
352 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
353 return df
354
355 #Restarting Radius server after sending client hello
356 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800357 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700358 df = defer.Deferred()
359 def eap_tls_restart_radius_server(df):
360 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700361 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700362 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
363 tls.runTest()
364 assert_equal(tls.failTest, True)
365 df.callback(0)
366 reactor.callLater(0, eap_tls_restart_radius_server, df)
367 return df
368
369 @deferred(TLS_TIMEOUT)
370 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
371 df = defer.Deferred()
372 def eap_tls_incorrect_handshake_type_client_hello(df):
373 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700374 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700375 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
376 tls.runTest()
377 assert_equal(tls.failTest, True)
378 df.callback(0)
379 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
380 return df
381
382 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
383 @deferred(TLS_TIMEOUT)
384 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
385 df = defer.Deferred()
386 def eap_tls_incorrect_handshake_type_certificate_request(df):
387 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700388 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700389 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
390 tls.runTest()
391 assert_equal(tls.failTest, True)
392 df.callback(0)
393 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
394 return df
395
396 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
397 @deferred(TLS_TIMEOUT)
398 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
399 df = defer.Deferred()
400 def eap_tls_incorrect_tlsrecord_certificate_request(df):
401 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700402 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700403 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
404 tls.runTest()
405 assert_equal(tls.failTest, True)
406 df.callback(0)
407 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
408 return df
409
410 #Sending client hello with zero lenght field in Handshake protocol
411 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800412 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700413 df = defer.Deferred()
414 def eap_tls_invalid_handshake_length_client_hello(df):
415 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700416 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700417 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
418 tls.runTest()
419 assert_equal(tls.failTest, True)
420 df.callback(0)
421 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
422 return df
423
424 @deferred(TLS_TIMEOUT)
425 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
426 df = defer.Deferred()
427 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
428 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700429 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700430 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
431 tls.runTest()
432 assert_equal(tls.failTest, True)
433 df.callback(0)
434 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
435 return df
436
437 #simulating authentication for multiple users, 1K in this test case
438 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800439 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700440 df = defer.Deferred()
441 def eap_tls_1k_with_diff_mac(df):
442 for i in xrange(1000):
443 tls = TLSAuthTest(src_mac = 'random')
444 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700445 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700446 df.callback(0)
447 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
448 return df
449
450 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800451 @deferred(TEST_TIMEOUT+1800)
452 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700453 df = defer.Deferred()
454 def eap_tls_5k_with_diff_mac(df):
455 for i in xrange(5000):
456 tls = TLSAuthTest(src_mac = 'random')
457 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700458 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700459 df.callback(0)
460 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
461 return df
462
A R Karthick8f930292017-07-07 12:36:22 -0700463 def tls_scale(self, num_sessions):
464 '''Called from scale test'''
465 def tls_session_fail_cb():
466 pass
467 for i in xrange(num_sessions):
468 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
469 tls.runTest()
470 if tls.failTest is False:
471 log_test.info('Authentication successful for user %d'%i)
472 else:
473 log_test.info('Authentication failed for user %d' %i)
474
A R Karthicka2e53d62016-02-19 17:38:30 -0800475if __name__ == '__main__':
476 t = TLSAuthTest()
477 t.runTest()