如何在Java Micro Edition中访问受信任的HTTPS / SSL服务器证书颁发机构?

时间:2016-09-09 22:06:22

标签: java ssl https java-me certificate-authority

我正在尝试确定Java Micro Edition应用程序中针对SSL / HTTPS的特定手机(Kyocera DuraXT和DuraXTP)信任哪些服务器证书颁发机构(CA)(请注意,这是与确定设备上浏览器的可信证书相同。)

使用以下代码,您可以检索有关特定HTTPS连接的特定服务器证书的信息:

HttpsConnection c = null;
InputStream is = null;
c = (HttpsConnection) Connector.open("https://www.website.com/",
Connector.READ_WRITE, true);
is = c.openInputStream();

SecurityInfo secuInfo;

try {
    secuInfo = c.getSecurityInfo();
} catch(Throwable t) {
    t.printStackTrace();
}
System.out.println(" ProtocolVersion "+secuInfo.getProtocolVersion());
System.out.println(" ProtocolName " + secuInfo.getProtocolName());
System.out.println(" CipherSuite " + secuInfo.getCipherSuite());

Certificate cer = secuInfo.getServerCertificate();
System.out.println(" CA Type " + cer.getType());
System.out.println(" CA Version " + cer.getVersion());
System.out.println(" CA NotAfter " + cer.getNotAfter());
System.out.println(" CA NotBefore " + cer.getNotBefore());
System.out.println(" CA Subject " + cer.getSubject());
System.out.println(" CA Issuer " + cer.getIssuer());
System.out.println(" CA SerialNumber " + cer.getSerialNumber());

如果此HTTPS连接的此特定CA不受信任,则会抛出CertificateException

有没有办法确定特定设备上J2ME应用的所有可信CA,而无需逐个尝试实际连接?

0 个答案:

没有答案