Built a simple https client.
package src;
import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
public class JavaHttpsExample
{
public static void main(String[] args) throws Exception {
String httpsURL = "https://services.gradle.org/";
URL myUrl = new URL(httpsURL);
HttpsURLConnection conn = (HttpsURLConnection)myUrl.openConnection();
InputStream is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String inputLine;
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
br.close();
}
}
An attempt to open a connection on Windows 10 Pro build 19044 crashes with an error:
Exception in thread "main" javax.net.ssl.SSLHandshakeException:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:371)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:314)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:309)
...
The connection on Windows 8.1 Pro build 6.3.9600 is successful. On both systems it is used:
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)
Run with -Djavax.net.debug=ssl:handshake
A fragment of the log on Windows 10:
...
javax.net.ssl|DEBUG|10|main|CertificateMessage.java:366|Consuming server Certificate handshake message (
"Certificates": [
"certificate" : {
"version" : "v3",
"serial number" : "008464BF921D4424172C45933D35C53139",
"signature algorithm": "SHA256withRSA",
"issuer" : "CN=Generic Root CA 3, C=EN",
"not before" : "2022-05-10 03:00:00.000",
"not after" : "2023-05-11 02:59:59.000",
"subject" : "CN=gradle.org, O="Cloudflare, Inc.", L=San Francisco, ST=California, C=US",
"subject public key" : "RSA",
"extensions" : [
{
ObjectId: 2.5.29.19 Criticality=true
BasicConstraints:[
CA:false
PathLen: undefined
]
},
{
ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
serverAuth
clientAuth
]
},
{
ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
DNSName: gradle.org
DNSName: *.gradle.org
]
}
]}
]
)
...
A fragment of the log on Windows 8:
...
javax.net.ssl|DEBUG|10|main|CertificateMessage.java:366|Consuming server Certificate handshake message (
"Certificates": [
"certificate" : {
"version" : "v3",
"serial number" : "04B9BF6E8CBB0976E5DA72B7CB24FD00",
"signature algorithm": "SHA256withECDSA",
"issuer" : "CN=Cloudflare Inc ECC CA-3, O="Cloudflare, Inc.", C=US",
"not before" : "2022-05-10 03:00:00.000",
"not after" : "2023-05-11 02:59:59.000",
"subject" : "CN=gradle.org, O="Cloudflare, Inc.", L=San Francisco, ST=California, C=US",
"subject public key" : "EC",
"extensions" : [
{
ObjectId: 1.3.6.1.4.1.11129.2.4.2 Criticality=false
},
{
ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false
AuthorityInfoAccess [
[
accessMethod: ocsp
accessLocation: URIName: http://ocsp.digicert.com
,
accessMethod: caIssuers
accessLocation: URIName: http://cacerts.digicert.com/CloudflareIncECCCA-3.crt
]
]
},
... and then the chain of certificates
I tried it with various sites. The result is the same – error. All sites are accessible from the browser.
Why is an incorrect certificate returned in Windows 10? How to fix it?
A similar question is here Unable to access any HTTPS site with any Java JRE on Windows 10