我使用OSGi条件权限机制试验。更具体地讲,我试图用org.osgi.service.condpermadmin.BundleSignerCondition限制哪些软件可以通过启动。文档我有一定的状态,为了使用这个权限,我用org.osgi.framework.trust.repositories框架配置属性必须指定路径JKS密钥。然而,同样的文件中提到,在此属性中提到JKS不能有密码。所以,问题是:如何在不使用密码创建JKS? Keytool实用拒绝使用空密码创建JKS。
您不能创建因为同时使用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 *****************
这可能为你工作。