summaryrefslogtreecommitdiff
path: root/lib/variables.c
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2017-10-27 09:49:06 -0400
committerPeter Jones <pmjones@gmail.com>2018-03-12 16:21:43 -0400
commit4d70f104818b947873698b5d9ba79e374e5b7586 (patch)
treeca7ec61dee597528c8ca99531ec09f0ac0a4083a /lib/variables.c
parent324db6bbabb32e3ef98f6fd8b4004403e2f8e04f (diff)
downloadefi-boot-shim-4d70f104818b947873698b5d9ba79e374e5b7586.tar.gz
efi-boot-shim-4d70f104818b947873698b5d9ba79e374e5b7586.zip
lib/variables.c: reformat CreateTimeBasedPayload()
Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'lib/variables.c')
-rw-r--r--lib/variables.c134
1 files changed, 66 insertions, 68 deletions
diff --git a/lib/variables.c b/lib/variables.c
index 8a993277..1fd95a7f 100644
--- a/lib/variables.c
+++ b/lib/variables.c
@@ -11,13 +11,13 @@
* Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
- * which accompanies this distribution. The full text of the license may be found
+ * which accompanies this distribution. The full text of the license may be found
* at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- *
+ *
*/
#include <efi.h>
#include <efilib.h>
@@ -51,76 +51,74 @@ variable_create_esl(void *cert, int cert_len, EFI_GUID *type, EFI_GUID *owner,
return EFI_SUCCESS;
}
-
EFI_STATUS
-CreateTimeBasedPayload (
- IN OUT UINTN *DataSize,
- IN OUT UINT8 **Data
- )
+CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data)
{
- EFI_STATUS Status;
- UINT8 *NewData;
- UINT8 *Payload;
- UINTN PayloadSize;
- EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData;
- UINTN DescriptorSize;
- EFI_TIME Time;
- EFI_GUID efi_cert_type = EFI_CERT_TYPE_PKCS7_GUID;
-
- if (Data == NULL || DataSize == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // In Setup mode or Custom mode, the variable does not need to be signed but the
- // parameters to the SetVariable() call still need to be prepared as authenticated
- // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor without certificate
- // data in it.
- //
- Payload = *Data;
- PayloadSize = *DataSize;
-
- DescriptorSize = OFFSET_OF(EFI_VARIABLE_AUTHENTICATION_2, AuthInfo) + OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData);
- NewData = (UINT8*) AllocateZeroPool (DescriptorSize + PayloadSize);
- if (NewData == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- if ((Payload != NULL) && (PayloadSize != 0)) {
- CopyMem (NewData + DescriptorSize, Payload, PayloadSize);
- }
-
- DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData);
-
- ZeroMem (&Time, sizeof (EFI_TIME));
- Status = uefi_call_wrapper(RT->GetTime,2, &Time, NULL);
- if (EFI_ERROR (Status)) {
- FreePool(NewData);
- return Status;
- }
- Time.Pad1 = 0;
- Time.Nanosecond = 0;
- Time.TimeZone = 0;
- Time.Daylight = 0;
- Time.Pad2 = 0;
- CopyMem (&DescriptorData->TimeStamp, &Time, sizeof (EFI_TIME));
-
- DescriptorData->AuthInfo.Hdr.dwLength = OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData);
- DescriptorData->AuthInfo.Hdr.wRevision = 0x0200;
- DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID;
- DescriptorData->AuthInfo.CertType = efi_cert_type;
-
- /* we're expecting an EFI signature list, so don't free the input since
- * it might not be in a pool */
+ EFI_STATUS Status;
+ UINT8 *NewData;
+ UINT8 *Payload;
+ UINTN PayloadSize;
+ EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData;
+ UINTN DescriptorSize;
+ EFI_TIME Time;
+
+ if (Data == NULL || DataSize == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // In Setup mode or Custom mode, the variable does not need to be signed but the
+ // parameters to the SetVariable() call still need to be prepared as authenticated
+ // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor without certificate
+ // data in it.
+ //
+ Payload = *Data;
+ PayloadSize = *DataSize;
+
+ DescriptorSize =
+ OFFSET_OF(EFI_VARIABLE_AUTHENTICATION_2,
+ AuthInfo) + OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID,
+ CertData);
+ NewData = (UINT8 *) AllocateZeroPool(DescriptorSize + PayloadSize);
+ if (NewData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if ((Payload != NULL) && (PayloadSize != 0)) {
+ CopyMem(NewData + DescriptorSize, Payload, PayloadSize);
+ }
+
+ DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData);
+
+ ZeroMem(&Time, sizeof(EFI_TIME));
+ Status = uefi_call_wrapper(RT->GetTime, 2, &Time, NULL);
+ if (EFI_ERROR(Status)) {
+ FreePool(NewData);
+ return Status;
+ }
+ Time.Pad1 = 0;
+ Time.Nanosecond = 0;
+ Time.TimeZone = 0;
+ Time.Daylight = 0;
+ Time.Pad2 = 0;
+ CopyMem(&DescriptorData->TimeStamp, &Time, sizeof(EFI_TIME));
+
+ DescriptorData->AuthInfo.Hdr.dwLength =
+ OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData);
+ DescriptorData->AuthInfo.Hdr.wRevision = 0x0200;
+ DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID;
+ DescriptorData->AuthInfo.CertType = EFI_CERT_TYPE_PKCS7_GUID;
+
+ /* we're expecting an EFI signature list, so don't free the input since
+ * it might not be in a pool */
#if 0
- if (Payload != NULL) {
- FreePool(Payload);
- }
+ if (Payload != NULL) {
+ FreePool(Payload);
+ }
#endif
-
- *DataSize = DescriptorSize + PayloadSize;
- *Data = NewData;
- return EFI_SUCCESS;
+
+ *DataSize = DescriptorSize + PayloadSize;
+ *Data = NewData;
+ return EFI_SUCCESS;
}
EFI_STATUS