Sfoglia il codice sorgente

Placeholder for TLS insertion

tags/v0.9.3
Michael Brown 18 anni fa
parent
commit
a3695b1ff6
2 ha cambiato i file con 31 aggiunte e 8 eliminazioni
  1. 12
    0
      src/include/gpxe/tls.h
  2. 19
    8
      src/net/tcp/http.c

+ 12
- 0
src/include/gpxe/tls.h Vedi File

@@ -0,0 +1,12 @@
1
+#ifndef _GPXE_TLS_H
2
+#define _GPXE_TLS_H
3
+
4
+#include <errno.h>
5
+
6
+struct stream_application;
7
+
8
+static inline int add_tls ( struct stream_application *app __unused ) {
9
+	return -ENOTSUP;
10
+}
11
+
12
+#endif /* _GPXE_TLS_H */

+ 19
- 8
src/net/tcp/http.c Vedi File

@@ -37,6 +37,7 @@
37 37
 #include <gpxe/download.h>
38 38
 #include <gpxe/resolv.h>
39 39
 #include <gpxe/tcp.h>
40
+#include <gpxe/tls.h>
40 41
 #include <gpxe/http.h>
41 42
 
42 43
 static struct async_operations http_async_operations;
@@ -387,6 +388,7 @@ static struct stream_application_operations http_stream_operations = {
387 388
  */
388 389
 int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
389 390
 	struct http_request *http = NULL;
391
+	struct sockaddr_tcpip *st;
390 392
 	int rc;
391 393
 
392 394
 	/* Allocate and populate HTTP structure */
@@ -398,6 +400,17 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
398 400
 	http->buffer = buffer;
399 401
 	async_init ( &http->async, &http_async_operations, parent );
400 402
 	http->stream.op = &http_stream_operations;
403
+	st = ( struct sockaddr_tcpip * ) &http->server;
404
+	st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
405
+
406
+	/* Open TCP connection */
407
+	if ( ( rc = tcp_open ( &http->stream ) ) != 0 )
408
+		goto err;
409
+	if ( strcmp ( http->uri->scheme, "https" ) == 0 ) {
410
+		st->st_port = htons ( uri_port ( http->uri, HTTPS_PORT ) );
411
+		if ( ( rc = add_tls ( &http->stream ) ) != 0 )
412
+			goto err;
413
+	}
401 414
 
402 415
 	/* Start name resolution.  The download proper will start when
403 416
 	 * name resolution completes.
@@ -424,7 +437,6 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
424 437
 static void http_sigchld ( struct async *async, enum signal signal __unused ) {
425 438
 	struct http_request *http =
426 439
 		container_of ( async, struct http_request, async );
427
-	struct sockaddr_tcpip *st = ( struct sockaddr_tcpip * ) &http->server;
428 440
 	int rc;
429 441
 
430 442
 	/* If name resolution failed, abort now */
@@ -435,13 +447,6 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
435 447
 	}
436 448
 
437 449
 	/* Otherwise, start the HTTP connection */
438
-	if ( ( rc = tcp_open ( &http->stream ) ) != 0 ) {
439
-		DBGC ( http, "HTTP %p could not open stream connection: %s\n",
440
-		       http, strerror ( rc ) );
441
-		http_done ( http, rc );
442
-		return;
443
-	}
444
-	st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
445 450
 	if ( ( rc = stream_connect ( &http->stream, &http->server ) ) != 0 ) {
446 451
 		DBGC ( http, "HTTP %p could not connect stream: %s\n",
447 452
 		       http, strerror ( rc ) );
@@ -472,3 +477,9 @@ struct download_protocol http_download_protocol __download_protocol = {
472 477
 	.name = "http",
473 478
 	.start_download = http_get,
474 479
 };
480
+
481
+/** HTTPS download protocol */
482
+struct download_protocol https_download_protocol __download_protocol = {
483
+	.name = "https",
484
+	.start_download = http_get,
485
+};

Loading…
Annulla
Salva