使用 HSM 保護開機金鑰產生和簽署 (範例)

1.3 版

以下是如何使用硬體安全性模組 (HSM) , (PK 和其他) 產生安全開機金鑰的範例。

您必須知道安全開機公開金鑰基礎結構 (PKI) 。 如需詳細資訊,請參閱Windows 8.1安全開機金鑰建立和管理指引

需求

所需的工具

  • certreq.exe – 可用的收件匣

  • certutil.exe – 可用的收件匣

  • Signtool.exe – 可在最新的 Windows SDK 中使用

硬體安全性模組 (HSM)

白皮書使用 nCipher (現在 Thales) PCI HSM 模型 nC1003P/nC3023P/nC3033P 和 SafeNet Luna HSM 中的範例來示範金鑰產生。 大部分的概念也適用于其他 HSM 廠商。

針對其他 HSM,請連絡製造商,以取得如何使用 HSM 密碼編譯服務提供者 (CSP) 量身打造方法的其他指示。

方法

我們使用 Microsoft 憑證建立工具: certreq.exe 產生安全開機平臺金鑰 (PK) 和其他安全開機所需的金鑰。

certreq 工具可藉由提供密碼編譯服務提供者 (CSP) 作為 HSM,來調整為使用 HSM。

尋找密碼編譯服務提供者 (CSP)

您可以使用 certutil.exe 工具或 HSM 用來列出 CSP 的工具。

  • 此範例會使用 certutil 工具在 Thales/nCipher HSM 上顯示 CSP:

    C:\secureboot_training\certreq> certutil -csplist
    Provider Name: Microsoft Base Cryptographic Provider v1.0
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Base DSS and Diffie-Hellman Cryptographic Provider
    Provider Type: 13 - PROV_DSS_DH
    
    Provider Name: Microsoft Base DSS Cryptographic Provider
    Provider Type: 3 - PROV_DSS
    
    Provider Name: Microsoft Base Smart Card Crypto Provider
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft DH SChannel Cryptographic Provider
    Provider Type: 18 - PROV_DH_SCHANNEL
    
    Provider Name: Microsoft Enhanced Cryptographic Provider v1.0
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider
    Provider Type: 13 - PROV_DSS_DH
    
    Provider Name: Microsoft Enhanced RSA and AES Cryptographic Provider
    Provider Type: 24 - PROV_RSA_AES
    
    Provider Name: Microsoft RSA SChannel Cryptographic Provider
    Provider Type: 12 - PROV_RSA_SCHANNEL
    
    Provider Name: Microsoft Strong Cryptographic Provider
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Software Key Storage Provider
    
    Provider Name: nCipher Security World Key Storage Provider
    
    Provider Name: Microsoft Smart Card Key Storage Provider
    CertUtil: -csplist command completed successfully.
    

    針對 SHA-256 摘要演算法,請使用 CNG 提供者: "nCipher Security World Key Storage Provider" 。 舊版提供者不支援 SHA-256,不適用於安全開機。

  • 此範例會使用內建 Thales/nCipher 工具來列出 CSP:

    C:\Program Files\nCipher\nfast\bin> cnglist --list-providers
    Microsoft Primitive Provider
    Microsoft Smart Card Key Storage Provider
    Microsoft Software Key Storage Provider
    Microsoft SSL Protocol Provider
    nCipher Primitive Provider
    nCipher Security World Key Storage Provider
    

    針對 SHA-256 摘要演算法,請使用 CNG 提供者: "nCipher Security World Key Storage Provider" 。 舊版提供者不支援 SHA-256,不適用於安全開機。

  • 此範例會使用 SafeNet Luna HSM 工具來列出 CSP:

    C:\>certutil -csplist
    ------------------------------------------------------------------------------------------
    Provider Name: Luna Cryptographic Services for Microsoft Windows
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Luna enhanced RSA and AES provider for Microsoft Windows
    Provider Type: 24 - PROV_RSA_AES
    
    Provider Name: Luna SChannel Cryptographic Services for Microsoft Windows
    Provider Type: 12 - PROV_RSA_SCHANNEL
    
    Provider Name: Microsoft Base Cryptographic Provider v1.0
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Base DSS and Diffie-Hellman Cryptographic Provider
    Provider Type: 13 - PROV_DSS_DH
    
    Provider Name: Microsoft Base DSS Cryptographic Provider
    Provider Type: 3 - PROV_DSS
    
    Provider Name: Microsoft Base Smart Card Crypto Provider
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft DH SChannel Cryptographic Provider
    Provider Type: 18 - PROV_DH_SCHANNEL
    
    Provider Name: Microsoft Enhanced Cryptographic Provider v1.0
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider
    Provider Type: 13 - PROV_DSS_DH
    
    Provider Name: Microsoft Enhanced RSA and AES Cryptographic Provider
    Provider Type: 24 - PROV_RSA_AES
    
    Provider Name: Microsoft RSA SChannel Cryptographic Provider
    Provider Type: 12 - PROV_RSA_SCHANNEL
    
    Provider Name: Microsoft Strong Cryptographic Provider
    Provider Type: 1 - PROV_RSA_FULL
    
    Provider Name: Microsoft Software Key Storage Provider
    
    Provider Name: Microsoft Smart Card Key Storage Provider
    
    Provider Name: SafeNet Key Storage Provider
    CertUtil: -csplist command completed successfully.
    ------------------------------------------------------------------------------------------
    

    針對 SHA-256 摘要演算法,您必須使用 CNG 提供者 – 「SafeNet Key Storage Provider」。 舊版提供者不支援 SHA-256,不適用於安全開機。

