⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 certpathfromserver.java

📁 本书以大量精简的实例介绍了Java安全性编程方面的概念和技术
💻 JAVA
字号:
/* 以下是若干用于测试HTTPS通讯的网页地址:

https://www.verisign.com/ 
https://happiness.dhs.org/ 
https://www.microsoft.com 
https://www.sun.com 
https://www.ftc.gov 


*/


import java.net.*;
import javax.net.*;
import java.io.*;
import javax.net.ssl.*;
import java.security.cert.*;
import java.util.*;
import java.math.*;
import java.security.*;



public class CertPathFromServer {
  public static void main(String args[ ])throws Exception {
try {
        // Create the client socket
        int port = 443;
//        String hostname = "www.microsoft.com"; //not all server could use https

String hostname =args[0];
        SSLSocketFactory factory = HttpsURLConnection.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().getPeerCertificates();
	System.out.println(serverCerts.length);
        for(int i=0;i<serverCerts.length;i++){
      		System.out.println(serverCerts[i]);
        }
        
        // Close the socket
        socket.close();
    } catch (SSLPeerUnverifiedException e) {
System.out.println(e);
    } catch (IOException e) {
System.out.println(e);
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -