]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Set the secure boot state to Standard Mode when user leaving secure boot setup...
authorsfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 9 Jan 2013 05:19:43 +0000 (05:19 +0000)
committersfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 9 Jan 2013 05:19:43 +0000 (05:19 +0000)
2. Add “Current SecureBoot State” field to reflect current secure boot status of the platform.

Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Dong Guo <guo.dong@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14042 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni

index 1ba934b92294afe44fd9551803e12e5cf11121a7..8552d31b252f9f30b8d6000740425753912f0d3f 100644 (file)
@@ -356,30 +356,23 @@ AutenticatedVariableServiceInitialize (
   DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_SECURE_BOOT_ENABLE_NAME, SecureBootEnable));\r
 \r
   //\r
-  // Check "CustomMode" variable's existence.\r
+  // Initialize "CustomMode" in STANDARD_SECURE_BOOT_MODE state.\r
   //\r
   FindVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
-  if (Variable.CurrPtr != NULL) {\r
-    CustomMode = *(GetVariableDataPtr (Variable.CurrPtr));\r
-  } else {\r
-    //\r
-    // "CustomMode" not exist, initialize it in STANDARD_SECURE_BOOT_MODE.\r
-    //\r
-    CustomMode = STANDARD_SECURE_BOOT_MODE;\r
-    Status = UpdateVariable (\r
-               EFI_CUSTOM_MODE_NAME,\r
-               &gEfiCustomModeEnableGuid,\r
-               &CustomMode,\r
-               sizeof (UINT8),\r
-               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-               0,\r
-               0,\r
-               &Variable,\r
-               NULL\r
-               );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+  CustomMode = STANDARD_SECURE_BOOT_MODE;\r
+  Status = UpdateVariable (\r
+             EFI_CUSTOM_MODE_NAME,\r
+             &gEfiCustomModeEnableGuid,\r
+             &CustomMode,\r
+             sizeof (UINT8),\r
+             EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+             0,\r
+             0,\r
+             &Variable,\r
+             NULL\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
   \r
   DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_CUSTOM_MODE_NAME, CustomMode));\r
index df7ff37a86d49886dd3728a0e337adbc5ee5fc26..ae4b71bffd0fbb480c7d9659a37fffceb56543d4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   VFR file used by the SecureBoot configuration component.\r
 \r
-Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -32,7 +32,12 @@ formset
     title = STRING_TOKEN(STR_SECUREBOOT_TITLE);\r
 \r
     subtitle text = STRING_TOKEN(STR_NULL);\r
-    \r
+\r
+    text\r
+      help   = STRING_TOKEN(STR_SECURE_BOOT_STATE_HELP),\r
+      text   = STRING_TOKEN(STR_SECURE_BOOT_STATE_PROMPT),\r
+        text   = STRING_TOKEN(STR_SECURE_BOOT_STATE_CONTENT);\r
+        \r
     //\r
     // Define of Check Box: Attempt Secure Boot\r
     //\r
@@ -47,7 +52,7 @@ formset
     // Display of Check Box: Attempt Secure Boot\r
     //\r
     grayoutif ideqval SECUREBOOT_CONFIGURATION.HideSecureBoot == 1;\r
-    checkbox varid = SECUREBOOT_CONFIGURATION.SecureBootState,\r
+    checkbox varid = SECUREBOOT_CONFIGURATION.AttemptSecureBoot,\r
           questionid = KEY_SECURE_BOOT_ENABLE,\r
           prompt = STRING_TOKEN(STR_SECURE_BOOT_PROMPT),\r
           help   = STRING_TOKEN(STR_SECURE_BOOT_HELP),\r
index c56a3117604acecc2a59a64303b586b890de8a9a..7df68851c8b1a348961459651f8287669fed406a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Config Access protocol implementation of SecureBoot configuration module.\r
 \r
-Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -253,6 +253,7 @@ DeleteVariable (
   if (Variable == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
+  FreePool (Variable);\r
 \r
   Data     = NULL;\r
   DataSize = 0;\r
@@ -278,6 +279,31 @@ DeleteVariable (
   return Status;\r
 }\r
 \r
+/**\r
+\r
+  Set the platform secure boot mode into "Custom" or "Standard" mode.\r
+\r
+  @param[in]   SecureBootMode        New secure boot mode: STANDARD_SECURE_BOOT_MODE or\r
+                                     CUSTOM_SECURE_BOOT_MODE.\r
+  \r
+  @return EFI_SUCCESS                The platform has switched to the special mode successfully.\r
+  @return other                      Fail to operate the secure boot mode.\r
+  \r
+**/\r
+EFI_STATUS\r
+SetSecureBootMode (\r
+  IN     UINT8         SecureBootMode\r
+  )\r
+{\r
+  return gRT->SetVariable (                          \r
+                EFI_CUSTOM_MODE_NAME,\r
+                &gEfiCustomModeEnableGuid,\r
+                EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                sizeof (UINT8),\r
+                &SecureBootMode\r
+                );\r
+}\r
+\r
 /**\r
   Generate the PK signature list from the X509 Certificate storing file (.cer)\r
 \r
@@ -380,6 +406,11 @@ EnrollPlatformKey (
 \r
   PkCert = NULL;\r
 \r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Parse the file's postfix. Only support DER encoded X.509 certificate files.\r
   //\r
@@ -457,6 +488,11 @@ DeletePlatformKey (
 {\r
   EFI_STATUS Status;\r
 \r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   Status = DeleteVariable (\r
              EFI_PLATFORM_KEY_NAME,\r
              &gEfiGlobalVariableGuid\r
@@ -766,11 +802,17 @@ EnrollKeyExchangeKey (
   ) \r
 {\r
   UINT16*     FilePostFix;\r
+  EFI_STATUS  Status;\r
   \r
   if ((Private->FileContext->FileName == NULL) || (Private->SignatureGUID == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Parse the file's postfix. Supports DER-encoded X509 certificate, \r
   // and .pbk as RSA public key file.\r
@@ -1508,11 +1550,17 @@ EnrollSignatureDatabase (
   ) \r
 {\r
   UINT16*      FilePostFix;\r
+  EFI_STATUS   Status;\r
 \r
   if ((Private->FileContext->FileName == NULL) || (Private->FileContext->FHandle == NULL) || (Private->SignatureGUID == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
   //\r
   // Parse the file's postfix. \r
   //\r
@@ -1756,6 +1804,11 @@ DeleteKeyExchangeKey (
   Cert            = NULL;\r
   Attr            = 0;   \r
   DeleteKekIndex  = QuestionId - OPTION_DEL_KEK_QUESTION_ID;\r
+\r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
   \r
   //\r
   // Get original KEK variable.\r
@@ -1944,6 +1997,11 @@ DeleteSignature (
   Cert            = NULL;\r
   Attr            = 0; \r
 \r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Get original signature list data.\r
   //                           \r
@@ -2103,23 +2161,25 @@ SecureBootExtractConfigFromVariable (
 {\r
   UINT8   *SecureBootEnable;\r
   UINT8   *SetupMode;\r
-  UINT8   *SecureBoot;\r
   UINT8   *SecureBootMode;\r
 \r
   SecureBootEnable = NULL;\r
   SetupMode        = NULL;\r
-  SecureBoot       = NULL;\r
   SecureBootMode   = NULL;\r
   \r
   //\r
   // If the SecureBootEnable Variable doesn't exist, hide the SecureBoot Enable/Disable\r
   // Checkbox.\r
   //\r
+  ConfigData->AttemptSecureBoot = FALSE;\r
   GetVariable2 (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, (VOID**)&SecureBootEnable, NULL);\r
   if (SecureBootEnable == NULL) {\r
     ConfigData->HideSecureBoot = TRUE;\r
   } else {\r
     ConfigData->HideSecureBoot = FALSE;\r
+    if ((*SecureBootEnable) == SECURE_BOOT_ENABLE) {\r
+      ConfigData->AttemptSecureBoot = TRUE;\r
+    }\r
   }\r
   \r
   //\r
@@ -2140,16 +2200,6 @@ SecureBootExtractConfigFromVariable (
   } else  {\r
     ConfigData->HasPk = TRUE;\r
   }\r
-  \r
-  //\r
-  // If the value of SecureBoot variable is 1, the platform is operating in secure boot mode.\r
-  //\r
-  GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBoot, NULL);\r
-  if (SecureBoot != NULL && *SecureBoot == SECURE_BOOT_MODE_ENABLE) {\r
-    ConfigData->SecureBootState = TRUE;\r
-  } else {\r
-    ConfigData->SecureBootState = FALSE;\r
-  }\r
 \r
   //\r
   // Get the SecureBootMode from CustomMode variable.\r
@@ -2160,7 +2210,16 @@ SecureBootExtractConfigFromVariable (
   } else {\r
     ConfigData->SecureBootMode = *(SecureBootMode);\r
   }\r
-  \r
+\r
+  if (SecureBootEnable != NULL) {\r
+    FreePool (SecureBootEnable);\r
+  }\r
+  if (SetupMode != NULL) {\r
+    FreePool (SetupMode);\r
+  }\r
+  if (SecureBootMode != NULL) {\r
+    FreePool (SecureBootMode);\r
+  }\r
 }\r
 \r
 /**\r
@@ -2206,6 +2265,7 @@ SecureBootExtractConfig (
   EFI_STRING                        ConfigRequestHdr;\r
   SECUREBOOT_CONFIG_PRIVATE_DATA    *PrivateData;\r
   BOOLEAN                           AllocatedRequest;\r
+  UINT8                             *SecureBoot;\r
 \r
   if (Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2215,6 +2275,7 @@ SecureBootExtractConfig (
   ConfigRequestHdr = NULL;\r
   ConfigRequest    = NULL;\r
   Size             = 0;\r
+  SecureBoot       = NULL;\r
   \r
   ZeroMem (&Configuration, sizeof (Configuration));\r
   PrivateData      = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);\r
@@ -2228,6 +2289,19 @@ SecureBootExtractConfig (
   // Get Configuration from Variable.\r
   //\r
   SecureBootExtractConfigFromVariable (&Configuration);\r
+\r
+  //\r
+  // Update current secure boot state.\r
+  //\r
+  GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBoot, NULL);\r
+  if (SecureBoot != NULL && *SecureBoot == SECURE_BOOT_MODE_ENABLE) {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SECURE_BOOT_STATE_CONTENT), L"Enabled", NULL);\r
+  } else {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SECURE_BOOT_STATE_CONTENT), L"Disabled", NULL);\r
+  }\r
+  if (SecureBoot != NULL) {\r
+    FreePool (SecureBoot);\r
+  }\r
   \r
   BufferSize = sizeof (SECUREBOOT_CONFIGURATION);\r
   ConfigRequest = Request;\r
@@ -2355,15 +2429,21 @@ SecureBootCallback (
   SECUREBOOT_CONFIGURATION        *IfrNvData;\r
   UINT16                          LabelId;\r
   UINT8                           *SecureBootEnable;\r
+  UINT8                           *SecureBootMode;\r
+  UINT8                           *SetupMode;\r
   CHAR16                          PromptString[100];\r
 \r
   SecureBootEnable = NULL;\r
+  SecureBootMode   = NULL;\r
+  SetupMode        = NULL;\r
 \r
   if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
+  if ((Action != EFI_BROWSER_ACTION_CHANGED) &&\r
+      (Action != EFI_BROWSER_ACTION_CHANGING) &&\r
+      (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
   \r
@@ -2388,6 +2468,7 @@ SecureBootCallback (
     case KEY_SECURE_BOOT_ENABLE:\r
       GetVariable2 (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, (VOID**)&SecureBootEnable, NULL);\r
       if (NULL != SecureBootEnable) {\r
+        FreePool (SecureBootEnable);\r
         if (EFI_ERROR (SaveSecureBootVariable (Value->u8))) {\r
           CreatePopUp (\r
             EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
@@ -2400,11 +2481,10 @@ SecureBootCallback (
           CreatePopUp (\r
             EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
             &Key,\r
-            L"Secure boot configuration is changed, please reset the platform to take effect!",\r
+            L"Configuration changed, please reset the platform to take effect!",\r
             NULL\r
             );\r
         }\r
-        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; \r
       }\r
       break;\r
 \r
@@ -2461,10 +2541,26 @@ SecureBootCallback (
       break;\r
 \r
     case KEY_SECURE_BOOT_DELETE_PK: \r
-        if (Value->u8) {\r
+      if (Value->u8) {\r
+        CreatePopUp (\r
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+          &Key,\r
+          L"Are you sure you want to delete PK? Secure boot will be disabled!",\r
+          L"Press 'Y' to delete PK and exit, 'N' to discard change and return",\r
+          NULL\r
+          );\r
+        if (Key.UnicodeChar == 'y' || Key.UnicodeChar == 'Y') {\r
           Status = DeletePlatformKey ();\r
-          *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+          if (EFI_ERROR (Status)) {\r
+            CreatePopUp (\r
+              EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+              &Key,\r
+              L"Only Physical Presence User could delete PK in custom mode!",\r
+              NULL\r
+              );\r
+          }\r
         }\r
+      }\r
       break;\r
 \r
     case KEY_DELETE_KEK:\r
@@ -2547,7 +2643,7 @@ SecureBootCallback (
   } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
     switch (QuestionId) {\r
     case KEY_SECURE_BOOT_ENABLE:\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;      \r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
       break;  \r
     case KEY_VALUE_SAVE_AND_EXIT_PK:\r
       Status = EnrollPlatformKey (Private);\r
@@ -2588,8 +2684,8 @@ SecureBootCallback (
       break;\r
       \r
     case KEY_SECURE_BOOT_MODE:\r
-      GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootEnable, NULL);\r
-      if (NULL != SecureBootEnable) {\r
+      GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootMode, NULL);\r
+      if (NULL != SecureBootMode) {\r
         Status = gRT->SetVariable (                          \r
                         EFI_CUSTOM_MODE_NAME,\r
                         &gEfiCustomModeEnableGuid,\r
@@ -2599,6 +2695,7 @@ SecureBootCallback (
                         );\r
         *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
         IfrNvData->SecureBootMode = Value->u8;\r
+        FreePool (SecureBootMode);\r
       }        \r
       break;\r
 \r
@@ -2619,11 +2716,33 @@ SecureBootCallback (
       break;\r
 \r
     case KEY_SECURE_BOOT_DELETE_PK:\r
-      if (Value->u8) {\r
+      GetVariable2 (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SetupMode, NULL);\r
+      if (SetupMode == NULL || (*SetupMode) == SETUP_MODE) {\r
+        IfrNvData->DeletePk = TRUE;\r
+        IfrNvData->HasPk    = FALSE;\r
         *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+      } else  {\r
+        IfrNvData->DeletePk = FALSE;\r
+        IfrNvData->HasPk    = TRUE;\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+      }\r
+      if (SetupMode != NULL) {\r
+        FreePool (SetupMode);\r
       }\r
       break;  \r
     }\r
+  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+    //\r
+    // Force the platform back to Standard Mode once user leave the setup screen.\r
+    //\r
+    GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootMode, NULL);\r
+    if (NULL != SecureBootMode && *SecureBootMode == CUSTOM_SECURE_BOOT_MODE) {\r
+      IfrNvData->SecureBootMode = STANDARD_SECURE_BOOT_MODE;\r
+      SetSecureBootMode(STANDARD_SECURE_BOOT_MODE);\r
+    }\r
+    if (SecureBootMode != NULL) {\r
+      FreePool (SecureBootMode);\r
+    }\r
   }\r
   \r
   if (!EFI_ERROR (Status)) {\r
index 6015dd636dd49d1f738b8f632215432ae3f7a62a..ea4319290026ca7780cc27a77a0ee9ce95baecb1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for NV data structure definition.\r
 \r
-Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -106,7 +106,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 // Nv Data structure referenced by IFR\r
 //\r
 typedef struct {\r
-  BOOLEAN SecureBootState; //Secure Boot Disable/Enable;\r
+  BOOLEAN AttemptSecureBoot;  //Attempt to enable/disable Secure Boot.\r
   BOOLEAN HideSecureBoot;  //Hiden Attempt Secure Boot\r
   CHAR16  SignatureGuid[SECURE_BOOT_GUID_STORAGE_SIZE];\r
   BOOLEAN PhysicalPresent; //If a Physical Present User;\r
index ed4db131e9b0dd8547b4cf22e3915a25fee3abd1..8a4cb36f72d307197e01abfa64c130a1f8bebc59 100644 (file)
Binary files a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni and b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni differ