globe with meridians Sprache: Deutsch · English

open book Code Beispiel für allgemeinen HTTPS Zugriff ohne Zertifikat

HttpsURLConnection ohne Zertifikatsprüfung – nur für Tests.

REFERENZ ENTWICKLER STAND: JUL 2026 GILT FUER NUCLOS 4.2026.X

Sicherheitshinweis

Deaktiviert die Zertifikatsprüfung – nur für Tests/Entwicklung, niemals produktiv.

Allgemeiner HTTPS-Zugriff über HttpsURLConnection ohne Zertifikatsprüfung (NullTrustManager/NullHostnameVerifier):

public class SSLExample {

   public static void main(String[] args) throws IOException {
      String sUrl = "https://sshrest.de";

      trustAllCertificates();

      URL url = new URL(sUrl);
      URLConnection urlConnection = url.openConnection();
      InputStream is = urlConnection.getInputStream();

      is.read();
      is.close();
   }

   private static void trustAllCertificates() {
      try {
         TrustManager[] trustManagerArray = {new NullX509TrustManager()};
         SSLContext sc = SSLContext.getInstance("SSL");
         sc.init(null, trustManagerArray, null);
         HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
         HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
      } catch (Exception e) {
         e.printStackTrace();
      }

   }

   /**
    * Host name verifier that does not perform any checks.
    */
   private static class NullHostnameVerifier implements HostnameVerifier {
      public boolean verify(String hostname, SSLSession session) {
         return true;
      }
   }

   /**
    * Trust manager that does not perform any checks.
    */
   private static class NullX509TrustManager implements X509TrustManager {
      public void checkClientTrusted(X509Certificate[] chain, String authType)
            throws CertificateException {
      }

      public void checkServerTrusted(X509Certificate[] chain, String authType)
            throws CertificateException {
      }

      public X509Certificate[] getAcceptedIssuers() {
         return new X509Certificate[0];
      }
   }

}

Verwandte Seiten

gear Code Beispiel für SSL REST Zugriff ohne Zertifikat


SSL REST.

Öffnen →

  • Keine Stichwörter