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 | dd06463 | 2017-07-12 13:02:17 -0700 | [diff] [blame] | 26 | from CordTestConfig import setup_module, teardown_module |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 27 | from scapy.all import * |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 28 | from scapy_ssl_tls.ssl_tls import * |
| 29 | from scapy_ssl_tls.ssl_tls_crypto import * |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 30 | log_test.setLevel('INFO') |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 31 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 32 | class eap_auth_exchange(CordLogger): |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 33 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 34 | app = 'org.opencord.aaa' |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 35 | TLS_TIMEOUT = 20 |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 36 | TEST_TIMEOUT = 3600 |
A R Karthick | bf1e4b0 | 2017-07-11 20:17:14 -0700 | [diff] [blame] | 37 | 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 Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 43 | #this is from ca.pem file |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 44 | CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE----- |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 45 | MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD |
| 46 | VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE |
| 47 | CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw |
| 48 | JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw |
| 49 | MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC |
| 50 | Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG |
| 51 | CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 52 | cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 53 | ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB |
| 54 | 1zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ |
| 55 | QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG |
| 56 | 46DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo |
| 57 | of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm |
| 58 | CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH |
| 59 | zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS |
| 60 | b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH |
| 61 | DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW |
| 62 | D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB |
| 63 | dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 64 | oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 65 | hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA |
| 66 | QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM |
| 67 | iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR |
| 68 | +oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP |
| 69 | dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI |
| 70 | 7cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A= |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 71 | -----END CERTIFICATE-----''' |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 72 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 73 | 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 Karthick | bf1e4b0 | 2017-07-11 20:17:14 -0700 | [diff] [blame] | 84 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 85 | def setUp(self): |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 86 | super(eap_auth_exchange, self).setUp() |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 87 | self.onos_ctrl = OnosCtrl(self.app) |
| 88 | self.onos_aaa_config() |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 89 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 90 | def onos_aaa_config(self): |
A R Karthick | a652c4a | 2017-03-10 17:47:08 -0800 | [diff] [blame] | 91 | aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 92 | 'radiusIp': '172.17.0.2' } } } } |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 93 | 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] | 94 | aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 95 | self.onos_ctrl.activate() |
| 96 | time.sleep(2) |
| 97 | self.onos_load_config(aaa_dict) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 98 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 99 | def onos_load_config(self, config): |
| 100 | status, code = OnosCtrl.config(config) |
| 101 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 102 | log_test.info('Configure request for AAA returned status %d' %code) |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 103 | assert_equal(status, True) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 104 | time.sleep(3) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 105 | |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 106 | @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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 121 | log_test.info('TLS authentication failed with no certificate') |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 122 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 134 | log_test.info('TLS authentication failed with invalid certificate') |
ChetanGaonker | d43b7d4 | 2016-06-08 11:07:34 -0700 | [diff] [blame] | 135 | |
| 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 Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 155 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 156 | @deferred(TLS_TIMEOUT) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 157 | def test_eap_tls_with_invalid_session_id(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 158 | df = defer.Deferred() |
| 159 | def eap_tls_invalid_session_id(df): |
| 160 | def tls_invalid_session_id_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 161 | log_test.info('TLS authentication failed with invalid session id') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 162 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 170 | def test_eap_tls_with_random_gmt_unix_time(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 171 | df = defer.Deferred() |
| 172 | def eap_tls_invalid_gmt_unix_time(df): |
| 173 | def eap_tls_invalid_gmt_unix_time_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 174 | 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] | 175 | for i in [0,7265,98758,23627238]: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 176 | 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] | 177 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 185 | def test_eap_tls_with_invalid_content_type(self,Positive_Test=True): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 186 | df = defer.Deferred() |
| 187 | def eap_tls_invalid_content_type(df): |
| 188 | def tls_invalid_content_type_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 189 | log_test.info('TLS authentication failed with invalid content type in TLSContentType packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 190 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 198 | def test_eap_tls_with_invalid_record_fragment_length(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 199 | df = defer.Deferred() |
| 200 | def eap_tls_invalid_record_fragment_length(df): |
| 201 | def eap_tls_invalid_record_fragment_length_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 202 | 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] | 203 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 216 | log_test.info('TLS authentication failed with invalid id in identifier packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 217 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 231 | log_test.info('TLS authentication failed with invalid id in client hello packet') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 232 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 245 | log_test.info('TLS authentication failed with not sending client hello') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 246 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 255 | def test_eap_tls_with_aaa_app_deactivation(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 256 | df = defer.Deferred() |
| 257 | def eap_tls_aaa_app_deactivate(df): |
| 258 | def tls_aaa_app_deactivate_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 259 | log_test.info('TLS authentication failed with aaa app deactivated in ONOS') |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 260 | tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb) |
| 261 | self.onos_ctrl.deactivate() |
| 262 | tls.runTest() |
| 263 | assert_equal(tls.failTest, True) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 264 | self.onos_ctrl.activate() |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 265 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 271 | def test_eap_tls_with_incorrect_cipher_suite_length_field(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 272 | df = defer.Deferred() |
| 273 | def eap_tls_incorrect_cipher_suite_length_field(df): |
| 274 | def tls_incorrect_cipher_suite_length_field_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 275 | 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] | 276 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 285 | def test_eap_tls_with_incorrect_compression_methods_length_field(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 286 | df = defer.Deferred() |
| 287 | def eap_tls_incorrect_compression_methods_length_field(df): |
| 288 | def tls_incorrect_compression_methods_length_field_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 289 | 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] | 290 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 299 | def test_eap_tls_with_invalid_source_mac_broadcast(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 300 | df = defer.Deferred() |
| 301 | def eap_tls_invalid_source_mac_broadcast(df): |
| 302 | def tls_invalid_source_mac_broadcast_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 303 | 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] | 304 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 313 | def test_eap_tls_with_invalid_source_mac_multicast(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 314 | df = defer.Deferred() |
| 315 | def eap_tls_invalid_source_mac_multicast(df): |
| 316 | def tls_invalid_source_mac_multicast_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 317 | 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] | 318 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 327 | def test_eap_tls_with_invalid_source_mac_zero(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 328 | df = defer.Deferred() |
| 329 | def eap_tls_invalid_source_mac_zero(df): |
| 330 | def tls_invalid_source_mac_zero_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 331 | 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] | 332 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 341 | def test_eap_tls_with_restart_of_radius_server(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 342 | df = defer.Deferred() |
| 343 | def eap_tls_restart_radius_server(df): |
| 344 | def tls_restart_radius_server_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 345 | 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] | 346 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 358 | 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] | 359 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 372 | 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] | 373 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 386 | 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] | 387 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 396 | def test_eap_tls_with_invalid_handshake_length_client_hello(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 397 | df = defer.Deferred() |
| 398 | def eap_tls_invalid_handshake_length_client_hello(df): |
| 399 | def tls_invalid_handshake_length_client_hello_cb(): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 400 | 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] | 401 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 413 | 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] | 414 | 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) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 423 | def test_eap_tls_1k_sessions_with_diff_mac(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 424 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 429 | log_test.info('Authentication successfull for user %d'%i) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 430 | 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 |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 435 | @deferred(TEST_TIMEOUT+1800) |
| 436 | def test_eap_tls_5k_sessions_with_diff_mac(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 437 | 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 Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 442 | log_test.info('Authentication successfull for user %d'%i) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 443 | df.callback(0) |
| 444 | reactor.callLater(0, eap_tls_5k_with_diff_mac, df) |
| 445 | return df |
| 446 | |
A R Karthick | 8f93029 | 2017-07-07 12:36:22 -0700 | [diff] [blame] | 447 | 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 Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 459 | if __name__ == '__main__': |
| 460 | t = TLSAuthTest() |
| 461 | t.runTest() |