Check the https connection from Java, not from the browser. The environment uses Java 8. No other library is used.
package ssltest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.cert.Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
public class Connect {
public static void main(String[] args) {
try {
URL url = new URL("https://google.co.jp/");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.connect();
dispEnv();
dispContents(url);
dispCerts(conn);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void dispEnv() {
try {
System.out.print("Operating system name(os.name):");
System.out.println(System.getProperty("os.name"));
System.out.print("Java version(java.version):");
System.out.println(System.getProperty("java.version"));
InetAddress ia = InetAddress.getLocalHost();
String ip = ia.getHostAddress();
String hostname = ia.getHostName();
System.out.println("IP address(getLocalHost):" + ip);
System.out.println("hostname(hostName):" + hostname);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public static void dispCerts(HttpsURLConnection conn) {
System.out.println("----View server certificate chain----");
try {
Certificate[] certs = conn.getServerCertificates();
for (Certificate cert : certs) {
System.out.println(cert);
}
} catch (SSLPeerUnverifiedException e) {
e.printStackTrace();
}
}
public static void dispContents(URL url) {
System.out.println("----View content----");
try {
InputStream strm = url.openStream();
InputStreamReader in = new InputStreamReader(strm);
BufferedReader inb = new BufferedReader(in);
String line;
while ((line = inb.readLine()) != null) {
System.out.println(line);
}
inb.close();
in.close();
strm.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Some of the content is hidden and omitted.
Operating system name(os.name):Windows 10
Java version(java.version):1.8.0_74
IP address(getLocalHost):192.168.XXX.XXX
hostname(hostName):DESKTOP-XXXXX
----View content----
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="ja"><head>
・ ・ ・
</body></html>
----View server certificate chain----
[
[
Version: V3
Subject: CN=*.google.co.jp, O=Google LLC, L=Mountain View, ST=California, C=US
Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11
・ ・ ・
An error has occurred on the site that I referred to when writing the article.
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at ssltest.Connect.main(Connect.java:22)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
... 11 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
... 17 more
Apparently, the basic limit is marked with △. I will add it if I find out.
We have prepared a jar file so that you can easily execute it. Please download the following jar file, place it on the server you want to run, and then specify the URL in the argument while passing the java path and use it. https://github.com/koni1212/httpsConnect/raw/master/jarfile/httpsConnect.jar
Recommended Posts