From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.84900.1670008354257768666 for ; Fri, 02 Dec 2022 11:12:42 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=h6zpBoaw; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: saloni.kasbekar@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670008362; x=1701544362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fmGYryDIZG3hUfbfy3O9ZDO6hZ/KfsdEveWA5rbMAw8=; b=h6zpBoawrBZ53Lz6hv80i4P8zeYrEoqYx431dc0V7MM2b3lhPoqu7MNL KhDs8dr8kM5C3ekvqTQUdci5puAdK5VH61A4gbkb6bndb5tNA4CqNpAe7 Lqns2iNMxLbNZxbuVjT5BfA6zpcquz+36J3Wr02zI/tRfOKLoMlz4chW1 lDjQONCOtLrr4ovOrajxrd+FTH+i5pzsTl2W1pO2Olcq8NstN7wNuHaq5 arQjhjEx6DsRK8yd+mCTarSMMNxPNCzYZKOvynZjo4h+mgtzrhGpSTjfU EVP2pFYoLuJQR28oipGD9GVKrv3xnysJLGuMFahgLuq/K4mbxcnPZxkJ8 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="296382637" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="296382637" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 11:12:40 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="733916728" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="733916728" Received: from fmbiosdev02.amr.corp.intel.com ([10.80.127.10]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 11:12:40 -0800 From: "Saloni Kasbekar" To: devel@edk2.groups.io Cc: Saloni Kasbekar , Maciej Rabeda , Wu Jiaxin , Siyuan Fu Subject: [edk2-staging/HttpProxy PATCH v3 7/7] NetworkPkg/HttpBootDxe: Add Proxy URI input in setup menu Date: Fri, 2 Dec 2022 11:12:26 -0800 Message-Id: <14497137c1d8f0a847047080bd9f5e922f780ffa.1670008048.git.saloni.kasbekar@intel.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3951 Allows users to input the Proxy Server URI in the HTTP setup menu Cc: Maciej Rabeda Cc: Wu Jiaxin Cc: Siyuan Fu Signed-off-by: Saloni Kasbekar --- NetworkPkg/HttpBootDxe/HttpBootConfig.c | 99 ++++++++++++++----- .../HttpBootDxe/HttpBootConfigNVDataStruc.h | 4 +- .../HttpBootDxe/HttpBootConfigStrings.uni | 2 + NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr | 9 ++ 4 files changed, 88 insertions(+), 26 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfig.c b/NetworkPkg/HttpBootDxe/HttpBootConfig.c index 42d3fdc1fb..2cdd5043fe 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootConfig.c +++ b/NetworkPkg/HttpBootDxe/HttpBootConfig.c @@ -18,6 +18,7 @@ CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA"; @param[in] UsingIpv6 Set to TRUE if creating boot option for IPv6. @param[in] Description The description text of the boot option. @param[in] Uri The URI string of the boot file. + @param[in] ProxyUri The Proxy URI string for the boot path. @retval EFI_SUCCESS The boot option is created successfully. @retval Others Failed to create new boot option. @@ -28,48 +29,59 @@ HttpBootAddBootOption ( IN HTTP_BOOT_PRIVATE_DATA *Private, IN BOOLEAN UsingIpv6, IN CHAR16 *Description, - IN CHAR16 *Uri + IN CHAR16 *Uri, + IN CHAR16 *ProxyUri ) { EFI_DEV_PATH *Node; EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + EFI_DEVICE_PATH_PROTOCOL *FinalDevicePath; UINTN Length; CHAR8 AsciiUri[URI_STR_MAX_SIZE]; + CHAR8 AsciiProxyUri[URI_STR_MAX_SIZE]; + UINTN AsciiProxyUriSize; EFI_STATUS Status; - UINTN Index; EFI_BOOT_MANAGER_LOAD_OPTION NewOption; - NewDevicePath = NULL; - Node = NULL; - TmpDevicePath = NULL; + NewDevicePath = NULL; + Node = NULL; + TmpDevicePath = NULL; + FinalDevicePath = NULL; if (StrLen (Description) == 0) { return EFI_INVALID_PARAMETER; } // - // Convert the scheme to all lower case. + // Check the URI Scheme // - for (Index = 0; Index < StrLen (Uri); Index++) { - if (Uri[Index] == L':') { - break; + UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri)); + UnicodeStrToAsciiStrS (ProxyUri, AsciiProxyUri, sizeof (AsciiProxyUri)); + Status = HttpBootCheckUriScheme (AsciiUri); + if (EFI_ERROR (Status)) { + if (Status == EFI_INVALID_PARAMETER) { + DEBUG ((DEBUG_ERROR, "Error: Invalid URI address.\n")); + } else if (Status == EFI_ACCESS_DENIED) { + DEBUG ((DEBUG_ERROR, "Error: Access forbidden, only HTTPS connection is allowed.\n")); } - if ((Uri[Index] >= L'A') && (Uri[Index] <= L'Z')) { - Uri[Index] -= (CHAR16)(L'A' - L'a'); - } + return Status; } - // - // Only accept empty URI, or http and https URI. - // - if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) { - return EFI_INVALID_PARAMETER; + Status = HttpBootCheckUriScheme (AsciiProxyUri); + if (EFI_ERROR (Status)) { + if (Status == EFI_INVALID_PARAMETER) { + DEBUG ((DEBUG_ERROR, "Error: Invalid URI address.\n")); + } else if (Status == EFI_ACCESS_DENIED) { + DEBUG ((DEBUG_ERROR, "Error: Access forbidden, only HTTPS connection is allowed.\n")); + } + + return Status; } // - // Create a new device path by appending the IP node and URI node to + // Create a new device path by appending the IP node, Proxy node and URI node to // the driver's parent device path // if (!UsingIpv6) { @@ -100,15 +112,43 @@ HttpBootAddBootOption ( return EFI_OUT_OF_RESOURCES; } + // + // Update the Proxy node with the input Proxy URI + // + if (StrLen (ProxyUri) != 0) { + AsciiProxyUriSize = AsciiStrSize (AsciiProxyUri); + Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiProxyUriSize; + Node = AllocatePool (Length); + if (Node == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + Node->DevPath.Type = MESSAGING_DEVICE_PATH; + Node->DevPath.SubType = MSG_URI_DP; + SetDevicePathNodeLength (Node, Length); + CopyMem ( + (UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), + AsciiProxyUri, + AsciiProxyUriSize + ); + NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); + FreePool (Node); + if (NewDevicePath == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + } else { + NewDevicePath = TmpDevicePath; + } + // // Update the URI node with the input boot file URI. // - UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri)); Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (AsciiUri); Node = AllocatePool (Length); if (Node == NULL) { Status = EFI_OUT_OF_RESOURCES; - FreePool (TmpDevicePath); goto ON_EXIT; } @@ -116,10 +156,9 @@ HttpBootAddBootOption ( Node->DevPath.SubType = MSG_URI_DP; SetDevicePathNodeLength (Node, Length); CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), AsciiUri, AsciiStrSize (AsciiUri)); - NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); + FinalDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); FreePool (Node); - FreePool (TmpDevicePath); - if (NewDevicePath == NULL) { + if (FinalDevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } @@ -133,7 +172,7 @@ HttpBootAddBootOption ( LoadOptionTypeBoot, LOAD_OPTION_ACTIVE, Description, - NewDevicePath, + FinalDevicePath, NULL, 0 ); @@ -146,10 +185,18 @@ HttpBootAddBootOption ( ON_EXIT: + if (TmpDevicePath != NULL) { + FreePool (TmpDevicePath); + } + if (NewDevicePath != NULL) { FreePool (NewDevicePath); } + if (FinalDevicePath != NULL) { + FreePool (FinalDevicePath); + } + return Status; } @@ -406,7 +453,8 @@ HttpBootFormRouteConfig ( Private, (CallbackInfo->HttpBootNvData.IpVersion == HTTP_BOOT_IP_VERSION_6) ? TRUE : FALSE, CallbackInfo->HttpBootNvData.Description, - CallbackInfo->HttpBootNvData.Uri + CallbackInfo->HttpBootNvData.Uri, + CallbackInfo->HttpBootNvData.ProxyUri ); return EFI_SUCCESS; @@ -472,6 +520,7 @@ HttpBootFormCallback ( switch (QuestionId) { case KEY_INITIATOR_URI: + case KEY_INITIATOR_PROXY_URI: // // Get user input URI string // diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h index a24fa5cb08..f0da21e8fd 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h +++ b/NetworkPkg/HttpBootDxe/HttpBootConfigNVDataStruc.h @@ -27,7 +27,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define FORMID_MAIN_FORM 1 -#define KEY_INITIATOR_URI 0x101 +#define KEY_INITIATOR_URI 0x101 +#define KEY_INITIATOR_PROXY_URI 0x102 #define HTTP_BOOT_DEFAULT_DESCRIPTION_STR L"UEFI HTTP" @@ -37,6 +38,7 @@ typedef struct _HTTP_BOOT_CONFIG_IFR_NVDATA { UINT8 Padding; CHAR16 Description[DESCRIPTION_STR_MAX_SIZE]; CHAR16 Uri[URI_STR_MAX_SIZE]; + CHAR16 ProxyUri[URI_STR_MAX_SIZE]; } HTTP_BOOT_CONFIG_IFR_NVDATA; #pragma pack() diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni b/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni index 40abb13d0d..28af02bc14 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni +++ b/NetworkPkg/HttpBootDxe/HttpBootConfigStrings.uni @@ -18,4 +18,6 @@ #string STR_BOOT_URI_PROMPT #language en-US "Boot URI" #string STR_BOOT_URI_HELP #language en-US "A new Boot Option will be created according to this Boot URI." #string STR_BOOT_DESCRIPTION_PROMPT #language en-US "Input the description" +#string STR_BOOT_PROXY_URI_PROMPT #language en-US "Proxy URI" +#string STR_BOOT_PROXY_URI_HELP #language en-US "Proxy URI through which to connect to Boot URI" #string STR_NULL_STRING #language en-US "" diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr index 65a60216bc..6a23e57d6b 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr +++ b/NetworkPkg/HttpBootDxe/HttpBootConfigVfr.vfr @@ -44,6 +44,15 @@ formset minsize = URI_STR_MIN_SIZE, maxsize = URI_STR_MAX_SIZE, endstring; + + string varid = HTTP_BOOT_CONFIG_IFR_NVDATA.ProxyUri, + prompt = STRING_TOKEN(STR_BOOT_PROXY_URI_PROMPT), + help = STRING_TOKEN(STR_BOOT_PROXY_URI_HELP), + flags = INTERACTIVE, + key = KEY_INITIATOR_PROXY_URI, + minsize = URI_STR_MIN_SIZE, + maxsize = URI_STR_MAX_SIZE, + endstring; endform; endformset; -- 2.36.1.windows.1