Re: [edk2-devel] [PATCH 1/1] NetworkPkg/HttpBootDxe: Add Support for HTTPS Proxy Server for HTTP Boot

2022-07-07 Thread Saloni Kasbekar
Hi Maciej,


  1.  I will update the code to add a new function to split that code into a 
separate function. Once the basic auth patch is checked in, I’ll re-send the 
changes for review so that we have the complete logic in the new function.
  2.  I see your point. I’ll update the code to fix it.
  3.  The code has been updated to include the proxy server and the endpoint 
server in the device path. Currently the device path just includes one URI 
which is described as (server_path/file_path). I’ve added a new option so that 
we can add an endpoint server to that device path to include the proxy server 
option. This will be have two URIs in the device path. For eg - 
(endpoint_server_path) /(proxy_server_path/file_path). If this is ok with you, 
I can update the code so that the comments makes this more clear.

Thanks,
Saloni

From: Rabeda, Maciej 
Sent: Friday, July 1, 2022 7:05 AM
To: Kasbekar, Saloni ; devel@edk2.groups.io
Cc: Wu, Jiaxin ; Siyuan Fu ; Wang, 
Jian J ; Gao, Liming 
Subject: Re: [PATCH 1/1] NetworkPkg/HttpBootDxe: Add Support for HTTPS Proxy 
Server for HTTP Boot


Hi Saloni,

This patch contains several problems. At minimum:

  1.  HttpBootLoadFile() logic around calling HttpBootGetBootFile() is becoming 
more complex - and BZ 2504 patch adds to it. I am becoming convinced that this 
part of HttpBootLoadFile() should have a separate function with a looped state 
machine, to cover all cases.
  2.  EfiHttpRequest(): "EndPointUrl = AllocateZeroPool (UrlLen)" followed 
with... "EndPointUrl = (CHAR8 *)Request->EndPointUrl". Was it supposed to be a 
copy from Request->EndPointUrl to EndPointUrl buffer or some other operation 
that I cannot comprehend?
  3.  Could you provide more more information on device path shenanigans around 
proxy URI?
Thanks,
Maciej
On 23 cze 2022 00:54, Saloni Kasbekar wrote:

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3951



Add CONNECT HTTP command in order to create a tunnel from HTTPS

Proxy Server to EndPoint Server.

Add support to connect through proxy server using DevicePath

sent to the Boot Manager.



Cc: Maciej Rabeda 


Cc: Wu Jiaxin 

Cc: Siyuan Fu 

Cc: Jian J Wang 

Cc: Liming Gao 

Signed-off-by: Saloni Kasbekar 


---

 .../Library/UefiBootManagerLib/BmBoot.c   |  11 ++

 MdePkg/Include/Protocol/Http.h|   5 +

 NetworkPkg/HttpBootDxe/HttpBootClient.c   | 168 +-

 NetworkPkg/HttpBootDxe/HttpBootClient.h   |  16 ++

 NetworkPkg/HttpBootDxe/HttpBootDxe.h  |   6 +

 NetworkPkg/HttpBootDxe/HttpBootImpl.c |  46 +++--

 NetworkPkg/HttpBootDxe/HttpBootSupport.c  |  13 +-

 NetworkPkg/HttpBootDxe/HttpBootSupport.h  |   8 +-

 NetworkPkg/HttpDxe/HttpImpl.c |  21 ++-

 NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c|   5 +

 10 files changed, 273 insertions(+), 26 deletions(-)



diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

index 962892d38f14..c5f09b619a89 100644

--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

@@ -1513,7 +1513,9 @@ BmExpandLoadFiles (

   UINTN HandleCount;

   UINTN Index;

   EFI_DEVICE_PATH_PROTOCOL  *Node;

+  URI_DEVICE_PATH   *NullUriPath;



+  NullUriPath = NULL;

   //

   // Get file buffer from load file instance.

   //

@@ -1543,10 +1545,19 @@ BmExpandLoadFiles (

   HandleCount = 0;

 }



+NullUriPath = (URI_DEVICE_PATH *)CreateDeviceNode (

+   MESSAGING_DEVICE_PATH,

+   MSG_URI_DP,

+   (UINT16)(sizeof (URI_DEVICE_PATH))

+   );

+

 for (Index = 0; Index < HandleCount; Index++) {

   if (BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), 
FilePath)) {

 Handle = Handles[Index];

 break;

+  } else if (BmMatchHttpBootDevicePath (AppendDevicePathNode 
(DevicePathFromHandle (Handles[Index]), (EFI_DEVICE_PATH_PROTOCOL 
*)NullUriPath), FilePath)) {

+Handle = Handles[Index];

+break;

   }

 }



