Windows 机器证书文件映射

Windows Machine Cert File Mappings

布鲁夫

如果您知道 windows 机器证书文件名,您可以查看 windows 证书存储中的文件内容吗?

背景

我正在使用 Windows 7+ VPN 客户端。它不会让您直接 select 应该用于连接的证书并提供非常有限的反馈。最臭名昭著的错误 RRAC 是 13801,它大致总结为“我不喜欢使用证书的某些方面,但我不会告诉你具体是什么”。

使用事件查看器查看安全条目,我确实看到有证书请求。类似于:

 ProviderName Microsoft Software Key Storage Provider 
  AlgorithmName UNKNOWN 
  KeyName {#################} 
  KeyType %%2499 
  KeyFilePath C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\<filename>
  Operation %%2458 
  ReturnCode 0x0 

我想知道如何使用上面提到的文件名来查看证书属性(IE:看到正在使用我想要的那个)。现在我唯一的方法是通过 mmc 导入证书并查看导入时正在创建的新文件。我无法对系统中已导入的证书使用此技巧。

这里所有的标识符都是私钥的。私钥不知道证书在哪里,因为架构是证书对象/证书存储知道给定证书的私钥在哪里。

要查看证书库中的证书与系统上的密钥之间的映射,您可以使用 certutil -store,例如:

C:\>certutil -store my
my
================ Certificate 0 ================
...
================ Certificate 7 ================
Serial Number: 3451b93c10f9279348a949f729d1ff10
Issuer: CN=localhost
 NotBefore: 1/26/2015 2:19 PM
 NotAfter: 1/25/2020 4:00 PM
Subject: CN=localhost
Signature matches Public Key
Root Certificate: Subject matches Issuer
Template:
Cert Hash(sha1): 15 e3 4c d3 2d a7 54 99 a9 17 8f 17 26 25 63 25 8f 3a 94 28
  Key Container = IIS Express Development Certificate Container
  Unique container name: fad662b360941f26a1193357aab3c12d_1fcb2e07-cec4-4ba1-9c78-58a431e1aefd
  Provider = Microsoft RSA SChannel Cryptographic Provider
Encryption test passed
CertUtil: -store command completed successfully.

这里要匹配的东西是Key Container在这个输出中和事件中的KeyContainerName是一样的,而这个输出中的Provider是事件中的ProviderName .

也可以转储用户存储(默认是本机):

C:\>certutil -user -store -silent my
my
================ Certificate 0 ================
Serial Number: 0123456789abcdef
Issuer: E=issueremail@example.org, CN=cn.issuer.example.org, OU=ExampleOU, O=ExampleO, L=Locality, S=State, C=Country
 NotBefore: 11/12/2013 6:15 AM
 NotAfter: 12/13/2014 7:16 AM
Subject: E=subjectemail@example.org, CN=cn.subject.example.org, OU=ExampleOU, O=ExampleO, L=Locality, S=State, C=Country
Non-root Certificate
Template:
Cert Hash(sha1): ff 3d 35 54 54 fd ff ea 52 cd 71 6f e7 14 24 75 3f f7 fe cf
  Key Container = {F76693EF-BDC3-4AEC-855A-3A2F65EB9C14}
  Unique container name: 0148994a057f4e05acb6407550cdde40_1fcb2e07-cec4-4ba1-9c78-58a431e1aefd
  Provider = Microsoft Enhanced RSA and AES Cryptographic Provider
Private key is NOT exportable
Encryption test passed

...
================ Certificate 51 ================
Serial Number: 0123456789abcdef
Issuer: E=issueremail@example.org, CN=cn.issuer.example.org, OU=ExampleOU, O=ExampleO, L=Locality, S=State, C=Country
 NotBefore: 11/12/2013 6:15 AM
 NotAfter: 12/13/2014 7:16 AM
Subject: E=subjectemail@example.org, L=Locality, S=State, C=Country
Non-root Certificate
Template:
Cert Hash(sha1): 2a 81 f8 d1 c7 40 13 2f 15 5a 5e 30 41 1a 2b 13 71 93 db 9e
  Key Container = {2572D484-D352-4B32-BB00-236B755B7F81}
  Unique container name: b11d717c1718a3bc6ad1769f2226998e_1fcb2e07-cec4-4ba1-9c78-58a431e1aefd
  Provider = Microsoft Enhanced RSA and AES Cryptographic Provider
Private key is NOT exportable
Encryption test passed

除了 -user 开关之外,我指定了 -silent,因为我有一些智能卡支持的证书,我不想处理卡和 PIN 的提示。