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