Przeglądaj źródła

Allowed HTTPS to be a separately configurable feature.

tags/v0.9.3
Michael Brown 17 lat temu
rodzic
commit
bf3d8fb1aa
5 zmienionych plików z 76 dodań i 13 usunięć
  1. 1
    0
      src/config.h
  2. 3
    0
      src/core/config.c
  3. 5
    0
      src/include/gpxe/http.h
  4. 21
    13
      src/net/tcp/http.c
  5. 46
    0
      src/net/tcp/https.c

+ 1
- 0
src/config.h Wyświetl plik

@@ -73,6 +73,7 @@
73 73
 #define	DOWNLOAD_PROTO_TFTP	/* Trivial File Transfer Protocol */
74 74
 #undef	DOWNLOAD_PROTO_NFS	/* Network File System */
75 75
 #define	DOWNLOAD_PROTO_HTTP	/* Hypertext Transfer Protocol */
76
+#undef	DOWNLOAD_PROTO_HTTPS	/* Secure Hypertext Transfer Protocol */
76 77
 #undef	DOWNLOAD_PROTO_FTP	/* File Transfer Protocol */
77 78
 #undef	DOWNLOAD_PROTO_TFTM	/* Multicast Trivial File Transfer Protocol */
78 79
 #undef	DOWNLOAD_PROTO_SLAM	/* Scalable Local Area Multicast */

+ 3
- 0
src/core/config.c Wyświetl plik

@@ -87,6 +87,9 @@ REQUIRE_OBJECT ( nfs );
87 87
 #ifdef DOWNLOAD_PROTO_HTTP
88 88
 REQUIRE_OBJECT ( http );
89 89
 #endif
90
+#ifdef DOWNLOAD_PROTO_HTTPS
91
+REQUIRE_OBJECT ( https );
92
+#endif
90 93
 #ifdef DOWNLOAD_PROTO_FTP
91 94
 REQUIRE_OBJECT ( ftp );
92 95
 #endif

+ 5
- 0
src/include/gpxe/http.h Wyświetl plik

@@ -13,4 +13,9 @@
13 13
 /** HTTPS default port */
14 14
 #define HTTPS_PORT 443
15 15
 
16
+extern int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
17
+			      unsigned int default_port,
18
+			      int ( * filter ) ( struct xfer_interface *,
19
+						 struct xfer_interface ** ) );
20
+
16 21
 #endif /* _GPXE_HTTP_H */

+ 21
- 13
src/net/tcp/http.c Wyświetl plik

@@ -40,7 +40,6 @@
40 40
 #include <gpxe/tcpip.h>
41 41
 #include <gpxe/process.h>
42 42
 #include <gpxe/linebuf.h>
43
-#include <gpxe/tls.h>
44 43
 #include <gpxe/http.h>
45 44
 
46 45
 /** HTTP receive state */
@@ -459,13 +458,18 @@ static struct xfer_interface_operations http_xfer_operations = {
459 458
 };
460 459
 
461 460
 /**
462
- * Initiate an HTTP connection
461
+ * Initiate an HTTP connection, with optional filter
463 462
  *
464 463
  * @v xfer		Data transfer interface
465 464
  * @v uri		Uniform Resource Identifier
465
+ * @v default_port	Default port number
466
+ * @v filter		Filter to apply to socket, or NULL
466 467
  * @ret rc		Return status code
467 468
  */
468
-static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
469
+int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
470
+		       unsigned int default_port,
471
+		       int ( * filter ) ( struct xfer_interface *xfer,
472
+					  struct xfer_interface **next ) ) {
469 473
 	struct http_request *http;
470 474
 	struct sockaddr_tcpip server;
471 475
 	struct xfer_interface *socket;
@@ -487,11 +491,10 @@ static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
487 491
 
488 492
 	/* Open socket */
489 493
 	memset ( &server, 0, sizeof ( server ) );
490
-	server.st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
494
+	server.st_port = htons ( uri_port ( http->uri, default_port ) );
491 495
 	socket = &http->socket;
492
-	if ( strcmp ( http->uri->scheme, "https" ) == 0 ) {
493
-		server.st_port = htons ( uri_port ( http->uri, HTTPS_PORT ) );
494
-		if ( ( rc = add_tls ( socket, &socket ) ) != 0 )
496
+	if ( filter ) {
497
+		if ( ( rc = filter ( socket, &socket ) ) != 0 )
495 498
 			goto err;
496 499
 	}
497 500
 	if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
@@ -512,14 +515,19 @@ static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
512 515
 	return rc;
513 516
 }
514 517
 
518
+/**
519
+ * Initiate an HTTP connection
520
+ *
521
+ * @v xfer		Data transfer interface
522
+ * @v uri		Uniform Resource Identifier
523
+ * @ret rc		Return status code
524
+ */
525
+static int http_open ( struct xfer_interface *xfer, struct uri *uri ) {
526
+	return http_open_filter ( xfer, uri, HTTP_PORT, NULL );
527
+}
528
+
515 529
 /** HTTP URI opener */
516 530
 struct uri_opener http_uri_opener __uri_opener = {
517 531
 	.scheme	= "http",
518 532
 	.open	= http_open,
519 533
 };
520
-
521
-/** HTTPS URI opener */
522
-struct uri_opener https_uri_opener __uri_opener = {
523
-	.scheme	= "https",
524
-	.open	= http_open,
525
-};

+ 46
- 0
src/net/tcp/https.c Wyświetl plik

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+/**
20
+ * @file
21
+ *
22
+ * Secure Hyper Text Transfer Protocol (HTTPS)
23
+ *
24
+ */
25
+
26
+#include <stddef.h>
27
+#include <gpxe/open.h>
28
+#include <gpxe/tls.h>
29
+#include <gpxe/http.h>
30
+
31
+/**
32
+ * Initiate an HTTPS connection
33
+ *
34
+ * @v xfer		Data transfer interface
35
+ * @v uri		Uniform Resource Identifier
36
+ * @ret rc		Return status code
37
+ */
38
+static int https_open ( struct xfer_interface *xfer, struct uri *uri ) {
39
+	return http_open_filter ( xfer, uri, HTTPS_PORT, add_tls );
40
+}
41
+
42
+/** HTTPS URI opener */
43
+struct uri_opener https_uri_opener __uri_opener = {
44
+	.scheme	= "https",
45
+	.open	= https_open,
46
+};

Ładowanie…
Anuluj
Zapisz