2012-11-30 55 views
0

使用Windows 7,JDK 6(和7)。某些證書Windows-MY中的私鑰未檢測到

我試圖獲得存儲在Windows MSCAPI密鑰存儲中的個人證書,它是基本屬性(爲了使用私鑰進行簽名)。然而,一些別名被標識爲沒有私鑰(isKeyEntry == false),儘管它實際上有一個。

任何建議如何處理這個「功能」?

帶證書的P12文件(已被吊銷)&擁有這個奇怪「屬性」的私鑰可以從http://download.upce.cz/terena-public.pfx下載。密碼是「密碼」。

KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI"); 
ks.load(null, null); 
Enumeration<String> aliases = ks.aliases(); 
while (aliases.hasMoreElements()) { 
    String alias = (String) aliases.nextElement(); 
    X509CertImpl certificate = (X509CertImpl)ks.getCertificate(alias); 
    System.out.println("Alias: " + alias); 
    System.out.println(" Subject: " + certificate.getSubjectDN()); 
    System.out.println(" Issued By: " + certificate.getIssuerDN()); 
    if (ks.isKeyEntry(alias)) { 
     System.out.println(" Has private key"); 
    } 
} 
+0

我測試了你的terena-public.pfx,我可以在Windows 7,Java 7,SunMSCAPI上確認相同的行爲。不幸的是,我不知道爲什麼會發生這種情況。 – gargii

+0

你有沒有深究這個問題的底部? – JimmyJames

回答

0

我將pfx文件導入到Mozilla Thunderbird中,並將其導出爲p12文件。現在我可以通過MSCAPI看到它。原始證書中必須有一些防止MSCAPI查看私鑰的內容。

我比較了這些文件,我注意到在原始文件中使用了密鑰使用部分。

原始PFX:

Bag Attributes 
    localKeyID: 01 00 00 00 
    friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541 
    Microsoft CSP Name: Microsoft Software Key Storage Provider 
Key Attributes 
    X509v3 Key Usage: 90 

轉換P12:

Bag Attributes 
    friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541 
    localKeyID: 47 E4 D3 F0 75 48 9D 77 07 E9 51 A4 F1 B6 DF E9 40 80 26 7A 
Key Attributes: <No Attributes> 

有兩個文件的詳細區別,但我不知道哪一個會導致不受歡迎的行爲。