?? certpathfromserver.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 + -