NetworkPkg/TlsAuthConfigDxe: preserve TlsCaCertificate variable attributes

If the platform creates the "TlsCaCertificate" variable as volatile, then
EnrollX509toVariable() shouldn't fail to extend it just because
TLS_AUTH_CONFIG_VAR_BASE_ATTR contains the EFI_VARIABLE_NON_VOLATILE
attribute.

Thus, if the variable exists, add the EFI_VARIABLE_APPEND_WRITE attribute
to the variable's current attributes. This is what DeleteCert() does
already.

Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Laszlo Ersek 2018-03-22 16:50:55 +01:00
parent 0fd13678a6
commit b90c335fbb

View File

@ -813,6 +813,7 @@ EnrollX509toVariable (
CACert = NULL; CACert = NULL;
CACertData = NULL; CACertData = NULL;
Data = NULL; Data = NULL;
Attr = 0;
Status = ReadFileContent ( Status = ReadFileContent (
Private->FileContext->FHandle, Private->FileContext->FHandle,
@ -847,22 +848,22 @@ EnrollX509toVariable (
CopyMem ((UINT8* ) (CACertData->SignatureData), X509Data, X509DataSize); CopyMem ((UINT8* ) (CACertData->SignatureData), X509Data, X509DataSize);
// //
// Check if signature database entry has been already existed. // Check if the signature database entry already exists. If it does, use the
// If true, use EFI_VARIABLE_APPEND_WRITE attribute to append the // EFI_VARIABLE_APPEND_WRITE attribute to append the new signature data to
// new signature data to original variable // the original variable, plus preserve the original variable attributes.
// //
Attr = TLS_AUTH_CONFIG_VAR_BASE_ATTR;
Status = gRT->GetVariable( Status = gRT->GetVariable(
VariableName, VariableName,
&gEfiTlsCaCertificateGuid, &gEfiTlsCaCertificateGuid,
NULL, &Attr,
&DataSize, &DataSize,
NULL NULL
); );
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
Attr |= EFI_VARIABLE_APPEND_WRITE; Attr |= EFI_VARIABLE_APPEND_WRITE;
} else if (Status != EFI_NOT_FOUND) { } else if (Status == EFI_NOT_FOUND) {
Attr = TLS_AUTH_CONFIG_VAR_BASE_ATTR;
} else {
goto ON_EXIT; goto ON_EXIT;
} }