ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 1 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 2 | # 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 |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 7 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 9 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 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 | # |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 16 | import unittest |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 17 | import time |
| 18 | import os |
| 19 | from nose.tools import * |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 20 | from nose.twistedtools import reactor, deferred |
| 21 | from twisted.internet import defer |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 22 | from EapTLS import TLSAuthTest |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 23 | from OnosCtrl import OnosCtrl |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 24 | from CordLogger import CordLogger |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 25 | from CordTestUtils import log_test |
A R Karthick | bf1e4b0 | 2017-07-11 20:17:14 -0700 | [diff] [blame^] | 26 | from CordTestConfig import setup_module |
| 27 | from VolthaCtrl import VolthaCtrl, voltha_setup, voltha_teardown |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 28 | from scapy.all import * |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 29 | from scapy_ssl_tls.ssl_tls import * |
| 30 | from scapy_ssl_tls.ssl_tls_crypto import * |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 31 | log_test.setLevel('INFO') |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 32 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 33 | class eap_auth_exchange(CordLogger): |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 34 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 35 | app = 'org.opencord.aaa' |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 36 | TLS_TIMEOUT = 20 |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 37 | TEST_TIMEOUT = 3600 |
A R Karthick | bf1e4b0 | 2017-07-11 20:17:14 -0700 | [diff] [blame^] | 38 | 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' } |
| 44 | voltha_device = None |
| 45 | voltha_ctrl = None |
| 46 | voltha_switch_map = None |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 47 | #this is from ca.pem file |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 48 | CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE----- |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 49 | MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD |
| 50 | VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE |
| 51 | CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw |
| 52 | JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw |
| 53 | MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC |
| 54 | Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG |
| 55 | CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 56 | cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 57 | ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB |
| 58 | 1zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ |
| 59 | QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG |
| 60 | 46DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo |
| 61 | of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm |
| 62 | CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH |
| 63 | zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS |
| 64 | b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH |
| 65 | DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW |
| 66 | D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB |
| 67 | dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 68 | oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 69 | hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA |
| 70 | QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM |
| 71 | iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR |
| 72 | +oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP |
| 73 | dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI |
| 74 | 7cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A= |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 75 | -----END CERTIFICATE-----''' |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 76 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 77 | invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256', |
| 78 | 'TLS_RSA_WITH_AES_128_CBC_SHA', |
| 79 | 'TLS_RSA_WITH_AES_128_CBC_SHA256', |
| 80 | 'TLS_RSA_WITH_AES_256_CBC_SHA256', |
| 81 | 'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256', |
| 82 | 'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256', |
| 83 | 'TLS_DH_anon_WITH_AES_128_CBC_SHA256', |
| 84 | 'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256', |
| 85 | 'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256', |
| 86 | 'TLS_DH_anon_WITH_AES_256_CBC_SHA256'] |
| 87 | |
A R Karthick | bf1e4b0 | 2017-07-11 20:17:14 -0700 | [diff] [blame^] | 88 | |
| 89 | @classmethod |
| 90 | def setUpClass(cls): |
| 91 | #activate the device if voltha was enabled |
| 92 | if cls.VOLTHA_ENABLED is False or cls.VOLTHA_HOST is None: |
| 93 | return |
| 94 | ret = voltha_setup(host = cls.VOLTHA_HOST, |
| 95 | rest_port = cls.VOLTHA_REST_PORT, |
| 96 | olt_type = cls.VOLTHA_OLT_TYPE, |
| 97 | olt_mac = cls.VOLTHA_OLT_MAC, |
| 98 | uplink_vlan_map = cls.VOLTHA_UPLINK_VLAN_MAP) |
| 99 | if ret is not None: |
| 100 | cls.voltha_ctrl, cls.voltha_device, cls.voltha_switch_map = ret[0], ret[1], ret[2] |
| 101 | |
| 102 | @classmethod |
| 103 | def tearDownClass(cls): |
| 104 | if cls.voltha_ctrl and cls.voltha_device: |
| 105 | voltha_teardown(cls.voltha_ctrl, cls.voltha_device, cls.voltha_switch_map) |
| 106 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 107 | def setUp(self): |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 108 | super(eap_auth_exchange, self).setUp() |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 109 | self.onos_ctrl = OnosCtrl(self.app) |
| 110 | self.onos_aaa_config() |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 111 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 112 | def onos_aaa_config(self): |
A R Karthick | a652c4a | 2017-03-10 17:47:08 -0800 | [diff] [blame] | 113 | aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 114 | 'radiusIp': '172.17.0.2' } } } } |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 115 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
A R Karthick | a652c4a | 2017-03-10 17:47:08 -0800 | [diff] [blame] | 116 | aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 117 | self.onos_ctrl.activate() |
| 118 | time.sleep(2) |
| 119 | self.onos_load_config(aaa_dict) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 120 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 121 | def onos_load_config(self, config): |
| 122 | status, code = OnosCtrl.config(config) |
| 123 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 124 | log_test.info('Configure request for AAA returned status %d' %code) |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 125 | assert_equal(status, True) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 126 | time.sleep(3) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 127 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 128 | @deferred(TLS_TIMEOUT) |
| 129 | def test_eap_tls(self): |
| 130 | df = defer.Deferred() |
| 131 | def eap_tls_verify(df): |
| 132 | tls = TLSAuthTest() |
| 133 | tls.runTest() |
| 134 | df.callback(0) |
| 135 | reactor.callLater(0, eap_tls_verify, df) |
| 136 | return df |
| 137 | |
| 138 | @deferred(TLS_TIMEOUT) |
| 139 | def test_eap_tls_with_no_cert(self): |
| 140 | df = defer.Deferred() |
| 141 | def eap_tls_no_cert(df): |
| 142 | def tls_no_cert_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 143 | log_test.info('TLS authentication failed with no certificate') |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 144 | tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '') |
| 145 | tls.runTest() |
| 146 | assert_equal(tls.failTest, True) |
| 147 | df.callback(0) |
| 148 | reactor.callLater(0, eap_tls_no_cert, df) |
| 149 | return df |
| 150 | |
| 151 | @deferred(TLS_TIMEOUT) |
| 152 | def test_eap_tls_with_invalid_cert(self): |
| 153 | df = defer.Deferred() |
| 154 | def eap_tls_invalid_cert(df): |
| 155 | def tls_invalid_cert_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 156 | log_test.info('TLS authentication failed with invalid certificate') |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 157 | |
| 158 | tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, |
| 159 | client_cert = self.CLIENT_CERT_INVALID) |
| 160 | tls.runTest() |
| 161 | assert_equal(tls.failTest, True) |
| 162 | df.callback(0) |
| 163 | reactor.callLater(0, eap_tls_invalid_cert, df) |
| 164 | return df |
| 165 | |
| 166 | @deferred(TLS_TIMEOUT) |
| 167 | def test_eap_tls_Nusers_with_same_valid_cert(self): |
| 168 | df = defer.Deferred() |
| 169 | def eap_tls_Nusers_with_same_valid_cert(df): |
| 170 | num_users = 3 |
| 171 | for i in xrange(num_users): |
| 172 | tls = TLSAuthTest(intf = 'veth{}'.format(i*2)) |
| 173 | tls.runTest() |
| 174 | df.callback(0) |
| 175 | reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df) |
| 176 | return df |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 177 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 178 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 179 | def test_eap_tls_with_invalid_session_id(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 180 | df = defer.Deferred() |
| 181 | def eap_tls_invalid_session_id(df): |
| 182 | def tls_invalid_session_id_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 183 | log_test.info('TLS authentication failed with invalid session id') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 184 | tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1) |
| 185 | tls.runTest() |
| 186 | assert_equal(tls.failTest, True) |
| 187 | df.callback(0) |
| 188 | reactor.callLater(0, eap_tls_invalid_session_id, df) |
| 189 | return df |
| 190 | |
| 191 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 192 | def test_eap_tls_with_random_gmt_unix_time(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 193 | df = defer.Deferred() |
| 194 | def eap_tls_invalid_gmt_unix_time(df): |
| 195 | def eap_tls_invalid_gmt_unix_time_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 196 | log_test.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 197 | for i in [0,7265,98758,23627238]: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 198 | log_test.info("\nExecuting test case with gmt_unix_time value is set to %d"%i) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 199 | tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i) |
| 200 | tls.runTest() |
| 201 | assert_equal(tls.failTest, True) |
| 202 | df.callback(0) |
| 203 | reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df) |
| 204 | return df |
| 205 | |
| 206 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 207 | def test_eap_tls_with_invalid_content_type(self,Positive_Test=True): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 208 | df = defer.Deferred() |
| 209 | def eap_tls_invalid_content_type(df): |
| 210 | def tls_invalid_content_type_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 211 | log_test.info('TLS authentication failed with invalid content type in TLSContentType packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 212 | tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24) |
| 213 | tls.runTest() |
| 214 | assert_equal(tls.failTest, True) |
| 215 | df.callback(0) |
| 216 | reactor.callLater(0, eap_tls_invalid_content_type, df) |
| 217 | return df |
| 218 | |
| 219 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 220 | def test_eap_tls_with_invalid_record_fragment_length(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 221 | df = defer.Deferred() |
| 222 | def eap_tls_invalid_record_fragment_length(df): |
| 223 | def eap_tls_invalid_record_fragment_length_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 224 | log_test.info('TLS authentication failed with invalid fragment length field in TLSRecord packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 225 | tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384) |
| 226 | tls.runTest() |
| 227 | assert_equal(tls.failTest, True) |
| 228 | df.callback(0) |
| 229 | reactor.callLater(0, eap_tls_invalid_record_fragment_length, df) |
| 230 | return df |
| 231 | |
| 232 | #invalid id field in identifier response packet |
| 233 | @deferred(TLS_TIMEOUT) |
| 234 | def test_eap_tls_with_invalid_id_in_identifier_response_packet(self): |
| 235 | df = defer.Deferred() |
| 236 | def eap_tls_with_invalid_id_in_identifier_response_packet(df): |
| 237 | def tls_with_invalid_id_in_identifier_response_packet_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 238 | log_test.info('TLS authentication failed with invalid id in identifier packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 239 | tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb, |
| 240 | id_mismatch_in_identifier_response_packet = True) |
| 241 | tls.runTest() |
| 242 | assert_equal(tls.failTest, True) |
| 243 | df.callback(0) |
| 244 | reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df) |
| 245 | return df |
| 246 | |
| 247 | #invalid id field in client hello packet |
| 248 | @deferred(TLS_TIMEOUT) |
| 249 | def test_eap_tls_with_invalid_id_in_client_hello_packet(self): |
| 250 | df = defer.Deferred() |
| 251 | def eap_tls_with_invalid_id_in_client_hello_packet(df): |
| 252 | def tls_with_invalid_id_in_client_hello_packet_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 253 | log_test.info('TLS authentication failed with invalid id in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 254 | tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb, |
| 255 | id_mismatch_in_client_hello_packet = True) |
| 256 | tls.runTest() |
| 257 | assert_equal(tls.failTest, True) |
| 258 | df.callback(0) |
| 259 | reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df) |
| 260 | return df |
| 261 | |
| 262 | @deferred(TLS_TIMEOUT) |
| 263 | def test_eap_tls_without_sending_client_hello(self): |
| 264 | df = defer.Deferred() |
| 265 | def eap_tls_without_sending_client_hello(df): |
| 266 | def tls_without_sending_client_hello_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 267 | log_test.info('TLS authentication failed with not sending client hello') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 268 | tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb, |
| 269 | dont_send_client_hello = True) |
| 270 | tls.runTest() |
| 271 | assert_equal(tls.failTest, True) |
| 272 | df.callback(0) |
| 273 | reactor.callLater(0, eap_tls_without_sending_client_hello, df) |
| 274 | return df |
| 275 | |
| 276 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 277 | def test_eap_tls_with_aaa_app_deactivation(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 278 | df = defer.Deferred() |
| 279 | def eap_tls_aaa_app_deactivate(df): |
| 280 | def tls_aaa_app_deactivate_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 281 | log_test.info('TLS authentication failed with aaa app deactivated in ONOS') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 282 | tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb) |
| 283 | self.onos_ctrl.deactivate() |
| 284 | tls.runTest() |
| 285 | assert_equal(tls.failTest, True) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 286 | self.onos_ctrl.activate() |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 287 | df.callback(0) |
| 288 | reactor.callLater(0, eap_tls_aaa_app_deactivate, df) |
| 289 | return df |
| 290 | |
| 291 | #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet |
| 292 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 293 | def test_eap_tls_with_incorrect_cipher_suite_length_field(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 294 | df = defer.Deferred() |
| 295 | def eap_tls_incorrect_cipher_suite_length_field(df): |
| 296 | def tls_incorrect_cipher_suite_length_field_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 297 | log_test.info('TLS authentication failed with incorrect cipher suite length field in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 298 | tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0) |
| 299 | tls.runTest() |
| 300 | assert_equal(tls.failTest, True) |
| 301 | df.callback(0) |
| 302 | reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df) |
| 303 | return df |
| 304 | |
| 305 | #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet |
| 306 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 307 | def test_eap_tls_with_incorrect_compression_methods_length_field(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 308 | df = defer.Deferred() |
| 309 | def eap_tls_incorrect_compression_methods_length_field(df): |
| 310 | def tls_incorrect_compression_methods_length_field_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 311 | log_test.info('TLS authentication failed with incorrect compression methods length field in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 312 | tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS) |
| 313 | tls.runTest() |
| 314 | assert_equal(tls.failTest, True) |
| 315 | df.callback(0) |
| 316 | reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df) |
| 317 | return df |
| 318 | |
| 319 | #checking with broadcast source mac of EAPOL packet |
| 320 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 321 | def test_eap_tls_with_invalid_source_mac_broadcast(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 322 | df = defer.Deferred() |
| 323 | def eap_tls_invalid_source_mac_broadcast(df): |
| 324 | def tls_invalid_source_mac_broadcast_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 325 | log_test.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 326 | tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast') |
| 327 | tls.runTest() |
| 328 | assert_equal(tls.failTest, True) |
| 329 | df.callback(0) |
| 330 | reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df) |
| 331 | return df |
| 332 | |
| 333 | #checking with multicast source mac of EAPOL packet |
| 334 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 335 | def test_eap_tls_with_invalid_source_mac_multicast(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 336 | df = defer.Deferred() |
| 337 | def eap_tls_invalid_source_mac_multicast(df): |
| 338 | def tls_invalid_source_mac_multicast_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 339 | log_test.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 340 | tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast') |
| 341 | tls.runTest() |
| 342 | assert_equal(tls.failTest, True) |
| 343 | df.callback(0) |
| 344 | reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df) |
| 345 | return df |
| 346 | |
| 347 | #checking with zero source mac of EAPOL packet |
| 348 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 349 | def test_eap_tls_with_invalid_source_mac_zero(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 350 | df = defer.Deferred() |
| 351 | def eap_tls_invalid_source_mac_zero(df): |
| 352 | def tls_invalid_source_mac_zero_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 353 | log_test.info('TLS authentication failed with invalid source mac as zero in EAPOL packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 354 | tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros') |
| 355 | tls.runTest() |
| 356 | assert_equal(tls.failTest, True) |
| 357 | df.callback(0) |
| 358 | reactor.callLater(0, eap_tls_invalid_source_mac_zero, df) |
| 359 | return df |
| 360 | |
| 361 | #Restarting Radius server after sending client hello |
| 362 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 363 | def test_eap_tls_with_restart_of_radius_server(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 364 | df = defer.Deferred() |
| 365 | def eap_tls_restart_radius_server(df): |
| 366 | def tls_restart_radius_server_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 367 | log_test.info('TLS authentication failed with radius server down in middle of authentication process') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 368 | tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True) |
| 369 | tls.runTest() |
| 370 | assert_equal(tls.failTest, True) |
| 371 | df.callback(0) |
| 372 | reactor.callLater(0, eap_tls_restart_radius_server, df) |
| 373 | return df |
| 374 | |
| 375 | @deferred(TLS_TIMEOUT) |
| 376 | def test_eap_tls_with_incorrect_handshake_type_client_hello(self): |
| 377 | df = defer.Deferred() |
| 378 | def eap_tls_incorrect_handshake_type_client_hello(df): |
| 379 | def tls_incorrect_handshake_type_client_hello_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 380 | log_test.info('TLS authentication failed with incorrect handshake type in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 381 | tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True) |
| 382 | tls.runTest() |
| 383 | assert_equal(tls.failTest, True) |
| 384 | df.callback(0) |
| 385 | reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df) |
| 386 | return df |
| 387 | |
| 388 | #Sending certificate request type of handhsake instead of certificate verify in client certificate request message |
| 389 | @deferred(TLS_TIMEOUT) |
| 390 | def test_eap_tls_with_incorrect_handshake_type_certificate_request(self): |
| 391 | df = defer.Deferred() |
| 392 | def eap_tls_incorrect_handshake_type_certificate_request(df): |
| 393 | def tls_incorrect_handshake_type_certificate_request_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 394 | log_test.info('TLS authentication failed with incorrect handshake type in client certificate request packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 395 | tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True) |
| 396 | tls.runTest() |
| 397 | assert_equal(tls.failTest, True) |
| 398 | df.callback(0) |
| 399 | reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df) |
| 400 | return df |
| 401 | |
| 402 | #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet |
| 403 | @deferred(TLS_TIMEOUT) |
| 404 | def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self): |
| 405 | df = defer.Deferred() |
| 406 | def eap_tls_incorrect_tlsrecord_certificate_request(df): |
| 407 | def tls_incorrect_tlsrecord_certificate_request_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 408 | log_test.info('TLS authentication failed with incorrect tlsrecord type in certificate request packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 409 | tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True) |
| 410 | tls.runTest() |
| 411 | assert_equal(tls.failTest, True) |
| 412 | df.callback(0) |
| 413 | reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df) |
| 414 | return df |
| 415 | |
| 416 | #Sending client hello with zero lenght field in Handshake protocol |
| 417 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 418 | def test_eap_tls_with_invalid_handshake_length_client_hello(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 419 | df = defer.Deferred() |
| 420 | def eap_tls_invalid_handshake_length_client_hello(df): |
| 421 | def tls_invalid_handshake_length_client_hello_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 422 | log_test.info('TLS authentication failed with invalid handshake length in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 423 | tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True) |
| 424 | tls.runTest() |
| 425 | assert_equal(tls.failTest, True) |
| 426 | df.callback(0) |
| 427 | reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df) |
| 428 | return df |
| 429 | |
| 430 | @deferred(TLS_TIMEOUT) |
| 431 | def test_eap_tls_clientkeyex_replace_with_serverkeyex(self): |
| 432 | df = defer.Deferred() |
| 433 | def eap_tls_clientkeyex_replace_with_serverkeyex(df): |
| 434 | def tls_clientkeyex_replace_with_serverkeyex_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 435 | log_test.info('TLS authentication failed with client key exchange replaced with server key exchange') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 436 | tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True) |
| 437 | tls.runTest() |
| 438 | assert_equal(tls.failTest, True) |
| 439 | df.callback(0) |
| 440 | reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df) |
| 441 | return df |
| 442 | |
| 443 | #simulating authentication for multiple users, 1K in this test case |
| 444 | @deferred(TEST_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 445 | def test_eap_tls_1k_sessions_with_diff_mac(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 446 | df = defer.Deferred() |
| 447 | def eap_tls_1k_with_diff_mac(df): |
| 448 | for i in xrange(1000): |
| 449 | tls = TLSAuthTest(src_mac = 'random') |
| 450 | tls.runTest() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 451 | log_test.info('Authentication successfull for user %d'%i) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 452 | df.callback(0) |
| 453 | reactor.callLater(0, eap_tls_1k_with_diff_mac, df) |
| 454 | return df |
| 455 | |
| 456 | #simulating authentication for multiple users, 5K in this test case |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 457 | @deferred(TEST_TIMEOUT+1800) |
| 458 | def test_eap_tls_5k_sessions_with_diff_mac(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 459 | df = defer.Deferred() |
| 460 | def eap_tls_5k_with_diff_mac(df): |
| 461 | for i in xrange(5000): |
| 462 | tls = TLSAuthTest(src_mac = 'random') |
| 463 | tls.runTest() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 464 | log_test.info('Authentication successfull for user %d'%i) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 465 | df.callback(0) |
| 466 | reactor.callLater(0, eap_tls_5k_with_diff_mac, df) |
| 467 | return df |
| 468 | |
A R Karthick | 8f93029 | 2017-07-07 12:36:22 -0700 | [diff] [blame] | 469 | def tls_scale(self, num_sessions): |
| 470 | '''Called from scale test''' |
| 471 | def tls_session_fail_cb(): |
| 472 | pass |
| 473 | for i in xrange(num_sessions): |
| 474 | tls = TLSAuthTest(src_mac = 'random', fail_cb = tls_session_fail_cb) |
| 475 | tls.runTest() |
| 476 | if tls.failTest is False: |
| 477 | log_test.info('Authentication successful for user %d'%i) |
| 478 | else: |
| 479 | log_test.info('Authentication failed for user %d' %i) |
| 480 | |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 481 | if __name__ == '__main__': |
| 482 | t = TLSAuthTest() |
| 483 | t.runTest() |