从android/BouncyCastle中的签名X509证书(CSR响应)中提取证书链信息
-
12-12-2019 - |
题
我是否能够使用Android或BouncyCastle libs从CA签名的X509客户端证书中提取证书链信息?
我有一个Android客户端,从受信任的服务器接收CA签名的X509证书。我想将签名的客户端证书和我的私钥保存到PKCS12(。p12)文件。我目前正在通过创建一个 KeyStore
对象并添加证书和私钥。当我添加客户端 PrivateKey
与 KeyStore.setKeyEntry()
方法,一 Certificate[] chain
是最后一个参数,当前只包含客户端证书。 这是否会阻止我的证书可验证,因为我没有CA证书在 Certificate[] chain
? 如果是,是否可以使用从签名中提取的信息填充证书链 X509Certificate
?
大多数示例似乎从PEM文件,BKS信任存储加载CA链,或者已经可以访问证书列表。
这是我所拥有的:
X509Certificate cert; // signed client cert
PrivateKey pkey; // client private key
String password;
KeyStore store;
store = KeyStore.getInstance("PKCS12", "BC");
store.load(null, null);
// adding the signed cert
store.setCertificateEntry("Client certificate", cert);
// creating the cert chain
X509Certificate[] chain = new X509Certificate[1];
chain[0] = cert;
// add rest of the certs in the chain here
// adding the private key
store.setKeyEntry("Client private key", pkey, password.toCharArray(), chain);
FileOutputStream fos;
fos = openFileOutput("clientCredentials.p12", Context.MODE_PRIVATE);
store.store(fos, password.toCharArray());
fos.flush();
fos.close();
提前感谢!
解决方案
CA证书不包括在您的签名证书中。你必须从某个地方(预安装,从受信任的服务器下载等)获取它们。).至于不安装完整链,如果验证者已经有权访问必要的CA证书,他们总是可以验证您的最终实体证书。您打算如何使用您的密钥和证书?
顺便说一句,你的电话 setCertificateEntry()
创建一个受信任的证书条目,这可能不是您想要的最终实体证书。
不隶属于 StackOverflow