若要產生金鑰:

certreq.exe -new request.inf PK.cer

範例 request.inf 檔案:

[Version]
Signature= "$Windows NT$"
[NewRequest]
ValidityPeriod = Years
ValidityPeriodUnits = 6
Subject = "CN=Corporation TODO Platform Key,O=TODO Corporation,L=TODO_City,S=TODO_State,C=TODO_Country"
MachineKeySet = true
RequestType=Cert
Exportable =  FALSE 
HashAlgorithm = SHA256
KeyAlgorithm = RSA
KeyLength = 2048
KeyContainer = "PKContainer"
ProviderName = "nCipher Security World Key Storage Provider"
KeyUsage = 0xf0

更新下列值:

  • 主題: 將 TODO 取代為實際資料 "CN=Corporation TODO Platform Key,O=TODO Corporation,L=TODO_City,S=TODO_State,C=TODO_Country"

  • ValidityPeriod、ValidityPeriodUnits: 使用 6 年的有效期間。 雖然 PK 可能只有 2 年有效,但 6 年期間允許未來的服務。

  • KeyContainer: 輸入您用來使用 HSM 建立金鑰的容器識別碼。 系統可能會要求您提供您用來建立 Thales HSM 安全世界權杖的權杖。

驗證憑證 (自我簽署)

確認憑證已正確產生:

certutil -store -v my  "<Certificate_serial_number_or_thumbprint>"

例如:certutil -store -v my "7569d364a2e77b814274c81ae6360ffe"

範例輸出:

my
================ Certificate 16 ================
X509 Certificate:
Version: 3
Serial Number: 7569d364a2e77b814274c81ae6360ffe
Signature Algorithm:
    Algorithm ObjectId: 1.2.840.113549.1.1.11 sha256RSA
    Algorithm Parameters:
    05 00
Issuer:
    CN=test self-signed

 NotBefore: 1/21/2013 7:25 PM
 NotAfter: 1/21/2015 7:35 PM

Subject:
    CN=test self-signed

Public Key Algorithm:
    Algorithm ObjectId: 1.2.840.113549.1.1.1 RSA (RSA_SIGN)
    Algorithm Parameters:
    05 00
Public Key Length: 2048 bits
Public Key: UnusedBits = 0
    0000  30 82 01 0a 02 82 01 01  00 cf e3 83 c7 a4 05 dd
    0010  be 05 76 b6 26 16 ae ba  0f a1 c6 3f 4f 58 11 2a
    0020  4c fe fc 44 f5 d2 11 36  75 c8 c9 90 15 d3 06 94
    0030  18 ea 10 d8 4c 77 60 1f  45 75 25 6f 21 08 84 d3
    0040  8f 6f 70 07 1b 3e eb 26  94 b8 aa 0d fd 0c 13 f1
    0050  7f 76 0c 33 a4 ad b4 7a  f3 c1 f1 d8 c9 a0 ba d2
    0060  c5 9e 2b ce 36 7e 34 9b  81 26 74 0b 32 47 48 48
    0070  08 ab c0 e7 c3 a2 8e e4  1f b8 6f 38 a2 31 84 65
    0080  75 67 db 01 fc 41 a8 98  83 ad ba 2f 4e 59 c3 6b
    0090  93 84 e0 ab de bd 6f 8f  61 9b b3 42 b3 fb 19 f7
    00a0  46 3a ad d7 e9 d1 fa 2b  a7 72 8d 76 ac 9f 6d c3
    00b0  79 ba 37 e4 6d 72 b1 6f  22 82 80 77 a7 92 3f b7
    00c0  e2 1f e0 c6 90 9a 82 ef  40 47 29 fb c3 83 7e 38
    00d0  01 35 1f 66 6c 1b 93 0d  c2 fc 5c e2 4e bd e1 85
    00e0  c3 7e a9 51 6f 57 82 86  37 79 92 63 b2 e0 42 4f
    00f0  25 5c 1b 03 50 29 2d ee  40 31 c3 a1 c3 cf 62 31
    0100  e0 8c 60 2f d4 34 56 f1  bf 02 03 01 00 01
