@@ -59,6 +59,7 @@ HII_VENDOR_DEVICE_PATH mSecureBootHiiVendorDevicePath = {
59
59
};
60
60
61
61
BOOLEAN mIsEnterSecureBootForm = FALSE;
62
+ BOOLEAN mResetSvBootState = FALSE;
62
63
63
64
//
64
65
// OID ASN.1 Value for Hash Algorithms
@@ -301,7 +302,7 @@ SaveSecureBootVariable (
301
302
/**
302
303
Set Sovereign Boot configuration into variable space.
303
304
304
- @param[in] SvBootEnable The satte of Sovereign Boot.
305
+ @param[in] SvBootEnable The state of Sovereign Boot.
305
306
306
307
@retval EFI_SUCCESS The operation is finished successfully.
307
308
@retval Others Other errors as indicated.
@@ -350,6 +351,53 @@ SaveSovereignBootVariable (
350
351
return Status ;
351
352
}
352
353
354
+ /**
355
+ Resets Sovereign Boot configuration and saves it into variable space.
356
+
357
+ @retval EFI_SUCCESS The operation is finished successfully.
358
+ @retval Others Other errors as indicated.
359
+
360
+ **/
361
+ EFI_STATUS
362
+ ResetSovereignBootState (
363
+ SECUREBOOT_CONFIG_PRIVATE_DATA * Private
364
+ )
365
+ {
366
+ SOVEREIGN_BOOT_WIZARD_NV_CONFIG SvBootConfig ;
367
+ EFI_STATUS Status ;
368
+ UINT32 Attrs ;
369
+ UINTN VarSize ;
370
+
371
+ VarSize = sizeof (SOVEREIGN_BOOT_WIZARD_NV_CONFIG );
372
+
373
+ Status = gRT -> GetVariable (
374
+ SV_BOOT_CONFIG_VAR ,
375
+ & gSovereignBootWizardFormSetGuid ,
376
+ & Attrs ,
377
+ & VarSize ,
378
+ & SvBootConfig
379
+ );
380
+
381
+ if (EFI_ERROR (Status ) ||
382
+ Attrs != (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ) ||
383
+ VarSize != sizeof (SOVEREIGN_BOOT_WIZARD_NV_CONFIG )
384
+ ) {
385
+ SvBootConfig .SvBootEnabled = FixedPcdGetBool (PcdSovereignBootDefaultState );
386
+ }
387
+
388
+ SvBootConfig .SvBootProvisioned = FALSE;
389
+
390
+ Status = gRT -> SetVariable (
391
+ SV_BOOT_CONFIG_VAR ,
392
+ & gSovereignBootWizardFormSetGuid ,
393
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ,
394
+ sizeof (SOVEREIGN_BOOT_WIZARD_NV_CONFIG ),
395
+ & SvBootConfig
396
+ );
397
+
398
+ return Status ;
399
+ }
400
+
353
401
/**
354
402
This code checks if the encode type and key strength of X.509
355
403
certificate is qualified.
@@ -3528,6 +3576,12 @@ SecureBootExtractConfigFromVariable (
3528
3576
ConfigData -> SvBootProvisioned = SvBootConfig -> SvBootProvisioned ;
3529
3577
FreePool (SvBootConfig );
3530
3578
}
3579
+
3580
+ HiiSetString (
3581
+ Private -> HiiHandle ,
3582
+ STRING_TOKEN (STR_SOVEREIGN_BOOT_STATE_CONTENT ),
3583
+ ConfigData -> SvBootProvisioned ? L"Yes" : L"No" ,
3584
+ NULL );
3531
3585
}
3532
3586
3533
3587
if (SecureBootEnable != NULL ) {
@@ -4989,6 +5043,21 @@ SecureBootCallback (
4989
5043
goto EXIT ;
4990
5044
}
4991
5045
5046
+ if (Action == EFI_BROWSER_ACTION_SUBMITTED ) {
5047
+ Status = EFI_UNSUPPORTED ;
5048
+ if (QuestionId == KEY_SOVEREIGN_BOOT_PROVISIONED ) {
5049
+ Status = EFI_SUCCESS ;
5050
+ if (mResetSvBootState && !Value -> b ) {
5051
+ Status = ResetSovereignBootState (Private );
5052
+ if (GetBrowserDataResult ) {
5053
+ SecureBootExtractConfigFromVariable (Private , IfrNvData );
5054
+ }
5055
+ mResetSvBootState = FALSE;
5056
+ }
5057
+ }
5058
+ goto EXIT ;
5059
+ }
5060
+
4992
5061
if ((Action != EFI_BROWSER_ACTION_CHANGED ) &&
4993
5062
(Action != EFI_BROWSER_ACTION_CHANGING ) &&
4994
5063
(Action != EFI_BROWSER_ACTION_FORM_CLOSE ) &&
@@ -5547,6 +5616,16 @@ SecureBootCallback (
5547
5616
Status = KeyEnrollReset ();
5548
5617
}
5549
5618
5619
+ if (EFI_ERROR (Status )) {
5620
+ return Status ;
5621
+ }
5622
+
5623
+ // Resetting the keys need to reset the Sovereign Boot state
5624
+ // as we will no longer have the trusted keys in db
5625
+ if (FixedPcdGetBool (PcdSovereignBootEnabled )) {
5626
+ Status = ResetSovereignBootState (Private );
5627
+ }
5628
+
5550
5629
//
5551
5630
// Update secure boot strings after key reset
5552
5631
//
@@ -5573,6 +5652,17 @@ SecureBootCallback (
5573
5652
if (UserSelection == EfiHiiPopupSelectionYes ) {
5574
5653
Status = KeyEraseAll ();
5575
5654
}
5655
+
5656
+ if (EFI_ERROR (Status )) {
5657
+ return Status ;
5658
+ }
5659
+
5660
+ // Erasing the keys need to reset the Sovereign Boot state
5661
+ // as we will no longer have the trusted keys in db
5662
+ if (FixedPcdGetBool (PcdSovereignBootEnabled )) {
5663
+ Status = ResetSovereignBootState (Private );
5664
+ }
5665
+
5576
5666
//
5577
5667
// Update secure boot strings after key reset
5578
5668
//
@@ -5589,12 +5679,19 @@ SecureBootCallback (
5589
5679
// If disabling, we need to restore Secure Boot keys
5590
5680
if (!Value -> b ) {
5591
5681
Status = KeyEnrollReset ();
5592
-
5682
+ if (EFI_ERROR (Status )) {
5683
+ break ;
5684
+ }
5685
+ // Reset the Sovereign Boot provisioning state
5686
+ Status = ResetSovereignBootState (Private );
5687
+ if (EFI_ERROR (Status )) {
5688
+ break ;
5689
+ }
5593
5690
//
5594
5691
// Update secure boot strings after key reset
5595
5692
//
5596
- if ( Status == EFI_SUCCESS ) {
5597
- Status = UpdateSecureBootString ( Private );
5693
+ Status = UpdateSecureBootString ( Private );
5694
+ if ( GetBrowserDataResult ) {
5598
5695
SecureBootExtractConfigFromVariable (Private , IfrNvData );
5599
5696
}
5600
5697
}
@@ -5647,6 +5744,13 @@ SecureBootCallback (
5647
5744
}
5648
5745
break ;
5649
5746
}
5747
+ case KEY_SOVEREIGN_BOOT_PROVISIONED :
5748
+ {
5749
+ Status = EFI_SUCCESS ;
5750
+ Value -> b = FALSE;
5751
+ mResetSvBootState = TRUE;
5752
+ break ;
5753
+ }
5650
5754
default :
5651
5755
break ;
5652
5756
}
0 commit comments