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