blob: c9648d44674cab58e7bbf6e58569b68e823e1071 [file] [log] [blame]
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
A R Karthicka2e53d62016-02-19 17:38:30 -080016import unittest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080017import time
18import os
19from nose.tools import *
A R Karthick22aa0c62016-05-31 11:17:12 -070020from nose.twistedtools import reactor, deferred
21from twisted.internet import defer
A R Karthicka2e53d62016-02-19 17:38:30 -080022from EapTLS import TLSAuthTest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080023from OnosCtrl import OnosCtrl
A R Karthick9313b762016-11-07 13:14:35 -080024from CordLogger import CordLogger
A R Karthick76a497a2017-04-12 10:59:39 -070025from CordTestUtils import log_test
A R Karthickdd064632017-07-12 13:02:17 -070026from CordTestConfig import setup_module, teardown_module
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070027from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070028from scapy_ssl_tls.ssl_tls import *
29from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070030log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080031
A R Karthick9313b762016-11-07 13:14:35 -080032class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080033
A.R Karthick95d044e2016-06-10 18:44:36 -070034 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070035 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070036 TEST_TIMEOUT = 3600
A R Karthickbf1e4b02017-07-11 20:17:14 -070037 VOLTHA_HOST = None
38 VOLTHA_REST_PORT = 8881
39 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
40 VOLTHA_OLT_TYPE = 'simulated_olt'
41 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
42 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthickeeac7e12017-03-10 17:35:39 -080043 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070044 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080045MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
46VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
47CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
48JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
49MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
50Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
51CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070052cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080053ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
541zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
55QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
5646DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
57of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
58CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
59zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
60b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
61DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
62D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
63dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070064oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080065hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
66QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
67iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
68+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
69dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
707cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070071-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080072
ChetanGaonker6138fcd2016-08-18 17:56:39 -070073 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
74 'TLS_RSA_WITH_AES_128_CBC_SHA',
75 'TLS_RSA_WITH_AES_128_CBC_SHA256',
76 'TLS_RSA_WITH_AES_256_CBC_SHA256',
77 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
78 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
79 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
80 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
81 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
82 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
83
A R Karthickbf1e4b02017-07-11 20:17:14 -070084
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070085 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -080086 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070087 self.onos_ctrl = OnosCtrl(self.app)
88 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080089
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070090 def onos_aaa_config(self):
A R Karthicka652c4a2017-03-10 17:47:08 -080091 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
92 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070093 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A R Karthicka652c4a2017-03-10 17:47:08 -080094 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070095 self.onos_ctrl.activate()
96 time.sleep(2)
97 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080098
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070099 def onos_load_config(self, config):
100 status, code = OnosCtrl.config(config)
101 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700102 log_test.info('Configure request for AAA returned status %d' %code)
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700103 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -0700104 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -0700105
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700106 @deferred(TLS_TIMEOUT)
107 def test_eap_tls(self):
108 df = defer.Deferred()
109 def eap_tls_verify(df):
110 tls = TLSAuthTest()
111 tls.runTest()
112 df.callback(0)
113 reactor.callLater(0, eap_tls_verify, df)
114 return df
115
116 @deferred(TLS_TIMEOUT)
117 def test_eap_tls_with_no_cert(self):
118 df = defer.Deferred()
119 def eap_tls_no_cert(df):
120 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700121 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700122 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
123 tls.runTest()
124 assert_equal(tls.failTest, True)
125 df.callback(0)
126 reactor.callLater(0, eap_tls_no_cert, df)
127 return df
128
129 @deferred(TLS_TIMEOUT)
130 def test_eap_tls_with_invalid_cert(self):
131 df = defer.Deferred()
132 def eap_tls_invalid_cert(df):
133 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700134 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700135
136 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
137 client_cert = self.CLIENT_CERT_INVALID)
138 tls.runTest()
139 assert_equal(tls.failTest, True)
140 df.callback(0)
141 reactor.callLater(0, eap_tls_invalid_cert, df)
142 return df
143
144 @deferred(TLS_TIMEOUT)
145 def test_eap_tls_Nusers_with_same_valid_cert(self):
146 df = defer.Deferred()
147 def eap_tls_Nusers_with_same_valid_cert(df):
148 num_users = 3
149 for i in xrange(num_users):
150 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
151 tls.runTest()
152 df.callback(0)
153 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
154 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800155
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700156 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800157 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700158 df = defer.Deferred()
159 def eap_tls_invalid_session_id(df):
160 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700161 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700162 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
163 tls.runTest()
164 assert_equal(tls.failTest, True)
165 df.callback(0)
166 reactor.callLater(0, eap_tls_invalid_session_id, df)
167 return df
168
169 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800170 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700171 df = defer.Deferred()
172 def eap_tls_invalid_gmt_unix_time(df):
173 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700174 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700175 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700176 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700177 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
178 tls.runTest()
179 assert_equal(tls.failTest, True)
180 df.callback(0)
181 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
182 return df
183
184 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800185 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700186 df = defer.Deferred()
187 def eap_tls_invalid_content_type(df):
188 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700189 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700190 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
191 tls.runTest()
192 assert_equal(tls.failTest, True)
193 df.callback(0)
194 reactor.callLater(0, eap_tls_invalid_content_type, df)
195 return df
196
197 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800198 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700199 df = defer.Deferred()
200 def eap_tls_invalid_record_fragment_length(df):
201 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700202 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700203 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
204 tls.runTest()
205 assert_equal(tls.failTest, True)
206 df.callback(0)
207 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
208 return df
209
210 #invalid id field in identifier response packet
211 @deferred(TLS_TIMEOUT)
212 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
213 df = defer.Deferred()
214 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
215 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700216 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700217 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
218 id_mismatch_in_identifier_response_packet = True)
219 tls.runTest()
220 assert_equal(tls.failTest, True)
221 df.callback(0)
222 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
223 return df
224
225 #invalid id field in client hello packet
226 @deferred(TLS_TIMEOUT)
227 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
228 df = defer.Deferred()
229 def eap_tls_with_invalid_id_in_client_hello_packet(df):
230 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700231 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700232 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
233 id_mismatch_in_client_hello_packet = True)
234 tls.runTest()
235 assert_equal(tls.failTest, True)
236 df.callback(0)
237 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
238 return df
239
240 @deferred(TLS_TIMEOUT)
241 def test_eap_tls_without_sending_client_hello(self):
242 df = defer.Deferred()
243 def eap_tls_without_sending_client_hello(df):
244 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700245 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700246 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
247 dont_send_client_hello = True)
248 tls.runTest()
249 assert_equal(tls.failTest, True)
250 df.callback(0)
251 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
252 return df
253
254 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800255 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700256 df = defer.Deferred()
257 def eap_tls_aaa_app_deactivate(df):
258 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700259 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700260 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
261 self.onos_ctrl.deactivate()
262 tls.runTest()
263 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800264 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700265 df.callback(0)
266 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
267 return df
268
269 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
270 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800271 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700272 df = defer.Deferred()
273 def eap_tls_incorrect_cipher_suite_length_field(df):
274 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700275 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700276 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
277 tls.runTest()
278 assert_equal(tls.failTest, True)
279 df.callback(0)
280 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
281 return df
282
283 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
284 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800285 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700286 df = defer.Deferred()
287 def eap_tls_incorrect_compression_methods_length_field(df):
288 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700289 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700290 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
291 tls.runTest()
292 assert_equal(tls.failTest, True)
293 df.callback(0)
294 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
295 return df
296
297 #checking with broadcast source mac of EAPOL packet
298 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800299 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700300 df = defer.Deferred()
301 def eap_tls_invalid_source_mac_broadcast(df):
302 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700303 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700304 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
305 tls.runTest()
306 assert_equal(tls.failTest, True)
307 df.callback(0)
308 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
309 return df
310
311 #checking with multicast source mac of EAPOL packet
312 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800313 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700314 df = defer.Deferred()
315 def eap_tls_invalid_source_mac_multicast(df):
316 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700317 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700318 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
319 tls.runTest()
320 assert_equal(tls.failTest, True)
321 df.callback(0)
322 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
323 return df
324
325 #checking with zero source mac of EAPOL packet
326 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800327 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700328 df = defer.Deferred()
329 def eap_tls_invalid_source_mac_zero(df):
330 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700331 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700332 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
333 tls.runTest()
334 assert_equal(tls.failTest, True)
335 df.callback(0)
336 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
337 return df
338
339 #Restarting Radius server after sending client hello
340 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800341 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700342 df = defer.Deferred()
343 def eap_tls_restart_radius_server(df):
344 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700345 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700346 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
347 tls.runTest()
348 assert_equal(tls.failTest, True)
349 df.callback(0)
350 reactor.callLater(0, eap_tls_restart_radius_server, df)
351 return df
352
353 @deferred(TLS_TIMEOUT)
354 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
355 df = defer.Deferred()
356 def eap_tls_incorrect_handshake_type_client_hello(df):
357 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700358 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700359 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
360 tls.runTest()
361 assert_equal(tls.failTest, True)
362 df.callback(0)
363 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
364 return df
365
366 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
367 @deferred(TLS_TIMEOUT)
368 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
369 df = defer.Deferred()
370 def eap_tls_incorrect_handshake_type_certificate_request(df):
371 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700372 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700373 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
374 tls.runTest()
375 assert_equal(tls.failTest, True)
376 df.callback(0)
377 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
378 return df
379
380 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
381 @deferred(TLS_TIMEOUT)
382 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
383 df = defer.Deferred()
384 def eap_tls_incorrect_tlsrecord_certificate_request(df):
385 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700386 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700387 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
388 tls.runTest()
389 assert_equal(tls.failTest, True)
390 df.callback(0)
391 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
392 return df
393
394 #Sending client hello with zero lenght field in Handshake protocol
395 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800396 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700397 df = defer.Deferred()
398 def eap_tls_invalid_handshake_length_client_hello(df):
399 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700400 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700401 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
402 tls.runTest()
403 assert_equal(tls.failTest, True)
404 df.callback(0)
405 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
406 return df
407
408 @deferred(TLS_TIMEOUT)
409 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
410 df = defer.Deferred()
411 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
412 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700413 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700414 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
415 tls.runTest()
416 assert_equal(tls.failTest, True)
417 df.callback(0)
418 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
419 return df
420
421 #simulating authentication for multiple users, 1K in this test case
422 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800423 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700424 df = defer.Deferred()
425 def eap_tls_1k_with_diff_mac(df):
426 for i in xrange(1000):
427 tls = TLSAuthTest(src_mac = 'random')
428 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700429 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700430 df.callback(0)
431 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
432 return df
433
434 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800435 @deferred(TEST_TIMEOUT+1800)
436 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700437 df = defer.Deferred()
438 def eap_tls_5k_with_diff_mac(df):
439 for i in xrange(5000):
440 tls = TLSAuthTest(src_mac = 'random')
441 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700442 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700443 df.callback(0)
444 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
445 return df
446
A R Karthick8f930292017-07-07 12:36:22 -0700447 def tls_scale(self, num_sessions):
448 '''Called from scale test'''
449 def tls_session_fail_cb():
450 pass
451 for i in xrange(num_sessions):
452 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
453 tls.runTest()
454 if tls.failTest is False:
455 log_test.info('Authentication successful for user %d'%i)
456 else:
457 log_test.info('Authentication failed for user %d' %i)
458
A R Karthicka2e53d62016-02-19 17:38:30 -0800459if __name__ == '__main__':
460 t = TLSAuthTest()
461 t.runTest()