]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: SecureBootConfigDxe: SecureBoot UI for Customized SecureBoot Mode
authorChao Zhang <chao.b.zhang@intel.com>
Mon, 7 Dec 2015 06:20:36 +0000 (06:20 +0000)
committerczhang46 <czhang46@Edk2>
Mon, 7 Dec 2015 06:20:36 +0000 (06:20 +0000)
  Add SecureBoot UI support for Customized SecureBoot Mode transition according to Mantis 1263. User can do secure boot mode transition through UI.
  https://mantis.uefi.org/mantis/view.php?id=1263

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Zeng Star <star.zeng@intel.com>
Reviewed-by: Long Qin <qin.long@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19134 6f19259b-4bc3-4df7-8a09-765794883524

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

index 3c994317f74b3bde670b9da2fa88696f88a95c76..1eb3599279d80d4680cfb0f61fcb806bf533ead7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   VFR file used by the SecureBoot configuration component.\r
 \r
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2015, 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
@@ -33,6 +33,14 @@ formset
 \r
     subtitle text = STRING_TOKEN(STR_NULL);\r
 \r
+    //\r
+    // Display current secure boot mode(one of SetupMode/AuditMode/UserMode/DeployedMode)\r
+    //\r
+    text\r
+      help   = STRING_TOKEN(STR_CUR_SECURE_BOOT_MODE_HELP),\r
+      text   = STRING_TOKEN(STR_CUR_SECURE_BOOT_MODE_PROMPT),\r
+        text   = STRING_TOKEN(STR_CUR_SECURE_BOOT_MODE_CONTENT);\r
+\r
     text\r
       help   = STRING_TOKEN(STR_SECURE_BOOT_STATE_HELP),\r
       text   = STRING_TOKEN(STR_SECURE_BOOT_STATE_PROMPT),\r
@@ -84,18 +92,18 @@ formset
       endoneof;\r
 \r
     //\r
-    //\r
-    // Display of 'Current Secure Boot Mode'\r
+    // Display PK include page\r
     //\r
     suppressif questionref(SecureBootMode) == SECURE_BOOT_MODE_STANDARD;\r
-      grayoutif NOT ideqval SECUREBOOT_CONFIGURATION.PhysicalPresent == 1;\r
-      goto FORMID_SECURE_BOOT_OPTION_FORM,\r
-           prompt = STRING_TOKEN(STR_SECURE_BOOT_OPTION),\r
-           help   = STRING_TOKEN(STR_SECURE_BOOT_OPTION_HELP),\r
-           flags  = INTERACTIVE,\r
-           key    = KEY_SECURE_BOOT_OPTION;\r
-      endif;\r
+    grayoutif NOT ideqval SECUREBOOT_CONFIGURATION.PhysicalPresent == 1;\r
+    goto FORMID_SECURE_BOOT_OPTION_FORM,\r
+         prompt = STRING_TOKEN(STR_SECURE_BOOT_OPTION),\r
+         help   = STRING_TOKEN(STR_SECURE_BOOT_OPTION_HELP),\r
+         flags  = INTERACTIVE,\r
+         key    = KEY_SECURE_BOOT_OPTION;\r
+    endif;\r
     endif;\r
+\r
   endform;\r
 \r
   //\r
@@ -106,6 +114,55 @@ formset
 \r
     subtitle text = STRING_TOKEN(STR_NULL);\r
 \r
+    //\r
+    // Display of SetupMode/UserMode/AuditMode/DeployedMode transition\r
+    //\r
+    disableif TRUE;\r
+      oneof varid  = SECUREBOOT_CONFIGURATION.TransSecureBootMode,\r
+            prompt = STRING_TOKEN(STR_TRANS_SECURE_BOOT_MODE_PROMPT),\r
+            help   = STRING_TOKEN(STR_TRANS_SECURE_BOOT_MODE_HELP),\r
+            flags  = INTERACTIVE,\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE\r
+              OR (ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE AND\r
+                  ideqval SECUREBOOT_CONFIGURATION.PhysicalPresent == 0);\r
+            option text = STRING_TOKEN(STR_USER_MODE),     value = SECURE_BOOT_MODE_USER_MODE,   flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE;\r
+            option text = STRING_TOKEN(STR_SETUP_MODE),    value = SECURE_BOOT_MODE_SETUP_MODE,  flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE;\r
+            option text = STRING_TOKEN(STR_AUDIT_MODE),    value = SECURE_BOOT_MODE_AUDIT_MODE,  flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE;\r
+            option text = STRING_TOKEN(STR_DEPLOYED_MODE), value = SECURE_BOOT_MODE_DEPLOYED_MODE,  flags = 0;\r
+      endif\r
+            option text = STRING_TOKEN(STR_DEPLOYED_MODE), value = 4,  flags = 0;\r
+      endoneof;\r
+    endif;\r
+      oneof name   = TransSecureBootMode,\r
+            questionid = KEY_TRANS_SECURE_BOOT_MODE,\r
+            prompt = STRING_TOKEN(STR_TRANS_SECURE_BOOT_MODE_PROMPT),\r
+            help   = STRING_TOKEN(STR_TRANS_SECURE_BOOT_MODE_HELP),\r
+            flags  = INTERACTIVE | NUMERIC_SIZE_1,\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE \r
+              OR (ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE AND\r
+                  ideqval SECUREBOOT_CONFIGURATION.PhysicalPresent == 0);\r
+            option text = STRING_TOKEN(STR_USER_MODE),     value = SECURE_BOOT_MODE_USER_MODE,   flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE;\r
+            option text = STRING_TOKEN(STR_SETUP_MODE),    value = SECURE_BOOT_MODE_SETUP_MODE,  flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE;\r
+            option text = STRING_TOKEN(STR_AUDIT_MODE),    value = SECURE_BOOT_MODE_AUDIT_MODE,  flags = 0;\r
+      endif\r
+      suppressif ideqval SECUREBOOT_CONFIGURATION.CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE;\r
+            option text = STRING_TOKEN(STR_DEPLOYED_MODE), value = SECURE_BOOT_MODE_DEPLOYED_MODE,  flags = 0;\r
+      endif\r
+\r
+      endoneof;\r
+\r
+    subtitle text = STRING_TOKEN(STR_NULL);\r
+\r
     goto FORMID_SECURE_BOOT_PK_OPTION_FORM,\r
          prompt = STRING_TOKEN(STR_SECURE_BOOT_PK_OPTION),\r
          help   = STRING_TOKEN(STR_SECURE_BOOT_PK_OPTION_HELP),\r
index e43c6e0ee7e2384ef02b27882bf88308ec845cd3..a685b409e2381afb0bde84ddfd97bd3492cd2090 100644 (file)
@@ -49,6 +49,8 @@ HII_VENDOR_DEVICE_PATH          mSecureBootHiiVendorDevicePath = {
 \r
 \r
 BOOLEAN mIsEnterSecureBootForm = FALSE;\r
+BOOLEAN mIsSelectedSecureBootModeForm = FALSE;\r
+BOOLEAN mIsSecureBootModeChanged = FALSE;\r
 \r
 //\r
 // OID ASN.1 Value for Hash Algorithms\r
@@ -2808,6 +2810,256 @@ ON_EXIT:
            );\r
 }\r
 \r