Certificate Extensions: 2
    2.5.29.15: Flags = 1(Critical), Length = 4
    Key Usage
        Digital Signature, Non-Repudiation, Key Encipherment, Data Encipherment (f0)

    2.5.29.14: Flags = 0, Length = 16
    Subject Key Identifier
        5b 3b 53 ed e3 0f a9 48 90 e0 93 09 0f f9 7b 32 3a 8d 89 4f

Signature Algorithm:
    Algorithm ObjectId: 1.2.840.113549.1.1.11 sha256RSA
    Algorithm Parameters:
    05 00
Signature: UnusedBits=0
    0000  3c 08 5f e0 a7 42 2a bc  58 61 64 43 b6 f4 23 99
    0010  ca 58 b1 8c a3 6b eb 9c  31 a0 ce 25 3a d5 b4 74
    0020  c2 0c 9c 00 1e c8 0f d2  05 3d fc 5d 6f 17 cd ac
    0030  4d 14 9e d4 2b 45 1e ad  5f 5b ee 23 a8 29 65 b3
    0040  cd c4 fd 5c e6 6a bd 95  ce f0 f9 be 31 19 87 90
    0050  f8 86 c4 31 a8 b3 d5 b3  14 24 5b de f8 c0 f9 9c
    0060  96 a2 b5 89 39 41 bd 4b  5f 04 16 10 c0 5c b8 fb
    0070  1d 8d 64 b2 87 00 72 46  b9 5e d0 3a 75 8d ea 5a
    0080  f6 5d 9c c5 03 cd c8 54  b7 7a ef c8 3e 3f 4b f6
    0090  d2 c7 70 67 29 92 70 44  fc c6 2e c9 42 dd 6e 01
    00a0  c5 71 27 20 51 ed 34 3c  98 c2 bc 1f 57 16 71 86
    00b0  24 e3 0e 41 57 82 ba 41  df b5 6d f9 4d e4 72 80
    00c0  6f 8d ab 10 06 cd 69 6b  d0 82 ac db 04 da 6b a5
    00d0  83 14 1a a0 6d 90 c4 01  5d 24 68 ac 10 ca db 96
    00e0  44 8b ef f1 13 7f 22 15  32 93 4e 2d 23 ce 7f fb
    00f0  18 9f d0 1c c1 45 2c e6  bb 23 7f 9e 22 ea fc 88
Signature matches Public Key
Root Certificate: Subject matches Issuer
Key Id Hash(rfc-sha1): 5b 3b 53 ed e3 0f a9 48 90 e0 93 09 0f f9 7b 32 3a 8d 89 4f
Key Id Hash(sha1): 1e 07 bb 05 ce d2 db 9c 9f ab d1 46 b8 32 20 e3 41 dc 4c 08
Cert Hash(md5): 45 ab 9b e4 6e 91 53 b5 96 81 10 8e 01 45 6c 54
Cert Hash(sha1): 37 ed 7c 3e ee 76 a2 d0 42 3a e3 1a 16 9f 74 d0 3c 7f 34 2c

  CERT_REQUEST_ORIGINATOR_PROP_ID(71):
    VM-DESKTEST.ntdev.corp.microsoft.com

  CERT_KEY_PROV_INFO_PROP_ID(2):
    Key Container = PKContainer
    Provider = nCipher Security World Key Storage Provider
    ProviderType = 0
    Flags = 20
    KeySpec = 0

  CERT_SHA1_HASH_PROP_ID(3):
    37 ed 7c 3e ee 76 a2 d0 42 3a e3 1a 16 9f 74 d0 3c 7f 34 2c

  CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID(25):
    12 eb 13 79 64 61 08 e9 a6 75 f2 9a 5c 49 b4 f9

  CERT_KEY_IDENTIFIER_PROP_ID(20):
    5b 3b 53 ed e3 0f a9 48 90 e0 93 09 0f f9 7b 32 3a 8d 89 4f

  CERT_SIGNATURE_HASH_PROP_ID(15):
       0000  38 c4 1b 14 d8 74 95 42  1b fb 7d 72 d2 0b 03 ad
    0010  bd e8 aa 19 14 9e a2 41  30 fe b4 d4 93 b6 9f 3b

  CERT_MD5_HASH_PROP_ID(4):
    45 ab 9b e4 6e 91 53 b5 96 81 10 8e 01 45 6c 54
  UI Policy = 0
    Version: 0