diff --git a/MdePkg/Include/Protocol/Http.h b/MdePkg/Include/Protocol/Http.h

index 28e622159392..4cf8fa4c0c97 100644

--- a/MdePkg/Include/Protocol/Http.h

+++ b/MdePkg/Include/Protocol/Http.h

@@ -191,6 +191,11 @@ typedef struct {

   /// is assumed. See RFC 3986 for more details on URI syntax.

   ///

   CHAR16 *Url;

+  ///

+  /// The URI of an endpoint host if the Url field contains the address of a 
proxy server.

+  /// This field will be NULL if a proxy server is not involved.

+  ///

+  CHAR16 *EndPointUrl;

 } 

Re: [edk2-devel] [PATCH 1/1] NetworkPkg/HttpBootDxe: Add Support for HTTPS Proxy Server for HTTP Boot

2022-07-01 Thread Maciej Rabeda

Hi Saloni,

This patch contains several problems. At minimum:

1. HttpBootLoadFile() logic around calling HttpBootGetBootFile() is
   becoming more complex - and BZ 2504 patch adds to it. I am becoming
   convinced that this part of HttpBootLoadFile() should have a
   separate function with a looped state machine, to cover all cases.
2. EfiHttpRequest(): "EndPointUrl = AllocateZeroPool (UrlLen)" followed
   with... "EndPointUrl = (CHAR8 *)Request->EndPointUrl". Was it
   supposed to be a copy from Request->EndPointUrl to EndPointUrl
   buffer or some other operation that I cannot comprehend?
3. Could you provide more more information on device path shenanigans
   around proxy URI?

Thanks,
Maciej

On 23 cze 2022 00:54, Saloni Kasbekar wrote:

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3951

Add CONNECT HTTP command in order to create a tunnel from HTTPS
Proxy Server to EndPoint Server.
Add support to connect through proxy server using DevicePath
sent to the Boot Manager.

Cc: Maciej Rabeda
Cc: Wu Jiaxin
Cc: Siyuan Fu
Cc: Jian J Wang
Cc: Liming Gao
Signed-off-by: Saloni Kasbekar
---
  .../Library/UefiBootManagerLib/BmBoot.c   |  11 ++
  MdePkg/Include/Protocol/Http.h|   5 +
  NetworkPkg/HttpBootDxe/HttpBootClient.c   | 168 +-
  NetworkPkg/HttpBootDxe/HttpBootClient.h   |  16 ++
  NetworkPkg/HttpBootDxe/HttpBootDxe.h  |   6 +
  NetworkPkg/HttpBootDxe/HttpBootImpl.c |  46 +++--
  NetworkPkg/HttpBootDxe/HttpBootSupport.c  |  13 +-
  NetworkPkg/HttpBootDxe/HttpBootSupport.h  |   8 +-
  NetworkPkg/HttpDxe/HttpImpl.c |  21 ++-
  NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c|   5 +
  10 files changed, 273 insertions(+), 26 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 962892d38f14..c5f09b619a89 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1513,7 +1513,9 @@ BmExpandLoadFiles (
UINTN HandleCount;
UINTN Index;
EFI_DEVICE_PATH_PROTOCOL  *Node;
+  URI_DEVICE_PATH   *NullUriPath;
  
+  NullUriPath = NULL;

//
// Get file buffer from load file instance.
//
@@ -1543,10 +1545,19 @@ BmExpandLoadFiles (
HandleCount = 0;
  }
  
+NullUriPath = (URI_DEVICE_PATH *)CreateDeviceNode (

+   MESSAGING_DEVICE_PATH,
+   MSG_URI_DP,
+   (UINT16)(sizeof (URI_DEVICE_PATH))
+   );
+
  for (Index = 0; Index < HandleCount; Index++) {
if (BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), 
FilePath)) {
  Handle = Handles[Index];
  break;
+  } else if (BmMatchHttpBootDevicePath (AppendDevicePathNode 
(DevicePathFromHandle (Handles[Index]), (EFI_DEVICE_PATH_PROTOCOL 
*)NullUriPath), FilePath)) {
+Handle = Handles[Index];
+break;
}
  }
  
