A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -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 |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -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 |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -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 sys, os |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 17 | from EapolAAA import * |
| 18 | from enum import * |
| 19 | import noseTlsAuthHolder as tlsAuthHolder |
| 20 | from scapy_ssl_tls.ssl_tls import * |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 21 | from scapy_ssl_tls.ssl_tls_crypto import * |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 22 | from tls_cert import Key |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 23 | from socket import * |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 24 | from CordTestServer import cord_test_radius_restart |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 25 | import struct |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 26 | import scapy |
| 27 | from nose.tools import * |
| 28 | from CordTestBase import CordTester |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 29 | from CordContainer import * |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 30 | import re |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 31 | import time |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 32 | |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 33 | log.setLevel('INFO') |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 34 | |
| 35 | def bytes_to_num(data): |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 36 | try: |
| 37 | return int(data.encode('hex'), 16) |
| 38 | except: |
| 39 | print('Exception') |
| 40 | return -1 |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 41 | |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 42 | class TLSAuthTest(EapolPacket, CordTester): |
| 43 | |
| 44 | tlsStateTable = Enumeration("TLSStateTable", ("ST_EAP_SETUP", |
| 45 | "ST_EAP_START", |
| 46 | "ST_EAP_ID_REQ", |
| 47 | "ST_EAP_TLS_HELLO_REQ", |
| 48 | "ST_EAP_TLS_CERT_REQ", |
Chetan Gaonker | f8f7718 | 2016-03-11 15:34:57 -0800 | [diff] [blame] | 49 | "ST_EAP_TLS_CHANGE_CIPHER_SPEC", |
| 50 | "ST_EAP_TLS_FINISHED", |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 51 | "ST_EAP_TLS_DONE" |
| 52 | ) |
| 53 | ) |
| 54 | tlsEventTable = Enumeration("TLSEventTable", ("EVT_EAP_SETUP", |
| 55 | "EVT_EAP_START", |
| 56 | "EVT_EAP_ID_REQ", |
| 57 | "EVT_EAP_TLS_HELLO_REQ", |
| 58 | "EVT_EAP_TLS_CERT_REQ", |
Chetan Gaonker | f8f7718 | 2016-03-11 15:34:57 -0800 | [diff] [blame] | 59 | "EVT_EAP_TLS_CHANGE_CIPHER_SPEC", |
| 60 | "EVT_EAP_TLS_FINISHED", |
A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 61 | "EVT_EAP_TLS_DONE" |
| 62 | ) |
| 63 | ) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 64 | server_hello_done_signature = '\x0e\x00\x00\x00' |
| 65 | SERVER_HELLO = '\x02' |
| 66 | SERVER_CERTIFICATE = '\x0b' |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 67 | CERTIFICATE_REQUEST = '\x0d' |
| 68 | SERVER_HELLO_DONE = '\x0e' |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 69 | SERVER_UNKNOWN = '\xff' |
| 70 | HANDSHAKE = '\x16' |
| 71 | CHANGE_CIPHER = '\x14' |
| 72 | TLS_OFFSET = 28 |
| 73 | HDR_IDX = 0 |
| 74 | DATA_IDX = 1 |
| 75 | CB_IDX = 2 |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 76 | |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 77 | #this is from client.crt file |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 78 | CLIENT_CERT = """-----BEGIN CERTIFICATE----- |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 79 | MIIDvTCCAqWgAwIBAgIBBjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx |
| 80 | CzAJBgNVBAgMAkNBMRIwEAYDVQQHDAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5h |
| 81 | IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwd |
| 82 | RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTcwMzExMDA0NzQ0WhcN |
| 83 | MjIxMDMxMDA0NzQ0WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExEzARBgNV |
| 84 | BAoMCkNpZW5hIEluYy4xFzAVBgNVBAMMDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 85 | hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 86 | AQoCggEBAOTxi5+TUuaosUh7f/4U9unLV3qHCC7Sf3e0o8F+FP4BVQiIslUTEupw |
| 87 | gd3VkiVAhxX74Oc3w7XF98msKx7dTetpQaZPZgEgGiDmzGzlAGkwqD4FO5JotJMg |
| 88 | I0rpcYw+M/z+WDVgJx3I+VGyC6lFKhIJWTlTySheyMYpcgSvOuN4z8keCNg2uaRZ |
| 89 | IOvIf6aUCTF7fp2HC/468/3T6R/VuYKFNdpsyU1ogbQqCUL4WHM2uWz6G7rzXI0/ |
| 90 | skkKemoGouFw+0I3ydPpGpiWK4NpPKHax4dRGaO1NmTDCtrJOAKPQx8CYYH0HMNp |
| 91 | BbYvidTnHBxYUBrWNpzOJ/xgopawA8kCAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB |
A R Karthick | aa10a20 | 2016-08-15 15:06:21 -0700 | [diff] [blame] | 92 | BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 93 | eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAosa5wV/RA2XO/SVGWx5K |
| 94 | JkQNBn6zKuLRODdkm1UwpkdSZpYoXw2ds6YPPbxV9gFeitCcPZQUho38Fg1LYrNW |
| 95 | 9UsDPC2HAYSxrvCinTLC2NuqLsPj7NSu+41l37hGVG4WTjPXPqet33e0mqz1eYVn |
| 96 | 3SsGvZl98sgG6ADD1RqUb0gpEocmoN+yx5W0hIAwZQPBt4nfAWdGH9AcJTL/Gjr7 |
| 97 | 5m4p3cQYm2AnROp+Bim4AELv02WIl77vYWivlzok1JfZ38GL94+CMLOSKNv9OLjc |
| 98 | M/uh5Q6PB+4xv8kAjmO/Fq9T6f0KcQNNPY63omZCjrFiMEMvoOD4GIg+WV2SKLsQ |
| 99 | 0g== |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 100 | -----END CERTIFICATE-----""" |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 101 | |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 102 | #this is from client.key |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 103 | CLIENT_PRIV_KEY = """-----BEGIN RSA PRIVATE KEY----- |
A R Karthick | eeac7e1 | 2017-03-10 17:35:39 -0800 | [diff] [blame] | 104 | MIIEowIBAAKCAQEA5PGLn5NS5qixSHt//hT26ctXeocILtJ/d7SjwX4U/gFVCIiy |
| 105 | VRMS6nCB3dWSJUCHFfvg5zfDtcX3yawrHt1N62lBpk9mASAaIObMbOUAaTCoPgU7 |
| 106 | kmi0kyAjSulxjD4z/P5YNWAnHcj5UbILqUUqEglZOVPJKF7IxilyBK8643jPyR4I |
| 107 | 2Da5pFkg68h/ppQJMXt+nYcL/jrz/dPpH9W5goU12mzJTWiBtCoJQvhYcza5bPob |
| 108 | uvNcjT+ySQp6agai4XD7QjfJ0+kamJYrg2k8odrHh1EZo7U2ZMMK2sk4Ao9DHwJh |
| 109 | gfQcw2kFti+J1OccHFhQGtY2nM4n/GCilrADyQIDAQABAoIBAF+xepvDl3Yj8p4K |
| 110 | SPBp0N7eCH2FbW0svOzLC1t4GMwmwGUlxex7YX+ucQnJGCIL+6q7skDS9THIQo8A |
| 111 | MLHg7I3GXBNowokb4u/3qGCnw2k0Vk4+H61NqJSKbVYFh1mIMnC/2xzMSO1RMKzu |
| 112 | D6O77h7F245zr/P40lDJyAefOq0S6sgZqxmHmoRTHhp0tXV4mkzV7P7RqoJrvAiG |
| 113 | tGMk5OfdoILnNfoeXNC50nw201UK7xhrrqqlAWZRAaUZJtsb1GxW+jOra6OtsCVg |
| 114 | AKS/FxzUGMsoqluM5mHLBEN69DAvBBs8g7UVKdmCDZC+feJ31eAnPAoc1gxBHdQU |
| 115 | pCnA8dECgYEA+Q6X80gnoyG0g66Gh62R7RgDLYPpgkZimLeoX49mwizAUkeSf/Mj |
| 116 | raVajRmJ8J1n4UklHdQe0PE9Jhuxo4Uo9sP71ZqpQPEvN35/Sw0xxQHcwxD73SWa |
| 117 | UEVsnWIDJ6QrkoBOhjDMM6tyDSPVDS23352E6sZ9EU45qWvncb5OTdUCgYEA61Np |
| 118 | Qs/CpEWtPG8IiEPKPEWUEwoO8SS6C4R/UfXNC96GhfIpA4Uy3fQwTUtHEMPL+7lh |
| 119 | SPFPQDBH90jOTYg30EfHiBMlKW4l21XS+PotTP3ktqZMgx06SnoM2a/+crpzFqkb |
| 120 | i4eAPCsdTispElbtqleLuUbFO9aG3jHMsK2RtCUCgYB04G9YYL0RJgkTXryNQVvg |
| 121 | ussK+gOD+kncxxtBtQcRCnU6Z5INb2mH3LgwzRJZk1SjeXLsm5XWkc8Tah2j0iKW |
| 122 | IwS0if7xlf2Felx8OPXpMOWLuRWpAzN2hg3hkZRPbxBvkLzI5m99s/Ay0GTz6UeH |
| 123 | reEpV/prO519r0COtTMD/QKBgCdRinbVS8oysh002BIccX/ciD8eIRz9a/BctQE2 |
| 124 | tonTJlre+SdTbApVsHRZrYgJjt2CPdT4LKum5X9VtNKTfe/Y7me3+y+O7dhV4Kgk |
| 125 | 9Mi2ay5xXrtReNnUxqzgkP0OVghlPOr1OuHSulTDNVuRFqitc/UC9BVpZKNfYrnq |
| 126 | ZjvZAoGBALzgzXajgIdhghCt5PFLkhh3xyOliTXWFstHcMZdQF2wQyeF/uQ2zrC/ |
| 127 | 2t1Sa+egV3QDUPYzW9YLQs9eaLh7MS9wCHLY2SMElAqYiNjRfkT4wWdPfeyFx4+E |
| 128 | Euwtu+lPJ7sEpNu5jX63OS2AeZsQYlsT0Ai+lB4TeyoE6Pj04iC0 |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 129 | -----END RSA PRIVATE KEY-----""" |
| 130 | |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 131 | def handle_server_hello_done(self, server_hello_done): |
| 132 | if server_hello_done[-4:] == self.server_hello_done_signature: |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 133 | log.info('server hello received') |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 134 | self.server_hello_done_received = True |
| 135 | |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 136 | def __init__(self, intf = 'veth0', client_cert = None, client_priv_key = None, |
| 137 | fail_cb = None, src_mac='default', version = "TLS_1_0", session_id = '', |
| 138 | session_id_length = None, gmt_unix_time=1234, invalid_content_type = 22, |
| 139 | record_fragment_length = None, cipher_suites_length = None, |
| 140 | compression_methods_length = None, compression_methods = TLSCompressionMethod.NULL, |
| 141 | CipherSuite = True, cipher_suite = 'RSA_WITH_AES_256_CBC_SHA', id_mismatch_in_identifier_response_packet = False, |
| 142 | id_mismatch_in_client_hello_packet = False , dont_send_client_certificate = False, |
| 143 | dont_send_client_hello = False, restart_radius = False, invalid_client_hello_handshake_type = False, |
| 144 | invalid_cert_req_handshake = False, incorrect_tlsrecord_type_cert_req = False, |
| 145 | invalid_client_hello_handshake_length = False, clientkeyex_replace_with_serverkeyex = False): |
| 146 | |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 147 | self.fsmTable = tlsAuthHolder.initTlsAuthHolderFsmTable(self, self.tlsStateTable, self.tlsEventTable) |
| 148 | EapolPacket.__init__(self, intf) |
| 149 | CordTester.__init__(self, self.fsmTable, self.tlsStateTable.ST_EAP_TLS_DONE) |
| 150 | #self.tlsStateTable, self.tlsEventTable) |
| 151 | self.currentState = self.tlsStateTable.ST_EAP_SETUP |
| 152 | self.currentEvent = self.tlsEventTable.EVT_EAP_SETUP |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 153 | self.src_mac = src_mac |
| 154 | self.version = version |
| 155 | self.session_id_length = session_id_length |
| 156 | self.session_id = session_id |
| 157 | self.gmt_unix_time = gmt_unix_time |
| 158 | self.invalid_content_type = invalid_content_type |
| 159 | self.CipherSuite = CipherSuite |
| 160 | self.cipher_suites_length = cipher_suites_length |
| 161 | self.compression_methods_length = compression_methods_length |
| 162 | self.cipher_suite = cipher_suite |
| 163 | self.compression_methods_length = compression_methods_length |
| 164 | self.compression_methods = compression_methods |
| 165 | self.record_fragment_length = record_fragment_length |
| 166 | self.invalid_client_hello_handshake_type = invalid_client_hello_handshake_type |
| 167 | self.invalid_client_hello_handshake_length = invalid_client_hello_handshake_length |
| 168 | self.invalid_cert_req_handshake = invalid_cert_req_handshake |
| 169 | self.id_mismatch_in_identifier_response_packet = id_mismatch_in_identifier_response_packet |
| 170 | self.id_mismatch_in_client_hello_packet = id_mismatch_in_client_hello_packet |
| 171 | self.dont_send_client_certificate = dont_send_client_certificate |
| 172 | self.dont_send_client_hello = dont_send_client_hello |
| 173 | self.incorrect_tlsrecord_type_cert_req = incorrect_tlsrecord_type_cert_req |
| 174 | self.restart_radius = restart_radius |
| 175 | self.clientkeyex_replace_with_serverkeyex = clientkeyex_replace_with_serverkeyex |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 176 | self.nextState = None |
| 177 | self.nextEvent = None |
| 178 | self.pending_bytes = 0 #for TLS fragment reassembly |
| 179 | self.server_hello_done_received = False |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 180 | self.server_hello_done_eap_id = 0 |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 181 | self.send_tls_response = True |
| 182 | self.server_certs = [] |
| 183 | self.pkt_last = '' |
| 184 | self.pkt_history = [] |
| 185 | self.pkt_map = { self.SERVER_HELLO: ['', '', lambda pkt: pkt ], |
| 186 | self.SERVER_CERTIFICATE: ['', '', lambda pkt: pkt ], |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 187 | self.CERTIFICATE_REQUEST: ['', '', lambda pkt: pkt ], |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 188 | self.SERVER_HELLO_DONE: ['', '', self.handle_server_hello_done ], |
| 189 | self.SERVER_UNKNOWN: ['', '', lambda pkt: pkt ] |
| 190 | } |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 191 | if self.clientkeyex_replace_with_serverkeyex: |
| 192 | self.tls_ctx = TLSSessionCtx(client = False) |
| 193 | else: |
| 194 | self.tls_ctx = TLSSessionCtx(client = True) |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 195 | self.client_cert = self.CLIENT_CERT if client_cert is None else client_cert |
| 196 | self.client_priv_key = self.CLIENT_PRIV_KEY if client_priv_key is None else client_priv_key |
| 197 | self.failTest = False |
| 198 | self.fail_cb = fail_cb |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 199 | |
| 200 | def load_tls_record(self, data, pkt_type = ''): |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 201 | #if pkt_type not in [ self.SERVER_HELLO_DONE, self.SERVER_UNKNOWN ]: |
| 202 | if pkt_type == self.SERVER_HELLO_DONE: |
| 203 | data = str(TLSRecord(content_type=TLSContentType.HANDSHAKE)/data) |
| 204 | elif pkt_type == self.CERTIFICATE_REQUEST: |
| 205 | data = str(TLSRecord()/TLSHandshake(type=TLSHandshakeType.CERTIFICATE_REQUEST)/data[9:]) |
| 206 | data = None #For now ignore this record |
| 207 | if data: |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 208 | TLS(data, ctx = self.tls_ctx) |
| 209 | |
| 210 | def pkt_update(self, pkt_type, data, hdr=None, reassembled = False): |
| 211 | if not self.pkt_map.has_key(pkt_type): |
| 212 | return |
| 213 | if hdr is not None: |
| 214 | self.pkt_map[pkt_type][self.HDR_IDX] += hdr |
| 215 | self.pkt_map[pkt_type][self.DATA_IDX] += data |
| 216 | if reassembled is True: |
| 217 | self.pkt_map[pkt_type][self.CB_IDX](self.pkt_map[pkt_type][self.DATA_IDX]) |
| 218 | log.info('Appending packet type %02x to packet history of len %d' |
| 219 | %(ord(pkt_type), len(self.pkt_map[pkt_type][self.DATA_IDX]))) |
| 220 | self.pkt_history.append(self.pkt_map[pkt_type][self.DATA_IDX]) |
| 221 | data = ''.join(self.pkt_map[pkt_type][:self.DATA_IDX+1]) |
| 222 | self.load_tls_record(data, pkt_type = pkt_type) |
| 223 | self.pkt_map[pkt_type][self.HDR_IDX] = '' |
| 224 | self.pkt_map[pkt_type][self.DATA_IDX] = '' |
| 225 | |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 226 | def tlsFail(self): |
| 227 | ##Force a failure |
ChetanGaonker | 3441faf | 2016-10-27 12:15:21 -0700 | [diff] [blame] | 228 | log.info('entering into testFail function') |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 229 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_FINISHED |
A.R Karthick | 7eb2ce0 | 2016-06-10 19:00:50 -0700 | [diff] [blame] | 230 | self.nextState = self.tlsStateTable.ST_EAP_TLS_FINISHED |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 231 | self.failTest = True |
| 232 | |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 233 | def eapol_server_hello_cb(self, pkt): |
| 234 | '''Reassemble and send response for server hello/certificate fragments''' |
| 235 | r = str(pkt) |
| 236 | offset = self.TLS_OFFSET |
| 237 | tls_data = r[offset:] |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 238 | type_hdrlen = 0 |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 239 | if self.pending_bytes > 0: |
| 240 | if len(tls_data) >= self.pending_bytes: |
| 241 | self.pkt_update(self.pkt_last, tls_data[:self.pending_bytes], reassembled = True) |
| 242 | offset += self.pending_bytes |
| 243 | self.pkt_last = '' |
| 244 | self.pending_bytes = 0 |
| 245 | else: |
| 246 | self.pkt_update(self.pkt_last, tls_data) |
| 247 | self.pending_bytes -= len(tls_data) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 248 | print('Offset: %d, pkt : %d, pending %d\n' %(offset, len(pkt), self.pending_bytes)) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 249 | while self.pending_bytes == 0 and offset < len(pkt): |
| 250 | tls_data = r[offset:] |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 251 | hexdump(tls_data) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 252 | self.pending_bytes = bytes_to_num(tls_data[3:5]) |
A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -0700 | [diff] [blame] | 253 | if self.pending_bytes < 0: |
| 254 | self.pending_bytes = 0 |
| 255 | return |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 256 | if tls_data[0] == self.HANDSHAKE: |
| 257 | pkt_type = tls_data[5] |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 258 | if pkt_type in [ self.CERTIFICATE_REQUEST ]: |
| 259 | self.pending_bytes = bytes_to_num(tls_data[6:9]) |
| 260 | type_hdrlen = 4 |
| 261 | if len(tls_data) - 5 - type_hdrlen >= self.pending_bytes: |
| 262 | data_received = tls_data[5: 5 + type_hdrlen + self.pending_bytes ] |
| 263 | offset += 5 + type_hdrlen + self.pending_bytes |
| 264 | type_hdrlen = 0 |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 265 | self.pending_bytes = 0 |
| 266 | self.pkt_update(pkt_type, data_received, |
| 267 | hdr = tls_data[:5], |
| 268 | reassembled = True) |
| 269 | else: |
| 270 | self.pkt_update(pkt_type, tls_data[5:], |
| 271 | hdr = tls_data[:5], |
| 272 | reassembled = False) |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 273 | self.pending_bytes -= len(tls_data) - 5 - type_hdrlen |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 274 | self.pkt_last = pkt_type |
| 275 | log.info('Pending bytes left %d' %(self.pending_bytes)) |
| 276 | assert self.pending_bytes > 0 |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 277 | elif tls_data[0] == self.SERVER_HELLO_DONE: |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 278 | self.server_hello_done_eap_id = pkt[EAP].id |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 279 | self.pkt_update(tls_data[0], tls_data, reassembled = True) |
| 280 | break |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 281 | else: |
| 282 | self.pkt_last = self.SERVER_UNKNOWN |
| 283 | if len(tls_data) - 5 >= self.pending_bytes: |
| 284 | offset += 5 + self.pending_bytes |
| 285 | self.pending_bytes = 0 |
| 286 | self.pkt_last = '' |
| 287 | |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 288 | #send TLS response ack till we receive server hello done |
| 289 | if self.server_hello_done_received == False: |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 290 | eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id, TLS_LENGTH_INCLUDED, '') |
| 291 | self.eapol_send(EAPOL_EAPPACKET, eap_payload) |
| 292 | |
| 293 | def _eapSetup(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 294 | #if self.src_mac == 'bcast':self.setup(src_mac='bcast') |
| 295 | #if self.src_mac == 'mcast': self.setup(src_mac='mcast') |
| 296 | #if self.src_mac == 'zeros': self.setup(src_mac='zeros') |
| 297 | #if self.src_mac == 'default': self.setup(src_mac='default') |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 298 | log.info('source mac is %s'%self.src_mac) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 299 | self.setup(src_mac=self.src_mac) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 300 | self.nextEvent = self.tlsEventTable.EVT_EAP_START |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 301 | |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 302 | def _eapStart(self): |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 303 | log.info('_eapStart method started') |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 304 | self.eapol_start() |
| 305 | self.nextEvent = self.tlsEventTable.EVT_EAP_ID_REQ |
| 306 | |
| 307 | def _eapIdReq(self): |
| 308 | log.info( 'Inside EAP ID Req' ) |
| 309 | def eapol_cb(pkt): |
| 310 | log.info('Got EAPOL packet with type id and code request') |
| 311 | log.info('Packet code: %d, type: %d, id: %d', pkt[EAP].code, pkt[EAP].type, pkt[EAP].id) |
| 312 | log.info("<====== Send EAP Response with identity = %s ================>" % USER) |
ChetanGaonker | e2b665b | 2016-12-07 00:50:56 -0800 | [diff] [blame] | 313 | if self.id_mismatch_in_identifier_response_packet: |
| 314 | log.info('\nSending invalid id field in EAP Identity Response packet') |
| 315 | self.eapol_id_req(pkt[EAP].id+10, USER) |
| 316 | else: |
| 317 | self.eapol_id_req(pkt[EAP].id, USER) |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 318 | |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 319 | r = self.eapol_scapy_recv(cb = eapol_cb, |
| 320 | lfilter = |
| 321 | lambda pkt: EAP in pkt and pkt[EAP].type == EAP.TYPE_ID and pkt[EAP].code == EAP.REQUEST) |
| 322 | if len(r) > 0: |
| 323 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_HELLO_REQ |
| 324 | else: |
| 325 | self.tlsFail() |
| 326 | return r |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 327 | |
| 328 | def _eapTlsHelloReq(self): |
| 329 | |
| 330 | def eapol_cb(pkt): |
| 331 | log.info('Got hello request for id %d', pkt[EAP].id) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 332 | self.client_hello = TLSClientHello(version= self.version, |
| 333 | gmt_unix_time=self.gmt_unix_time, |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 334 | random_bytes= '\xAB' * 28, |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 335 | session_id_length = self.session_id_length, |
| 336 | session_id= self.session_id, |
| 337 | compression_methods_length = self.compression_methods_length, |
| 338 | compression_methods= self.compression_methods, |
| 339 | cipher_suites_length = self.cipher_suites_length, |
| 340 | cipher_suites=[self.cipher_suite] |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 341 | ) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 342 | if self.invalid_client_hello_handshake_type: |
| 343 | log.info('sending server_hello instead of client_hello handshape type in client hello packet') |
| 344 | client_hello_data = TLSHandshake(type='server_hello')/self.client_hello |
| 345 | elif self.invalid_client_hello_handshake_length: |
| 346 | log.info('sending TLS Handshake message with zero length field in client hello packet') |
| 347 | client_hello_data = TLSHandshake(length=0)/self.client_hello |
| 348 | else: |
| 349 | client_hello_data = TLSHandshake()/self.client_hello |
| 350 | #client_hello_data = TLSHandshake()/self.client_hello |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 351 | self.pkt_history.append( str(client_hello_data) ) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 352 | if self.record_fragment_length: |
| 353 | reqdata = TLSRecord(length=self.record_fragment_length)/client_hello_data |
| 354 | else: |
| 355 | reqdata = TLSRecord()/client_hello_data |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 356 | self.load_tls_record(str(reqdata)) |
| 357 | log.info("Sending Client Hello TLS payload of len %d, id %d" %(len(reqdata),pkt[EAP].id)) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 358 | if self.id_mismatch_in_client_hello_packet: |
| 359 | log.info('\nsending invalid id field in client hello packet') |
| 360 | eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id+10, TLS_LENGTH_INCLUDED, str(reqdata)) |
| 361 | else: |
| 362 | eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id, TLS_LENGTH_INCLUDED, str(reqdata)) |
| 363 | if self.dont_send_client_hello: |
| 364 | log.info('\nskipping client hello packet sending part') |
| 365 | pass |
| 366 | else: |
| 367 | self.eapol_send(EAPOL_EAPPACKET, eap_payload) |
| 368 | if self.restart_radius: |
| 369 | cord_test_radius_restart() |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 370 | |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 371 | r = self.eapol_scapy_recv(cb = eapol_cb, |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 372 | lfilter = |
| 373 | lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and pkt[EAP].code == EAP.REQUEST) |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 374 | |
| 375 | if len(r) == 0: |
| 376 | self.tlsFail() |
| 377 | return r |
| 378 | |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 379 | #move to client/server certificate request |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 380 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CERT_REQ |
| 381 | |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 382 | def get_verify_data(self): |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 383 | all_handshake_pkts = ''.join(self.pkt_history) |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 384 | return self.tls_ctx.get_verify_data(data = all_handshake_pkts) |
| 385 | |
| 386 | def get_verify_signature(self, pem_data): |
| 387 | all_handshake_pkts = ''.join(self.pkt_history) |
| 388 | k = Key(pem_data) |
| 389 | signature = k.sign(all_handshake_pkts, t = 'pkcs', h = 'tls') |
| 390 | signature_data = '{}{}'.format(struct.pack('!H', len(signature)), signature) |
| 391 | return signature_data |
| 392 | |
| 393 | def get_encrypted_handshake_msg(self, finish_val=''): |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 394 | if not finish_val: |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 395 | finish_val = self.get_verify_data() |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 396 | msg = str(TLSHandshake(type=TLSHandshakeType.FINISHED)/finish_val) |
| 397 | crypto_container = CryptoContainer(self.tls_ctx, data = msg, |
| 398 | content_type = TLSContentType.HANDSHAKE) |
| 399 | return crypto_container.encrypt() |
| 400 | |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 401 | def get_encrypted_application_msg(self, msg = ''): |
| 402 | '''Needed with tunneled TLS''' |
| 403 | if not msg: |
| 404 | msg = 'test data' |
| 405 | return to_raw(TLSPlaintext(data = 'GET / HTTP/1.1\r\nHOST: localhost\r\n\r\n'), self.tls_ctx) |
| 406 | |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 407 | def _eapTlsCertReq(self): |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 408 | log.info('Receiving server certificates') |
| 409 | while self.server_hello_done_received == False: |
| 410 | r = self.eapol_scapy_recv(cb = self.eapol_server_hello_cb, |
| 411 | lfilter = |
| 412 | lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \ |
| 413 | pkt[EAP].code == EAP.REQUEST) |
| 414 | if len(r) == 0: |
| 415 | self.tlsFail() |
| 416 | return r |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 417 | log.info('Sending client certificate request') |
| 418 | rex_pem = re.compile(r'\-+BEGIN[^\-]+\-+(.*?)\-+END[^\-]+\-+', re.DOTALL) |
| 419 | if self.client_cert: |
| 420 | der_cert = rex_pem.findall(self.client_cert)[0].decode("base64") |
| 421 | client_certificate_list = TLSHandshake()/TLSCertificateList( |
| 422 | certificates=[TLSCertificate(data=x509.X509Cert(der_cert))]) |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 423 | else: |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 424 | client_certificate_list = TLSHandshake()/TLSCertificateList(certificates=[]) |
| 425 | client_certificate = TLSRecord(version="TLS_1_0")/client_certificate_list |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 426 | kex_data = self.tls_ctx.get_client_kex_data() |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 427 | client_key_ex_data = TLSHandshake()/kex_data |
| 428 | client_key_ex = TLSRecord()/client_key_ex_data |
| 429 | if self.client_cert: |
| 430 | self.load_tls_record(str(client_certificate)) |
| 431 | self.pkt_history.append(str(client_certificate_list)) |
| 432 | self.load_tls_record(str(client_key_ex)) |
| 433 | self.pkt_history.append(str(client_key_ex_data)) |
| 434 | verify_signature = self.get_verify_signature(self.client_priv_key) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 435 | if self.invalid_cert_req_handshake: |
| 436 | log.info("sending 'certificate-request' type of handshake message instead of 'certificate-verify' type") |
| 437 | client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_REQUEST)/verify_signature |
| 438 | else: |
| 439 | client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_VERIFY)/verify_signature |
| 440 | if self.incorrect_tlsrecord_type_cert_req: |
| 441 | log.info("sending TLS Record type as ALERT instead of HANDSHAKE in certificate request packet") |
| 442 | client_cert_record = TLSRecord(content_type=TLSContentType.ALERT)/client_cert_verify |
| 443 | else: |
| 444 | client_cert_record = TLSRecord(content_type=TLSContentType.HANDSHAKE)/client_cert_verify |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 445 | self.pkt_history.append(str(client_cert_verify)) |
| 446 | #log.info('TLS ctxt: %s' %self.tls_ctx) |
| 447 | client_ccs = TLSRecord(version="TLS_1_0")/TLSChangeCipherSpec() |
| 448 | enc_handshake_msg = self.get_encrypted_handshake_msg() |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 449 | if self.invalid_content_type: |
| 450 | handshake_msg = str(TLSRecord(content_type=self.invalid_content_type)/enc_handshake_msg) |
| 451 | else: |
| 452 | handshake_msg = str(TLSRecord(content_type=TLSContentType.HANDSHAKE)/enc_handshake_msg) |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 453 | reqdata = str(TLS.from_records([client_certificate, client_key_ex, client_cert_record, client_ccs])) |
| 454 | reqdata += handshake_msg |
| 455 | log.info("------> Sending Client Hello TLS Certificate payload of len %d ----------->" %len(reqdata)) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 456 | if self.dont_send_client_certificate: |
| 457 | log.info('\nskipping sending client certificate part') |
| 458 | pass |
| 459 | else: |
| 460 | status = self.eapFragmentSend(EAP_RESPONSE, self.server_hello_done_eap_id, TLS_LENGTH_INCLUDED, |
A R Karthick | f028ec9 | 2016-08-15 16:58:11 -0700 | [diff] [blame] | 461 | payload = reqdata, fragsize = 1024) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 462 | assert_equal(status, True) |
| 463 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CHANGE_CIPHER_SPEC |
Chetan Gaonker | f8f7718 | 2016-03-11 15:34:57 -0800 | [diff] [blame] | 464 | |
ChetanGaonker | 3441faf | 2016-10-27 12:15:21 -0700 | [diff] [blame] | 465 | def _eapTlsCertReq_delay(self): |
| 466 | self.server_hello_done_received = True |
| 467 | log.info('Sending client certificate request') |
| 468 | rex_pem = re.compile(r'\-+BEGIN[^\-]+\-+(.*?)\-+END[^\-]+\-+', re.DOTALL) |
| 469 | |
| 470 | if self.client_cert: |
| 471 | der_cert = rex_pem.findall(self.client_cert)[0].decode("base64") |
| 472 | client_certificate_list = TLSHandshake()/TLSCertificateList( |
| 473 | certificates=[TLSCertificate(data=x509.X509Cert(der_cert))]) |
| 474 | else: |
| 475 | client_certificate_list = TLSHandshake()/TLSCertificateList(certificates=[]) |
| 476 | |
| 477 | client_certificate = TLSRecord(version="TLS_1_0")/client_certificate_list |
| 478 | kex_data = self.tls_ctx.get_client_kex_data() |
| 479 | client_key_ex_data = TLSHandshake()/kex_data |
| 480 | client_key_ex = TLSRecord()/client_key_ex_data |
| 481 | |
| 482 | if self.client_cert: |
| 483 | self.load_tls_record(str(client_certificate)) |
| 484 | self.pkt_history.append(str(client_certificate_list)) |
| 485 | |
| 486 | self.load_tls_record(str(client_key_ex)) |
| 487 | self.pkt_history.append(str(client_key_ex_data)) |
| 488 | verify_signature = self.get_verify_signature(self.client_priv_key) |
| 489 | |
| 490 | if self.invalid_cert_req_handshake: |
| 491 | log.info("Sending 'certificate-request' type of handshake message instead of 'certificate-verify' type") |
| 492 | client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_REQUEST)/verify_signature |
| 493 | else: |
| 494 | client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_VERIFY)/verify_signature |
| 495 | |
| 496 | if self.incorrect_tlsrecord_type_cert_req: |
| 497 | log.info("Sending TLS Record type as ALERT instead of HANDSHAKE in certificate request packet") |
| 498 | client_cert_record = TLSRecord(content_type=TLSContentType.ALERT)/client_cert_verify |
| 499 | else: |
| 500 | client_cert_record = TLSRecord(content_type=TLSContentType.HANDSHAKE)/client_cert_verify |
| 501 | |
| 502 | self.pkt_history.append(str(client_cert_verify)) |
| 503 | #log.info('TLS ctxt: %s' %self.tls_ctx) |
| 504 | client_ccs = TLSRecord(version="TLS_1_0")/TLSChangeCipherSpec() |
| 505 | enc_handshake_msg = self.get_encrypted_handshake_msg() |
| 506 | |
| 507 | if self.invalid_content_type: |
| 508 | handshake_msg = str(TLSRecord(content_type=self.invalid_content_type)/enc_handshake_msg) |
| 509 | else: |
| 510 | handshake_msg = str(TLSRecord(content_type=TLSContentType.HANDSHAKE)/enc_handshake_msg) |
| 511 | reqdata = str(TLS.from_records([client_certificate, client_key_ex, client_cert_record, client_ccs])) |
| 512 | reqdata += handshake_msg |
| 513 | log.info("------> Sending Client Hello TLS Certificate payload of len %d ----------->" %len(reqdata)) |
| 514 | |
| 515 | if self.dont_send_client_certificate: |
| 516 | log.info('\nSkipping sending client certificate part') |
| 517 | pass |
| 518 | else: |
| 519 | status = self.eapFragmentSend(EAP_RESPONSE, self.server_hello_done_eap_id, TLS_LENGTH_INCLUDED, |
| 520 | payload = reqdata, fragsize = 1024) |
| 521 | assert_equal(status, True) |
| 522 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CHANGE_CIPHER_SPEC |
| 523 | |
Chetan Gaonker | f8f7718 | 2016-03-11 15:34:57 -0800 | [diff] [blame] | 524 | def _eapTlsChangeCipherSpec(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 525 | def eapol_cb(pkt): |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 526 | r = str(pkt) |
ChetanGaonker | 6138fcd | 2016-08-18 17:56:39 -0700 | [diff] [blame] | 527 | log.info('data received in change cipher spec function is %s'%pkt.show()) |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 528 | tls_data = r[self.TLS_OFFSET:] |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 529 | log.info('Verifying TLS Change Cipher spec record type %x' %ord(tls_data[0])) |
| 530 | assert tls_data[0] == self.CHANGE_CIPHER |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 531 | log.info('Handshake finished. Sending empty data') |
| 532 | eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id, 0, '') |
| 533 | self.eapol_send(EAPOL_EAPPACKET, eap_payload) |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 534 | |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 535 | r = self.eapol_scapy_recv(cb = eapol_cb, |
| 536 | lfilter = |
| 537 | lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and pkt[EAP].code == EAP.REQUEST) |
| 538 | if len(r) > 0: |
| 539 | self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_FINISHED |
| 540 | else: |
| 541 | self.tlsFail() |
| 542 | return r |
Chetan Gaonker | f8f7718 | 2016-03-11 15:34:57 -0800 | [diff] [blame] | 543 | |
| 544 | def _eapTlsFinished(self): |
A.R Karthick | 7eb2ce0 | 2016-06-10 19:00:50 -0700 | [diff] [blame] | 545 | self.nextEvent = None |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 546 | def eapol_cb(pkt): |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 547 | log.info('Server authentication successfull') |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 548 | |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 549 | timeout = 5 |
| 550 | if self.failTest is True: |
| 551 | if self.fail_cb is not None: |
| 552 | self.fail_cb() |
| 553 | return |
| 554 | timeout = None ##Wait forever on failure and force testcase timeouts |
| 555 | |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 556 | self.eapol_scapy_recv(cb = eapol_cb, |
A R Karthick | 22aa0c6 | 2016-05-31 11:17:12 -0700 | [diff] [blame] | 557 | lfilter = |
A R Karthick | 05d9b5f | 2016-06-08 11:53:54 -0700 | [diff] [blame] | 558 | lambda pkt: EAP in pkt and pkt[EAP].code == EAP.SUCCESS, |
| 559 | timeout = timeout) |
A R Karthick | 307483c | 2016-06-06 17:05:19 -0700 | [diff] [blame] | 560 | self.eapol_logoff() |