PKContainer

  Export Policy = 0
  Key Usage = 3
    NCRYPT_ALLOW_DECRYPT_FLAG -- 1
    NCRYPT_ALLOW_SIGNING_FLAG -- 2

  D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)

    Allow WriteNT AUTHORITY\SYSTEM
    Allow WriteBUILTIN\Administrators
    Allow WriteBUILTIN\Users

Private key is NOT exportable
Signature test passed
CertUtil: -store command completed successfully.

備份憑證

備份您的憑證。 如此一來,如果憑證存放區或伺服器關閉,您可以將憑證新增回存放區。 如需certreq.exe的詳細資訊,請參閱 進階憑證註冊和管理:附錄 3:Certreq.exe語法

請注意,PK 是自我簽署憑證,也用來簽署 KEK。

PK 簽署/初始布建有 2 個部分。 請連絡您的 Microsoft 連絡人以取得這些腳本:

  • subcreate_set_PK_example_initial_provisioning_example.ps1. 由 signtool 用來簽署 PK,稍後會在服務案例中提供。

  • subcreate_set_PK_service_example.ps1. 由於我們正在處理 HSM 案例,因此下列這一行適用于腳本。

使用 PK 憑證 (服務案例進行簽署)

本節適用于使用 PK 憑證簽署,而且可能不適用於系統的初始布建。 不過,您可以使用這裡的 方法來測試您的服務案例。

判斷憑證雜湊 (sha1)

判斷憑證的 SHA1 雜湊。 您可以使用下列其中一種方法來取得 SHA1 雜湊:

  • 在 Windows 中,開啟 [ 憑證 ] 檔案,選取 [ 詳細資料 ] 索引標籤,然後檢查 指紋的值。

  • 或使用下列命令:

    C:\>certutil -store My PKContainer
    

    範例輸出:

    My
    ================ Certificate 5 ================
    Serial Number: 58efcfd8f929c5bd41152a8ec413051e
    Issuer: CN=test self-signed
     NotBefore: 1/30/2013 3:24 PM
     NotAfter: 1/30/2019 3:34 PM
    Subject: CN=test self-signed
    Signature matches Public Key
    Root Certificate: Subject matches Issuer
    Template:
    Cert Hash(sha1): db 31 4d a0 d0 ef 87 d4 2b 42 f7 4b 9c 38 a1 f9 17 3e f7 a2
      Key Container = PKContainer
      Provider = nCipher Security World Key Storage Provider
    Private key is NOT exportable
    Signature test passed
    CertUtil: -store command completed successfully.
    

使用 signtool 簽署,並將憑證存放區指定為參考

使用 SHA1 雜湊簽署 KEK 憑證:

C:\> signtool.exe  sign /v /fd sha256 /sha1 "db314da0d0ef87d42b42f74b9c38a1f9173ef7a2" /sm /p7  .\ /p7co 1.2.840.113549.1.7.1 /p7ce  DetachedSignedData KEK.bin

其中 KEK.bin 是您要簽署之二進位憑證的檔案名。

範例輸出:

The following certificate was selected:
    Issued to: test self-signed
    Issued by: test self-signed
    Expires:   Fri Jan 30 15:34:32 2019
    SHA1 hash: DB314DA0D0EF87D42B42F74B9C38A1F9173EF7A2

Done Adding Additional Store
Successfully signed: KEK.bin

Number of files successfully Signed: 1
Number of warnings: 0
Number of errors: 0