diff --git a/MdePkg/Include/Protocol/Http.h b/MdePkg/Include/Protocol/Http.h

index 28e622159392..4cf8fa4c0c97 100644
--- a/MdePkg/Include/Protocol/Http.h
+++ b/MdePkg/Include/Protocol/Http.h
@@ -191,6 +191,11 @@ typedef struct {
/// is assumed. See RFC 3986 for more details on URI syntax.
///
CHAR16 *Url;
+  ///
+  /// The URI of an endpoint host if the Url field contains the address of a 
proxy server.
+  /// This field will be NULL if a proxy server is not involved.
+  ///
+  CHAR16 *EndPointUrl;
  } EFI_HTTP_REQUEST_DATA;
  
  ///

diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c 
b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index 62e87238fef7..2a4608414bd9 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -901,6 +901,168 @@ HttpBootGetBootFileCallback (
return EFI_SUCCESS;
  }
  
+/**

+  This function establishes a connection through a proxy server
+
+  @param[in]   Private The pointer to the driver's private data.
+
+  @retval EFI_SUCCESS  Connection successful.
+  @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
+  @retval Others   Unexpected error happened.
+
+**/
+EFI_STATUS
+HttpBootConnectProxy (
+  IN HTTP_BOOT_PRIVATE_DATA  *Private
+  )
+{
+  EFI_STATUS Status;
+  EFI_HTTP_STATUS_CODE   StatusCode;
+  CHAR8  *HostName;
+  EFI_HTTP_REQUEST_DATA  *RequestData;
+  HTTP_IO_RESPONSE_DATA  *ResponseData;
+  HTTP_IO*HttpIo;
+  HTTP_IO_HEADER *HttpIoHeader;
+  CHAR16 *Url;
+  CHAR16 *EndPointUrl;
+  UINTN  UrlSize;
+
+  UrlSize = AsciiStrSize (Private->BootFileUri);
+  Url = AllocatePool (UrlSize * sizeof (CHAR16));
+  if (Url == NULL) {
+return EFI_OUT_OF_RESOURCES;
+  }
+
+  

[edk2-devel] [PATCH 1/1] NetworkPkg/HttpBootDxe: Add Support for HTTPS Proxy Server for HTTP Boot

2022-06-22 Thread Saloni Kasbekar
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3951

Add CONNECT HTTP command in order to create a tunnel from HTTPS
Proxy Server to EndPoint Server.
Add support to connect through proxy server using DevicePath
sent to the Boot Manager.

Cc: Maciej Rabeda 
Cc: Wu Jiaxin 
Cc: Siyuan Fu 
Cc: Jian J Wang 
Cc: Liming Gao 
Signed-off-by: Saloni Kasbekar 
---
 .../Library/UefiBootManagerLib/BmBoot.c   |  11 ++
 MdePkg/Include/Protocol/Http.h|   5 +
 NetworkPkg/HttpBootDxe/HttpBootClient.c   | 168 +-
 NetworkPkg/HttpBootDxe/HttpBootClient.h   |  16 ++
 NetworkPkg/HttpBootDxe/HttpBootDxe.h  |   6 +
 NetworkPkg/HttpBootDxe/HttpBootImpl.c |  46 +++--
 NetworkPkg/HttpBootDxe/HttpBootSupport.c  |  13 +-
 NetworkPkg/HttpBootDxe/HttpBootSupport.h  |   8 +-
 NetworkPkg/HttpDxe/HttpImpl.c |  21 ++-
 NetworkPkg/Library/DxeHttpLib/DxeHttpLib.c|   5 +
 10 files changed, 273 insertions(+), 26 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 962892d38f14..c5f09b619a89 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1513,7 +1513,9 @@ BmExpandLoadFiles (
   UINTN HandleCount;
   UINTN Index;
   EFI_DEVICE_PATH_PROTOCOL  *Node;
+  URI_DEVICE_PATH   *NullUriPath;
 
+  NullUriPath = NULL;
   //
   // Get file buffer from load file instance.
   //
@@ -1543,10 +1545,19 @@ BmExpandLoadFiles (
   HandleCount = 0;
 }
 
+NullUriPath = (URI_DEVICE_PATH *)CreateDeviceNode (
+   MESSAGING_DEVICE_PATH,
+   MSG_URI_DP,
+   (UINT16)(sizeof (URI_DEVICE_PATH))
+   );
+
 for (Index = 0; Index < HandleCount; Index++) {
   if (BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), 
FilePath)) {
 Handle = Handles[Index];
 break;
+  } else if (BmMatchHttpBootDevicePath (AppendDevicePathNode 
(DevicePathFromHandle (Handles[Index]), (EFI_DEVICE_PATH_PROTOCOL 
*)NullUriPath), FilePath)) {
+Handle = Handles[Index];
+break;
   }
 }
 
