blob: 8735f028ad13eaa42d0732d0cc661e05a2afb3e6 [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
A R Karthicke7232092017-09-07 18:01:33 -070043from VolthaCtrl import VolthaCtrl
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070044from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070045from scapy_ssl_tls.ssl_tls import *
46from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070047log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080048
A R Karthick9313b762016-11-07 13:14:35 -080049class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080050
A.R Karthick95d044e2016-06-10 18:44:36 -070051 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070052 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070053 TEST_TIMEOUT = 3600
A R Karthickbf1e4b02017-07-11 20:17:14 -070054 VOLTHA_HOST = None
A R Karthicke7232092017-09-07 18:01:33 -070055 VOLTHA_REST_PORT = VolthaCtrl.REST_PORT
A R Karthickbf1e4b02017-07-11 20:17:14 -070056 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
57 VOLTHA_OLT_TYPE = 'simulated_olt'
58 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
59 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthickeeac7e12017-03-10 17:35:39 -080060 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070061 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080062MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
63VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
64CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
65JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
66MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
67Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
68CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070069cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080070ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
711zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
72QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
7346DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
74of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
75CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
76zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
77b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
78DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
79D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
80dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070081oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080082hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
83QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
84iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
85+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
86dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
877cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070088-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080089
ChetanGaonker6138fcd2016-08-18 17:56:39 -070090 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
91 'TLS_RSA_WITH_AES_128_CBC_SHA',
92 'TLS_RSA_WITH_AES_128_CBC_SHA256',
93 'TLS_RSA_WITH_AES_256_CBC_SHA256',
94 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
95 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
96 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
97 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
98 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
99 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
100
A R Karthickbf1e4b02017-07-11 20:17:14 -0700101
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700102 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -0800103 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700104 self.onos_ctrl = OnosCtrl(self.app)
105 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -0800106
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700107 def onos_aaa_config(self):
A R Karthick1555c7c2017-09-07 14:59:41 -0700108 OnosCtrl.aaa_load_config()
A R Karthick22aa0c62016-05-31 11:17:12 -0700109
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700110 @deferred(TLS_TIMEOUT)
111 def test_eap_tls(self):
112 df = defer.Deferred()
113 def eap_tls_verify(df):
114 tls = TLSAuthTest()
115 tls.runTest()
116 df.callback(0)
117 reactor.callLater(0, eap_tls_verify, df)
118 return df
119
120 @deferred(TLS_TIMEOUT)
121 def test_eap_tls_with_no_cert(self):
122 df = defer.Deferred()
123 def eap_tls_no_cert(df):
124 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700125 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700126 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
127 tls.runTest()
128 assert_equal(tls.failTest, True)
129 df.callback(0)
130 reactor.callLater(0, eap_tls_no_cert, df)
131 return df
132
133 @deferred(TLS_TIMEOUT)
134 def test_eap_tls_with_invalid_cert(self):
135 df = defer.Deferred()
136 def eap_tls_invalid_cert(df):
137 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700138 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700139
140 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
141 client_cert = self.CLIENT_CERT_INVALID)
142 tls.runTest()
143 assert_equal(tls.failTest, True)
144 df.callback(0)
145 reactor.callLater(0, eap_tls_invalid_cert, df)
146 return df
147
148 @deferred(TLS_TIMEOUT)
149 def test_eap_tls_Nusers_with_same_valid_cert(self):
150 df = defer.Deferred()
151 def eap_tls_Nusers_with_same_valid_cert(df):
152 num_users = 3
153 for i in xrange(num_users):
154 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
155 tls.runTest()
156 df.callback(0)
157 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
158 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800159
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700160 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800161 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700162 df = defer.Deferred()
163 def eap_tls_invalid_session_id(df):
164 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700165 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700166 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
167 tls.runTest()
168 assert_equal(tls.failTest, True)
169 df.callback(0)
170 reactor.callLater(0, eap_tls_invalid_session_id, df)
171 return df
172
173 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800174 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700175 df = defer.Deferred()
176 def eap_tls_invalid_gmt_unix_time(df):
177 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700178 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700179 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700180 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700181 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
182 tls.runTest()
183 assert_equal(tls.failTest, True)
184 df.callback(0)
185 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
186 return df
187
188 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800189 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700190 df = defer.Deferred()
191 def eap_tls_invalid_content_type(df):
192 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700193 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700194 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
195 tls.runTest()
196 assert_equal(tls.failTest, True)
197 df.callback(0)
198 reactor.callLater(0, eap_tls_invalid_content_type, df)
199 return df
200
201 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800202 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700203 df = defer.Deferred()
204 def eap_tls_invalid_record_fragment_length(df):
205 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700206 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700207 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
208 tls.runTest()
209 assert_equal(tls.failTest, True)
210 df.callback(0)
211 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
212 return df
213
214 #invalid id field in identifier response packet
215 @deferred(TLS_TIMEOUT)
216 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
217 df = defer.Deferred()
218 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
219 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700220 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700221 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
222 id_mismatch_in_identifier_response_packet = True)
223 tls.runTest()
224 assert_equal(tls.failTest, True)
225 df.callback(0)
226 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
227 return df
228
229 #invalid id field in client hello packet
230 @deferred(TLS_TIMEOUT)
231 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
232 df = defer.Deferred()
233 def eap_tls_with_invalid_id_in_client_hello_packet(df):
234 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700235 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700236 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
237 id_mismatch_in_client_hello_packet = True)
238 tls.runTest()
239 assert_equal(tls.failTest, True)
240 df.callback(0)
241 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
242 return df
243
244 @deferred(TLS_TIMEOUT)
245 def test_eap_tls_without_sending_client_hello(self):
246 df = defer.Deferred()
247 def eap_tls_without_sending_client_hello(df):
248 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700249 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700250 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
251 dont_send_client_hello = True)
252 tls.runTest()
253 assert_equal(tls.failTest, True)
254 df.callback(0)
255 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
256 return df
257
258 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800259 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700260 df = defer.Deferred()
261 def eap_tls_aaa_app_deactivate(df):
262 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700263 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700264 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
265 self.onos_ctrl.deactivate()
266 tls.runTest()
267 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800268 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700269 df.callback(0)
270 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
271 return df
272
273 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
274 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800275 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700276 df = defer.Deferred()
277 def eap_tls_incorrect_cipher_suite_length_field(df):
278 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700279 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700280 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
281 tls.runTest()
282 assert_equal(tls.failTest, True)
283 df.callback(0)
284 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
285 return df
286
287 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
288 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800289 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700290 df = defer.Deferred()
291 def eap_tls_incorrect_compression_methods_length_field(df):
292 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700293 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700294 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
295 tls.runTest()
296 assert_equal(tls.failTest, True)
297 df.callback(0)
298 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
299 return df
300
301 #checking with broadcast source mac of EAPOL packet
302 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800303 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700304 df = defer.Deferred()
305 def eap_tls_invalid_source_mac_broadcast(df):
306 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700307 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700308 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
309 tls.runTest()
310 assert_equal(tls.failTest, True)
311 df.callback(0)
312 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
313 return df
314
315 #checking with multicast source mac of EAPOL packet
316 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800317 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700318 df = defer.Deferred()
319 def eap_tls_invalid_source_mac_multicast(df):
320 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700321 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700322 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
323 tls.runTest()
324 assert_equal(tls.failTest, True)
325 df.callback(0)
326 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
327 return df
328
329 #checking with zero source mac of EAPOL packet
330 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800331 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700332 df = defer.Deferred()
333 def eap_tls_invalid_source_mac_zero(df):
334 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700335 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700336 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
337 tls.runTest()
338 assert_equal(tls.failTest, True)
339 df.callback(0)
340 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
341 return df
342
343 #Restarting Radius server after sending client hello
344 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800345 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700346 df = defer.Deferred()
347 def eap_tls_restart_radius_server(df):
348 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700349 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700350 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
351 tls.runTest()
352 assert_equal(tls.failTest, True)
353 df.callback(0)
354 reactor.callLater(0, eap_tls_restart_radius_server, df)
355 return df
356
357 @deferred(TLS_TIMEOUT)
358 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
359 df = defer.Deferred()
360 def eap_tls_incorrect_handshake_type_client_hello(df):
361 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700362 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700363 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
364 tls.runTest()
365 assert_equal(tls.failTest, True)
366 df.callback(0)
367 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
368 return df
369
370 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
371 @deferred(TLS_TIMEOUT)
372 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
373 df = defer.Deferred()
374 def eap_tls_incorrect_handshake_type_certificate_request(df):
375 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700376 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700377 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
378 tls.runTest()
379 assert_equal(tls.failTest, True)
380 df.callback(0)
381 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
382 return df
383
384 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
385 @deferred(TLS_TIMEOUT)
386 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
387 df = defer.Deferred()
388 def eap_tls_incorrect_tlsrecord_certificate_request(df):
389 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700390 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700391 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
392 tls.runTest()
393 assert_equal(tls.failTest, True)
394 df.callback(0)
395 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
396 return df
397
398 #Sending client hello with zero lenght field in Handshake protocol
399 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800400 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700401 df = defer.Deferred()
402 def eap_tls_invalid_handshake_length_client_hello(df):
403 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700404 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700405 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
406 tls.runTest()
407 assert_equal(tls.failTest, True)
408 df.callback(0)
409 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
410 return df
411
412 @deferred(TLS_TIMEOUT)
413 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
414 df = defer.Deferred()
415 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
416 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700417 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700418 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
419 tls.runTest()
420 assert_equal(tls.failTest, True)
421 df.callback(0)
422 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
423 return df
424
425 #simulating authentication for multiple users, 1K in this test case
426 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800427 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700428 df = defer.Deferred()
429 def eap_tls_1k_with_diff_mac(df):
430 for i in xrange(1000):
431 tls = TLSAuthTest(src_mac = 'random')
432 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700433 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700434 df.callback(0)
435 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
436 return df
437
438 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800439 @deferred(TEST_TIMEOUT+1800)
440 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700441 df = defer.Deferred()
442 def eap_tls_5k_with_diff_mac(df):
443 for i in xrange(5000):
444 tls = TLSAuthTest(src_mac = 'random')
445 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700446 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700447 df.callback(0)
448 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
449 return df
450
A R Karthick8f930292017-07-07 12:36:22 -0700451 def tls_scale(self, num_sessions):
452 '''Called from scale test'''
453 def tls_session_fail_cb():
454 pass
455 for i in xrange(num_sessions):
456 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
457 tls.runTest()
458 if tls.failTest is False:
459 log_test.info('Authentication successful for user %d'%i)
460 else:
461 log_test.info('Authentication failed for user %d' %i)
462
A R Karthicka2e53d62016-02-19 17:38:30 -0800463if __name__ == '__main__':
464 t = TLSAuthTest()
465 t.runTest()