blob: 3417b1f4ea287bfb1710e6473e76e34d2e3c1272 [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
27from VolthaCtrl import VolthaCtrl
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070028from scapy.all import *
ChetanGaonker6138fcd2016-08-18 17:56:39 -070029from scapy_ssl_tls.ssl_tls import *
30from scapy_ssl_tls.ssl_tls_crypto import *
A R Karthick76a497a2017-04-12 10:59:39 -070031log_test.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080032
A R Karthick9313b762016-11-07 13:14:35 -080033class eap_auth_exchange(CordLogger):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080034
A.R Karthick95d044e2016-06-10 18:44:36 -070035 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070036 TLS_TIMEOUT = 20
ChetanGaonker6138fcd2016-08-18 17:56:39 -070037 TEST_TIMEOUT = 3600
A R Karthickbf1e4b02017-07-11 20:17:14 -070038 VOLTHA_HOST = None
39 VOLTHA_REST_PORT = 8881
40 VOLTHA_ENABLED = bool(int(os.getenv('VOLTHA_ENABLED', 0)))
41 VOLTHA_OLT_TYPE = 'simulated_olt'
42 VOLTHA_OLT_MAC = '00:0c:e2:31:12:00'
43 VOLTHA_UPLINK_VLAN_MAP = { 'of:0000000000000001' : '222' }
A R Karthickeeac7e12017-03-10 17:35:39 -080044 #this is from ca.pem file
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070045 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
A R Karthickeeac7e12017-03-10 17:35:39 -080046MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
47VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
48CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
49JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
50MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
51Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
52CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
A R Karthickaa10a202016-08-15 15:06:21 -070053cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
A R Karthickeeac7e12017-03-10 17:35:39 -080054ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
551zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
56QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
5746DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
58of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
59CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
60zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
61b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
62DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
63D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
64dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
A R Karthickaa10a202016-08-15 15:06:21 -070065oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
A R Karthickeeac7e12017-03-10 17:35:39 -080066hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
67QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
68iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
69+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
70dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
717cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070072-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080073
ChetanGaonker6138fcd2016-08-18 17:56:39 -070074 invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
75 'TLS_RSA_WITH_AES_128_CBC_SHA',
76 'TLS_RSA_WITH_AES_128_CBC_SHA256',
77 'TLS_RSA_WITH_AES_256_CBC_SHA256',
78 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
79 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
80 'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
81 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
82 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
83 'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
84
A R Karthickbf1e4b02017-07-11 20:17:14 -070085
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070086 def setUp(self):
A R Karthick9313b762016-11-07 13:14:35 -080087 super(eap_auth_exchange, self).setUp()
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070088 self.onos_ctrl = OnosCtrl(self.app)
89 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080090
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070091 def onos_aaa_config(self):
A R Karthicka652c4a2017-03-10 17:47:08 -080092 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
93 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070094 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A R Karthicka652c4a2017-03-10 17:47:08 -080095 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070096 self.onos_ctrl.activate()
97 time.sleep(2)
98 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080099
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700100 def onos_load_config(self, config):
101 status, code = OnosCtrl.config(config)
102 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700103 log_test.info('Configure request for AAA returned status %d' %code)
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700104 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -0700105 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -0700106
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700107 @deferred(TLS_TIMEOUT)
108 def test_eap_tls(self):
109 df = defer.Deferred()
110 def eap_tls_verify(df):
111 tls = TLSAuthTest()
112 tls.runTest()
113 df.callback(0)
114 reactor.callLater(0, eap_tls_verify, df)
115 return df
116
117 @deferred(TLS_TIMEOUT)
118 def test_eap_tls_with_no_cert(self):
119 df = defer.Deferred()
120 def eap_tls_no_cert(df):
121 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700122 log_test.info('TLS authentication failed with no certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700123 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
124 tls.runTest()
125 assert_equal(tls.failTest, True)
126 df.callback(0)
127 reactor.callLater(0, eap_tls_no_cert, df)
128 return df
129
130 @deferred(TLS_TIMEOUT)
131 def test_eap_tls_with_invalid_cert(self):
132 df = defer.Deferred()
133 def eap_tls_invalid_cert(df):
134 def tls_invalid_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700135 log_test.info('TLS authentication failed with invalid certificate')
ChetanGaonkerd43b7d42016-06-08 11:07:34 -0700136
137 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
138 client_cert = self.CLIENT_CERT_INVALID)
139 tls.runTest()
140 assert_equal(tls.failTest, True)
141 df.callback(0)
142 reactor.callLater(0, eap_tls_invalid_cert, df)
143 return df
144
145 @deferred(TLS_TIMEOUT)
146 def test_eap_tls_Nusers_with_same_valid_cert(self):
147 df = defer.Deferred()
148 def eap_tls_Nusers_with_same_valid_cert(df):
149 num_users = 3
150 for i in xrange(num_users):
151 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
152 tls.runTest()
153 df.callback(0)
154 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
155 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800156
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700157 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800158 def test_eap_tls_with_invalid_session_id(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700159 df = defer.Deferred()
160 def eap_tls_invalid_session_id(df):
161 def tls_invalid_session_id_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700162 log_test.info('TLS authentication failed with invalid session id')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700163 tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
164 tls.runTest()
165 assert_equal(tls.failTest, True)
166 df.callback(0)
167 reactor.callLater(0, eap_tls_invalid_session_id, df)
168 return df
169
170 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800171 def test_eap_tls_with_random_gmt_unix_time(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700172 df = defer.Deferred()
173 def eap_tls_invalid_gmt_unix_time(df):
174 def eap_tls_invalid_gmt_unix_time_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700175 log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700176 for i in [0,7265,98758,23627238]:
A R Karthick76a497a2017-04-12 10:59:39 -0700177 log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700178 tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
179 tls.runTest()
180 assert_equal(tls.failTest, True)
181 df.callback(0)
182 reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
183 return df
184
185 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800186 def test_eap_tls_with_invalid_content_type(self,Positive_Test=True):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700187 df = defer.Deferred()
188 def eap_tls_invalid_content_type(df):
189 def tls_invalid_content_type_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700190 log_test.info('TLS authentication failed with invalid content type in TLSContentType packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700191 tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
192 tls.runTest()
193 assert_equal(tls.failTest, True)
194 df.callback(0)
195 reactor.callLater(0, eap_tls_invalid_content_type, df)
196 return df
197
198 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800199 def test_eap_tls_with_invalid_record_fragment_length(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700200 df = defer.Deferred()
201 def eap_tls_invalid_record_fragment_length(df):
202 def eap_tls_invalid_record_fragment_length_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700203 log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700204 tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
205 tls.runTest()
206 assert_equal(tls.failTest, True)
207 df.callback(0)
208 reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
209 return df
210
211 #invalid id field in identifier response packet
212 @deferred(TLS_TIMEOUT)
213 def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
214 df = defer.Deferred()
215 def eap_tls_with_invalid_id_in_identifier_response_packet(df):
216 def tls_with_invalid_id_in_identifier_response_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700217 log_test.info('TLS authentication failed with invalid id in identifier packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700218 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
219 id_mismatch_in_identifier_response_packet = True)
220 tls.runTest()
221 assert_equal(tls.failTest, True)
222 df.callback(0)
223 reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
224 return df
225
226 #invalid id field in client hello packet
227 @deferred(TLS_TIMEOUT)
228 def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
229 df = defer.Deferred()
230 def eap_tls_with_invalid_id_in_client_hello_packet(df):
231 def tls_with_invalid_id_in_client_hello_packet_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700232 log_test.info('TLS authentication failed with invalid id in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700233 tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
234 id_mismatch_in_client_hello_packet = True)
235 tls.runTest()
236 assert_equal(tls.failTest, True)
237 df.callback(0)
238 reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
239 return df
240
241 @deferred(TLS_TIMEOUT)
242 def test_eap_tls_without_sending_client_hello(self):
243 df = defer.Deferred()
244 def eap_tls_without_sending_client_hello(df):
245 def tls_without_sending_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700246 log_test.info('TLS authentication failed with not sending client hello')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700247 tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
248 dont_send_client_hello = True)
249 tls.runTest()
250 assert_equal(tls.failTest, True)
251 df.callback(0)
252 reactor.callLater(0, eap_tls_without_sending_client_hello, df)
253 return df
254
255 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800256 def test_eap_tls_with_aaa_app_deactivation(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700257 df = defer.Deferred()
258 def eap_tls_aaa_app_deactivate(df):
259 def tls_aaa_app_deactivate_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700260 log_test.info('TLS authentication failed with aaa app deactivated in ONOS')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700261 tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
262 self.onos_ctrl.deactivate()
263 tls.runTest()
264 assert_equal(tls.failTest, True)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800265 self.onos_ctrl.activate()
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700266 df.callback(0)
267 reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
268 return df
269
270 #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
271 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800272 def test_eap_tls_with_incorrect_cipher_suite_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700273 df = defer.Deferred()
274 def eap_tls_incorrect_cipher_suite_length_field(df):
275 def tls_incorrect_cipher_suite_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700276 log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700277 tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
278 tls.runTest()
279 assert_equal(tls.failTest, True)
280 df.callback(0)
281 reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
282 return df
283
284 #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
285 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800286 def test_eap_tls_with_incorrect_compression_methods_length_field(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700287 df = defer.Deferred()
288 def eap_tls_incorrect_compression_methods_length_field(df):
289 def tls_incorrect_compression_methods_length_field_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700290 log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700291 tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
292 tls.runTest()
293 assert_equal(tls.failTest, True)
294 df.callback(0)
295 reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
296 return df
297
298 #checking with broadcast source mac of EAPOL packet
299 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800300 def test_eap_tls_with_invalid_source_mac_broadcast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700301 df = defer.Deferred()
302 def eap_tls_invalid_source_mac_broadcast(df):
303 def tls_invalid_source_mac_broadcast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700304 log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700305 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
306 tls.runTest()
307 assert_equal(tls.failTest, True)
308 df.callback(0)
309 reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
310 return df
311
312 #checking with multicast source mac of EAPOL packet
313 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800314 def test_eap_tls_with_invalid_source_mac_multicast(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700315 df = defer.Deferred()
316 def eap_tls_invalid_source_mac_multicast(df):
317 def tls_invalid_source_mac_multicast_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700318 log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700319 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
320 tls.runTest()
321 assert_equal(tls.failTest, True)
322 df.callback(0)
323 reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
324 return df
325
326 #checking with zero source mac of EAPOL packet
327 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800328 def test_eap_tls_with_invalid_source_mac_zero(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700329 df = defer.Deferred()
330 def eap_tls_invalid_source_mac_zero(df):
331 def tls_invalid_source_mac_zero_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700332 log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700333 tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
334 tls.runTest()
335 assert_equal(tls.failTest, True)
336 df.callback(0)
337 reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
338 return df
339
340 #Restarting Radius server after sending client hello
341 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800342 def test_eap_tls_with_restart_of_radius_server(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700343 df = defer.Deferred()
344 def eap_tls_restart_radius_server(df):
345 def tls_restart_radius_server_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700346 log_test.info('TLS authentication failed with radius server down in middle of authentication process')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700347 tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
348 tls.runTest()
349 assert_equal(tls.failTest, True)
350 df.callback(0)
351 reactor.callLater(0, eap_tls_restart_radius_server, df)
352 return df
353
354 @deferred(TLS_TIMEOUT)
355 def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
356 df = defer.Deferred()
357 def eap_tls_incorrect_handshake_type_client_hello(df):
358 def tls_incorrect_handshake_type_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700359 log_test.info('TLS authentication failed with incorrect handshake type in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700360 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
361 tls.runTest()
362 assert_equal(tls.failTest, True)
363 df.callback(0)
364 reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
365 return df
366
367 #Sending certificate request type of handhsake instead of certificate verify in client certificate request message
368 @deferred(TLS_TIMEOUT)
369 def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
370 df = defer.Deferred()
371 def eap_tls_incorrect_handshake_type_certificate_request(df):
372 def tls_incorrect_handshake_type_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700373 log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700374 tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
375 tls.runTest()
376 assert_equal(tls.failTest, True)
377 df.callback(0)
378 reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
379 return df
380
381 #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
382 @deferred(TLS_TIMEOUT)
383 def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
384 df = defer.Deferred()
385 def eap_tls_incorrect_tlsrecord_certificate_request(df):
386 def tls_incorrect_tlsrecord_certificate_request_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700387 log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700388 tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
389 tls.runTest()
390 assert_equal(tls.failTest, True)
391 df.callback(0)
392 reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
393 return df
394
395 #Sending client hello with zero lenght field in Handshake protocol
396 @deferred(TLS_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800397 def test_eap_tls_with_invalid_handshake_length_client_hello(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700398 df = defer.Deferred()
399 def eap_tls_invalid_handshake_length_client_hello(df):
400 def tls_invalid_handshake_length_client_hello_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700401 log_test.info('TLS authentication failed with invalid handshake length in client hello packet')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700402 tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
403 tls.runTest()
404 assert_equal(tls.failTest, True)
405 df.callback(0)
406 reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
407 return df
408
409 @deferred(TLS_TIMEOUT)
410 def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
411 df = defer.Deferred()
412 def eap_tls_clientkeyex_replace_with_serverkeyex(df):
413 def tls_clientkeyex_replace_with_serverkeyex_cb():
A R Karthick76a497a2017-04-12 10:59:39 -0700414 log_test.info('TLS authentication failed with client key exchange replaced with server key exchange')
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700415 tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
416 tls.runTest()
417 assert_equal(tls.failTest, True)
418 df.callback(0)
419 reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
420 return df
421
422 #simulating authentication for multiple users, 1K in this test case
423 @deferred(TEST_TIMEOUT)
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800424 def test_eap_tls_1k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700425 df = defer.Deferred()
426 def eap_tls_1k_with_diff_mac(df):
427 for i in xrange(1000):
428 tls = TLSAuthTest(src_mac = 'random')
429 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700430 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700431 df.callback(0)
432 reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
433 return df
434
435 #simulating authentication for multiple users, 5K in this test case
ChetanGaonkere2b665b2016-12-07 00:50:56 -0800436 @deferred(TEST_TIMEOUT+1800)
437 def test_eap_tls_5k_sessions_with_diff_mac(self):
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700438 df = defer.Deferred()
439 def eap_tls_5k_with_diff_mac(df):
440 for i in xrange(5000):
441 tls = TLSAuthTest(src_mac = 'random')
442 tls.runTest()
A R Karthick76a497a2017-04-12 10:59:39 -0700443 log_test.info('Authentication successfull for user %d'%i)
ChetanGaonker6138fcd2016-08-18 17:56:39 -0700444 df.callback(0)
445 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
446 return df
447
A R Karthick8f930292017-07-07 12:36:22 -0700448 def tls_scale(self, num_sessions):
449 '''Called from scale test'''
450 def tls_session_fail_cb():
451 pass
452 for i in xrange(num_sessions):
453 tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb)
454 tls.runTest()
455 if tls.failTest is False:
456 log_test.info('Authentication successful for user %d'%i)
457 else:
458 log_test.info('Authentication failed for user %d' %i)
459
A R Karthicka2e53d62016-02-19 17:38:30 -0800460if __name__ == '__main__':
461 t = TLSAuthTest()
462 t.runTest()