Android API无法获取X509Certificate
我一直在尝试从 X509Certificate 获取主题备用名称,但似乎 cert.getSubjectAlternativeNames()
在 Android 中不起作用,它会返回 null。 但是,当我使用 cert.getExtensionValue("2.5.29.17") 提取主题备用名称时,这些名称确实存在,我可以逐字节解析它。
顺便说一句,我确信我的 PKCS12 证书是有效的,因为我可以使用 getSubjectAlternativeNames() 并在 Java 程序中获得正确的结果。
有谁知道如何在 Android 中正确使用 getSubjectAlternativeNames()
或者我错过了 Android 中的某些配置?
谢谢 奥亭
I have been trying to get subject alternative names from an X509Certificate, but it seems cert.getSubjectAlternativeNames()
does not work in Android, which returns null.
However, when I use cert.getExtensionValue("2.5.29.17")
to extract subject alternative names, the names DO exist and I can parse it byte by byte.
Btw, I am sure my PKCS12 certificate is valid, because I can use getSubjectAlternativeNames()
and get the correct result in Java program.
Does any body know how to use getSubjectAlternativeNames()
in Android correctly or I miss some configuration in Android?
Thanks
Aoting
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 org.bouncycastle.x509.extension.X509ExtensionUtil.getSubjectAlternativeNames(X509Certificate cert) 作为解决方法。如果扩展存在,并且假设错误不在
X509ExtensionUtil
本身中,而是在X509Certificate
中,则它应该可以工作。Try using
org.bouncycastle.x509.extension.X509ExtensionUtil.getSubjectAlternativeNames(X509Certificate cert)
as a workaround. If the extension is there, and assuming the bug is not inX509ExtensionUtil
itself, but inX509Certificate
, it should work.证书似乎不包含SubjectAltName 扩展名。另外,您正在哪个版本的 Android 上尝试此操作?已有一个 问题就此问题向 Google 报告,该问题似乎已在 Froyo 中得到解决。
It seems that certificate does not contain SubjectAltName extension. Also on which version of Android you are trying this ? There is already an issue reported to Google around this, which see to have been resolved in Froyo.