以编程方式获取服务器证书

时间:2016-03-23 16:55:49

标签: java ssl jboss certificate

我已经像这样配置了JBoss AS7 SSL:

<connector
    name="https"
    protocol="HTTP/1.1"
    scheme="https"
    socket-binding="https"
    enable-lookups="false"
    secure="true">
        <ssl
            name="foo-ssl"
            key-alias="server"
            password="123456"
            certificate-key-file="../standalone/configuration/server.keystore"
            protocol="TLS"
            verify-client="false"
            ca-certificate-file="../standalone/configuration/server.keystore"
        />
</connector>

我想知道是否有任何更改我可以通过编程方式访问此密钥库中定义的证书,但没有在Java代码中具体指定其路径

我试过这个

  TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmf.init((KeyStore) null);

  // Get hold of the default trust manager
  X509TrustManager x509Tm = null;
  for (TrustManager tm : tmf.getTrustManagers())
  {
    if (tm instanceof X509TrustManager)
    {
      x509Tm = (X509TrustManager) tm;
      break;
    }
  }

  for (X509Certificate currentCertificate : x509Tm.getAcceptedIssuers())
  {
    System.out.println(currentCertificate.getIssuerX500Principal().toString());
  }

但是id没有显示密钥库上的证书。

0 个答案:

没有答案