]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/HttpDxe: Destroy the TLS instance when cleaning up the HTTP child
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
index d19f73348d4931d3058bf6afbbca03e5bd4aed1e..8a9e57345af8802f0e53b2db0ff380d92465cb2f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of EFI_HTTP_PROTOCOL protocol interfaces.\r
 \r
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
 \r
   This program and the accompanying materials\r
@@ -130,7 +130,7 @@ EFI_STATUS
 EFIAPI\r
 EfiHttpConfigure (\r
   IN  EFI_HTTP_PROTOCOL         *This,\r
-  IN  EFI_HTTP_CONFIG_DATA      *HttpConfigData\r
+  IN  EFI_HTTP_CONFIG_DATA      *HttpConfigData OPTIONAL\r
   ) \r
 {\r
   HTTP_PROTOCOL                 *HttpInstance;\r
@@ -249,6 +249,7 @@ EfiHttpRequest (
   HTTP_TOKEN_WRAP               *Wrap;\r
   CHAR8                         *FileUrl;\r
   UINTN                         RequestMsgSize;\r
+  EFI_HANDLE                    ImageHandle;\r
 \r
   //\r
   // Initializations\r
@@ -354,6 +355,16 @@ EfiHttpRequest (
     //\r
     HttpInstance->UseHttps = IsHttpsUrl (Url);\r
 \r
+    //\r
+    // HTTP is disabled, return directly if the URI is not HTTPS.\r
+    //\r
+    if (!PcdGetBool (PcdAllowHttpConnections) && !(HttpInstance->UseHttps)) {\r
+      \r
+      DEBUG ((EFI_D_ERROR, "EfiHttpRequest: HTTP is disabled.\n"));\r
+\r
+      return EFI_ACCESS_DENIED;\r
+    }\r
+\r
     //\r
     // Check whether we need to create Tls child and open the TLS protocol.\r
     //\r
@@ -361,8 +372,15 @@ EfiHttpRequest (
       //\r
       // Use TlsSb to create Tls child and open the TLS protocol.\r
       //\r
+      if (HttpInstance->LocalAddressIsIPv6) {\r
+        ImageHandle = HttpInstance->Service->Ip6DriverBindingHandle;\r
+      } else {\r
+        ImageHandle = HttpInstance->Service->Ip4DriverBindingHandle;\r
+      }\r
+\r
       HttpInstance->TlsChildHandle = TlsCreateChild (\r
-                                       HttpInstance->Service->ImageHandle,\r
+                                       ImageHandle,\r
+                                       &(HttpInstance->TlsSb),\r
                                        &(HttpInstance->Tls),\r
                                        &(HttpInstance->TlsConfiguration)\r
                                        );\r
@@ -1325,7 +1343,7 @@ HttpResponseWorker (
     // We receive part of header of next HTTP msg.\r
     //\r
     if (HttpInstance->NextMsg != NULL) {\r
-      HttpMsg->BodyLength = MIN ((UINTN) (HttpInstance->NextMsg - (CHAR8 *) Fragment.Bulk), HttpMsg->BodyLength);\r
+      HttpMsg->BodyLength = MIN ((UINTN) HttpInstance->NextMsg - (UINTN) Fragment.Bulk, HttpMsg->BodyLength);\r
       CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
       \r
       HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
@@ -1343,7 +1361,7 @@ HttpResponseWorker (
         CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
         HttpInstance->CacheOffset = 0;\r
 \r
-        HttpInstance->NextMsg = HttpInstance->CacheBody + (UINTN) (HttpInstance->NextMsg - (CHAR8 *) (Fragment.Bulk + HttpMsg->BodyLength));\r
+        HttpInstance->NextMsg = HttpInstance->CacheBody + ((UINTN) HttpInstance->NextMsg - (UINTN) (Fragment.Bulk + HttpMsg->BodyLength));\r
       }\r
     } else {\r
       HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength);\r