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