Reputation: 1647
I'm trying to convert some python web socket code to Java (code that talks to a consumer device:)
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
ws_connection_local = connect(f"wss://{target_ip}:{WEBSOCKET_SSL_PORT}", ssl_context=ssl_context)
my Java .. (actually groovy) replacement is this...
CountDownLatch latch = new CountDownLatch(1);
String url = "wss://$host:$port"
WebSocket ws = HttpClient
.newHttpClient()
.newWebSocketBuilder()
.buildAsync(URI.create(url), new WebSocketClient(latch))
whereupon I get the error:
java.util.concurrent.CompletionException: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
On the theory that the problem is something to do with SSL certificates or host verification, I followed this advice prior to opening the connection: How to disable SSL verification?
and set trust all certificates with the recommended no-op HttpsURLConnection.setDefaultSSLSocketFactory etc and HttpsURLConnection.setDefaultHostnameVerifier etc. However that didn't help, I get the same error. I also set debugger breakpoints in the TrustManager and HostnameVerifier to see if they were invoked, and they were not.
Upvotes: 0
Views: 41