2 Miscellaneous routines specific to Https for HttpDxe driver.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HttpDriver.h"
19 Returns the first occurrence of a Null-terminated ASCII sub-string in a Null-terminated
20 ASCII string and ignore case during the search process.
22 This function scans the contents of the ASCII string specified by String
23 and returns the first occurrence of SearchString and ignore case during the search process.
24 If SearchString is not found in String, then NULL is returned. If the length of SearchString
25 is zero, then String is returned.
27 If String is NULL, then ASSERT().
28 If SearchString is NULL, then ASSERT().
30 @param[in] String A pointer to a Null-terminated ASCII string.
31 @param[in] SearchString A pointer to a Null-terminated ASCII string to search for.
33 @retval NULL If the SearchString does not appear in String.
34 @retval others If there is a match return the first occurrence of SearchingString.
35 If the length of SearchString is zero,return String.
40 IN CONST CHAR8
*String
,
41 IN CONST CHAR8
*SearchString
44 CONST CHAR8
*FirstMatch
;
45 CONST CHAR8
*SearchStringTmp
;
51 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
53 ASSERT (AsciiStrSize (String
) != 0);
54 ASSERT (AsciiStrSize (SearchString
) != 0);
56 if (*SearchString
== '\0') {
57 return (CHAR8
*) String
;
60 while (*String
!= '\0') {
61 SearchStringTmp
= SearchString
;
64 while ((*SearchStringTmp
!= '\0')
65 && (*String
!= '\0')) {
67 Dst
= *SearchStringTmp
;
69 if ((Src
>= 'A') && (Src
<= 'Z')) {
73 if ((Dst
>= 'A') && (Dst
<= 'Z')) {
85 if (*SearchStringTmp
== '\0') {
86 return (CHAR8
*) FirstMatch
;
89 String
= FirstMatch
+ 1;
96 The callback function to free the net buffer list.
98 @param[in] Arg The opaque parameter.
107 ASSERT (Arg
!= NULL
);
109 NetbufFreeList ((LIST_ENTRY
*) Arg
);
114 Check whether the Url is from Https.
116 @param[in] Url The pointer to a HTTP or HTTPS URL string.
118 @retval TRUE The Url is from HTTPS.
119 @retval FALSE The Url is from HTTP.
131 Tmp
= AsciiStrCaseStr (Url
, HTTPS_FLAG
);
132 if (Tmp
!= NULL
&& Tmp
== Url
) {
140 Creates a Tls child handle, open EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
142 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
143 @param[out] TlsSb Pointer to the TLS SERVICE_BINDING_PROTOCOL.
144 @param[out] TlsProto Pointer to the EFI_TLS_PROTOCOL instance.
145 @param[out] TlsConfiguration Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance.
147 @return The child handle with opened EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL.
153 IN EFI_HANDLE ImageHandle
,
154 OUT EFI_SERVICE_BINDING_PROTOCOL
**TlsSb
,
155 OUT EFI_TLS_PROTOCOL
**TlsProto
,
156 OUT EFI_TLS_CONFIGURATION_PROTOCOL
**TlsConfiguration
160 EFI_HANDLE TlsChildHandle
;
165 // Locate TlsServiceBinding protocol.
167 gBS
->LocateProtocol (
168 &gEfiTlsServiceBindingProtocolGuid
,
172 if (*TlsSb
== NULL
) {
176 Status
= (*TlsSb
)->CreateChild (*TlsSb
, &TlsChildHandle
);
177 if (EFI_ERROR (Status
)) {
181 Status
= gBS
->OpenProtocol (
183 &gEfiTlsProtocolGuid
,
187 EFI_OPEN_PROTOCOL_GET_PROTOCOL
189 if (EFI_ERROR (Status
)) {
190 (*TlsSb
)->DestroyChild (*TlsSb
, TlsChildHandle
);
194 Status
= gBS
->OpenProtocol (
196 &gEfiTlsConfigurationProtocolGuid
,
197 (VOID
**) TlsConfiguration
,
200 EFI_OPEN_PROTOCOL_GET_PROTOCOL
202 if (EFI_ERROR (Status
)) {
203 (*TlsSb
)->DestroyChild (*TlsSb
, TlsChildHandle
);
207 return TlsChildHandle
;
211 Create event for the TLS receive and transmit tokens which are used to receive and
212 transmit TLS related messages.
214 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
216 @retval EFI_SUCCESS The events are created successfully.
217 @retval others Other error as indicated.
223 IN OUT HTTP_PROTOCOL
*HttpInstance
228 if (!HttpInstance
->LocalAddressIsIPv6
) {
230 // For Tcp4TlsTxToken.
232 Status
= gBS
->CreateEvent (
236 &HttpInstance
->TlsIsTxDone
,
237 &HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Event
239 if (EFI_ERROR (Status
)) {
243 HttpInstance
->Tcp4TlsTxData
.Push
= TRUE
;
244 HttpInstance
->Tcp4TlsTxData
.Urgent
= FALSE
;
245 HttpInstance
->Tcp4TlsTxData
.DataLength
= 0;
246 HttpInstance
->Tcp4TlsTxData
.FragmentCount
= 1;
247 HttpInstance
->Tcp4TlsTxData
.FragmentTable
[0].FragmentLength
= HttpInstance
->Tcp4TlsTxData
.DataLength
;
248 HttpInstance
->Tcp4TlsTxData
.FragmentTable
[0].FragmentBuffer
= NULL
;
249 HttpInstance
->Tcp4TlsTxToken
.Packet
.TxData
= &HttpInstance
->Tcp4TlsTxData
;
250 HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Status
= EFI_NOT_READY
;
253 // For Tcp4TlsRxToken.
255 Status
= gBS
->CreateEvent (
259 &HttpInstance
->TlsIsRxDone
,
260 &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Event
262 if (EFI_ERROR (Status
)) {
266 HttpInstance
->Tcp4TlsRxData
.DataLength
= 0;
267 HttpInstance
->Tcp4TlsRxData
.FragmentCount
= 1;
268 HttpInstance
->Tcp4TlsRxData
.FragmentTable
[0].FragmentLength
= HttpInstance
->Tcp4TlsRxData
.DataLength
;
269 HttpInstance
->Tcp4TlsRxData
.FragmentTable
[0].FragmentBuffer
= NULL
;
270 HttpInstance
->Tcp4TlsRxToken
.Packet
.RxData
= &HttpInstance
->Tcp4TlsRxData
;
271 HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Status
= EFI_NOT_READY
;
274 // For Tcp6TlsTxToken.
276 Status
= gBS
->CreateEvent (
280 &HttpInstance
->TlsIsTxDone
,
281 &HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Event
283 if (EFI_ERROR (Status
)) {
287 HttpInstance
->Tcp6TlsTxData
.Push
= TRUE
;
288 HttpInstance
->Tcp6TlsTxData
.Urgent
= FALSE
;
289 HttpInstance
->Tcp6TlsTxData
.DataLength
= 0;
290 HttpInstance
->Tcp6TlsTxData
.FragmentCount
= 1;
291 HttpInstance
->Tcp6TlsTxData
.FragmentTable
[0].FragmentLength
= HttpInstance
->Tcp6TlsTxData
.DataLength
;
292 HttpInstance
->Tcp6TlsTxData
.FragmentTable
[0].FragmentBuffer
= NULL
;
293 HttpInstance
->Tcp6TlsTxToken
.Packet
.TxData
= &HttpInstance
->Tcp6TlsTxData
;
294 HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Status
= EFI_NOT_READY
;
297 // For Tcp6TlsRxToken.
299 Status
= gBS
->CreateEvent (
303 &HttpInstance
->TlsIsRxDone
,
304 &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Event
306 if (EFI_ERROR (Status
)) {
310 HttpInstance
->Tcp6TlsRxData
.DataLength
= 0;
311 HttpInstance
->Tcp6TlsRxData
.FragmentCount
= 1;
312 HttpInstance
->Tcp6TlsRxData
.FragmentTable
[0].FragmentLength
= HttpInstance
->Tcp6TlsRxData
.DataLength
;
313 HttpInstance
->Tcp6TlsRxData
.FragmentTable
[0].FragmentBuffer
= NULL
;
314 HttpInstance
->Tcp6TlsRxToken
.Packet
.RxData
= &HttpInstance
->Tcp6TlsRxData
;
315 HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Status
= EFI_NOT_READY
;
324 TlsCloseTxRxEvent (HttpInstance
);
330 Close events in the TlsTxToken and TlsRxToken.
332 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
338 IN HTTP_PROTOCOL
*HttpInstance
341 ASSERT (HttpInstance
!= NULL
);
342 if (!HttpInstance
->LocalAddressIsIPv6
) {
343 if (NULL
!= HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Event
) {
344 gBS
->CloseEvent(HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Event
);
345 HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Event
= NULL
;
348 if (NULL
!= HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Event
) {
349 gBS
->CloseEvent (HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Event
);
350 HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Event
= NULL
;
353 if (NULL
!= HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Event
) {
354 gBS
->CloseEvent(HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Event
);
355 HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Event
= NULL
;
358 if (NULL
!= HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Event
) {
359 gBS
->CloseEvent (HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Event
);
360 HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Event
= NULL
;
366 Read the TlsCaCertificate variable and configure it.
368 @param[in, out] HttpInstance The HTTP instance private data.
370 @retval EFI_SUCCESS TlsCaCertificate is configured.
371 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
372 @retval EFI_NOT_FOUND Fail to get 'TlsCaCertificate' variable.
373 @retval Others Other error as indicated.
377 TlsConfigCertificate (
378 IN OUT HTTP_PROTOCOL
*HttpInstance
385 EFI_SIGNATURE_LIST
*CertList
;
386 EFI_SIGNATURE_DATA
*Cert
;
394 // Try to read the TlsCaCertificate variable.
396 Status
= gRT
->GetVariable (
397 EFI_TLS_CA_CERTIFICATE_VARIABLE
,
398 &gEfiTlsCaCertificateGuid
,
404 if (EFI_ERROR (Status
) && Status
!= EFI_BUFFER_TOO_SMALL
) {
409 // Allocate buffer and read the config variable.
411 CACert
= AllocatePool (CACertSize
);
412 if (CACert
== NULL
) {
413 return EFI_OUT_OF_RESOURCES
;
416 Status
= gRT
->GetVariable (
417 EFI_TLS_CA_CERTIFICATE_VARIABLE
,
418 &gEfiTlsCaCertificateGuid
,
423 if (EFI_ERROR (Status
)) {
425 // GetVariable still error or the variable is corrupted.
426 // Fall back to the default value.
428 Status
= EFI_NOT_FOUND
;
432 ASSERT (CACert
!= NULL
);
435 // Enumerate all data and erasing the target item.
437 ItemDataSize
= (UINT32
) CACertSize
;
438 CertList
= (EFI_SIGNATURE_LIST
*) CACert
;
439 while ((ItemDataSize
> 0) && (ItemDataSize
>= CertList
->SignatureListSize
)) {
440 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
441 CertCount
= (CertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - CertList
->SignatureHeaderSize
) / CertList
->SignatureSize
;
442 for (Index
= 0; Index
< CertCount
; Index
++) {
444 // EfiTlsConfigDataTypeCACertificate
446 Status
= HttpInstance
->TlsConfiguration
->SetData (
447 HttpInstance
->TlsConfiguration
,
448 EfiTlsConfigDataTypeCACertificate
,
450 CertList
->SignatureSize
- sizeof (Cert
->SignatureOwner
)
452 if (EFI_ERROR (Status
)) {
456 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) Cert
+ CertList
->SignatureSize
);
459 ItemDataSize
-= CertList
->SignatureListSize
;
460 CertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) CertList
+ CertList
->SignatureListSize
);
469 Read the HttpTlsCipherList variable and configure it for HTTPS session.
471 @param[in, out] HttpInstance The HTTP instance private data.
473 @retval EFI_SUCCESS The prefered HTTP TLS CipherList is configured.
474 @retval EFI_NOT_FOUND Fail to get 'HttpTlsCipherList' variable.
475 @retval EFI_INVALID_PARAMETER The contents of variable are invalid.
476 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
478 @retval Others Other error as indicated.
482 TlsConfigCipherList (
483 IN OUT HTTP_PROTOCOL
*HttpInstance
488 UINTN CipherListSize
;
494 // Try to read the HttpTlsCipherList variable.
496 Status
= gRT
->GetVariable (
497 EDKII_HTTP_TLS_CIPHER_LIST_VARIABLE
,
498 &gEdkiiHttpTlsCipherListGuid
,
503 ASSERT (EFI_ERROR (Status
));
504 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
508 if (CipherListSize
% sizeof (EFI_TLS_CIPHER
) != 0) {
509 return EFI_INVALID_PARAMETER
;
513 // Allocate buffer and read the config variable.
515 CipherList
= AllocatePool (CipherListSize
);
516 if (CipherList
== NULL
) {
517 return EFI_OUT_OF_RESOURCES
;
520 Status
= gRT
->GetVariable (
521 EDKII_HTTP_TLS_CIPHER_LIST_VARIABLE
,
522 &gEdkiiHttpTlsCipherListGuid
,
527 if (EFI_ERROR (Status
)) {
529 // GetVariable still error or the variable is corrupted.
534 ASSERT (CipherList
!= NULL
);
536 Status
= HttpInstance
->Tls
->SetSessionData (
544 FreePool (CipherList
);
550 Configure TLS session data.
552 @param[in, out] HttpInstance The HTTP instance private data.
554 @retval EFI_SUCCESS TLS session data is configured.
555 @retval Others Other error as indicated.
560 TlsConfigureSession (
561 IN OUT HTTP_PROTOCOL
*HttpInstance
567 // TlsConfigData initialization
569 HttpInstance
->TlsConfigData
.ConnectionEnd
= EfiTlsClient
;
570 HttpInstance
->TlsConfigData
.VerifyMethod
= EFI_TLS_VERIFY_PEER
;
571 HttpInstance
->TlsConfigData
.SessionState
= EfiTlsSessionNotStarted
;
574 // EfiTlsConnectionEnd,
575 // EfiTlsVerifyMethod
576 // EfiTlsSessionState
578 Status
= HttpInstance
->Tls
->SetSessionData (
581 &(HttpInstance
->TlsConfigData
.ConnectionEnd
),
582 sizeof (EFI_TLS_CONNECTION_END
)
584 if (EFI_ERROR (Status
)) {
588 Status
= HttpInstance
->Tls
->SetSessionData (
591 &HttpInstance
->TlsConfigData
.VerifyMethod
,
592 sizeof (EFI_TLS_VERIFY
)
594 if (EFI_ERROR (Status
)) {
598 Status
= HttpInstance
->Tls
->SetSessionData (
601 &(HttpInstance
->TlsConfigData
.SessionState
),
602 sizeof (EFI_TLS_SESSION_STATE
)
604 if (EFI_ERROR (Status
)) {
611 Status
= TlsConfigCipherList (HttpInstance
);
612 if (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
) {
613 DEBUG ((EFI_D_ERROR
, "TlsConfigCipherList: return %r error.\n", Status
));
618 // Tls Config Certificate
620 Status
= TlsConfigCertificate (HttpInstance
);
621 if (EFI_ERROR (Status
)) {
622 DEBUG ((EFI_D_ERROR
, "TLS Certificate Config Error!\n"));
627 // TlsCreateTxRxEvent
629 Status
= TlsCreateTxRxEvent (HttpInstance
);
630 if (EFI_ERROR (Status
)) {
637 TlsCloseTxRxEvent (HttpInstance
);
643 Transmit the Packet by processing the associated HTTPS token.
645 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
646 @param[in] Packet The packet to transmit.
648 @retval EFI_SUCCESS The packet is transmitted.
649 @retval EFI_INVALID_PARAMETER HttpInstance is NULL or Packet is NULL.
650 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
651 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
652 @retval Others Other errors as indicated.
658 IN OUT HTTP_PROTOCOL
*HttpInstance
,
666 if ((HttpInstance
== NULL
) || (Packet
== NULL
)) {
667 return EFI_INVALID_PARAMETER
;
670 if (!HttpInstance
->LocalAddressIsIPv6
) {
671 Size
= sizeof (EFI_TCP4_TRANSMIT_DATA
) +
672 (Packet
->BlockOpNum
- 1) * sizeof (EFI_TCP4_FRAGMENT_DATA
);
674 Size
= sizeof (EFI_TCP6_TRANSMIT_DATA
) +
675 (Packet
->BlockOpNum
- 1) * sizeof (EFI_TCP6_FRAGMENT_DATA
);
678 Data
= AllocatePool (Size
);
680 return EFI_OUT_OF_RESOURCES
;
683 if (!HttpInstance
->LocalAddressIsIPv6
) {
684 ((EFI_TCP4_TRANSMIT_DATA
*) Data
)->Push
= TRUE
;
685 ((EFI_TCP4_TRANSMIT_DATA
*) Data
)->Urgent
= FALSE
;
686 ((EFI_TCP4_TRANSMIT_DATA
*) Data
)->DataLength
= Packet
->TotalSize
;
689 // Build the fragment table.
691 ((EFI_TCP4_TRANSMIT_DATA
*) Data
)->FragmentCount
= Packet
->BlockOpNum
;
695 (NET_FRAGMENT
*) &((EFI_TCP4_TRANSMIT_DATA
*) Data
)->FragmentTable
[0],
696 &((EFI_TCP4_TRANSMIT_DATA
*) Data
)->FragmentCount
699 HttpInstance
->Tcp4TlsTxToken
.Packet
.TxData
= (EFI_TCP4_TRANSMIT_DATA
*) Data
;
701 Status
= EFI_DEVICE_ERROR
;
704 // Transmit the packet.
706 Status
= HttpInstance
->Tcp4
->Transmit (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsTxToken
);
707 if (EFI_ERROR (Status
)) {
711 while (!HttpInstance
->TlsIsTxDone
) {
712 HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);
715 HttpInstance
->TlsIsTxDone
= FALSE
;
716 Status
= HttpInstance
->Tcp4TlsTxToken
.CompletionToken
.Status
;
718 ((EFI_TCP6_TRANSMIT_DATA
*) Data
)->Push
= TRUE
;
719 ((EFI_TCP6_TRANSMIT_DATA
*) Data
)->Urgent
= FALSE
;
720 ((EFI_TCP6_TRANSMIT_DATA
*) Data
)->DataLength
= Packet
->TotalSize
;
723 // Build the fragment table.
725 ((EFI_TCP6_TRANSMIT_DATA
*) Data
)->FragmentCount
= Packet
->BlockOpNum
;
729 (NET_FRAGMENT
*) &((EFI_TCP6_TRANSMIT_DATA
*) Data
)->FragmentTable
[0],
730 &((EFI_TCP6_TRANSMIT_DATA
*) Data
)->FragmentCount
733 HttpInstance
->Tcp6TlsTxToken
.Packet
.TxData
= (EFI_TCP6_TRANSMIT_DATA
*) Data
;
735 Status
= EFI_DEVICE_ERROR
;
738 // Transmit the packet.
740 Status
= HttpInstance
->Tcp6
->Transmit (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsTxToken
);
741 if (EFI_ERROR (Status
)) {
745 while (!HttpInstance
->TlsIsTxDone
) {
746 HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
749 HttpInstance
->TlsIsTxDone
= FALSE
;
750 Status
= HttpInstance
->Tcp6TlsTxToken
.CompletionToken
.Status
;
760 Receive the Packet by processing the associated HTTPS token.
762 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
763 @param[in] Packet The packet to transmit.
764 @param[in] Timeout The time to wait for connection done.
766 @retval EFI_SUCCESS The Packet is received.
767 @retval EFI_INVALID_PARAMETER HttpInstance is NULL or Packet is NULL.
768 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
769 @retval EFI_TIMEOUT The operation is time out.
770 @retval Others Other error as indicated.
776 IN OUT HTTP_PROTOCOL
*HttpInstance
,
781 EFI_TCP4_RECEIVE_DATA
*Tcp4RxData
;
782 EFI_TCP6_RECEIVE_DATA
*Tcp6RxData
;
784 NET_FRAGMENT
*Fragment
;
785 UINT32 FragmentCount
;
786 UINT32 CurrentFragment
;
791 if ((HttpInstance
== NULL
) || (Packet
== NULL
)) {
792 return EFI_INVALID_PARAMETER
;
795 FragmentCount
= Packet
->BlockOpNum
;
796 Fragment
= AllocatePool (FragmentCount
* sizeof (NET_FRAGMENT
));
797 if (Fragment
== NULL
) {
798 Status
= EFI_OUT_OF_RESOURCES
;
803 // Build the fragment table.
805 NetbufBuildExt (Packet
, Fragment
, &FragmentCount
);
807 if (!HttpInstance
->LocalAddressIsIPv6
) {
808 Tcp4RxData
= HttpInstance
->Tcp4TlsRxToken
.Packet
.RxData
;
809 if (Tcp4RxData
== NULL
) {
810 return EFI_INVALID_PARAMETER
;
812 Tcp4RxData
->FragmentCount
= 1;
814 Tcp6RxData
= HttpInstance
->Tcp6TlsRxToken
.Packet
.RxData
;
815 if (Tcp6RxData
== NULL
) {
816 return EFI_INVALID_PARAMETER
;
818 Tcp6RxData
->FragmentCount
= 1;
822 Status
= EFI_SUCCESS
;
824 while (CurrentFragment
< FragmentCount
) {
825 if (!HttpInstance
->LocalAddressIsIPv6
) {
826 Tcp4RxData
->DataLength
= Fragment
[CurrentFragment
].Len
;
827 Tcp4RxData
->FragmentTable
[0].FragmentLength
= Fragment
[CurrentFragment
].Len
;
828 Tcp4RxData
->FragmentTable
[0].FragmentBuffer
= Fragment
[CurrentFragment
].Bulk
;
829 Status
= HttpInstance
->Tcp4
->Receive (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
);
831 Tcp6RxData
->DataLength
= Fragment
[CurrentFragment
].Len
;
832 Tcp6RxData
->FragmentTable
[0].FragmentLength
= Fragment
[CurrentFragment
].Len
;
833 Tcp6RxData
->FragmentTable
[0].FragmentBuffer
= Fragment
[CurrentFragment
].Bulk
;
834 Status
= HttpInstance
->Tcp6
->Receive (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
);
836 if (EFI_ERROR (Status
)) {
840 while (!HttpInstance
->TlsIsRxDone
&& ((Timeout
== NULL
) || EFI_ERROR (gBS
->CheckEvent (Timeout
)))) {
842 // Poll until some data is received or an error occurs.
844 if (!HttpInstance
->LocalAddressIsIPv6
) {
845 HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);
847 HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
851 if (!HttpInstance
->TlsIsRxDone
) {
853 // Timeout occurs, cancel the receive request.
855 if (!HttpInstance
->LocalAddressIsIPv6
) {
856 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
858 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
861 Status
= EFI_TIMEOUT
;
864 HttpInstance
->TlsIsRxDone
= FALSE
;
867 if (!HttpInstance
->LocalAddressIsIPv6
) {
868 Status
= HttpInstance
->Tcp4TlsRxToken
.CompletionToken
.Status
;
869 if (EFI_ERROR (Status
)) {
873 Fragment
[CurrentFragment
].Len
-= Tcp4RxData
->FragmentTable
[0].FragmentLength
;
874 if (Fragment
[CurrentFragment
].Len
== 0) {
877 Fragment
[CurrentFragment
].Bulk
+= Tcp4RxData
->FragmentTable
[0].FragmentLength
;
880 Status
= HttpInstance
->Tcp6TlsRxToken
.CompletionToken
.Status
;
881 if (EFI_ERROR (Status
)) {
885 Fragment
[CurrentFragment
].Len
-= Tcp6RxData
->FragmentTable
[0].FragmentLength
;
886 if (Fragment
[CurrentFragment
].Len
== 0) {
889 Fragment
[CurrentFragment
].Bulk
+= Tcp6RxData
->FragmentTable
[0].FragmentLength
;
896 if (Fragment
!= NULL
) {
904 Receive one TLS PDU. An TLS PDU contains an TLS record header and it's
905 corresponding record data. These two parts will be put into two blocks of buffers in the
908 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
909 @param[out] Pdu The received TLS PDU.
910 @param[in] Timeout The time to wait for connection done.
912 @retval EFI_SUCCESS An TLS PDU is received.
913 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
914 @retval EFI_PROTOCOL_ERROR An unexpected TLS packet was received.
915 @retval Others Other errors as indicated.
921 IN OUT HTTP_PROTOCOL
*HttpInstance
,
928 LIST_ENTRY
*NbufList
;
934 TLS_RECORD_HEADER RecordHeader
;
943 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
944 if (NbufList
== NULL
) {
945 return EFI_OUT_OF_RESOURCES
;
948 InitializeListHead (NbufList
);
951 // Allocate buffer to receive one TLS header.
953 Len
= TLS_RECORD_HEADER_LENGTH
;
954 PduHdr
= NetbufAlloc (Len
);
955 if (PduHdr
== NULL
) {
956 Status
= EFI_OUT_OF_RESOURCES
;
960 Header
= NetbufAllocSpace (PduHdr
, Len
, NET_BUF_TAIL
);
961 if (Header
== NULL
) {
962 Status
= EFI_OUT_OF_RESOURCES
;
967 // First step, receive one TLS header.
969 Status
= TlsCommonReceive (HttpInstance
, PduHdr
, Timeout
);
970 if (EFI_ERROR (Status
)) {
974 RecordHeader
= *(TLS_RECORD_HEADER
*) Header
;
975 if ((RecordHeader
.ContentType
== TlsContentTypeHandshake
||
976 RecordHeader
.ContentType
== TlsContentTypeAlert
||
977 RecordHeader
.ContentType
== TlsContentTypeChangeCipherSpec
||
978 RecordHeader
.ContentType
== TlsContentTypeApplicationData
) &&
979 (RecordHeader
.Version
.Major
== 0x03) && /// Major versions are same.
980 (RecordHeader
.Version
.Minor
== TLS10_PROTOCOL_VERSION_MINOR
||
981 RecordHeader
.Version
.Minor
==TLS11_PROTOCOL_VERSION_MINOR
||
982 RecordHeader
.Version
.Minor
== TLS12_PROTOCOL_VERSION_MINOR
)
984 InsertTailList (NbufList
, &PduHdr
->List
);
986 Status
= EFI_PROTOCOL_ERROR
;
990 Len
= SwapBytes16(RecordHeader
.Length
);
999 // Allocate buffer to receive one TLS payload.
1001 DataSeg
= NetbufAlloc (Len
);
1002 if (DataSeg
== NULL
) {
1003 Status
= EFI_OUT_OF_RESOURCES
;
1007 NetbufAllocSpace (DataSeg
, Len
, NET_BUF_TAIL
);
1010 // Second step, receive one TLS payload.
1012 Status
= TlsCommonReceive (HttpInstance
, DataSeg
, Timeout
);
1013 if (EFI_ERROR (Status
)) {
1017 InsertTailList (NbufList
, &DataSeg
->List
);
1021 // Form the PDU from a list of PDU.
1023 *Pdu
= NetbufFromBufList (NbufList
, 0, 0, FreeNbufList
, NbufList
);
1025 Status
= EFI_OUT_OF_RESOURCES
;
1030 if (EFI_ERROR (Status
)) {
1032 // Free the Nbufs in this NbufList and the NbufList itself.
1034 FreeNbufList (NbufList
);
1041 Connect one TLS session by finishing the TLS handshake process.
1043 @param[in] HttpInstance The HTTP instance private data.
1044 @param[in] Timeout The time to wait for connection done.
1046 @retval EFI_SUCCESS The TLS session is established.
1047 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1048 @retval EFI_ABORTED TLS session state is incorrect.
1049 @retval Others Other error as indicated.
1055 IN HTTP_PROTOCOL
*HttpInstance
,
1056 IN EFI_EVENT Timeout
1061 UINTN BufferOutSize
;
1067 UINT8
*GetSessionDataBuffer
;
1068 UINTN GetSessionDataBufferSize
;
1077 // Initialize TLS state.
1079 HttpInstance
->TlsSessionState
= EfiTlsSessionNotStarted
;
1080 Status
= HttpInstance
->Tls
->SetSessionData (
1083 &(HttpInstance
->TlsSessionState
),
1084 sizeof (EFI_TLS_SESSION_STATE
)
1086 if (EFI_ERROR (Status
)) {
1091 // Create ClientHello
1093 BufferOutSize
= DEF_BUF_LEN
;
1094 BufferOut
= AllocateZeroPool (BufferOutSize
);
1095 if (BufferOut
== NULL
) {
1096 Status
= EFI_OUT_OF_RESOURCES
;
1100 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1107 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1108 FreePool (BufferOut
);
1109 BufferOut
= AllocateZeroPool (BufferOutSize
);
1110 if (BufferOut
== NULL
) {
1111 Status
= EFI_OUT_OF_RESOURCES
;
1115 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1123 if (EFI_ERROR (Status
)) {
1124 FreePool (BufferOut
);
1129 // Transmit ClientHello
1131 PacketOut
= NetbufAlloc ((UINT32
) BufferOutSize
);
1132 DataOut
= NetbufAllocSpace (PacketOut
, (UINT32
) BufferOutSize
, NET_BUF_TAIL
);
1133 if (DataOut
== NULL
) {
1134 FreePool (BufferOut
);
1135 return EFI_OUT_OF_RESOURCES
;
1138 CopyMem (DataOut
, BufferOut
, BufferOutSize
);
1139 Status
= TlsCommonTransmit (HttpInstance
, PacketOut
);
1141 FreePool (BufferOut
);
1142 NetbufFree (PacketOut
);
1144 if (EFI_ERROR (Status
)) {
1148 while(HttpInstance
->TlsSessionState
!= EfiTlsSessionDataTransferring
&& \
1149 ((Timeout
== NULL
) || EFI_ERROR (gBS
->CheckEvent (Timeout
)))) {
1151 // Receive one TLS record.
1153 Status
= TlsReceiveOnePdu (HttpInstance
, &Pdu
, Timeout
);
1154 if (EFI_ERROR (Status
)) {
1158 BufferInSize
= Pdu
->TotalSize
;
1159 BufferIn
= AllocateZeroPool (BufferInSize
);
1160 if (BufferIn
== NULL
) {
1162 Status
= EFI_OUT_OF_RESOURCES
;
1166 NetbufCopy (Pdu
, 0, (UINT32
)BufferInSize
, BufferIn
);
1171 // Handle Receive data.
1173 BufferOutSize
= DEF_BUF_LEN
;
1174 BufferOut
= AllocateZeroPool (BufferOutSize
);
1175 if (BufferOut
== NULL
) {
1176 Status
= EFI_OUT_OF_RESOURCES
;
1180 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1187 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1188 FreePool (BufferOut
);
1189 BufferOut
= AllocateZeroPool (BufferOutSize
);
1190 if (BufferOut
== NULL
) {
1191 FreePool (BufferIn
);
1192 Status
= EFI_OUT_OF_RESOURCES
;
1196 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1205 FreePool (BufferIn
);
1207 if (EFI_ERROR (Status
)) {
1208 FreePool (BufferOut
);
1212 if (BufferOutSize
!= 0) {
1214 // Transmit the response packet.
1216 PacketOut
= NetbufAlloc ((UINT32
) BufferOutSize
);
1217 DataOut
= NetbufAllocSpace (PacketOut
, (UINT32
) BufferOutSize
, NET_BUF_TAIL
);
1218 if (DataOut
== NULL
) {
1219 FreePool (BufferOut
);
1220 return EFI_OUT_OF_RESOURCES
;
1223 CopyMem (DataOut
, BufferOut
, BufferOutSize
);
1225 Status
= TlsCommonTransmit (HttpInstance
, PacketOut
);
1227 NetbufFree (PacketOut
);
1229 if (EFI_ERROR (Status
)) {
1230 FreePool (BufferOut
);
1235 FreePool (BufferOut
);
1238 // Get the session state, then decide whether need to continue handle received packet.
1240 GetSessionDataBufferSize
= DEF_BUF_LEN
;
1241 GetSessionDataBuffer
= AllocateZeroPool (GetSessionDataBufferSize
);
1242 if (GetSessionDataBuffer
== NULL
) {
1243 Status
= EFI_OUT_OF_RESOURCES
;
1247 Status
= HttpInstance
->Tls
->GetSessionData (
1250 GetSessionDataBuffer
,
1251 &GetSessionDataBufferSize
1253 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1254 FreePool (GetSessionDataBuffer
);
1255 GetSessionDataBuffer
= AllocateZeroPool (GetSessionDataBufferSize
);
1256 if (GetSessionDataBuffer
== NULL
) {
1257 Status
= EFI_OUT_OF_RESOURCES
;
1261 Status
= HttpInstance
->Tls
->GetSessionData (
1264 GetSessionDataBuffer
,
1265 &GetSessionDataBufferSize
1268 if (EFI_ERROR (Status
)) {
1269 FreePool(GetSessionDataBuffer
);
1273 ASSERT(GetSessionDataBufferSize
== sizeof (EFI_TLS_SESSION_STATE
));
1274 HttpInstance
->TlsSessionState
= *(EFI_TLS_SESSION_STATE
*) GetSessionDataBuffer
;
1276 FreePool (GetSessionDataBuffer
);
1278 if(HttpInstance
->TlsSessionState
== EfiTlsSessionError
) {
1283 if (HttpInstance
->TlsSessionState
!= EfiTlsSessionDataTransferring
) {
1284 Status
= EFI_ABORTED
;
1291 Close the TLS session and send out the close notification message.
1293 @param[in] HttpInstance The HTTP instance private data.
1295 @retval EFI_SUCCESS The TLS session is closed.
1296 @retval EFI_INVALID_PARAMETER HttpInstance is NULL.
1297 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1298 @retval Others Other error as indicated.
1304 IN HTTP_PROTOCOL
*HttpInstance
1310 UINTN BufferOutSize
;
1315 Status
= EFI_SUCCESS
;
1320 if (HttpInstance
== NULL
) {
1321 return EFI_INVALID_PARAMETER
;
1324 HttpInstance
->TlsSessionState
= EfiTlsSessionClosing
;
1326 Status
= HttpInstance
->Tls
->SetSessionData (
1329 &(HttpInstance
->TlsSessionState
),
1330 sizeof (EFI_TLS_SESSION_STATE
)
1332 if (EFI_ERROR (Status
)) {
1336 BufferOutSize
= DEF_BUF_LEN
;
1337 BufferOut
= AllocateZeroPool (BufferOutSize
);
1338 if (BufferOut
== NULL
) {
1339 Status
= EFI_OUT_OF_RESOURCES
;
1343 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1350 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1351 FreePool (BufferOut
);
1352 BufferOut
= AllocateZeroPool (BufferOutSize
);
1353 if (BufferOut
== NULL
) {
1354 Status
= EFI_OUT_OF_RESOURCES
;
1358 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1367 if (EFI_ERROR (Status
)) {
1368 FreePool (BufferOut
);
1372 PacketOut
= NetbufAlloc ((UINT32
) BufferOutSize
);
1373 DataOut
= NetbufAllocSpace (PacketOut
, (UINT32
) BufferOutSize
, NET_BUF_TAIL
);
1374 if (DataOut
== NULL
) {
1375 FreePool (BufferOut
);
1376 return EFI_OUT_OF_RESOURCES
;
1379 CopyMem (DataOut
, BufferOut
, BufferOutSize
);
1381 Status
= TlsCommonTransmit (HttpInstance
, PacketOut
);
1383 FreePool (BufferOut
);
1384 NetbufFree (PacketOut
);
1390 Process one message according to the CryptMode.
1392 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
1393 @param[in] Message Pointer to the message buffer needed to processed.
1394 If ProcessMode is EfiTlsEncrypt, the message contain the TLS
1395 header and plain text TLS APP payload.
1396 If ProcessMode is EfiTlsDecrypt, the message contain the TLS
1397 header and cipher text TLS APP payload.
1398 @param[in] MessageSize Pointer to the message buffer size.
1399 @param[in] ProcessMode Process mode.
1400 @param[in, out] Fragment Only one Fragment returned after the Message is
1401 processed successfully.
1402 If ProcessMode is EfiTlsEncrypt, the fragment contain the TLS
1403 header and cipher text TLS APP payload.
1404 If ProcessMode is EfiTlsDecrypt, the fragment contain the TLS
1405 header and plain text TLS APP payload.
1407 @retval EFI_SUCCESS Message is processed successfully.
1408 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1409 @retval Others Other errors as indicated.
1415 IN HTTP_PROTOCOL
*HttpInstance
,
1417 IN UINTN MessageSize
,
1418 IN EFI_TLS_CRYPT_MODE ProcessMode
,
1419 IN OUT NET_FRAGMENT
*Fragment
1426 EFI_TLS_FRAGMENT_DATA
*FragmentTable
;
1427 UINT32 FragmentCount
;
1428 EFI_TLS_FRAGMENT_DATA
*OriginalFragmentTable
;
1431 Status
= EFI_SUCCESS
;
1435 FragmentTable
= NULL
;
1436 OriginalFragmentTable
= NULL
;
1439 // Rebuild fragment table from BufferIn.
1442 FragmentTable
= AllocateZeroPool (FragmentCount
* sizeof (EFI_TLS_FRAGMENT_DATA
));
1443 if (FragmentTable
== NULL
) {
1444 Status
= EFI_OUT_OF_RESOURCES
;
1448 FragmentTable
->FragmentLength
= (UINT32
) MessageSize
;
1449 FragmentTable
->FragmentBuffer
= Message
;
1452 // Record the original FragmentTable.
1454 OriginalFragmentTable
= FragmentTable
;
1457 // Process the Message.
1459 Status
= HttpInstance
->Tls
->ProcessPacket (
1465 if (EFI_ERROR (Status
)) {
1470 // Calculate the size according to FragmentTable.
1472 for (Index
= 0; Index
< FragmentCount
; Index
++) {
1473 BufferSize
+= FragmentTable
[Index
].FragmentLength
;
1477 // Allocate buffer for processed data.
1479 Buffer
= AllocateZeroPool (BufferSize
);
1480 if (Buffer
== NULL
) {
1481 Status
= EFI_OUT_OF_RESOURCES
;
1486 // Copy the new FragmentTable buffer into Buffer.
1488 for (Index
= 0; Index
< FragmentCount
; Index
++) {
1490 (Buffer
+ BytesCopied
),
1491 FragmentTable
[Index
].FragmentBuffer
,
1492 FragmentTable
[Index
].FragmentLength
1494 BytesCopied
+= FragmentTable
[Index
].FragmentLength
;
1497 // Free the FragmentBuffer since it has been copied.
1499 FreePool (FragmentTable
[Index
].FragmentBuffer
);
1502 Fragment
->Len
= BufferSize
;
1503 Fragment
->Bulk
= Buffer
;
1507 if (OriginalFragmentTable
!= NULL
) {
1508 if( FragmentTable
== OriginalFragmentTable
) {
1509 FragmentTable
= NULL
;
1511 FreePool (OriginalFragmentTable
);
1512 OriginalFragmentTable
= NULL
;
1516 // Caller has the responsibility to free the FragmentTable.
1518 if (FragmentTable
!= NULL
) {
1519 FreePool (FragmentTable
);
1520 FragmentTable
= NULL
;
1527 Receive one fragment decrypted from one TLS record.
1529 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
1530 @param[in, out] Fragment The received Fragment.
1531 @param[in] Timeout The time to wait for connection done.
1533 @retval EFI_SUCCESS One fragment is received.
1534 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
1535 @retval EFI_ABORTED Something wrong decryption the message.
1536 @retval Others Other errors as indicated.
1542 IN HTTP_PROTOCOL
*HttpInstance
,
1543 IN OUT NET_FRAGMENT
*Fragment
,
1544 IN EFI_EVENT Timeout
1549 TLS_RECORD_HEADER RecordHeader
;
1552 NET_FRAGMENT TempFragment
;
1554 UINTN BufferOutSize
;
1557 UINT8
*GetSessionDataBuffer
;
1558 UINTN GetSessionDataBufferSize
;
1560 Status
= EFI_SUCCESS
;
1568 GetSessionDataBuffer
= NULL
;
1569 GetSessionDataBufferSize
= 0;
1572 // Receive only one TLS record
1574 Status
= TlsReceiveOnePdu (HttpInstance
, &Pdu
, Timeout
);
1575 if (EFI_ERROR (Status
)) {
1579 BufferInSize
= Pdu
->TotalSize
;
1580 BufferIn
= AllocateZeroPool (BufferInSize
);
1581 if (BufferIn
== NULL
) {
1582 Status
= EFI_OUT_OF_RESOURCES
;
1587 NetbufCopy (Pdu
, 0, (UINT32
) BufferInSize
, BufferIn
);
1592 // Handle Receive data.
1594 RecordHeader
= *(TLS_RECORD_HEADER
*) BufferIn
;
1596 if ((RecordHeader
.ContentType
== TlsContentTypeApplicationData
) &&
1597 (RecordHeader
.Version
.Major
== 0x03) &&
1598 (RecordHeader
.Version
.Minor
== TLS10_PROTOCOL_VERSION_MINOR
||
1599 RecordHeader
.Version
.Minor
== TLS11_PROTOCOL_VERSION_MINOR
||
1600 RecordHeader
.Version
.Minor
== TLS12_PROTOCOL_VERSION_MINOR
)
1605 Status
= TlsProcessMessage (
1613 FreePool (BufferIn
);
1615 if (EFI_ERROR (Status
)) {
1616 if (Status
== EFI_ABORTED
) {
1618 // Something wrong decryption the message.
1619 // BuildResponsePacket() will be called to generate Error Alert message and send it out.
1621 BufferOutSize
= DEF_BUF_LEN
;
1622 BufferOut
= AllocateZeroPool (BufferOutSize
);
1623 if (BufferOut
== NULL
) {
1624 Status
= EFI_OUT_OF_RESOURCES
;
1628 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1635 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1636 FreePool (BufferOut
);
1637 BufferOut
= AllocateZeroPool (BufferOutSize
);
1638 if (BufferOut
== NULL
) {
1639 Status
= EFI_OUT_OF_RESOURCES
;
1643 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1651 if (EFI_ERROR (Status
)) {
1652 FreePool(BufferOut
);
1656 if (BufferOutSize
!= 0) {
1657 PacketOut
= NetbufAlloc ((UINT32
)BufferOutSize
);
1658 DataOut
= NetbufAllocSpace (PacketOut
, (UINT32
) BufferOutSize
, NET_BUF_TAIL
);
1659 if (DataOut
== NULL
) {
1660 FreePool (BufferOut
);
1661 return EFI_OUT_OF_RESOURCES
;
1664 CopyMem (DataOut
, BufferOut
, BufferOutSize
);
1666 Status
= TlsCommonTransmit (HttpInstance
, PacketOut
);
1668 NetbufFree (PacketOut
);
1671 FreePool(BufferOut
);
1673 if (EFI_ERROR (Status
)) {
1686 ASSERT (((TLS_RECORD_HEADER
*) (TempFragment
.Bulk
))->ContentType
== TlsContentTypeApplicationData
);
1688 BufferInSize
= ((TLS_RECORD_HEADER
*) (TempFragment
.Bulk
))->Length
;
1689 BufferIn
= AllocateZeroPool (BufferInSize
);
1690 if (BufferIn
== NULL
) {
1691 Status
= EFI_OUT_OF_RESOURCES
;
1695 CopyMem (BufferIn
, TempFragment
.Bulk
+ TLS_RECORD_HEADER_LENGTH
, BufferInSize
);
1698 // Free the buffer in TempFragment.
1700 FreePool (TempFragment
.Bulk
);
1702 } else if ((RecordHeader
.ContentType
== TlsContentTypeAlert
) &&
1703 (RecordHeader
.Version
.Major
== 0x03) &&
1704 (RecordHeader
.Version
.Minor
== TLS10_PROTOCOL_VERSION_MINOR
||
1705 RecordHeader
.Version
.Minor
== TLS11_PROTOCOL_VERSION_MINOR
||
1706 RecordHeader
.Version
.Minor
== TLS12_PROTOCOL_VERSION_MINOR
)
1708 BufferOutSize
= DEF_BUF_LEN
;
1709 BufferOut
= AllocateZeroPool (BufferOutSize
);
1710 if (BufferOut
== NULL
) {
1711 FreePool (BufferIn
);
1712 Status
= EFI_OUT_OF_RESOURCES
;
1716 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1723 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1724 FreePool (BufferOut
);
1725 BufferOut
= AllocateZeroPool (BufferOutSize
);
1726 if (BufferOut
== NULL
) {
1727 FreePool (BufferIn
);
1728 Status
= EFI_OUT_OF_RESOURCES
;
1732 Status
= HttpInstance
->Tls
->BuildResponsePacket (
1741 FreePool (BufferIn
);
1743 if (EFI_ERROR (Status
)) {
1744 FreePool (BufferOut
);
1748 if (BufferOutSize
!= 0) {
1749 PacketOut
= NetbufAlloc ((UINT32
) BufferOutSize
);
1750 DataOut
= NetbufAllocSpace (PacketOut
, (UINT32
) BufferOutSize
, NET_BUF_TAIL
);
1751 if (DataOut
== NULL
) {
1752 FreePool (BufferOut
);
1753 return EFI_OUT_OF_RESOURCES
;
1756 CopyMem (DataOut
, BufferOut
, BufferOutSize
);
1758 Status
= TlsCommonTransmit (HttpInstance
, PacketOut
);
1760 NetbufFree (PacketOut
);
1763 FreePool (BufferOut
);
1766 // Get the session state.
1768 GetSessionDataBufferSize
= DEF_BUF_LEN
;
1769 GetSessionDataBuffer
= AllocateZeroPool (GetSessionDataBufferSize
);
1770 if (GetSessionDataBuffer
== NULL
) {
1771 Status
= EFI_OUT_OF_RESOURCES
;
1775 Status
= HttpInstance
->Tls
->GetSessionData (
1778 GetSessionDataBuffer
,
1779 &GetSessionDataBufferSize
1781 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1782 FreePool (GetSessionDataBuffer
);
1783 GetSessionDataBuffer
= AllocateZeroPool (GetSessionDataBufferSize
);
1784 if (GetSessionDataBuffer
== NULL
) {
1785 Status
= EFI_OUT_OF_RESOURCES
;
1789 Status
= HttpInstance
->Tls
->GetSessionData (
1792 GetSessionDataBuffer
,
1793 &GetSessionDataBufferSize
1796 if (EFI_ERROR (Status
)) {
1797 FreePool (GetSessionDataBuffer
);
1801 ASSERT(GetSessionDataBufferSize
== sizeof (EFI_TLS_SESSION_STATE
));
1802 HttpInstance
->TlsSessionState
= *(EFI_TLS_SESSION_STATE
*) GetSessionDataBuffer
;
1804 FreePool (GetSessionDataBuffer
);
1806 if(HttpInstance
->TlsSessionState
== EfiTlsSessionError
) {
1807 DEBUG ((EFI_D_ERROR
, "TLS Session State Error!\n"));
1815 Fragment
->Bulk
= BufferIn
;
1816 Fragment
->Len
= (UINT32
) BufferInSize
;