2014-05-13 60 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 ***************** 

这可能适用于您。

相关问题