blob: 6ac5e6b0d5f5e65c1d09b7ecd4c2372ba4bbc789 [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
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070026from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070027from scapy_ssl_tls.ssl_tls import *
28from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070029log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080030
A R Karthick9313b762016-11-07 13:14:35 -080031class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080032
A.R Karthick95d044e2016-06-10 18:44:36 -070033 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070034 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070035 TEST_TIMEOUT = 3600
A R Karthickeeac7e12017-03-10 17:35:39 -080036 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070037 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080038MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
39VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
40CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
41JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
42MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
43Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
44CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070045cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080046ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
471zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
48QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
4946DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
50of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
51CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
52zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
53b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
54DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
55D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
56dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070057oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080058hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
59QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
60iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
61+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
62dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
637cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070064-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080065
ChetanGaonker6138fcd2016-08-18 17:56:39 -070066 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
67 'TLS_RSA_WITH_AES_128_CBC_SHA',
68 'TLS_RSA_WITH_AES_128_CBC_SHA256',
69 'TLS_RSA_WITH_AES_256_CBC_SHA256',
70 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
71 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
72 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
73 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
74 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
75 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
76
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070077 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -080078 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070079 self.onos_ctrl = OnosCtrl(self.app)
80 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080081
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070082 def onos_aaa_config(self):
A R Karthicka652c4a2017-03-10 17:47:08 -080083 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
84 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070085 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A R Karthicka652c4a2017-03-10 17:47:08 -080086 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070087 self.onos_ctrl.activate()
88 time.sleep(2)
89 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080090
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070091 def onos_load_config(self, config):
92 status, code = OnosCtrl.config(config)
93 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -070094 log_test.info('Configure request for AAA returned status %d' %code)
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070095 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -070096 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -070097
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070098 @deferred(TLS_TIMEOUT)
99 def test_eap_tls(self):
100 df = defer.Deferred()
101 def eap_tls_verify(df):
102 tls = TLSAuthTest()
103 tls.runTest()
104 df.callback(0)
105 reactor.callLater(0, eap_tls_verify, df)
106 return df
107
108 @deferred(TLS_TIMEOUT)
109 def test_eap_tls_with_no_cert(self):
110 df = defer.Deferred()
111 def eap_tls_no_cert(df):
112 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700113 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700114 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
115 tls.runTest()
116 assert_equal(tls.failTest, True)
117 df.callback(0)
118 reactor.callLater(0, eap_tls_no_cert, df)
119 return df
120
121 @deferred(TLS_TIMEOUT)
122 def test_eap_tls_with_invalid_cert(self):
123 df = defer.Deferred()
124 def eap_tls_invalid_cert(df):
125 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700126 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700127
128 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
129 client_cert = self.CLIENT_CERT_INVALID)
130 tls.runTest()
131 assert_equal(tls.failTest, True)
132 df.callback(0)
133 reactor.callLater(0, eap_tls_invalid_cert, df)
134 return df
135
136 @deferred(TLS_TIMEOUT)
137 def test_eap_tls_Nusers_with_same_valid_cert(self):
138 df = defer.Deferred()
139 def eap_tls_Nusers_with_same_valid_cert(df):
140 num_users = 3
141 for i in xrange(num_users):
142 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
143 tls.runTest()
144 df.callback(0)
145 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
146 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800147
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700148 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800149 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700150 df = defer.Deferred()
151 def eap_tls_invalid_session_id(df):
152 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700153 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700154 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
155 tls.runTest()
156 assert_equal(tls.failTest, True)
157 df.callback(0)
158 reactor.callLater(0, eap_tls_invalid_session_id, df)
159 return df
160
161 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800162 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700163 df = defer.Deferred()
164 def eap_tls_invalid_gmt_unix_time(df):
165 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700166 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700167 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700168 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700169 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
170 tls.runTest()
171 assert_equal(tls.failTest, True)
172 df.callback(0)
173 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
174 return df
175
176 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800177 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700178 df = defer.Deferred()
179 def eap_tls_invalid_content_type(df):
180 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700181 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700182 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
183 tls.runTest()
184 assert_equal(tls.failTest, True)
185 df.callback(0)
186 reactor.callLater(0, eap_tls_invalid_content_type, df)
187 return df
188
189 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800190 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700191 df = defer.Deferred()
192 def eap_tls_invalid_record_fragment_length(df):
193 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700194 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700195 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
196 tls.runTest()
197 assert_equal(tls.failTest, True)
198 df.callback(0)
199 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
200 return df
201
202 #invalid id field in identifier response packet
203 @deferred(TLS_TIMEOUT)
204 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
205 df = defer.Deferred()
206 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
207 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700208 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700209 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
210 id_mismatch_in_identifier_response_packet = True)
211 tls.runTest()
212 assert_equal(tls.failTest, True)
213 df.callback(0)
214 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
215 return df
216
217 #invalid id field in client hello packet
218 @deferred(TLS_TIMEOUT)
219 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
220 df = defer.Deferred()
221 def eap_tls_with_invalid_id_in_client_hello_packet(df):
222 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700223 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700224 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
225 id_mismatch_in_client_hello_packet = True)
226 tls.runTest()
227 assert_equal(tls.failTest, True)
228 df.callback(0)
229 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
230 return df
231
232 @deferred(TLS_TIMEOUT)
233 def test_eap_tls_without_sending_client_hello(self):
234 df = defer.Deferred()
235 def eap_tls_without_sending_client_hello(df):
236 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700237 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700238 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
239 dont_send_client_hello = True)
240 tls.runTest()
241 assert_equal(tls.failTest, True)
242 df.callback(0)
243 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
244 return df
245
246 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800247 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700248 df = defer.Deferred()
249 def eap_tls_aaa_app_deactivate(df):
250 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700251 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700252 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
253 self.onos_ctrl.deactivate()
254 tls.runTest()
255 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800256 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700257 df.callback(0)
258 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
259 return df
260
261 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
262 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800263 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700264 df = defer.Deferred()
265 def eap_tls_incorrect_cipher_suite_length_field(df):
266 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700267 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700268 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
269 tls.runTest()
270 assert_equal(tls.failTest, True)
271 df.callback(0)
272 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
273 return df
274
275 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
276 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800277 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700278 df = defer.Deferred()
279 def eap_tls_incorrect_compression_methods_length_field(df):
280 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700281 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700282 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
283 tls.runTest()
284 assert_equal(tls.failTest, True)
285 df.callback(0)
286 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
287 return df
288
289 #checking with broadcast source mac of EAPOL packet
290 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800291 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700292 df = defer.Deferred()
293 def eap_tls_invalid_source_mac_broadcast(df):
294 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700295 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700296 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
297 tls.runTest()
298 assert_equal(tls.failTest, True)
299 df.callback(0)
300 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
301 return df
302
303 #checking with multicast source mac of EAPOL packet
304 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800305 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700306 df = defer.Deferred()
307 def eap_tls_invalid_source_mac_multicast(df):
308 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700309 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700310 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
311 tls.runTest()
312 assert_equal(tls.failTest, True)
313 df.callback(0)
314 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
315 return df
316
317 #checking with zero source mac of EAPOL packet
318 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800319 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700320 df = defer.Deferred()
321 def eap_tls_invalid_source_mac_zero(df):
322 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700323 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700324 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
325 tls.runTest()
326 assert_equal(tls.failTest, True)
327 df.callback(0)
328 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
329 return df
330
331 #Restarting Radius server after sending client hello
332 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800333 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700334 df = defer.Deferred()
335 def eap_tls_restart_radius_server(df):
336 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700337 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700338 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
339 tls.runTest()
340 assert_equal(tls.failTest, True)
341 df.callback(0)
342 reactor.callLater(0, eap_tls_restart_radius_server, df)
343 return df
344
345 @deferred(TLS_TIMEOUT)
346 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
347 df = defer.Deferred()
348 def eap_tls_incorrect_handshake_type_client_hello(df):
349 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700350 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700351 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
352 tls.runTest()
353 assert_equal(tls.failTest, True)
354 df.callback(0)
355 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
356 return df
357
358 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
359 @deferred(TLS_TIMEOUT)
360 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
361 df = defer.Deferred()
362 def eap_tls_incorrect_handshake_type_certificate_request(df):
363 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700364 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700365 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
366 tls.runTest()
367 assert_equal(tls.failTest, True)
368 df.callback(0)
369 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
370 return df
371
372 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
373 @deferred(TLS_TIMEOUT)
374 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
375 df = defer.Deferred()
376 def eap_tls_incorrect_tlsrecord_certificate_request(df):
377 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700378 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700379 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
380 tls.runTest()
381 assert_equal(tls.failTest, True)
382 df.callback(0)
383 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
384 return df
385
386 #Sending client hello with zero lenght field in Handshake protocol
387 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800388 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700389 df = defer.Deferred()
390 def eap_tls_invalid_handshake_length_client_hello(df):
391 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700392 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700393 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
394 tls.runTest()
395 assert_equal(tls.failTest, True)
396 df.callback(0)
397 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
398 return df
399
400 @deferred(TLS_TIMEOUT)
401 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
402 df = defer.Deferred()
403 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
404 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700405 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700406 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
407 tls.runTest()
408 assert_equal(tls.failTest, True)
409 df.callback(0)
410 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
411 return df
412
413 #simulating authentication for multiple users, 1K in this test case
414 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800415 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700416 df = defer.Deferred()
417 def eap_tls_1k_with_diff_mac(df):
418 for i in xrange(1000):
419 tls = TLSAuthTest(src_mac = 'random')
420 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700421 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700422 df.callback(0)
423 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
424 return df
425
426 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800427 @deferred(TEST_TIMEOUT+1800)
428 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700429 df = defer.Deferred()
430 def eap_tls_5k_with_diff_mac(df):
431 for i in xrange(5000):
432 tls = TLSAuthTest(src_mac = 'random')
433 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700434 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700435 df.callback(0)
436 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
437 return df
438
A R Karthicka2e53d62016-02-19 17:38:30 -0800439if __name__ == '__main__':
440 t = TLSAuthTest()
441 t.runTest()