+/**\r
+  Perform secure boot mode transition from User Mode by setting AuditMode \r
+  or DeployedMode variable.\r
+\r
+  @param[in]  NewMode          New secure boot mode.\r
+\r
+  @retval   EFI_SUCCESS        Secure Boot mode transition is successful.\r
+**/\r
+EFI_STATUS\r
+TransitionFromUserMode(\r
+  IN  UINT8 NewMode\r
+  )\r
+{\r
+  UINT8      Data;\r
+  EFI_STATUS Status;\r
+\r
+  if (NewMode == SECURE_BOOT_MODE_AUDIT_MODE) {\r
+    Data = 1;\r
+    Status = gRT->SetVariable(\r
+                    EFI_AUDIT_MODE_NAME,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    sizeof(UINT8),\r
+                    &Data\r
+                    );\r
+    return Status;\r
+  } else if (NewMode == SECURE_BOOT_MODE_DEPLOYED_MODE) {\r
+    Data = 1;\r
+    Status = gRT->SetVariable(\r
+                    EFI_DEPLOYED_MODE_NAME,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    sizeof(UINT8),\r
+                    &Data\r
+                    );\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Other case do nothing here. May Goto enroll PK page.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Perform secure boot mode transition from Setup Mode by setting AuditMode \r
+  variable.\r
+\r
+  @param[in]  NewMode          New secure boot mode.\r
+\r
+  @retval   EFI_SUCCESS        Secure Boot mode transition is successful.\r
+**/\r
+EFI_STATUS\r
+TransitionFromSetupMode(\r
+  IN UINT8 NewMode\r
+  )\r
+{\r
+  UINT8      Data;\r
+  EFI_STATUS Status;\r
+\r
+  Status = EFI_INVALID_PARAMETER;\r
+\r
+  if (NewMode == SECURE_BOOT_MODE_AUDIT_MODE) {\r
+    Data = 1;\r
+    Status = gRT->SetVariable(\r
+                    EFI_AUDIT_MODE_NAME,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    sizeof(UINT8),\r
+                    &Data\r
+                    );\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Other case do nothing here. May Goto enroll PK page.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Perform secure boot mode transition from Audit Mode. Nothing is done here,\r
+  should goto enroll PK page.\r
+\r
+  @param[in]  NewMode          New secure boot mode.\r
+\r
+  @retval   EFI_SUCCESS        Secure Boot mode transition is successful.\r
+**/\r
+EFI_STATUS\r
+TransitionFromAuditMode(\r
+  IN UINT8 NewMode\r
+  )\r
+{\r
+  //\r
+  // Other case do nothing here. Should Goto enroll PK page.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+   Perform secure boot mode transition from Deployed Mode by setting Deployed Mode\r
+   variable to 0.\r
+\r
+  @param[in]  NewMode          New secure boot mode.\r
+\r
+  @retval   EFI_SUCCESS        Secure Boot mode transition is successful.\r
+**/\r
+EFI_STATUS\r
+TransitionFromDeployedMode(\r
+  IN UINT8 NewMode\r
+  )\r
+{\r
+  UINT8      Data;\r
+  EFI_STATUS Status;\r
+\r
+  //\r
+  // Platform specific logic. when physical presence,  Allow to set DeployedMode =:0\r
+  // to switch back to UserMode\r
+  //\r
+  if (NewMode == SECURE_BOOT_MODE_USER_MODE) {\r
+    Data = 0;\r
+    Status = gRT->SetVariable(\r
+                    EFI_DEPLOYED_MODE_NAME,\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    sizeof(UINT8),\r
+                    &Data\r
+                    );\r
+    DEBUG((EFI_D_INFO, "DeployedMode Status %x\n", Status));\r
+    return Status;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+   Perform main secure boot mode transition.\r
+\r
+  @param[in]  CurMode          New secure boot mode.\r
+  @param[in]  NewMode          New secure boot mode.\r
+\r
+  @retval   EFI_SUCCESS        Secure Boot mode transition is successful.\r
+**/\r
+EFI_STATUS\r
+SecureBootModeTransition(\r
+  IN  UINT8  CurMode,\r
+  IN  UINT8  NewMode\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+\r
+  //\r
+  // Set platform to be customized mode to ensure platform specific mode switch sucess\r
+  //\r
+  Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // SecureBootMode transition\r
+  //\r
+  switch (CurMode) {\r
+    case SECURE_BOOT_MODE_USER_MODE:\r
+      Status = TransitionFromUserMode(NewMode);\r
+      break;\r
+\r
+    case SECURE_BOOT_MODE_SETUP_MODE:\r
+      Status = TransitionFromSetupMode(NewMode);\r
+      break;\r
+\r
+    case SECURE_BOOT_MODE_AUDIT_MODE:\r
+      Status = TransitionFromAuditMode(NewMode);\r
+      break;\r
+\r
+    case SECURE_BOOT_MODE_DEPLOYED_MODE:\r
+      Status = TransitionFromDeployedMode(NewMode);\r
+      break;\r
+\r
+    default:\r
+      Status = EFI_INVALID_PARAMETER;\r
+      ASSERT(FALSE);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+   Get current secure boot mode by retrieve data from SetupMode/AuditMode/DeployedMode.\r
+\r
+  @param[out]  SecureBootMode                Current secure boot mode.\r
+\r
+**/\r
+VOID\r
+ExtractSecureBootModeFromVariable(\r
+  OUT UINT8      *SecureBootMode\r
+  )\r
+{\r
+  UINT8     *SetupMode;\r
+  UINT8     *AuditMode;\r
+  UINT8     *DeployedMode;\r
+\r
+  SetupMode        = NULL;\r
+  AuditMode        = NULL;\r
+  DeployedMode     = NULL;\r
+\r
+  //\r
+  // Get AuditMode/DeployedMode from variable\r
+  //\r
+  GetVariable2 (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SetupMode, NULL);\r
+  GetVariable2 (EFI_AUDIT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&AuditMode, NULL);\r
+  GetVariable2 (EFI_DEPLOYED_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&DeployedMode, NULL);\r
+  if (SetupMode != NULL && AuditMode != NULL && DeployedMode != NULL) {\r
+    if (*SetupMode == 0 && *AuditMode == 0 && *DeployedMode == 0) {\r
+      //\r
+      // User Mode\r
+      //\r
+      *SecureBootMode = SECURE_BOOT_MODE_USER_MODE;\r
+    } else if (*SetupMode == 1 && *AuditMode == 0 && *DeployedMode == 0) {\r
+      //\r
+      // Setup Mode\r
+      //\r
+      *SecureBootMode = SECURE_BOOT_MODE_SETUP_MODE;\r
+    } else if (*SetupMode == 1 && *AuditMode == 1 && *DeployedMode == 0) {\r
+      //\r
+      // Audit Mode\r
+      //\r
+      *SecureBootMode = SECURE_BOOT_MODE_AUDIT_MODE;\r
+    } else if (*SetupMode == 0 && *AuditMode == 0 && *DeployedMode == 1) {\r
+      //\r
+      // Deployed Mode\r
+      //\r
+      *SecureBootMode = SECURE_BOOT_MODE_DEPLOYED_MODE;\r
+    } else {\r
+      ASSERT(FALSE);\r
+    }\r
+  }else {\r
+    ASSERT(FALSE);\r
+  }\r
+\r
+  if (SetupMode != NULL) {\r
+    FreePool (SetupMode);\r
+  }\r
+  if (DeployedMode != NULL) {\r
+    FreePool (DeployedMode);\r
+  }\r
+  if (AuditMode != NULL) {\r
+    FreePool (AuditMode);\r
+  }\r
+}\r
+\r
 /**\r
   This function extracts configuration from variable.\r
 \r
@@ -2820,12 +3072,10 @@ SecureBootExtractConfigFromVariable (
   )\r
 {\r
   UINT8     *SecureBootEnable;\r
-  UINT8     *SetupMode;\r
   UINT8     *SecureBootMode;\r
   EFI_TIME  CurrTime;\r
 \r
   SecureBootEnable = NULL;\r
-  SetupMode        = NULL;\r
   SecureBootMode   = NULL;\r
 \r
   //\r
@@ -2865,16 +3115,6 @@ SecureBootExtractConfigFromVariable (
     ConfigData->PhysicalPresent = FALSE;\r
   }\r
 \r
-  //\r
-  // If there is no PK then the Delete Pk button will be gray.\r
-  //\r
-  GetVariable2 (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SetupMode, NULL);\r
-  if (SetupMode == NULL || (*SetupMode) == SETUP_MODE) {\r
-    ConfigData->HasPk = FALSE;\r
-  } else  {\r
-    ConfigData->HasPk = TRUE;\r
-  }\r
-\r
   //\r
   // Get the SecureBootMode from CustomMode variable.\r
   //\r
@@ -2885,12 +3125,24 @@ SecureBootExtractConfigFromVariable (
     ConfigData->SecureBootMode = *(SecureBootMode);\r
   }\r
 \r
+  //\r
+  // Extact current Secure Boot Mode\r
+  //\r
+  ExtractSecureBootModeFromVariable(&ConfigData->CurSecureBootMode);\r
+\r
+  //\r
+  // If there is no PK then the Delete Pk button will be gray.\r
+  //\r
+  if (ConfigData->CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE || ConfigData->CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE) {\r
+    ConfigData->HasPk = FALSE;\r
+  } else  {\r
+    ConfigData->HasPk = TRUE;\r
+  }\r
+\r
   if (SecureBootEnable != NULL) {\r
     FreePool (SecureBootEnable);\r
   }\r
-  if (SetupMode != NULL) {\r
-    FreePool (SetupMode);\r
-  }\r
+\r
   if (SecureBootMode != NULL) {\r
     FreePool (SecureBootMode);\r
   }\r
@@ -2965,16 +3217,28 @@ SecureBootExtractConfig (
   SecureBootExtractConfigFromVariable (&Configuration);\r
 \r
   //\r
-  // Update current secure boot state.\r
+  // Get current secure boot state.\r
   //\r
   GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBoot, NULL);\r
+\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
+  // Get current secure boot mode\r
+  //\r
+  DEBUG((EFI_D_INFO, "Configuration.CurSecureBootMode %d\n", Configuration.CurSecureBootMode));\r
+  if (Configuration.CurSecureBootMode == SECURE_BOOT_MODE_USER_MODE) {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"UserMode", NULL);\r
+  } else if (Configuration.CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE) {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"SetupMode", NULL);\r
+  } else if (Configuration.CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE) {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"AuditMode", NULL);\r
+  } else if (Configuration.CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE) {\r
+    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"DeployedMode", NULL);\r
   }\r
 \r
   BufferSize = sizeof (SECUREBOOT_CONFIGURATION);\r
@@ -3021,6 +3285,10 @@ SecureBootExtractConfig (
     *Progress = Request + StrLen (Request);\r
   }\r
 \r
+  if (SecureBoot != NULL) {\r
+    FreePool (SecureBoot);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -3142,23 +3410,41 @@ SecureBootCallback (
   UINT16                          LabelId;\r
   UINT8                           *SecureBootEnable;\r
   UINT8                           *SecureBootMode;\r
-  UINT8                           *SetupMode;\r
   CHAR16                          PromptString[100];\r
+  UINT8                           CurSecureBootMode;\r
 \r
+  Status           = EFI_SUCCESS;\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
+  Private = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);\r
+\r
+  //\r
+  // Retrieve uncommitted data from Browser\r
+  //\r
+  BufferSize = sizeof (SECUREBOOT_CONFIGURATION);\r
+  IfrNvData = AllocateZeroPool (BufferSize);\r
+  if (IfrNvData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  HiiGetBrowserData (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, BufferSize, (UINT8 *) IfrNvData);\r
 \r
   if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
     if (QuestionId == KEY_SECURE_BOOT_MODE) {\r
       mIsEnterSecureBootForm = TRUE;\r
+    } else if (QuestionId == KEY_TRANS_SECURE_BOOT_MODE){\r
+      //\r
+      // Secure Boot Policy variable changes after tranistion. Re-sync CurSecureBootMode\r
+      //\r
+      ExtractSecureBootModeFromVariable(&IfrNvData->CurSecureBootMode);\r
+      mIsSelectedSecureBootModeForm = TRUE;\r
+      mIsSecureBootModeChanged = FALSE;\r
     }\r
-\r
-    return EFI_SUCCESS;\r
+    goto EXIT;\r
   }\r
 \r
   if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
@@ -3168,32 +3454,23 @@ SecureBootCallback (
         Value->u8 = SECURE_BOOT_MODE_STANDARD;\r
         Status = EFI_SUCCESS;\r
       }\r
+    } else if (QuestionId == KEY_TRANS_SECURE_BOOT_MODE) {\r
+      if (mIsSelectedSecureBootModeForm) {\r
+        Value->u8 = IfrNvData->CurSecureBootMode;\r
+        Status = EFI_SUCCESS;\r
+      }\r
     }\r
-    return Status;\r
+    goto EXIT;\r
   }\r
 \r
   if ((Action != EFI_BROWSER_ACTION_CHANGED) &&\r
       (Action != EFI_BROWSER_ACTION_CHANGING) &&\r
       (Action != EFI_BROWSER_ACTION_FORM_CLOSE) &&\r
       (Action != EFI_BROWSER_ACTION_DEFAULT_STANDARD)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  Private = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);\r
-\r
-  //\r
-  // Retrieve uncommitted data from Browser\r
-  //\r
-  BufferSize = sizeof (SECUREBOOT_CONFIGURATION);\r
-  IfrNvData = AllocateZeroPool (BufferSize);\r
-  if (IfrNvData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    Status = EFI_UNSUPPORTED;\r
+    goto EXIT;\r
   }\r
 \r
-  Status = EFI_SUCCESS;\r
-\r
-  HiiGetBrowserData (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, BufferSize, (UINT8 *) IfrNvData);\r
-\r
   if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
 \r
     switch (QuestionId) {\r
@@ -3419,6 +3696,66 @@ SecureBootCallback (
           );\r
       }\r
       break;\r
+    case KEY_TRANS_SECURE_BOOT_MODE:\r
+      //\r
+      // Pop up to alert user want to change secure boot mode \r
+      //\r
+      if ((IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_USER_MODE && \r
+           (Value->u8 == SECURE_BOOT_MODE_AUDIT_MODE || Value->u8 == SECURE_BOOT_MODE_DEPLOYED_MODE))\r
+        ||(IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE && \r
+           Value->u8 == SECURE_BOOT_MODE_AUDIT_MODE)\r
+        ||(IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE && \r
+          Value->u8 == SECURE_BOOT_MODE_USER_MODE && IfrNvData->PhysicalPresent == 1)){\r
+        CreatePopUp (\r
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+          &Key,\r
+          L"Are you sure you want to switch secure boot mode?",\r
+          L"Press 'Y' to switch secure boot mode, 'N' to discard change and return",\r
+          NULL\r
+          );\r
+        if (Key.UnicodeChar != 'y' && Key.UnicodeChar != 'Y') {\r
+          //\r
+          // If not 'Y'/''y' restore to defualt secure boot mode\r
+          //\r
+          Value->u8 = IfrNvData->CurSecureBootMode;\r
+          goto EXIT;\r
+        }\r
+      } else if ((IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE && Value->u8 == SECURE_BOOT_MODE_USER_MODE)\r
+               ||(IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_USER_MODE && Value->u8 == SECURE_BOOT_MODE_SETUP_MODE)\r
+               ||(IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE && Value->u8 == SECURE_BOOT_MODE_DEPLOYED_MODE)\r
+               ||(IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE && Value->u8 == SECURE_BOOT_MODE_SETUP_MODE)) {\r
+        CreatePopUp (\r
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+          &Key,\r
+          L"Secure boot mode tranistion requires PK change",\r
+          L"Please go to link below to update PK",\r
+          NULL\r
+          );\r
+      } else {\r
+        Status = EFI_INVALID_PARAMETER;\r
+        goto EXIT;\r
+      }\r
+\r
+      Status = SecureBootModeTransition(IfrNvData->CurSecureBootMode, Value->u8);\r
+      //\r
+      // Secure Boot Policy variable may change after tranistion. Re-sync CurSecureBootMode\r
+      //\r
+      ExtractSecureBootModeFromVariable(&CurSecureBootMode);\r
+      if (IfrNvData->CurSecureBootMode != CurSecureBootMode) {\r
+        IfrNvData->CurSecureBootMode = CurSecureBootMode;\r
+        mIsSecureBootModeChanged = TRUE;\r
+\r
+        if (IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_USER_MODE) {\r
+          HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"UserMode", NULL);\r
+        } else if (IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_SETUP_MODE) {\r
+          HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"SetupMode", NULL);\r
+        } else if (IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_AUDIT_MODE) {\r
+          HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"AuditMode", NULL);\r
+        } else if (IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE) {\r
+          HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_CUR_SECURE_BOOT_MODE_CONTENT), L"DeployedMode", NULL);\r
+        }\r
+      }\r
+      break;\r
 \r
     default:\r
       if (QuestionId >= FILE_OPTION_GOTO_OFFSET) {\r
@@ -3509,7 +3846,13 @@ SecureBootCallback (
     case KEY_SECURE_BOOT_MODE:\r
       mIsEnterSecureBootForm = FALSE;\r
       break;\r
-\r
+    case KEY_TRANS_SECURE_BOOT_MODE:\r
+      mIsSelectedSecureBootModeForm = FALSE;\r
+      if (mIsSecureBootModeChanged) {\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_RESET;\r
+      }\r
+      mIsSecureBootModeChanged = FALSE;\r
+      break;\r
     case KEY_SECURE_BOOT_KEK_GUID:\r
     case KEY_SECURE_BOOT_SIGNATURE_GUID_DB:\r
     case KEY_SECURE_BOOT_SIGNATURE_GUID_DBX:\r
@@ -3528,8 +3871,7 @@ SecureBootCallback (
       break;\r
 \r
     case KEY_SECURE_BOOT_DELETE_PK:\r
-      GetVariable2 (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SetupMode, NULL);\r
-      if (SetupMode == NULL || (*SetupMode) == SETUP_MODE) {\r
+      if (IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_USER_MODE || IfrNvData->CurSecureBootMode == SECURE_BOOT_MODE_DEPLOYED_MODE) {\r
         IfrNvData->DeletePk = TRUE;\r
         IfrNvData->HasPk    = FALSE;\r
         *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
@@ -3538,9 +3880,6 @@ SecureBootCallback (
         IfrNvData->HasPk    = TRUE;\r
         *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
       }\r
-      if (SetupMode != NULL) {\r
-        FreePool (SetupMode);\r
-      }\r
       break;\r
     default:\r
       if (QuestionId >= FILE_OPTION_OFFSET && QuestionId < FILE_OPTION_GOTO_OFFSET) {\r
@@ -3575,10 +3914,13 @@ SecureBootCallback (
     }\r
   }\r
 \r
+EXIT:\r
+\r
   if (!EFI_ERROR (Status)) {\r
     BufferSize = sizeof (SECUREBOOT_CONFIGURATION);\r
     HiiSetBrowserData (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, BufferSize, (UINT8*) IfrNvData, NULL);\r
   }\r
+\r
   FreePool (IfrNvData);\r
 \r
   return EFI_SUCCESS;\r
index 7aebc1f99e85f4382bb2cfa69811d4ff2fec41b9..75f41e896bfaaced882ed856b1eb58369ee31d38 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for NV data structure definition.\r
 \r
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2015, 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
@@ -84,6 +84,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define LABEL_DBT_DELETE                      0x1203\r
 #define LABEL_END                             0xffff\r
 \r
+#define KEY_TRANS_SECURE_BOOT_MODE            0x2000\r
+\r
 #define SECURE_BOOT_MAX_ATTEMPTS_NUM          255\r
 \r
 #define CONFIG_OPTION_OFFSET                  0x2000\r
@@ -116,6 +118,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define SECURE_BOOT_GUID_SIZE                 36\r
 #define SECURE_BOOT_GUID_STORAGE_SIZE         37\r
 \r
+#define SECURE_BOOT_MODE_USER_MODE            0\r
+#define SECURE_BOOT_MODE_SETUP_MODE           1\r
+#define SECURE_BOOT_MODE_AUDIT_MODE           2\r
+#define SECURE_BOOT_MODE_DEPLOYED_MODE        3\r
+\r
 //\r
 // Nv Data structure referenced by IFR\r
 //\r
@@ -125,6 +132,8 @@ typedef struct {
   CHAR16  SignatureGuid[SECURE_BOOT_GUID_STORAGE_SIZE];\r
   BOOLEAN PhysicalPresent;     // If a Physical Present User\r
   UINT8   SecureBootMode;      // Secure Boot Mode: Standard Or Custom\r
+  UINT8   CurSecureBootMode;   // Current SecureBoot Mode SetupMode/UserMode/AuditMode/DeployedMode\r
+  UINT8   TransSecureBootMode; // Trans Next SecureBoot Mode\r
   BOOLEAN DeletePk;\r
   BOOLEAN HasPk;               // If Pk is existed it is true\r
   BOOLEAN AlwaysRevocation;    // If the certificate is always revoked. Revocation time is hidden\r
index 063a10d44d125cda13a2b62d56dc4cbed528f01c..263811b05216b72148392d968fc12c65fd8591ff 100644 (file)
Binary files a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni and b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni differ