From: "Chang, Abner via groups.io" <abner.chang=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>,
Zachary Clark-williams <zachary.clark-williams@intel.com>,
Michael Brown <mcb30@ipxe.org>, Nickle Wang <nicklew@nvidia.com>,
Igor Kulchytskyy <igork@ami.com>
Subject: [edk2-devel] [PATCH 1/5] NetworkPkg/HttpDxe: Refactor TlsCreateChild function
Date: Sat, 30 Dec 2023 19:29:25 +0800 [thread overview]
Message-ID: <20231230112929.1711-2-abner.chang@amd.com> (raw)
In-Reply-To: <20231230112929.1711-1-abner.chang@amd.com>
From: Abner Chang <abner.chang@amd.com>
- Use HTTP instance as the parameter for TlsCreateChild function.
- Install TLS protocol on the HTTP instance that creates TLS child.
Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Cc: Zachary Clark-williams <zachary.clark-williams@intel.com>
Cc: Michael Brown <mcb30@ipxe.org>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
NetworkPkg/HttpDxe/HttpsSupport.h | 17 +++----
NetworkPkg/HttpDxe/HttpImpl.c | 20 ++-------
NetworkPkg/HttpDxe/HttpsSupport.c | 75 +++++++++++++++++--------------
3 files changed, 52 insertions(+), 60 deletions(-)
diff --git a/NetworkPkg/HttpDxe/HttpsSupport.h b/NetworkPkg/HttpDxe/HttpsSupport.h
index 3c70825e8c3..326a4e50120 100644
--- a/NetworkPkg/HttpDxe/HttpsSupport.h
+++ b/NetworkPkg/HttpDxe/HttpsSupport.h
@@ -30,21 +30,18 @@ IsHttpsUrl (
/**
Creates a Tls child handle, open EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
- @param[in] ImageHandle The firmware allocated handle for the UEFI image.
- @param[out] TlsSb Pointer to the TLS SERVICE_BINDING_PROTOCOL.
- @param[out] TlsProto Pointer to the EFI_TLS_PROTOCOL instance.
- @param[out] TlsConfiguration Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance.
+ @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
- @return The child handle with opened EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
+ @return EFI_SUCCESS TLS child handle is returned in HttpInstance->TlsChildHandle
+ with opened EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
+ EFI_DEVICE_ERROR TLS service binding protocol is not found.
+ Otherwise Fail to create TLS chile handle.
**/
-EFI_HANDLE
+EFI_STATUS
EFIAPI
TlsCreateChild (
- IN EFI_HANDLE ImageHandle,
- OUT EFI_SERVICE_BINDING_PROTOCOL **TlsSb,
- OUT EFI_TLS_PROTOCOL **TlsProto,
- OUT EFI_TLS_CONFIGURATION_PROTOCOL **TlsConfiguration
+ IN HTTP_PROTOCOL *HttpInstance
);
/**
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index 7c5c925cf78..aa4efedbf6b 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -248,7 +248,6 @@ EfiHttpRequest (
HTTP_TOKEN_WRAP *Wrap;
CHAR8 *FileUrl;
UINTN RequestMsgSize;
- EFI_HANDLE ImageHandle;
//
// Initializations
@@ -372,22 +371,9 @@ EfiHttpRequest (
// Check whether we need to create Tls child and open the TLS protocol.
//
if (HttpInstance->UseHttps && (HttpInstance->TlsChildHandle == NULL)) {
- //
- // Use TlsSb to create Tls child and open the TLS protocol.
- //
- if (HttpInstance->LocalAddressIsIPv6) {
- ImageHandle = HttpInstance->Service->Ip6DriverBindingHandle;
- } else {
- ImageHandle = HttpInstance->Service->Ip4DriverBindingHandle;
- }
-
- HttpInstance->TlsChildHandle = TlsCreateChild (
- ImageHandle,
- &(HttpInstance->TlsSb),
- &(HttpInstance->Tls),
- &(HttpInstance->TlsConfiguration)
- );
- if (HttpInstance->TlsChildHandle == NULL) {
+ // Create TLS child for this HTTP instance.
+ Status = TlsCreateChild (HttpInstance);
+ if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
diff --git a/NetworkPkg/HttpDxe/HttpsSupport.c b/NetworkPkg/HttpDxe/HttpsSupport.c
index 7330be42c00..fb7c1ea59f2 100644
--- a/NetworkPkg/HttpDxe/HttpsSupport.c
+++ b/NetworkPkg/HttpDxe/HttpsSupport.c
@@ -134,27 +134,31 @@ IsHttpsUrl (
/**
Creates a Tls child handle, open EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
- @param[in] ImageHandle The firmware allocated handle for the UEFI image.
- @param[out] TlsSb Pointer to the TLS SERVICE_BINDING_PROTOCOL.
- @param[out] TlsProto Pointer to the EFI_TLS_PROTOCOL instance.
- @param[out] TlsConfiguration Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance.
+ @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
- @return The child handle with opened EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
+ @return EFI_SUCCESS TLS child handle is returned in HttpInstance->TlsChildHandle
+ with opened EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
+ EFI_DEVICE_ERROR TLS service binding protocol is not found.
+ Otherwise Fail to create TLS chile handle.
**/
-EFI_HANDLE
+EFI_STATUS
EFIAPI
TlsCreateChild (
- IN EFI_HANDLE ImageHandle,
- OUT EFI_SERVICE_BINDING_PROTOCOL **TlsSb,
- OUT EFI_TLS_PROTOCOL **TlsProto,
- OUT EFI_TLS_CONFIGURATION_PROTOCOL **TlsConfiguration
+ IN HTTP_PROTOCOL *HttpInstance
)
{
+ EFI_HANDLE ImageHandle;
EFI_STATUS Status;
- EFI_HANDLE TlsChildHandle;
- TlsChildHandle = 0;
+ //
+ // Use TlsSb to create Tls child and open the TLS protocol.
+ //
+ if (HttpInstance->LocalAddressIsIPv6) {
+ ImageHandle = HttpInstance->Service->Ip6DriverBindingHandle;
+ } else {
+ ImageHandle = HttpInstance->Service->Ip4DriverBindingHandle;
+ }
//
// Locate TlsServiceBinding protocol.
@@ -162,44 +166,49 @@ TlsCreateChild (
gBS->LocateProtocol (
&gEfiTlsServiceBindingProtocolGuid,
NULL,
- (VOID **)TlsSb
+ (VOID **)&HttpInstance->TlsSb
);
- if (*TlsSb == NULL) {
- return NULL;
+ if (HttpInstance->TlsSb == NULL) {
+ return EFI_DEVICE_ERROR;
}
- Status = (*TlsSb)->CreateChild (*TlsSb, &TlsChildHandle);
+ //
+ // Create TLS protocol on HTTP handle, this creates the association between HTTP and TLS
+ // for HTTP driver external usages.
+ //
+ Status = HttpInstance->TlsSb->CreateChild (HttpInstance->TlsSb, &HttpInstance->Handle);
if (EFI_ERROR (Status)) {
- return NULL;
+ return Status;
}
- Status = gBS->OpenProtocol (
- TlsChildHandle,
- &gEfiTlsProtocolGuid,
- (VOID **)TlsProto,
- ImageHandle,
- TlsChildHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
+ HttpInstance->TlsChildHandle = HttpInstance->Handle;
+ Status = gBS->OpenProtocol (
+ HttpInstance->TlsChildHandle,
+ &gEfiTlsProtocolGuid,
+ (VOID **)&HttpInstance->Tls,
+ ImageHandle,
+ HttpInstance->TlsChildHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
if (EFI_ERROR (Status)) {
- (*TlsSb)->DestroyChild (*TlsSb, TlsChildHandle);
- return NULL;
+ HttpInstance->TlsSb->DestroyChild (HttpInstance->TlsSb, HttpInstance->TlsChildHandle);
+ return Status;
}
Status = gBS->OpenProtocol (
- TlsChildHandle,
+ HttpInstance->TlsChildHandle,
&gEfiTlsConfigurationProtocolGuid,
- (VOID **)TlsConfiguration,
+ (VOID **)&HttpInstance->TlsConfiguration,
ImageHandle,
- TlsChildHandle,
+ HttpInstance->TlsChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
- (*TlsSb)->DestroyChild (*TlsSb, TlsChildHandle);
- return NULL;
+ HttpInstance->TlsSb->DestroyChild (HttpInstance->TlsSb, HttpInstance->TlsChildHandle);
+ return Status;
}
- return TlsChildHandle;
+ return EFI_SUCCESS;
}
/**
--
2.37.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113005): https://edk2.groups.io/g/devel/message/113005
Mute This Topic: https://groups.io/mt/103430430/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-12-30 11:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-30 11:29 [edk2-devel] [PATCH 0/5] Support HTTP application TLS configuration protocol Chang, Abner via groups.io
2023-12-30 11:29 ` Chang, Abner via groups.io [this message]
2024-01-01 22:09 ` [edk2-devel] [PATCH 1/5] NetworkPkg/HttpDxe: Refactor TlsCreateChild function Michael Brown
2024-01-02 2:55 ` Chang, Abner via groups.io
2023-12-30 11:29 ` [edk2-devel] [PATCH 2/5] NetworkPkg: Introduce HttpsTlsConfigDataProtocol Chang, Abner via groups.io
2023-12-30 11:29 ` [edk2-devel] [PATCH 3/5] NetworkPkg/HttpDxe: Use HttpsTlsConfigDataProtocol Chang, Abner via groups.io
2023-12-30 11:29 ` [edk2-devel] [PATCH 4/5] RedfishPkg/RedfishRestExDxe: Produce EdkiiHttpsTlsConfigData protocol Chang, Abner via groups.io
2023-12-30 11:29 ` [edk2-devel] [PATCH 5/5] RedfishPkg/RedfishRestExDxe: Update the Supported function Chang, Abner via groups.io
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231230112929.1711-2-abner.chang@amd.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox