Browse Source

[tls] Mark security negotiation as a pending operation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
af47789ef2
2 changed files with 18 additions and 7 deletions
  1. 5
    4
      src/include/ipxe/tls.h
  2. 13
    3
      src/net/tls.c

+ 5
- 4
src/include/ipxe/tls.h View File

18
 #include <ipxe/sha1.h>
18
 #include <ipxe/sha1.h>
19
 #include <ipxe/sha256.h>
19
 #include <ipxe/sha256.h>
20
 #include <ipxe/x509.h>
20
 #include <ipxe/x509.h>
21
+#include <ipxe/pending.h>
21
 
22
 
22
 /** A TLS header */
23
 /** A TLS header */
23
 struct tls_header {
24
 struct tls_header {
240
 	/** Certificate validator */
241
 	/** Certificate validator */
241
 	struct interface validator;
242
 	struct interface validator;
242
 
243
 
243
-	/** Client has finished security negotiation */
244
-	unsigned int client_finished;
245
-	/** Server has finished security negotiation */
246
-	unsigned int server_finished;
244
+	/** Client security negotiation pending operation */
245
+	struct pending_operation client_negotiation;
246
+	/** Server security negotiation pending operation */
247
+	struct pending_operation server_negotiation;
247
 
248
 
248
 	/** TX sequence number */
249
 	/** TX sequence number */
249
 	uint64_t tx_seq;
250
 	uint64_t tx_seq;

+ 13
- 3
src/net/tls.c View File

31
 #include <time.h>
31
 #include <time.h>
32
 #include <errno.h>
32
 #include <errno.h>
33
 #include <byteswap.h>
33
 #include <byteswap.h>
34
+#include <ipxe/pending.h>
34
 #include <ipxe/hmac.h>
35
 #include <ipxe/hmac.h>
35
 #include <ipxe/md5.h>
36
 #include <ipxe/md5.h>
36
 #include <ipxe/sha1.h>
37
 #include <ipxe/sha1.h>
101
  * @ret is_ready	TLS session is ready
102
  * @ret is_ready	TLS session is ready
102
  */
103
  */
103
 static int tls_ready ( struct tls_session *tls ) {
104
 static int tls_ready ( struct tls_session *tls ) {
104
-	return ( tls->client_finished && tls->server_finished );
105
+	return ( ( ! is_pending ( &tls->client_negotiation ) ) &&
106
+		 ( ! is_pending ( &tls->server_negotiation ) ) );
105
 }
107
 }
106
 
108
 
107
 /******************************************************************************
109
 /******************************************************************************
205
  */
207
  */
206
 static void tls_close ( struct tls_session *tls, int rc ) {
208
 static void tls_close ( struct tls_session *tls, int rc ) {
207
 
209
 
210
+	/* Remove pending operations, if applicable */
211
+	pending_put ( &tls->client_negotiation );
212
+	pending_put ( &tls->server_negotiation );
213
+
208
 	/* Remove process */
214
 	/* Remove process */
209
 	process_del ( &tls->process );
215
 	process_del ( &tls->process );
210
 
216
 
1141
 		return rc;
1147
 		return rc;
1142
 
1148
 
1143
 	/* Mark client as finished */
1149
 	/* Mark client as finished */
1144
-	tls->client_finished = 1;
1150
+	pending_put ( &tls->client_negotiation );
1145
 
1151
 
1146
 	return 0;
1152
 	return 0;
1147
 }
1153
 }
1489
 	}
1495
 	}
1490
 
1496
 
1491
 	/* Mark server as finished */
1497
 	/* Mark server as finished */
1492
-	tls->server_finished = 1;
1498
+	pending_put ( &tls->server_negotiation );
1493
 
1499
 
1494
 	/* Send notification of a window change */
1500
 	/* Send notification of a window change */
1495
 	xfer_window_changed ( &tls->plainstream );
1501
 	xfer_window_changed ( &tls->plainstream );
2396
 	tls->handshake_ctx = tls->handshake_sha256_ctx;
2402
 	tls->handshake_ctx = tls->handshake_sha256_ctx;
2397
 	tls->tx_pending = TLS_TX_CLIENT_HELLO;
2403
 	tls->tx_pending = TLS_TX_CLIENT_HELLO;
2398
 
2404
 
2405
+	/* Add pending operations for server and client Finished messages */
2406
+	pending_get ( &tls->client_negotiation );
2407
+	pending_get ( &tls->server_negotiation );
2408
+
2399
 	/* Attach to parent interface, mortalise self, and return */
2409
 	/* Attach to parent interface, mortalise self, and return */
2400
 	intf_plug_plug ( &tls->plainstream, xfer );
2410
 	intf_plug_plug ( &tls->plainstream, xfer );
2401
 	*next = &tls->cipherstream;
2411
 	*next = &tls->cipherstream;

Loading…
Cancel
Save