blob: 300201cef3a9211038693c7c669f84597995f3aa [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 Karthick1555c7c2017-09-07 14:59:41 -0700107 OnosCtrl.aaa_load_config()
A R Karthick22aa0c62016-05-31 11:17:12 -0700108
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700109 @deferred(TLS_TIMEOUT)
110 def test_eap_tls(self):
111 df = defer.Deferred()
112 def eap_tls_verify(df):
113 tls = TLSAuthTest()
114 tls.runTest()
115 df.callback(0)
116 reactor.callLater(0, eap_tls_verify, df)
117 return df
118
119 @deferred(TLS_TIMEOUT)
120 def test_eap_tls_with_no_cert(self):
121 df = defer.Deferred()
122 def eap_tls_no_cert(df):
123 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700124 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700125 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
126 tls.runTest()
127 assert_equal(tls.failTest, True)
128 df.callback(0)
129 reactor.callLater(0, eap_tls_no_cert, df)
130 return df
131
132 @deferred(TLS_TIMEOUT)
133 def test_eap_tls_with_invalid_cert(self):
134 df = defer.Deferred()
135 def eap_tls_invalid_cert(df):
136 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700137 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700138
139 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
140 client_cert = self.CLIENT_CERT_INVALID)
141 tls.runTest()
142 assert_equal(tls.failTest, True)
143 df.callback(0)
144 reactor.callLater(0, eap_tls_invalid_cert, df)
145 return df
146
147 @deferred(TLS_TIMEOUT)
148 def test_eap_tls_Nusers_with_same_valid_cert(self):
149 df = defer.Deferred()
150 def eap_tls_Nusers_with_same_valid_cert(df):
151 num_users = 3
152 for i in xrange(num_users):
153 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
154 tls.runTest()
155 df.callback(0)
156 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
157 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800158
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700159 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800160 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700161 df = defer.Deferred()
162 def eap_tls_invalid_session_id(df):
163 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700164 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700165 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
166 tls.runTest()
167 assert_equal(tls.failTest, True)
168 df.callback(0)
169 reactor.callLater(0, eap_tls_invalid_session_id, df)
170 return df
171
172 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800173 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700174 df = defer.Deferred()
175 def eap_tls_invalid_gmt_unix_time(df):
176 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700177 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700178 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700179 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700180 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
181 tls.runTest()
182 assert_equal(tls.failTest, True)
183 df.callback(0)
184 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
185 return df
186
187 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800188 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700189 df = defer.Deferred()
190 def eap_tls_invalid_content_type(df):
191 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700192 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700193 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
194 tls.runTest()
195 assert_equal(tls.failTest, True)
196 df.callback(0)
197 reactor.callLater(0, eap_tls_invalid_content_type, df)
198 return df
199
200 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800201 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700202 df = defer.Deferred()
203 def eap_tls_invalid_record_fragment_length(df):
204 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700205 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700206 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
207 tls.runTest()
208 assert_equal(tls.failTest, True)
209 df.callback(0)
210 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
211 return df
212
213 #invalid id field in identifier response packet
214 @deferred(TLS_TIMEOUT)
215 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
216 df = defer.Deferred()
217 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
218 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700219 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700220 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
221 id_mismatch_in_identifier_response_packet = True)
222 tls.runTest()
223 assert_equal(tls.failTest, True)
224 df.callback(0)
225 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
226 return df
227
228 #invalid id field in client hello packet
229 @deferred(TLS_TIMEOUT)
230 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
231 df = defer.Deferred()
232 def eap_tls_with_invalid_id_in_client_hello_packet(df):
233 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700234 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700235 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
236 id_mismatch_in_client_hello_packet = True)
237 tls.runTest()
238 assert_equal(tls.failTest, True)
239 df.callback(0)
240 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
241 return df
242
243 @deferred(TLS_TIMEOUT)
244 def test_eap_tls_without_sending_client_hello(self):
245 df = defer.Deferred()
246 def eap_tls_without_sending_client_hello(df):
247 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700248 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700249 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
250 dont_send_client_hello = True)
251 tls.runTest()
252 assert_equal(tls.failTest, True)
253 df.callback(0)
254 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
255 return df
256
257 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800258 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700259 df = defer.Deferred()
260 def eap_tls_aaa_app_deactivate(df):
261 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700262 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700263 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
264 self.onos_ctrl.deactivate()
265 tls.runTest()
266 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800267 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700268 df.callback(0)
269 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
270 return df
271
272 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
273 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800274 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700275 df = defer.Deferred()
276 def eap_tls_incorrect_cipher_suite_length_field(df):
277 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700278 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700279 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
280 tls.runTest()
281 assert_equal(tls.failTest, True)
282 df.callback(0)
283 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
284 return df
285
286 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
287 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800288 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700289 df = defer.Deferred()
290 def eap_tls_incorrect_compression_methods_length_field(df):
291 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700292 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700293 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
294 tls.runTest()
295 assert_equal(tls.failTest, True)
296 df.callback(0)
297 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
298 return df
299
300 #checking with broadcast source mac of EAPOL packet
301 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800302 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700303 df = defer.Deferred()
304 def eap_tls_invalid_source_mac_broadcast(df):
305 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700306 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700307 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
308 tls.runTest()
309 assert_equal(tls.failTest, True)
310 df.callback(0)
311 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
312 return df
313
314 #checking with multicast source mac of EAPOL packet
315 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800316 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700317 df = defer.Deferred()
318 def eap_tls_invalid_source_mac_multicast(df):
319 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700320 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700321 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
322 tls.runTest()
323 assert_equal(tls.failTest, True)
324 df.callback(0)
325 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
326 return df
327
328 #checking with zero source mac of EAPOL packet
329 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800330 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700331 df = defer.Deferred()
332 def eap_tls_invalid_source_mac_zero(df):
333 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700334 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700335 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
336 tls.runTest()
337 assert_equal(tls.failTest, True)
338 df.callback(0)
339 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
340 return df
341
342 #Restarting Radius server after sending client hello
343 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800344 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700345 df = defer.Deferred()
346 def eap_tls_restart_radius_server(df):
347 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700348 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700349 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
350 tls.runTest()
351 assert_equal(tls.failTest, True)
352 df.callback(0)
353 reactor.callLater(0, eap_tls_restart_radius_server, df)
354 return df
355
356 @deferred(TLS_TIMEOUT)
357 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
358 df = defer.Deferred()
359 def eap_tls_incorrect_handshake_type_client_hello(df):
360 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700361 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700362 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
363 tls.runTest()
364 assert_equal(tls.failTest, True)
365 df.callback(0)
366 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
367 return df
368
369 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
370 @deferred(TLS_TIMEOUT)
371 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
372 df = defer.Deferred()
373 def eap_tls_incorrect_handshake_type_certificate_request(df):
374 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700375 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700376 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
377 tls.runTest()
378 assert_equal(tls.failTest, True)
379 df.callback(0)
380 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
381 return df
382
383 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
384 @deferred(TLS_TIMEOUT)
385 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
386 df = defer.Deferred()
387 def eap_tls_incorrect_tlsrecord_certificate_request(df):
388 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700389 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700390 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
391 tls.runTest()
392 assert_equal(tls.failTest, True)
393 df.callback(0)
394 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
395 return df
396
397 #Sending client hello with zero lenght field in Handshake protocol
398 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800399 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700400 df = defer.Deferred()
401 def eap_tls_invalid_handshake_length_client_hello(df):
402 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700403 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700404 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
405 tls.runTest()
406 assert_equal(tls.failTest, True)
407 df.callback(0)
408 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
409 return df
410
411 @deferred(TLS_TIMEOUT)
412 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
413 df = defer.Deferred()
414 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
415 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700416 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700417 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
418 tls.runTest()
419 assert_equal(tls.failTest, True)
420 df.callback(0)
421 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
422 return df
423
424 #simulating authentication for multiple users, 1K in this test case
425 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800426 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700427 df = defer.Deferred()
428 def eap_tls_1k_with_diff_mac(df):
429 for i in xrange(1000):
430 tls = TLSAuthTest(src_mac = 'random')
431 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700432 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700433 df.callback(0)
434 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
435 return df
436
437 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800438 @deferred(TEST_TIMEOUT+1800)
439 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700440 df = defer.Deferred()
441 def eap_tls_5k_with_diff_mac(df):
442 for i in xrange(5000):
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_5k_with_diff_mac, df)
448 return df
449
A R Karthick8f930292017-07-07 12:36:22 -0700450 def tls_scale(self, num_sessions):
451 '''Called from scale test'''
452 def tls_session_fail_cb():
453 pass
454 for i in xrange(num_sessions):
455 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
456 tls.runTest()
457 if tls.failTest is False:
458 log_test.info('Authentication successful for user %d'%i)
459 else:
460 log_test.info('Authentication failed for user %d' %i)
461
A R Karthicka2e53d62016-02-19 17:38:30 -0800462if __name__ == '__main__':
463 t = TLSAuthTest()
464 t.runTest()