osgi - 是否可以在没有密码的情况下创建 JKS keystore 文件?

标签 osgi jks

我正在试验 OSGi 条件权限机制。更具体地说,我正在尝试使用 org.osgi.service.condpermadmin.BundleSignerCondition 来限制可以启动哪些包。我的文档指出,为了使用此权限,我必须使用 org.osgi.framework.trust.repositories 框架配置属性指定 JKS keystore 的路径。但是,相同的文档提到此属性中提到的 JKS 不得具有密码。所以问题是:如何在没有密码的情况下创建 JKS? Keytool 实用程序拒绝使用空白密码创建 JKS。

最佳答案

一段时间以来,您无法使用 keytool 创建具有空白密码的 keystore ,但您仍然可以通过编程方式进行创建。

阅读这样的证书:

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

然后使用空密码创建 keystore ,如下所示:

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

它会要求输入密码,但您只需按回车键即可。您将收到以下警告,但会列出 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  *****************

这可能对你有用。

关于osgi - 是否可以在没有密码的情况下创建 JKS keystore 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629246/

相关文章:

java - 带有嵌套 jar 的 RCP ClassNotFoundException

java - 通过 Notes-UpdateSite 数据库将 jar 部署到 Domino 服务器,以 NoClassDefFoundException 结尾

web-services - 如何在 websphere 5 的 web 服务客户端中配置 jks 证书

java - 使用基于 Java Key Store 别名的单个证书

java - 如何从 OSGi 框架外部调用 OSGi 服务。?

Eclipse OSGI 配置 : relative paths and/or @config. 类似目录的替换?

java - JCEKS PBE 用于加密私钥的算法是什么?

java - 连接到 HTTPS 站点时发生 SSLHandshakeException

android - 无法在 Android Studio 中导出已签名的 APK

gradle - Liferay 7 服务模块 Unresolved 需求