2017-04-06 04:10:39 +02:00
|
|
|
/** @file
|
|
|
|
The Miscellaneous Routines for TlsAuthConfigDxe driver.
|
|
|
|
|
2018-06-27 15:12:32 +02:00
|
|
|
Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2019-04-04 01:06:13 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "TlsAuthConfigImpl.h"
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
VOID *mStartOpCodeHandle = NULL;
|
|
|
|
VOID *mEndOpCodeHandle = NULL;
|
|
|
|
EFI_IFR_GUID_LABEL *mStartLabel = NULL;
|
|
|
|
EFI_IFR_GUID_LABEL *mEndLabel = NULL;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
CHAR16 mTlsAuthConfigStorageName[] = L"TLS_AUTH_CONFIG_IFR_NVDATA";
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
TLS_AUTH_CONFIG_PRIVATE_DATA *mTlsAuthPrivateData = NULL;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
HII_VENDOR_DEVICE_PATH mTlsAuthConfigHiiVendorDevicePath = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HARDWARE_DEVICE_PATH,
|
|
|
|
HW_VENDOR_DP,
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
(UINT8)(sizeof (VENDOR_DEVICE_PATH)),
|
|
|
|
(UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
TLS_AUTH_CONFIG_GUID
|
|
|
|
},
|
|
|
|
{
|
|
|
|
END_DEVICE_PATH_TYPE,
|
|
|
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
(UINT8)(END_DEVICE_PATH_LENGTH),
|
|
|
|
(UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Possible DER-encoded certificate file suffixes, end with NULL pointer.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
CHAR16 *mDerPemEncodedSuffix[] = {
|
2017-04-06 04:10:39 +02:00
|
|
|
L".cer",
|
|
|
|
L".der",
|
|
|
|
L".crt",
|
|
|
|
L".pem",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This code checks if the FileSuffix is one of the possible DER/PEM-encoded certificate suffix.
|
|
|
|
|
|
|
|
@param[in] FileSuffix The suffix of the input certificate file
|
|
|
|
|
|
|
|
@retval TRUE It's a DER/PEM-encoded certificate.
|
|
|
|
@retval FALSE It's NOT a DER/PEM-encoded certificate.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
IsDerPemEncodeCertificate (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN CONST CHAR16 *FileSuffix
|
|
|
|
)
|
2017-04-06 04:10:39 +02:00
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
UINTN Index;
|
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
for (Index = 0; mDerPemEncodedSuffix[Index] != NULL; Index++) {
|
|
|
|
if (StrCmp (FileSuffix, mDerPemEncodedSuffix[Index]) == 0) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Worker function that prints an EFI_GUID into specified Buffer.
|
|
|
|
|
|
|
|
@param[in] Guid Pointer to GUID to print.
|
|
|
|
@param[in] Buffer Buffer to print Guid into.
|
|
|
|
@param[in] BufferSize Size of Buffer.
|
|
|
|
|
|
|
|
@retval Number of characters printed.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINTN
|
|
|
|
GuidToString (
|
|
|
|
IN EFI_GUID *Guid,
|
|
|
|
IN CHAR16 *Buffer,
|
|
|
|
IN UINTN BufferSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return UnicodeSPrint (
|
|
|
|
Buffer,
|
|
|
|
BufferSize,
|
|
|
|
L"%g",
|
|
|
|
Guid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
List all cert in specified database by GUID in the page
|
|
|
|
for user to select and delete as needed.
|
|
|
|
|
|
|
|
@param[in] PrivateData Module's private data.
|
|
|
|
@param[in] VariableName The variable name of the vendor's signature database.
|
|
|
|
@param[in] VendorGuid A unique identifier for the vendor.
|
|
|
|
@param[in] LabelNumber Label number to insert opcodes.
|
|
|
|
@param[in] FormId Form ID of current page.
|
|
|
|
@param[in] QuestionIdBase Base question id of the signature list.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Success to update the signature list page
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Unable to allocate required resources.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UpdateDeletePage (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private,
|
|
|
|
IN CHAR16 *VariableName,
|
|
|
|
IN EFI_GUID *VendorGuid,
|
|
|
|
IN UINT16 LabelNumber,
|
|
|
|
IN EFI_FORM_ID FormId,
|
|
|
|
IN EFI_QUESTION_ID QuestionIdBase
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Index;
|
|
|
|
UINTN CertCount;
|
|
|
|
UINTN GuidIndex;
|
|
|
|
VOID *StartOpCodeHandle;
|
|
|
|
VOID *EndOpCodeHandle;
|
|
|
|
EFI_IFR_GUID_LABEL *StartLabel;
|
|
|
|
EFI_IFR_GUID_LABEL *EndLabel;
|
|
|
|
UINTN DataSize;
|
|
|
|
UINT8 *Data;
|
|
|
|
EFI_SIGNATURE_LIST *CertList;
|
|
|
|
EFI_SIGNATURE_DATA *Cert;
|
|
|
|
UINT32 ItemDataSize;
|
|
|
|
CHAR16 *GuidStr;
|
|
|
|
EFI_STRING_ID GuidID;
|
|
|
|
EFI_STRING_ID Help;
|
|
|
|
|
|
|
|
Data = NULL;
|
|
|
|
CertList = NULL;
|
|
|
|
Cert = NULL;
|
|
|
|
GuidStr = NULL;
|
2017-04-06 04:10:39 +02:00
|
|
|
StartOpCodeHandle = NULL;
|
|
|
|
EndOpCodeHandle = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the container for dynamic opcodes.
|
|
|
|
//
|
|
|
|
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
if (StartOpCodeHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
if (EndOpCodeHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
|
|
|
|
StartOpCodeHandle,
|
|
|
|
&gEfiIfrTianoGuid,
|
|
|
|
NULL,
|
|
|
|
sizeof (EFI_IFR_GUID_LABEL)
|
|
|
|
);
|
|
|
|
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
StartLabel->Number = LabelNumber;
|
|
|
|
|
|
|
|
EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
|
|
|
|
EndOpCodeHandle,
|
|
|
|
&gEfiIfrTianoGuid,
|
|
|
|
NULL,
|
|
|
|
sizeof (EFI_IFR_GUID_LABEL)
|
|
|
|
);
|
|
|
|
EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
EndLabel->Number = LABEL_END;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Read Variable.
|
|
|
|
//
|
|
|
|
DataSize = 0;
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gRT->GetVariable (VariableName, VendorGuid, NULL, &DataSize, Data);
|
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
Data = (UINT8 *)AllocateZeroPool (DataSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (Data == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gRT->GetVariable (VariableName, VendorGuid, NULL, &DataSize, Data);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
GuidStr = AllocateZeroPool (100);
|
|
|
|
if (GuidStr == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enumerate all data.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
ItemDataSize = (UINT32)DataSize;
|
|
|
|
CertList = (EFI_SIGNATURE_LIST *)Data;
|
|
|
|
GuidIndex = 0;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
while ((ItemDataSize > 0) && (ItemDataSize >= CertList->SignatureListSize)) {
|
|
|
|
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
|
|
|
|
Help = STRING_TOKEN (STR_CERT_TYPE_PCKS_GUID);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// The signature type is not supported in current implementation.
|
|
|
|
//
|
|
|
|
ItemDataSize -= CertList->SignatureListSize;
|
2021-12-05 23:54:07 +01:00
|
|
|
CertList = (EFI_SIGNATURE_LIST *)((UINT8 *)CertList + CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
for (Index = 0; Index < CertCount; Index++) {
|
2021-12-05 23:54:07 +01:00
|
|
|
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList
|
|
|
|
+ sizeof (EFI_SIGNATURE_LIST)
|
|
|
|
+ CertList->SignatureHeaderSize
|
|
|
|
+ Index * CertList->SignatureSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
//
|
|
|
|
// Display GUID and help
|
|
|
|
//
|
|
|
|
GuidToString (&Cert->SignatureOwner, GuidStr, 100);
|
2021-12-05 23:54:07 +01:00
|
|
|
GuidID = HiiSetString (Private->RegisteredHandle, 0, GuidStr, NULL);
|
2017-04-06 04:10:39 +02:00
|
|
|
HiiCreateCheckBoxOpCode (
|
|
|
|
StartOpCodeHandle,
|
2021-12-05 23:54:07 +01:00
|
|
|
(EFI_QUESTION_ID)(QuestionIdBase + GuidIndex++),
|
2017-04-06 04:10:39 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
GuidID,
|
|
|
|
Help,
|
|
|
|
EFI_IFR_FLAG_CALLBACK,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemDataSize -= CertList->SignatureListSize;
|
2021-12-05 23:54:07 +01:00
|
|
|
CertList = (EFI_SIGNATURE_LIST *)((UINT8 *)CertList + CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
HiiUpdateForm (
|
|
|
|
Private->RegisteredHandle,
|
|
|
|
&gTlsAuthConfigGuid,
|
|
|
|
FormId,
|
|
|
|
StartOpCodeHandle,
|
|
|
|
EndOpCodeHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
if (StartOpCodeHandle != NULL) {
|
|
|
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EndOpCodeHandle != NULL) {
|
|
|
|
HiiFreeOpCodeHandle (EndOpCodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Data != NULL) {
|
|
|
|
FreePool (Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GuidStr != NULL) {
|
|
|
|
FreePool (GuidStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Delete one entry from cert database.
|
|
|
|
|
2017-04-10 04:30:38 +02:00
|
|
|
@param[in] Private Module's private data.
|
2017-04-06 04:10:39 +02:00
|
|
|
@param[in] VariableName The variable name of the database.
|
|
|
|
@param[in] VendorGuid A unique identifier for the vendor.
|
|
|
|
@param[in] LabelNumber Label number to insert opcodes.
|
|
|
|
@param[in] FormId Form ID of current page.
|
|
|
|
@param[in] QuestionIdBase Base question id of the cert list.
|
|
|
|
@param[in] DeleteIndex Cert index to delete.
|
|
|
|
|
2020-02-07 02:08:02 +01:00
|
|
|
@retval EFI_SUCCESS Delete signature successfully.
|
2017-04-06 04:10:39 +02:00
|
|
|
@retval EFI_NOT_FOUND Can't find the signature item,
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
DeleteCert (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private,
|
|
|
|
IN CHAR16 *VariableName,
|
|
|
|
IN EFI_GUID *VendorGuid,
|
|
|
|
IN UINT16 LabelNumber,
|
|
|
|
IN EFI_FORM_ID FormId,
|
|
|
|
IN EFI_QUESTION_ID QuestionIdBase,
|
|
|
|
IN UINTN DeleteIndex
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN DataSize;
|
|
|
|
UINT8 *Data;
|
|
|
|
UINT8 *OldData;
|
|
|
|
UINT32 Attr;
|
|
|
|
UINT32 Index;
|
|
|
|
EFI_SIGNATURE_LIST *CertList;
|
|
|
|
EFI_SIGNATURE_LIST *NewCertList;
|
|
|
|
EFI_SIGNATURE_DATA *Cert;
|
|
|
|
UINTN CertCount;
|
|
|
|
UINT32 Offset;
|
|
|
|
BOOLEAN IsItemFound;
|
|
|
|
UINT32 ItemDataSize;
|
|
|
|
UINTN GuidIndex;
|
|
|
|
|
|
|
|
Data = NULL;
|
|
|
|
OldData = NULL;
|
|
|
|
CertList = NULL;
|
|
|
|
Cert = NULL;
|
|
|
|
Attr = 0;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get original signature list data.
|
|
|
|
//
|
|
|
|
DataSize = 0;
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gRT->GetVariable (VariableName, VendorGuid, NULL, &DataSize, NULL);
|
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
OldData = (UINT8 *)AllocateZeroPool (DataSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (OldData == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gRT->GetVariable (VariableName, VendorGuid, &Attr, &DataSize, OldData);
|
2021-12-05 23:54:07 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate space for new variable.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
Data = (UINT8 *)AllocateZeroPool (DataSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (Data == NULL) {
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enumerate all data and erasing the target item.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
IsItemFound = FALSE;
|
|
|
|
ItemDataSize = (UINT32)DataSize;
|
|
|
|
CertList = (EFI_SIGNATURE_LIST *)OldData;
|
|
|
|
Offset = 0;
|
|
|
|
GuidIndex = 0;
|
2017-04-06 04:10:39 +02:00
|
|
|
while ((ItemDataSize > 0) && (ItemDataSize >= CertList->SignatureListSize)) {
|
|
|
|
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
|
|
|
|
//
|
|
|
|
// Copy EFI_SIGNATURE_LIST header then calculate the signature count in this list.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
CopyMem (Data + Offset, CertList, (sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize));
|
|
|
|
NewCertList = (EFI_SIGNATURE_LIST *)(Data + Offset);
|
|
|
|
Offset += (sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
|
|
|
|
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
|
|
|
|
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
for (Index = 0; Index < CertCount; Index++) {
|
|
|
|
if (GuidIndex == DeleteIndex) {
|
|
|
|
//
|
|
|
|
// Find it! Skip it!
|
|
|
|
//
|
|
|
|
NewCertList->SignatureListSize -= CertList->SignatureSize;
|
2021-12-05 23:54:07 +01:00
|
|
|
IsItemFound = TRUE;
|
2017-04-06 04:10:39 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// This item doesn't match. Copy it to the Data buffer.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
CopyMem (Data + Offset, (UINT8 *)(Cert), CertList->SignatureSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
Offset += CertList->SignatureSize;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
GuidIndex++;
|
2021-12-05 23:54:07 +01:00
|
|
|
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)Cert + CertList->SignatureSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// This List doesn't match. Just copy it to the Data buffer.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
CopyMem (Data + Offset, (UINT8 *)(CertList), CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
Offset += CertList->SignatureListSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemDataSize -= CertList->SignatureListSize;
|
2021-12-05 23:54:07 +01:00
|
|
|
CertList = (EFI_SIGNATURE_LIST *)((UINT8 *)CertList + CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsItemFound) {
|
|
|
|
//
|
|
|
|
// Doesn't find the signature Item!
|
|
|
|
//
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Delete the EFI_SIGNATURE_LIST header if there is no signature in the list.
|
|
|
|
//
|
|
|
|
ItemDataSize = Offset;
|
2021-12-05 23:54:07 +01:00
|
|
|
CertList = (EFI_SIGNATURE_LIST *)Data;
|
|
|
|
Offset = 0;
|
2017-04-06 04:10:39 +02:00
|
|
|
ZeroMem (OldData, ItemDataSize);
|
|
|
|
while ((ItemDataSize > 0) && (ItemDataSize >= CertList->SignatureListSize)) {
|
2021-12-05 23:54:07 +01:00
|
|
|
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
DEBUG ((DEBUG_INFO, " CertCount = %x\n", CertCount));
|
|
|
|
if (CertCount != 0) {
|
2021-12-05 23:54:07 +01:00
|
|
|
CopyMem (OldData + Offset, (UINT8 *)(CertList), CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
Offset += CertList->SignatureListSize;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
ItemDataSize -= CertList->SignatureListSize;
|
2021-12-05 23:54:07 +01:00
|
|
|
CertList = (EFI_SIGNATURE_LIST *)((UINT8 *)CertList + CertList->SignatureListSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DataSize = Offset;
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gRT->SetVariable (
|
2017-04-06 04:10:39 +02:00
|
|
|
VariableName,
|
|
|
|
VendorGuid,
|
|
|
|
Attr,
|
|
|
|
DataSize,
|
|
|
|
OldData
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "Failed to set variable, Status = %r\n", Status));
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
if (Data != NULL) {
|
2021-12-05 23:54:07 +01:00
|
|
|
FreePool (Data);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OldData != NULL) {
|
2021-12-05 23:54:07 +01:00
|
|
|
FreePool (OldData);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return UpdateDeletePage (
|
|
|
|
Private,
|
|
|
|
VariableName,
|
|
|
|
VendorGuid,
|
|
|
|
LabelNumber,
|
|
|
|
FormId,
|
|
|
|
QuestionIdBase
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-10 04:30:38 +02:00
|
|
|
Clean the file related resource.
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2017-04-10 04:30:38 +02:00
|
|
|
@param[in] Private Module's private data.
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2017-04-10 04:30:38 +02:00
|
|
|
CleanFileContext (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2017-04-10 04:30:38 +02:00
|
|
|
if (Private->FileContext->FHandle != NULL) {
|
|
|
|
Private->FileContext->FHandle->Close (Private->FileContext->FHandle);
|
|
|
|
Private->FileContext->FHandle = NULL;
|
2021-12-05 23:54:07 +01:00
|
|
|
if (Private->FileContext->FileName != NULL) {
|
|
|
|
FreePool (Private->FileContext->FileName);
|
2017-04-10 04:30:38 +02:00
|
|
|
Private->FileContext->FileName = NULL;
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read file content into BufferPtr, the size of the allocate buffer
|
|
|
|
is *FileSize plus AddtionAllocateSize.
|
|
|
|
|
|
|
|
@param[in] FileHandle The file to be read.
|
|
|
|
@param[in, out] BufferPtr Pointers to the pointer of allocated buffer.
|
|
|
|
@param[out] FileSize Size of input file
|
|
|
|
@param[in] AddtionAllocateSize Addtion size the buffer need to be allocated.
|
|
|
|
In case the buffer need to contain others besides the file content.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The file was read into the buffer.
|
|
|
|
@retval EFI_INVALID_PARAMETER A parameter was invalid.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
|
|
|
@retval others Unexpected error.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ReadFileContent (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN EFI_FILE_HANDLE FileHandle,
|
|
|
|
IN OUT VOID **BufferPtr,
|
|
|
|
OUT UINTN *FileSize,
|
|
|
|
IN UINTN AddtionAllocateSize
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
UINTN BufferSize;
|
|
|
|
UINT64 SourceFileSize;
|
|
|
|
VOID *Buffer;
|
|
|
|
EFI_STATUS Status;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if ((FileHandle == NULL) || (FileSize == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the file size
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = FileHandle->SetPosition (FileHandle, (UINT64)-1);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = FileHandle->GetPosition (FileHandle, &SourceFileSize);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = FileHandle->SetPosition (FileHandle, 0);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
BufferSize = (UINTN)SourceFileSize + AddtionAllocateSize;
|
|
|
|
Buffer = AllocateZeroPool (BufferSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (Buffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
BufferSize = (UINTN)SourceFileSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
*FileSize = BufferSize;
|
|
|
|
|
|
|
|
Status = FileHandle->Read (FileHandle, &BufferSize, Buffer);
|
2021-12-05 23:54:07 +01:00
|
|
|
if (EFI_ERROR (Status) || (BufferSize != *FileSize)) {
|
2017-04-06 04:10:39 +02:00
|
|
|
FreePool (Buffer);
|
|
|
|
Buffer = NULL;
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = EFI_BAD_BUFFER_SIZE;
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
|
|
|
|
*BufferPtr = Buffer;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function converts an input device structure to a Unicode string.
|
|
|
|
|
|
|
|
@param[in] DevPath A pointer to the device path structure.
|
|
|
|
|
|
|
|
@return A new allocated Unicode string that represents the device path.
|
|
|
|
|
|
|
|
**/
|
|
|
|
CHAR16 *
|
|
|
|
EFIAPI
|
|
|
|
DevicePathToStr (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return ConvertDevicePathToText (
|
|
|
|
DevPath,
|
|
|
|
FALSE,
|
|
|
|
TRUE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.
|
|
|
|
The caller is responsible for freeing the allocated buffer using FreePool(). If return NULL
|
|
|
|
means not enough memory resource.
|
|
|
|
|
|
|
|
@param DevicePath Device path.
|
|
|
|
|
2020-02-07 02:08:02 +01:00
|
|
|
@retval NULL Not enough memory resource for AllocateCopyPool.
|
2017-04-06 04:10:39 +02:00
|
|
|
@retval Other A new allocated string that represents the file name.
|
|
|
|
|
|
|
|
**/
|
|
|
|
CHAR16 *
|
|
|
|
ExtractFileNameFromDevicePath (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
CHAR16 *String;
|
|
|
|
CHAR16 *MatchString;
|
|
|
|
CHAR16 *LastMatch;
|
|
|
|
CHAR16 *FileName;
|
|
|
|
UINTN Length;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
ASSERT (DevicePath != NULL);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
String = DevicePathToStr (DevicePath);
|
2017-04-06 04:10:39 +02:00
|
|
|
MatchString = String;
|
|
|
|
LastMatch = String;
|
|
|
|
FileName = NULL;
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
while (MatchString != NULL) {
|
2017-04-06 04:10:39 +02:00
|
|
|
LastMatch = MatchString + 1;
|
2021-12-05 23:54:07 +01:00
|
|
|
MatchString = StrStr (LastMatch, L"\\");
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
Length = StrLen (LastMatch);
|
|
|
|
FileName = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), LastMatch);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (FileName != NULL) {
|
|
|
|
*(FileName + Length) = 0;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
FreePool (String);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
return FileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enroll a new X509 certificate into Variable.
|
|
|
|
|
|
|
|
@param[in] PrivateData The module's private data.
|
|
|
|
@param[in] VariableName Variable name of CA database.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS New X509 is enrolled successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EnrollX509toVariable (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private,
|
|
|
|
IN CHAR16 *VariableName
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN X509DataSize;
|
|
|
|
VOID *X509Data;
|
|
|
|
EFI_SIGNATURE_LIST *CACert;
|
|
|
|
EFI_SIGNATURE_DATA *CACertData;
|
|
|
|
VOID *Data;
|
|
|
|
UINTN DataSize;
|
|
|
|
UINTN SigDataSize;
|
|
|
|
UINT32 Attr;
|
|
|
|
|
|
|
|
X509DataSize = 0;
|
|
|
|
SigDataSize = 0;
|
|
|
|
DataSize = 0;
|
|
|
|
X509Data = NULL;
|
|
|
|
CACert = NULL;
|
|
|
|
CACertData = NULL;
|
|
|
|
Data = NULL;
|
|
|
|
Attr = 0;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
Status = ReadFileContent (
|
|
|
|
Private->FileContext->FHandle,
|
|
|
|
&X509Data,
|
|
|
|
&X509DataSize,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
ASSERT (X509Data != NULL);
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
SigDataSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
Data = AllocateZeroPool (SigDataSize);
|
|
|
|
if (Data == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill Certificate Database parameters.
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
CACert = (EFI_SIGNATURE_LIST *)Data;
|
|
|
|
CACert->SignatureListSize = (UINT32)SigDataSize;
|
2017-04-06 04:10:39 +02:00
|
|
|
CACert->SignatureHeaderSize = 0;
|
2021-12-05 23:54:07 +01:00
|
|
|
CACert->SignatureSize = (UINT32)(sizeof (EFI_SIGNATURE_DATA) - 1 + X509DataSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
CopyGuid (&CACert->SignatureType, &gEfiCertX509Guid);
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
CACertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CACert + sizeof (EFI_SIGNATURE_LIST));
|
2017-04-06 04:10:39 +02:00
|
|
|
CopyGuid (&CACertData->SignatureOwner, Private->CertGuid);
|
2021-12-05 23:54:07 +01:00
|
|
|
CopyMem ((UINT8 *)(CACertData->SignatureData), X509Data, X509DataSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
//
|
2018-03-22 16:50:55 +01:00
|
|
|
// Check if the signature database entry already exists. If it does, use the
|
|
|
|
// EFI_VARIABLE_APPEND_WRITE attribute to append the new signature data to
|
|
|
|
// the original variable, plus preserve the original variable attributes.
|
2017-04-06 04:10:39 +02:00
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gRT->GetVariable (
|
2017-04-06 04:10:39 +02:00
|
|
|
VariableName,
|
|
|
|
&gEfiTlsCaCertificateGuid,
|
2020-03-28 06:55:36 +01:00
|
|
|
&Attr,
|
2017-04-06 04:10:39 +02:00
|
|
|
&DataSize,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
Attr |= EFI_VARIABLE_APPEND_WRITE;
|
2018-03-22 16:50:55 +01:00
|
|
|
} else if (Status == EFI_NOT_FOUND) {
|
|
|
|
Attr = TLS_AUTH_CONFIG_VAR_BASE_ATTR;
|
|
|
|
} else {
|
2017-04-06 04:10:39 +02:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gRT->SetVariable (
|
2017-04-06 04:10:39 +02:00
|
|
|
VariableName,
|
|
|
|
&gEfiTlsCaCertificateGuid,
|
|
|
|
Attr,
|
|
|
|
SigDataSize,
|
|
|
|
Data
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
2017-04-10 04:30:38 +02:00
|
|
|
CleanFileContext (Private);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if (Private->CertGuid != NULL) {
|
|
|
|
FreePool (Private->CertGuid);
|
|
|
|
Private->CertGuid = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Data != NULL) {
|
|
|
|
FreePool (Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (X509Data != NULL) {
|
|
|
|
FreePool (X509Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enroll Cert into TlsCaCertificate. The GUID will be Private->CertGuid.
|
|
|
|
|
|
|
|
@param[in] PrivateData The module's private data.
|
|
|
|
@param[in] VariableName Variable name of signature database.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS New Cert enrolled successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER The parameter is invalid.
|
|
|
|
@retval EFI_UNSUPPORTED The Cert file is unsupported type.
|
|
|
|
@retval others Fail to enroll Cert data.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EnrollCertDatabase (
|
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private,
|
|
|
|
IN CHAR16 *VariableName
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
UINT16 *FilePostFix;
|
|
|
|
UINTN NameLength;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if ((Private->FileContext->FileName == NULL) || (Private->FileContext->FHandle == NULL) || (Private->CertGuid == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse the file's postfix.
|
|
|
|
//
|
|
|
|
NameLength = StrLen (Private->FileContext->FileName);
|
|
|
|
if (NameLength <= 4) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
FilePostFix = Private->FileContext->FileName + NameLength - 4;
|
|
|
|
|
|
|
|
if (IsDerPemEncodeCertificate (FilePostFix)) {
|
|
|
|
//
|
|
|
|
// Supports DER-encoded X509 certificate.
|
|
|
|
//
|
|
|
|
return EnrollX509toVariable (Private, VariableName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Refresh the global UpdateData structure.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
RefreshUpdateData (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Free current updated date
|
|
|
|
//
|
|
|
|
if (mStartOpCodeHandle != NULL) {
|
|
|
|
HiiFreeOpCodeHandle (mStartOpCodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create new OpCode Handle
|
|
|
|
//
|
|
|
|
mStartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
mStartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
|
|
|
|
mStartOpCodeHandle,
|
|
|
|
&gEfiIfrTianoGuid,
|
|
|
|
NULL,
|
|
|
|
sizeof (EFI_IFR_GUID_LABEL)
|
|
|
|
);
|
2017-04-06 04:10:39 +02:00
|
|
|
mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clean up the dynamic opcode at label and form specified by both LabelId.
|
|
|
|
|
|
|
|
@param[in] LabelId It is both the Form ID and Label ID for opcode deletion.
|
|
|
|
@param[in] PrivateData Module private data.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CleanUpPage (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN UINT16 LabelId,
|
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *PrivateData
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
RefreshUpdateData ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remove all op-codes from dynamic page
|
|
|
|
//
|
|
|
|
mStartLabel->Number = LabelId;
|
|
|
|
HiiUpdateForm (
|
|
|
|
PrivateData->RegisteredHandle,
|
|
|
|
&gTlsAuthConfigGuid,
|
|
|
|
LabelId,
|
|
|
|
mStartOpCodeHandle, // Label LabelId
|
|
|
|
mEndOpCodeHandle // LABEL_END
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the form base on the selected file.
|
|
|
|
|
|
|
|
@param FilePath Point to the file path.
|
|
|
|
@param FormId The form need to display.
|
|
|
|
|
|
|
|
@retval TRUE Exit caller function.
|
|
|
|
@retval FALSE Not exit caller function.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2021-12-05 23:54:07 +01:00
|
|
|
UpdatePage (
|
2017-04-06 04:10:39 +02:00
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
|
|
|
|
IN EFI_FORM_ID FormId
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
CHAR16 *FileName;
|
|
|
|
EFI_STRING_ID StringToken;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
FileName = NULL;
|
|
|
|
|
|
|
|
if (FilePath != NULL) {
|
2021-12-05 23:54:07 +01:00
|
|
|
FileName = ExtractFileNameFromDevicePath (FilePath);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
if (FileName == NULL) {
|
|
|
|
//
|
|
|
|
// FileName = NULL has two case:
|
|
|
|
// 1. FilePath == NULL, not select file.
|
|
|
|
// 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.
|
|
|
|
// In these two case, no need to update the form, and exit the caller function.
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
StringToken = HiiSetString (mTlsAuthPrivateData->RegisteredHandle, 0, FileName, NULL);
|
|
|
|
|
|
|
|
mTlsAuthPrivateData->FileContext->FileName = FileName;
|
|
|
|
|
2018-07-18 19:38:40 +02:00
|
|
|
EfiOpenFileByDevicePath (
|
2017-04-06 04:10:39 +02:00
|
|
|
&FilePath,
|
|
|
|
&mTlsAuthPrivateData->FileContext->FHandle,
|
|
|
|
EFI_FILE_MODE_READ,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
//
|
|
|
|
// Create Subtitle op-code for the display string of the option.
|
|
|
|
//
|
|
|
|
RefreshUpdateData ();
|
|
|
|
mStartLabel->Number = FormId;
|
|
|
|
|
|
|
|
HiiCreateSubTitleOpCode (
|
|
|
|
mStartOpCodeHandle,
|
|
|
|
StringToken,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
2021-12-05 23:54:07 +01:00
|
|
|
);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
HiiUpdateForm (
|
|
|
|
mTlsAuthPrivateData->RegisteredHandle,
|
|
|
|
&gTlsAuthConfigGuid,
|
|
|
|
FormId,
|
|
|
|
mStartOpCodeHandle, /// Label FormId
|
|
|
|
mEndOpCodeHandle /// LABEL_END
|
|
|
|
);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the form base on the input file path info.
|
|
|
|
|
|
|
|
@param FilePath Point to the file path.
|
|
|
|
|
|
|
|
@retval TRUE Exit caller function.
|
|
|
|
@retval FALSE Not exit caller function.
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EFIAPI
|
|
|
|
UpdateCAFromFile (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *FilePath
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
return UpdatePage (FilePath, TLS_AUTH_CONFIG_FORMID4_FORM);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Unload the configuration form, this includes: delete all the configuration
|
|
|
|
entries, uninstall the form callback protocol, and free the resources used.
|
|
|
|
|
|
|
|
@param[in] Private Pointer to the driver private data.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The configuration form is unloaded.
|
|
|
|
@retval Others Failed to unload the form.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
TlsAuthConfigFormUnload (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Private->DriverHandle != NULL) {
|
|
|
|
//
|
|
|
|
// Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
|
|
|
|
//
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
Private->DriverHandle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
&mTlsAuthConfigHiiVendorDevicePath,
|
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
|
|
|
&Private->ConfigAccess,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
Private->DriverHandle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Private->RegisteredHandle != NULL) {
|
|
|
|
//
|
|
|
|
// Remove HII package list
|
|
|
|
//
|
|
|
|
HiiRemovePackages (Private->RegisteredHandle);
|
|
|
|
Private->RegisteredHandle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Private->CertGuid != NULL) {
|
|
|
|
FreePool (Private->CertGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Private->FileContext != NULL) {
|
|
|
|
FreePool (Private->FileContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreePool (Private);
|
|
|
|
|
|
|
|
if (mStartOpCodeHandle != NULL) {
|
|
|
|
HiiFreeOpCodeHandle (mStartOpCodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEndOpCodeHandle != NULL) {
|
|
|
|
HiiFreeOpCodeHandle (mEndOpCodeHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the configuration form.
|
|
|
|
|
|
|
|
@param[in] Private Pointer to the driver private data.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The configuration form is initialized.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
TlsAuthConfigFormInit (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
Private->Signature = TLS_AUTH_CONFIG_PRIVATE_DATA_SIGNATURE;
|
|
|
|
|
|
|
|
Private->ConfigAccess.ExtractConfig = TlsAuthConfigAccessExtractConfig;
|
|
|
|
Private->ConfigAccess.RouteConfig = TlsAuthConfigAccessRouteConfig;
|
|
|
|
Private->ConfigAccess.Callback = TlsAuthConfigAccessCallback;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install Device Path Protocol and Config Access protocol to driver handle.
|
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&Private->DriverHandle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
&mTlsAuthConfigHiiVendorDevicePath,
|
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
|
|
|
&Private->ConfigAccess,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Publish our HII data.
|
|
|
|
//
|
|
|
|
Private->RegisteredHandle = HiiAddPackages (
|
|
|
|
&gTlsAuthConfigGuid,
|
|
|
|
Private->DriverHandle,
|
|
|
|
TlsAuthConfigDxeStrings,
|
|
|
|
TlsAuthConfigVfrBin,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (Private->RegisteredHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
Private->FileContext = AllocateZeroPool (sizeof (TLS_AUTH_CONFIG_FILE_CONTEXT));
|
|
|
|
if (Private->FileContext == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Init OpCode Handle and Allocate space for creation of Buffer
|
|
|
|
//
|
|
|
|
mStartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
if (mStartOpCodeHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEndOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
if (mEndOpCodeHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
mStartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
|
|
|
|
mStartOpCodeHandle,
|
|
|
|
&gEfiIfrTianoGuid,
|
|
|
|
NULL,
|
|
|
|
sizeof (EFI_IFR_GUID_LABEL)
|
|
|
|
);
|
2017-04-06 04:10:39 +02:00
|
|
|
mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the end opcode
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
mEndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
|
|
|
|
mEndOpCodeHandle,
|
|
|
|
&gEfiIfrTianoGuid,
|
|
|
|
NULL,
|
|
|
|
sizeof (EFI_IFR_GUID_LABEL)
|
|
|
|
);
|
2017-04-06 04:10:39 +02:00
|
|
|
mEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
mEndLabel->Number = LABEL_END;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
TlsAuthConfigFormUnload (Private);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
This function allows the caller to request the current
|
|
|
|
configuration for one or more named elements. The resulting
|
|
|
|
string is in <ConfigAltResp> format. Any and all alternative
|
|
|
|
configuration strings shall also be appended to the end of the
|
|
|
|
current configuration string. If they are, they must appear
|
|
|
|
after the current configuration. They must contain the same
|
|
|
|
routing (GUID, NAME, PATH) as the current configuration string.
|
|
|
|
They must have an additional description indicating the type of
|
|
|
|
alternative configuration the string represents,
|
|
|
|
"ALTCFG=<StringToken>". That <StringToken> (when
|
|
|
|
converted from Hex UNICODE to binary) is a reference to a
|
|
|
|
string in the associated string pack.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
|
|
|
|
@param Request A null-terminated Unicode string in
|
|
|
|
<ConfigRequest> format. Note that this
|
|
|
|
includes the routing information as well as
|
|
|
|
the configurable name / value pairs. It is
|
|
|
|
invalid for this string to be in
|
|
|
|
<MultiConfigRequest> format.
|
|
|
|
If a NULL is passed in for the Request field,
|
|
|
|
all of the settings being abstracted by this function
|
|
|
|
will be returned in the Results field. In addition,
|
|
|
|
if a ConfigHdr is passed in with no request elements,
|
|
|
|
all of the settings being abstracted for that particular
|
|
|
|
ConfigHdr reference will be returned in the Results Field.
|
|
|
|
|
|
|
|
@param Progress On return, points to a character in the
|
|
|
|
Request string. Points to the string's null
|
|
|
|
terminator if request was successful. Points
|
|
|
|
to the most recent "&" before the first
|
|
|
|
failing name / value pair (or the beginning
|
|
|
|
of the string if the failure is in the first
|
|
|
|
name / value pair) if the request was not
|
|
|
|
successful.
|
|
|
|
|
|
|
|
@param Results A null-terminated Unicode string in
|
|
|
|
<MultiConfigAltResp> format which has all values
|
|
|
|
filled in for the names in the Request string.
|
|
|
|
String to be allocated by the called function.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The Results string is filled with the
|
|
|
|
values corresponding to all requested
|
|
|
|
names.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the
|
|
|
|
parts of the results that must be
|
|
|
|
stored awaiting possible future
|
|
|
|
protocols.
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND Routing data doesn't match any
|
|
|
|
known driver. Progress set to the
|
|
|
|
first character in the routing header.
|
|
|
|
Note: There is no requirement that the
|
|
|
|
driver validate the routing data. It
|
|
|
|
must skip the <ConfigHdr> in order to
|
|
|
|
process the names.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
|
|
|
|
to most recent "&" before the
|
|
|
|
error or the beginning of the
|
|
|
|
string.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER Unknown name. Progress points
|
|
|
|
to the & before the name in
|
|
|
|
question.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TlsAuthConfigAccessExtractConfig (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN CONST EFI_STRING Request,
|
|
|
|
OUT EFI_STRING *Progress,
|
|
|
|
OUT EFI_STRING *Results
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
UINTN Size;
|
|
|
|
EFI_STRING ConfigRequest;
|
|
|
|
EFI_STRING ConfigRequestHdr;
|
|
|
|
TLS_AUTH_CONFIG_PRIVATE_DATA *Private;
|
|
|
|
BOOLEAN AllocatedRequest;
|
|
|
|
|
|
|
|
if ((Progress == NULL) || (Results == NULL)) {
|
2017-04-06 04:10:39 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
AllocatedRequest = FALSE;
|
|
|
|
ConfigRequestHdr = NULL;
|
|
|
|
ConfigRequest = NULL;
|
|
|
|
Size = 0;
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
Private = TLS_AUTH_CONFIG_PRIVATE_FROM_THIS (This);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
BufferSize = sizeof (TLS_AUTH_CONFIG_IFR_NVDATA);
|
2017-04-06 04:10:39 +02:00
|
|
|
ZeroMem (&Private->TlsAuthConfigNvData, BufferSize);
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
*Progress = Request;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gTlsAuthConfigGuid, mTlsAuthConfigStorageName)) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigRequest = Request;
|
|
|
|
if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
|
|
|
|
//
|
|
|
|
// Request is set to NULL or OFFSET is NULL, construct full request string.
|
|
|
|
//
|
|
|
|
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template
|
|
|
|
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
|
|
|
|
//
|
|
|
|
ConfigRequestHdr = HiiConstructConfigHdr (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, Private->DriverHandle);
|
2021-12-05 23:54:07 +01:00
|
|
|
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
|
|
|
|
ConfigRequest = AllocateZeroPool (Size);
|
2017-04-06 04:10:39 +02:00
|
|
|
ASSERT (ConfigRequest != NULL);
|
|
|
|
AllocatedRequest = TRUE;
|
|
|
|
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
|
|
|
|
FreePool (ConfigRequestHdr);
|
|
|
|
ConfigRequestHdr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gHiiConfigRouting->BlockToConfig (
|
|
|
|
gHiiConfigRouting,
|
|
|
|
ConfigRequest,
|
2021-12-05 23:54:07 +01:00
|
|
|
(UINT8 *)&Private->TlsAuthConfigNvData,
|
2017-04-06 04:10:39 +02:00
|
|
|
BufferSize,
|
|
|
|
Results,
|
|
|
|
Progress
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Free the allocated config request string.
|
|
|
|
//
|
|
|
|
if (AllocatedRequest) {
|
|
|
|
FreePool (ConfigRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set Progress string to the original request string.
|
|
|
|
//
|
|
|
|
if (Request == NULL) {
|
|
|
|
*Progress = NULL;
|
|
|
|
} else if (StrStr (Request, L"OFFSET") == NULL) {
|
|
|
|
*Progress = Request + StrLen (Request);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
This function applies changes in a driver's configuration.
|
|
|
|
Input is a Configuration, which has the routing data for this
|
|
|
|
driver followed by name / value configuration pairs. The driver
|
|
|
|
must apply those pairs to its configurable storage. If the
|
|
|
|
driver's configuration is stored in a linear block of data
|
|
|
|
and the driver's name / value pairs are in <BlockConfig>
|
|
|
|
format, it may use the ConfigToBlock helper function (above) to
|
|
|
|
simplify the job.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
|
|
|
|
@param Configuration A null-terminated Unicode string in
|
|
|
|
<ConfigString> format.
|
|
|
|
|
|
|
|
@param Progress A pointer to a string filled in with the
|
|
|
|
offset of the most recent '&' before the
|
|
|
|
first failing name / value pair (or the
|
2020-02-07 02:08:02 +01:00
|
|
|
beginning of the string if the failure
|
2017-04-06 04:10:39 +02:00
|
|
|
is in the first name / value pair) or
|
|
|
|
the terminating NULL if all was
|
|
|
|
successful.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The results have been distributed or are
|
|
|
|
awaiting distribution.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the
|
|
|
|
parts of the results that must be
|
|
|
|
stored awaiting possible future
|
|
|
|
protocols.
|
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETERS Passing in a NULL for the
|
|
|
|
Results parameter would result
|
|
|
|
in this type of error.
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND Target for the specified routing data
|
|
|
|
was not found
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TlsAuthConfigAccessRouteConfig (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN CONST EFI_STRING Configuration,
|
|
|
|
OUT EFI_STRING *Progress
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
TLS_AUTH_CONFIG_PRIVATE_DATA *Private;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if (Progress == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2021-12-05 23:54:07 +01:00
|
|
|
|
2017-04-06 04:10:39 +02:00
|
|
|
*Progress = Configuration;
|
|
|
|
|
|
|
|
if (Configuration == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check routing data in <ConfigHdr>.
|
|
|
|
// Note: there is no name for Name/Value storage, only GUID will be checked
|
|
|
|
//
|
|
|
|
if (!HiiIsConfigHdrMatch (Configuration, &gTlsAuthConfigGuid, mTlsAuthConfigStorageName)) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
Private = TLS_AUTH_CONFIG_PRIVATE_FROM_THIS (This);
|
|
|
|
|
|
|
|
BufferSize = sizeof (TLS_AUTH_CONFIG_IFR_NVDATA);
|
|
|
|
ZeroMem (&Private->TlsAuthConfigNvData, BufferSize);
|
|
|
|
|
|
|
|
Status = gHiiConfigRouting->ConfigToBlock (
|
|
|
|
gHiiConfigRouting,
|
|
|
|
Configuration,
|
2021-12-05 23:54:07 +01:00
|
|
|
(UINT8 *)&Private->TlsAuthConfigNvData,
|
2017-04-06 04:10:39 +02:00
|
|
|
&BufferSize,
|
|
|
|
Progress
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
This function is called to provide results data to the driver.
|
|
|
|
This data consists of a unique key that is used to identify
|
|
|
|
which data is either being passed back or being asked for.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
@param Action Specifies the type of action taken by the browser.
|
|
|
|
@param QuestionId A unique value which is sent to the original
|
|
|
|
exporting driver so that it can identify the type
|
|
|
|
of data to expect. The format of the data tends to
|
|
|
|
vary based on the opcode that generated the callback.
|
|
|
|
@param Type The type of value for the question.
|
|
|
|
@param Value A pointer to the data being sent to the original
|
|
|
|
exporting driver.
|
|
|
|
@param ActionRequest On return, points to the action requested by the
|
|
|
|
callback function.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The callback successfully handled the action.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
|
|
|
|
variable and its data.
|
|
|
|
@retval EFI_DEVICE_ERROR The variable could not be saved.
|
|
|
|
@retval EFI_UNSUPPORTED The specified Action is not supported by the
|
|
|
|
callback.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TlsAuthConfigAccessCallback (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN EFI_BROWSER_ACTION Action,
|
|
|
|
IN EFI_QUESTION_ID QuestionId,
|
|
|
|
IN UINT8 Type,
|
|
|
|
IN OUT EFI_IFR_TYPE_VALUE *Value,
|
|
|
|
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
|
2017-04-06 04:10:39 +02:00
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:07 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
RETURN_STATUS RStatus;
|
|
|
|
TLS_AUTH_CONFIG_PRIVATE_DATA *Private;
|
|
|
|
UINTN BufferSize;
|
|
|
|
TLS_AUTH_CONFIG_IFR_NVDATA *IfrNvData;
|
|
|
|
UINT16 LabelId;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *File;
|
|
|
|
EFI_HII_POPUP_PROTOCOL *HiiPopUp;
|
|
|
|
EFI_HII_POPUP_SELECTION PopUpSelect;
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
File = NULL;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Private = TLS_AUTH_CONFIG_PRIVATE_FROM_THIS (This);
|
|
|
|
|
|
|
|
mTlsAuthPrivateData = Private;
|
2021-12-05 23:54:07 +01:00
|
|
|
Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **)&HiiPopUp);
|
2020-04-09 08:56:41 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "Can't find Form PopUp protocol. Exit (%r)\n", Status));
|
|
|
|
return Status;
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieve uncommitted data from Browser
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (TLS_AUTH_CONFIG_IFR_NVDATA);
|
2021-12-05 23:54:07 +01:00
|
|
|
IfrNvData = AllocateZeroPool (BufferSize);
|
2017-04-06 04:10:39 +02:00
|
|
|
if (IfrNvData == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *)IfrNvData);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
|
|
|
if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
|
2018-06-27 15:12:32 +02:00
|
|
|
(Action != EFI_BROWSER_ACTION_CHANGING) &&
|
2021-12-05 23:54:07 +01:00
|
|
|
(Action != EFI_BROWSER_ACTION_FORM_CLOSE))
|
|
|
|
{
|
2017-04-06 04:10:39 +02:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Action == EFI_BROWSER_ACTION_CHANGING) {
|
|
|
|
switch (QuestionId) {
|
2021-12-05 23:54:07 +01:00
|
|
|
case KEY_TLS_AUTH_CONFIG_CLIENT_CERT:
|
|
|
|
case KEY_TLS_AUTH_CONFIG_SERVER_CA:
|
|
|
|
//
|
|
|
|
// Clear Cert GUID.
|
|
|
|
//
|
|
|
|
ZeroMem (IfrNvData->CertGuid, sizeof (IfrNvData->CertGuid));
|
2017-04-06 04:10:39 +02:00
|
|
|
if (Private->CertGuid == NULL) {
|
2021-12-05 23:54:07 +01:00
|
|
|
Private->CertGuid = (EFI_GUID *)AllocateZeroPool (sizeof (EFI_GUID));
|
|
|
|
if (Private->CertGuid == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
if (QuestionId == KEY_TLS_AUTH_CONFIG_CLIENT_CERT) {
|
|
|
|
LabelId = TLS_AUTH_CONFIG_FORMID3_FORM;
|
|
|
|
} else {
|
|
|
|
LabelId = TLS_AUTH_CONFIG_FORMID4_FORM;
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
//
|
|
|
|
// Refresh selected file.
|
|
|
|
//
|
|
|
|
CleanUpPage (LabelId, Private);
|
|
|
|
break;
|
|
|
|
case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:
|
|
|
|
//
|
|
|
|
// If the file is already opened, clean the file related resource first.
|
|
|
|
//
|
2017-04-10 04:30:38 +02:00
|
|
|
CleanFileContext (Private);
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
ChooseFile (NULL, NULL, UpdateCAFromFile, &File);
|
|
|
|
break;
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT:
|
|
|
|
Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
CleanFileContext (Private);
|
|
|
|
|
|
|
|
HiiPopUp->CreatePopup (
|
|
|
|
HiiPopUp,
|
|
|
|
EfiHiiPopupStyleError,
|
|
|
|
EfiHiiPopupTypeOk,
|
|
|
|
Private->RegisteredHandle,
|
|
|
|
STRING_TOKEN (STR_TLS_AUTH_ENROLL_CERT_FAILURE),
|
|
|
|
&PopUpSelect
|
|
|
|
);
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
|
|
|
|
CleanFileContext (Private);
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
if (Private->CertGuid != NULL) {
|
|
|
|
FreePool (Private->CertGuid);
|
|
|
|
Private->CertGuid = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_TLS_AUTH_CONFIG_DELETE_CERT:
|
|
|
|
UpdateDeletePage (
|
2017-04-06 04:10:39 +02:00
|
|
|
Private,
|
|
|
|
EFI_TLS_CA_CERTIFICATE_VARIABLE,
|
|
|
|
&gEfiTlsCaCertificateGuid,
|
|
|
|
LABEL_CA_DELETE,
|
|
|
|
TLS_AUTH_CONFIG_FORMID5_FORM,
|
2021-12-05 23:54:07 +01:00
|
|
|
OPTION_DEL_CA_ESTION_ID
|
2017-04-06 04:10:39 +02:00
|
|
|
);
|
2021-12-05 23:54:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ((QuestionId >= OPTION_DEL_CA_ESTION_ID) &&
|
|
|
|
(QuestionId < (OPTION_DEL_CA_ESTION_ID + OPTION_CONFIG_RANGE)))
|
|
|
|
{
|
|
|
|
DeleteCert (
|
|
|
|
Private,
|
|
|
|
EFI_TLS_CA_CERTIFICATE_VARIABLE,
|
|
|
|
&gEfiTlsCaCertificateGuid,
|
|
|
|
LABEL_CA_DELETE,
|
|
|
|
TLS_AUTH_CONFIG_FORMID5_FORM,
|
|
|
|
OPTION_DEL_CA_ESTION_ID,
|
|
|
|
QuestionId - OPTION_DEL_CA_ESTION_ID
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
} else if (Action == EFI_BROWSER_ACTION_CHANGED) {
|
|
|
|
switch (QuestionId) {
|
2021-12-05 23:54:07 +01:00
|
|
|
case KEY_TLS_AUTH_CONFIG_CERT_GUID:
|
|
|
|
ASSERT (Private->CertGuid != NULL);
|
|
|
|
RStatus = StrToGuid (
|
|
|
|
IfrNvData->CertGuid,
|
|
|
|
Private->CertGuid
|
|
|
|
);
|
|
|
|
if (RETURN_ERROR (RStatus) || (IfrNvData->CertGuid[GUID_STRING_LENGTH] != L'\0')) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2017-04-06 04:10:39 +02:00
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
2017-04-10 04:30:38 +02:00
|
|
|
} else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
|
|
|
|
CleanFileContext (Private);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EXIT:
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
BufferSize = sizeof (TLS_AUTH_CONFIG_IFR_NVDATA);
|
2021-12-05 23:54:07 +01:00
|
|
|
HiiSetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *)IfrNvData, NULL);
|
2017-04-06 04:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FreePool (IfrNvData);
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
if (File != NULL) {
|
|
|
|
FreePool (File);
|
2017-04-06 04:10:39 +02:00
|
|
|
File = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|