注意 為了與 UEFI 規格相容,以及 UEFI 實作之間的最大相容性, 必須 存在 /p7co 和 /p7ce 參數,傳遞至 /p7co 的值 必須是 1.2.840.113549.1.7.1,而傳遞給 /p7ce 的值 必須是 DetachedSignedData。 此外,為了改善與生產簽署環境的相容性,完整指定硬體金鑰容器的signtool.exe命令列如下所示:

signtool.exe sign /p7 .\ /p7co 1.2.840.113549.1.7.1 /p7ce DetachedSignedData /fd SHA256 /u 1.3.6.1.4.1.311.79.1 /f "{CertificatePath}" /kc "{KeyContainer}" /sha1 "{ThumbPrint}" /csp "{CertificateCSP}" "{FilePath}"

如需詳細資訊,請參閱簽署工具 (SignTool.exe) Windows 8.1安全開機金鑰建立和管理指引

附錄 A – 使用 Thales KeySafe 檢視金鑰

Thales KeySafe 是以 GUI 為基礎。

若要使用 KeySafe,您必須已安裝 JRE/JDK 1.4.2、1.5 或 1.6。 安裝 nCipher 軟體之前,請先安裝 JAVA。

在 資料夾底下 %NFAST_KMDATA%\config\ 設定 hardserver 組態檔:

編輯區段中的 server_startup 設定:

nonpriv_port。 此欄位會指定硬式伺服器接聽本機非特殊許可權 TCP 連線的埠。

  • 預設為連線到埠 9000。

  • NFAST_SERVER_PORT如果已設定環境變數,它會覆寫針對 nonpriv_port 設定的任何值

priv_port。 此欄位會指定硬式伺服器接聽本機特殊許可權 TCP 連線的埠。

  • 預設為連線到埠 9001。

  • NFAST_SERVER_PRIVPORT如果已設定環境變數,它會覆寫針對 priv_port 設定的任何值

以下是 Thales KeySafe GUI 的螢幕擷取畫面:

thales keysafe 鍵作業功能表的螢幕擷取畫面

下圖是藉由啟動 KeySafe 公用程式,然後流覽至 KeyList 功能表來產生。

thales keysafe keylist 功能表的螢幕擷取畫面

如需詳細資訊,請參閱 nCipher/Thales 使用者指南。

附錄 B:使用 SafeNet CMU 公用程式檢視金鑰

如需詳細資訊,請參閱 SafeNet Luna HSM 檔。

C:\Program Files\SafeNet\LunaClient>cmu list
Please enter password for token in slot 1: ********
handle=72       label=PKContainer
handle=43       label=PKContainer

C:\Program Files\SafeNet\LunaClient>cmu getattribute
Please enter password for token in slot 1: ********
Select object to query
Handler Label
72      PKContainer
43      PKContainer
Enter handler (or 0 for exit): 72
class=privateKey
token=true
private=true
label=PKContainer
keytype=RSA
subject=
id=3081cd300d02050080000010020401000000300c02050080000011020346494d3053020500800
00014024a660064006400340064006400330061002d0064003900610064002d00340066006200630
02d0062003000320031002d006300660034006100650064006100650035006400350033000000301
d0205008000001302140100000000000000000000000000000000000000300d02050080000015020
400000000300d02050080000016020400000000300d02050080000017020400000000300d0205008
0000018020400000000
sensitive=true
decrypt=true
unwrap=true
sign=true
derive=false
startdate=
enddate=
modulus=b56a518c2744a3341dd1ed27cfe5dc6cabac7d4b820c00d60cb2a4b713f28b3e1836b619
b61b79be76d1870e09961972c83cc338a2065880ec4f6fb00c48f1f953c7fff132be9df36f13bcda
f0f873bcfaa81734290f85ff123072b258fb16b0833722af72f90fd29c533153b0ba52d502ab11c4
81cd6e60733cfa39a811c7ff381ba57081c818881a6bbeeb60091ab9f26f6cd177dcff884d7d9edb
e69e61b316ef12785f5957a1e6bb0b21497b328e475f82e7efac71815d2c153b5991ebfacf4bb75c
72afff513a55f68f260f09aa9d687639a24e1ce35fd5588d27c2ff69b7e6c9b5fcb4ec7d55674e85
45f051d4945ae5d46d958056aaf7e01943eda91d
modulusbits=2048
publicexponent=010001
extractable=true
local=true
neverextractable=false
alwayssensitive=true
modifiable=true

安全開機金鑰建立和管理指引

安全開機概觀