SSLHandshakeException

Durchstarter

Mitglied
Hallo, ich versuche schon seit geraumer Zeit eine 'Verbindung' zu einer URL herzustellen um den String auszulesen:
Ziel URL: https://decapi.me/twitch/uptime.php?channel=twitch
allerdings brauche ich einen SSLHandshake und ich komme nicht weiter!

1. Versuch, Fehlschlag:
Code:
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

Code:
    public String channelUptime() {
        String urlString = "";
        Security.addProvider(new Provider());
        SSLSocket sslSocket = null;
        SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        BufferedReader in = null;
        try {
            sslSocket = (SSLSocket) sslsocketfactory.createSocket("decapi.me", 443);
            in = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
            String current;
            while ((current = in.readLine()) != null)
                urlString += current;
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return urlString;
    }

Nach einer kleinen Tour durchs Internet, Versuch 2:
Code:
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
Stacktrace end:             while ((current = in.readLine()) != null)
Code:
    public void testConnectionTo(String aURL) throws Exception {
        URL destinationURL = new URL(aURL);
        HttpsURLConnection conn = (HttpsURLConnection) destinationURL
                .openConnection();
        conn.connect();
        Certificate[] certs = conn.getServerCertificates();
        for (Certificate cert : certs) {
            System.out.println("Certificate is: " + cert);
            if(cert instanceof X509Certificate) {
                try {
                    ( (X509Certificate) cert).checkValidity();
                    System.out.println("Certificate is active for current date");
                } catch(CertificateExpiredException cee) {
                    System.out.println("Certificate is expired");
                }
            }
        }
       
    }

Wie schaffe ich es eine Verbindung aufzubauen...?
 

Bitfehler

Bekanntes Mitglied
Das letzte wie ich die Meldung "PKIX path building failed" bekommen hatte, lag es daran, dass meine Zertifikate-Kette nicht vollständig dem Java-Programm bekannt war. Das Hinzufügen der fehlenden Zertifizierungsstellen in den Truststore (oder cacerts) hat das Problem gelöst.
 

Ähnliche Java Themen

Neue Themen


Oben