

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立 AWS UEFI 安全開機的二進位 Blob
<a name="aws-binary-blob-creation"></a>

您可以使用以下步驟在 AMI 建立過程中自定義 UEFI 安全開機變數。在這些步驟中使用的 KEK 截至 2021 年 9 月都是最新的。如果 Microsoft 更新 KEK，則您必須使用最新的 KEK。

**建立 AWS 二進位 Blob**

1. 建立一個空白的 PK 簽章清單。

   ```
   touch empty_key.crt
   cert-to-efi-sig-list empty_key.crt PK.esl
   ```

1. 下載 KEK 憑證。

   ```
   https://go.microsoft.com/fwlink/?LinkId=321185
   ```

1. 將 KEK 憑證包裝在 UEFI 簽章清單中 (`siglist`)。

   ```
   sbsiglist --owner 77fa9abd-0359-4d32-bd60-28f4e78f784b --type x509 --output MS_Win_KEK.esl MicCorKEKCA2011_2011-06-24.crt 
   ```

1. 下載 Microsoft 的 db 憑證。

   ```
   https://www.microsoft.com/pkiops/certs/MicWinProPCA2011_2011-10-19.crt
   https://www.microsoft.com/pkiops/certs/MicCorUEFCA2011_2011-06-27.crt
   ```

1. 產生 db 簽章清單。

   ```
   sbsiglist --owner 77fa9abd-0359-4d32-bd60-28f4e78f784b --type x509 --output MS_Win_db.esl MicWinProPCA2011_2011-10-19.crt
   sbsiglist --owner 77fa9abd-0359-4d32-bd60-28f4e78f784b --type x509 --output MS_UEFI_db.esl MicCorUEFCA2011_2011-06-27.crt
   cat MS_Win_db.esl MS_UEFI_db.esl > MS_db.esl
   ```

1. Unified Extensible Firmware Interface 論壇不再提供 DBX 檔案。這些檔案目前由 Microsoft 在 GitHub 上提供。請前往 [ https://github.com/microsoft/secureboot\$1objects](https://github.com/microsoft/secureboot_objects)，透過 Microsoft 安全啟動更新儲存庫下載最新 DBX 更新。

1. 解壓縮簽署的 update-binary。

   透過下面的指令碼內容來建立 `SplitDbxContent.ps1`。或者，您可使用 `Install-Script -Name SplitDbxContent`，透過 [PowerShell Gallery](https://www.powershellgallery.com/packages/SplitDbxContent/1.0) 來安裝指令碼。

   ```
   <#PSScriptInfo
    
   .VERSION 1.0
    
   .GUID ec45a3fc-5e87-4d90-b55e-bdea083f732d
    
   .AUTHOR Microsoft Secure Boot Team
    
   .COMPANYNAME Microsoft
    
   .COPYRIGHT Microsoft
    
   .TAGS Windows Security
    
   .LICENSEURI
    
   .PROJECTURI
    
   .ICONURI
    
   .EXTERNALMODULEDEPENDENCIES
    
   .REQUIREDSCRIPTS
    
   .EXTERNALSCRIPTDEPENDENCIES
    
   .RELEASENOTES
   Version 1.0: Original published version.
    
   #>
   
   <#
   .DESCRIPTION
    Splits a DBX update package into the new DBX variable contents and the signature authorizing the change.
    To apply an update using the output files of this script, try:
    Set-SecureBootUefi -Name dbx -ContentFilePath .\content.bin -SignedFilePath .\signature.p7 -Time 2010-03-06T19:17:21Z -AppendWrite'
   .EXAMPLE
   .\SplitDbxAuthInfo.ps1 DbxUpdate_x64.bin
   #>
   
   
   # Get file from script input
   $file  = Get-Content -Encoding Byte $args[0]
   
   # Identify file signature
   $chop = $file[40..($file.Length - 1)]
   if (($chop[0] -ne 0x30) -or ($chop[1] -ne 0x82 )) {
       Write-Error "Cannot find signature"
       exit 1
   }
   
   # Signature is known to be ASN size plus header of 4 bytes
   $sig_length = ($chop[2] * 256) + $chop[3] + 4
   $sig = $chop[0..($sig_length - 1)]
   
   if ($sig_length -gt ($file.Length + 40)) {
       Write-Error "Signature longer than file size!"
       exit 1
   }
   
   # Content is everything else
   $content = $file[0..39] + $chop[$sig_length..($chop.Length - 1)]
   
   # Write signature and content to files
   Set-Content -Encoding Byte signature.p7 $sig
   Set-Content -Encoding Byte content.bin $content
   ```

   使用指令碼來解壓縮簽署的 DBX 檔案。

   ```
   PS C:\Windows\system32> SplitDbxContent.ps1 .\dbx.bin
   ```

   這會產生兩個檔案 - `signature.p7` 與 `content.bin`。在下一個步驟使用 `content.bin`。

1. 使用 `uefivars.py` 指令碼建置 UEFI 變數存放區。

   ```
   ./uefivars.py -i none -o aws -O uefiblob-microsoft-keys-empty-pk.bin -P ~/PK.esl -K ~/MS_Win_KEK.esl --db ~/MS_db.esl  --dbx ~/content.bin 
   ```

1. 檢查二進位 blob 和 UEFI 變數存放區。

   ```
   ./uefivars.py -i aws -I uefiblob-microsoft-keys-empty-pk.bin -o json | less
   ```

1. 您可以透過再次將 blob 傳遞給同一工具來更新 Blob。

   ```
   ./uefivars.py -i aws -I uefiblob-microsoft-keys-empty-pk.bin -o aws -O uefiblob-microsoft-keys-empty-pk.bin -P ~/PK.esl -K ~/MS_Win_KEK.esl --db ~/MS_db.esl  --dbx ~/content.bin
   ```

   預期的輸出結果

   ```
   Replacing PK
   Replacing KEK
   Replacing db
   Replacing dbx
   ```