集册 Java实例教程 检索SSL服务器的证书路径

检索SSL服务器的证书路径

欢马劈雪     最近更新时间:2020-01-02 10:19:05

568
检索SSL服务器的认证路径

import java.io.IOException;
/**from n o w j a v a . c o m - 时代Java**/

import javax.net.ssl.HttpsURLConnection;

import javax.net.ssl.SSLPeerUnverifiedException;

import javax.net.ssl.SSLSocket;

import javax.net.ssl.SSLSocketFactory;


public class Main {


  public void main(String[] argv) {

    try {

      // Create the client socket

      int port = 443;

      String hostname = "hostname";

      SSLSocketFactory factory = HttpsURLConnection
      /* 
       来自 
      *时 代 J a v a - nowjava.com*/

          .getDefaultSSLSocketFactory();

      SSLSocket socket = (SSLSocket) factory.createSocket(hostname, port);


      // Connect to the server

      socket.startHandshake();


      // Retrieve the server's certificate chain

      java.security.cert.Certificate[] serverCerts = socket.getSession()

          .getPeerCertificate
展开阅读全文