diff --git a/MdePkg/Include/Protocol/Http.h b/MdePkg/Include/Protocol/Http.h
index 28e622159392..4cf8fa4c0c97 100644
--- a/MdePkg/Include/Protocol/Http.h
+++ b/MdePkg/Include/Protocol/Http.h
@@ -191,6 +191,11 @@ typedef struct {
   /// is assumed. See RFC 3986 for more details on URI syntax.
   ///
   CHAR16 *Url;
+  ///
+  /// The URI of an endpoint host if the Url field contains the address of a 
proxy server.
+  /// This field will be NULL if a proxy server is not involved.
+  ///
+  CHAR16 *EndPointUrl;
 } EFI_HTTP_REQUEST_DATA;
 
 ///
diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c 
b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index 62e87238fef7..2a4608414bd9 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -901,6 +901,168 @@ HttpBootGetBootFileCallback (
   return EFI_SUCCESS;
 }
 
+/**
+  This function establishes a connection through a proxy server
+
+  @param[in]   Private The pointer to the driver's private data.
+
+  @retval EFI_SUCCESS  Connection successful.
+  @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
+  @retval Others   Unexpected error happened.
+
+**/
+EFI_STATUS
+HttpBootConnectProxy (
+  IN HTTP_BOOT_PRIVATE_DATA  *Private
+  )
+{
+  EFI_STATUS Status;
+  EFI_HTTP_STATUS_CODE   StatusCode;
+  CHAR8  *HostName;
+  EFI_HTTP_REQUEST_DATA  *RequestData;
+  HTTP_IO_RESPONSE_DATA  *ResponseData;
+  HTTP_IO*HttpIo;
+  HTTP_IO_HEADER *HttpIoHeader;
+  CHAR16 *Url;
+  CHAR16 *EndPointUrl;
+  UINTN  UrlSize;
+
+  UrlSize = AsciiStrSize (Private->BootFileUri);
+  Url = AllocatePool (UrlSize * sizeof (CHAR16));
+  if (Url == NULL) {
+return EFI_OUT_OF_RESOURCES;
+  }
+
+  AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize);
+
+  UrlSize = AsciiStrSize (Private->EndPointUri);
+  EndPointUrl = AllocatePool (UrlSize * (sizeof (CHAR16)));
+  if (EndPointUrl == NULL) {
+return EFI_OUT_OF_RESOURCES;
+  }
+
+  CopyMem (EndPointUrl, Private->EndPointUri, UrlSize);
+
+  //
+  // 2. Send HTTP request message.
+  //
+
+  //
+  // 2.1 Build HTTP header for the request, 2 header is needed to send a 
CONNECT method:
+  //   Host
+  //   User
+  //
+  HttpIoHeader = HttpIoCreateHeader (2);
+  if (HttpIoHeader == NULL) {
+Status = EFI_OUT_OF_RESOURCES;
+goto ERROR_3;
+  }
+
+  //
+  // Add HTTP header field 1: Host (proxy)
+  //
+  HostName = Private->EndPointUri;
+  Status   = HttpIoSetHeader (
+   HttpIoHeader,
+