2014-05-13 64 views
9

我正在嘗試使用OSGi條件權限機制。更具體地說,我試圖使用org.osgi.service.condpermadmin.BundleSignerCondition來限制哪些bundle可以啓動。文檔我已經聲明,爲了使用此權限,我必須使用org.osgi.framework.trust.repositories框架配置屬性指定JKS密鑰庫的路徑。但是,同樣的文檔提到JKS中提到的JKS不能有密碼。所以問題是:如何創建一個沒有密碼的JKS? Keytool實用程序拒絕使用空白密碼創建JKS。是否可以創建沒有密碼的JKS密鑰庫文件?

回答

14

自一段時間以後,您無法使用keytool創建密碼存儲空白密碼,但仍可以通過編程方式執行。

閱讀這樣的證書:

private static Certificate readCert(String path) throws IOException, CertificateException { 
    try (FileInputStream fin = new FileInputStream(path)) { 
     return CertificateFactory.getInstance("X.509").generateCertificate(fin); 
    } 
} 

比創建一個空密碼這樣的密鑰庫:

try { 
    // Reading the cert 
    Certificate cert = readCert("/tmp/cert.cert"); 

    // Creating an empty JKS keystore 
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); 
    keystore.load(null, null); 

    // Adding the cert to the keystore 
    keystore.setCertificateEntry("somecert", cert); 

    // Saving the keystore with a zero length password 
    FileOutputStream fout = new FileOutputStream("/tmp/keystore"); 
    keystore.store(fout, new char[0]); 
} catch (GeneralSecurityException | IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

運行命令:

keytool -list -keystore keystore 

它會要求一個密碼,但你可以簡單地按下輸入。您將收到以下警告,但密鑰庫的內容將被列出:

***************** WARNING WARNING WARNING ***************** 
* The integrity of the information stored in your keystore * 
* has NOT been verified! In order to verify its integrity, * 
* you must provide your keystore password.     * 
***************** WARNING WARNING WARNING ***************** 

這可能適用於您。

相關問題