@@ -54,13 +54,54 @@ def __init__(self, auth_socket,
54
54
# Client random data is 32 bytes long
55
55
client_random = random_data or int (datetime .now ().timestamp ()).to_bytes (4 , 'big' ) + os .urandom (28 )
56
56
57
- self ._security_parameters : SecurityParameters = SecurityParameters ().copy (client_random = client_random )
57
+ # Keep separate send/receive parameters so we can handle various receive sequences from server
58
+
59
+ self ._receive_security_parameters : SecurityParameters = SecurityParameters ().copy (client_random = client_random )
60
+ self ._send_security_parameters : SecurityParameters = SecurityParameters ().copy (client_random = client_random )
61
+
62
+
63
+ # TLS breaks it up into pending and active (Look at state machine and its transitions setting of this)
64
+ # it uses the following, so tie the values below into what we save here
65
+ # self._k_send = ""
66
+ # self._k_recv = ""
67
+ #
68
+ self ._security_parameters = {
69
+ 'active_tx' : SecurityParameters ().copy (client_random = client_random ),
70
+ 'active_rx' : SecurityParameters ().copy (client_random = client_random ),
71
+ 'pending_tx' : SecurityParameters ().copy (client_random = client_random ),
72
+ 'pending_rx' : SecurityParameters ().copy (client_random = client_random )
73
+ }
74
+ # So when we get the server_hello, use the 'pending_send_parameters' to stuff values in and later on during
75
+ # server_key_exchange download, use that pending value
76
+ #
77
+ #
78
+ # static void init_protection_parameters( ProtectionParameters *parameters )
79
+ # {
80
+ # parameters->MAC_secret = NULL;
81
+ # parameters->key = NULL;
82
+ # parameters->IV = NULL;
83
+ # parameters->seq_num = 0;
84
+ # parameters->suite = TLS_NULL_WITH_NULL_NULL;
85
+ # }
86
+ # static void init_parameters( TLSParameters *parameters )
87
+ # {
88
+ # init_protection_parameters( ¶meters->pending_send_parameters );
89
+ # init_protection_parameters( ¶meters->pending_recv_parameters );
90
+ # init_protection_parameters( ¶meters->active_send_parameters );
91
+ # init_protection_parameters( ¶meters->active_recv_parameters );
92
+
93
+
94
+
95
+
58
96
# self.server_random = None
59
97
self .session_id = session_id
60
98
self .ciphers = ciphers or get_cipher_suites_by_version (self .tls_version , excluded = ("PSK" ,))
61
99
self .extensions = extensions
62
100
self .cipher_suite : CipherSuite = None
63
- self .server_certificate = None
101
+
102
+ # Following are decode from server messages. Any better place for them
103
+ self .server_certificates = None
104
+ self .server_public_key = b""
64
105
65
106
# TODO: Next are copied over from the AUTH machine and may or may not be used
66
107
# so we need to investigate if they are used or are duplicated above
@@ -75,18 +116,14 @@ def __init__(self, auth_socket,
75
116
self .tls_session = None
76
117
self .eap_tls_state = None
77
118
78
- self .eap_tls_server_data = b'' # Reassembly area for EAP-TLS
79
- self .eap_tls_expected_len = 0
80
- self .eap_tls_last_id = 256
81
- self .eap_tls_client_data_len = 0
82
- # self.eap_tls_client_data_max_len = 994 # TODO: support fragmentation....
119
+
83
120
print ("*** Not enforcing client EAP-TLS fragmentation yet" )
84
121
self .eap_tls_client_data_max_len = 16000
85
122
86
123
self ._debug = debug
87
124
self .is_server_key_exchange = False
88
125
89
- # Probably want these
126
+ # Probably want these - TODO Eventually calculate the hash on the fly if possible
90
127
self ._client_handshake_records_sent : List ['TLSRecord' ] = []
91
128
self ._server_handshake_records_received : List ['TLSRecord' ] = []
92
129
@@ -111,8 +148,12 @@ def __init__(self, auth_socket,
111
148
self .state_machine : TLSClientStateMachine = TLSClientStateMachine (self )
112
149
113
150
@property
114
- def security_parameters (self ) -> SecurityParameters :
115
- return self ._security_parameters
151
+ def rx_security_parameters (self ) -> SecurityParameters :
152
+ return self ._receive_security_parameters
153
+
154
+ @property
155
+ def tx_security_parameters (self ) -> SecurityParameters :
156
+ return self ._send_security_parameters
116
157
117
158
@property
118
159
def tls_version (self ) -> TLS :
@@ -163,10 +204,12 @@ def handle_tls_data(self, eap_id: int, eap_tls: 'EAP_TLS', eap: 'EAP') -> None:
163
204
print (f"*** Last EAP ID: { eap_id } , EAP-LAST-ID: { self .eap_tls_last_id } " )
164
205
165
206
if self .state_machine .state == TLSClientStateMachine .INITIAL :
207
+ print (f"TLSClient.handle_tls_data: Start: { eap_id } " )
166
208
self .state_machine .start (eap_id = eap_id )
167
209
168
210
elif eap_id == self ._eap_tls_last_sent_id and self ._eap_tls_last_sent_data is not None :
169
211
# Handle a retransmit
212
+ print (f"TLSClient.handle_tls_data: Rx retransmit: eap_id: { eap_id } " )
170
213
self .auth_socket .send_response (eap_id , self ._eap_tls_last_sent_data )
171
214
172
215
else :
@@ -203,7 +246,7 @@ def handle_tls_data(self, eap_id: int, eap_tls: 'EAP_TLS', eap: 'EAP') -> None:
203
246
self .save_server_record (packet )
204
247
self .state_machine .rx_packet (eap_id , packet )
205
248
206
- def _rx_server_eap_tls (self , eap_id : int , eap_tls : 'EAP_TLS' ) -> Union [Packet , List [Packet ], None ]:
249
+ def _rx_server_eap_tls (self , eap_id : int , eap_tls : Union [ 'EAP_TLS' , 'EapTls' ] ) -> Union [Packet , List [Packet ], None ]:
207
250
"""
208
251
Handle server data
209
252
@@ -259,7 +302,7 @@ def _rx_server_eap_tls(self, eap_id: int, eap_tls: 'EAP_TLS') -> Union[Packet, L
259
302
260
303
try :
261
304
print (f"Reassembled packet: { self .eap_tls_server_data .hex ()} " )
262
- record_list = TLSRecord .parse (self .eap_tls_server_data , self .security_parameters )
305
+ record_list = TLSRecord .parse (self .eap_tls_server_data , self .rx_security_parameters )
263
306
264
307
except Exception as _e :
265
308
record_list = None
0 commit comments