Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.
Auszug
hiddentrue

Nuclos HTTPS: HttpsURLConnection, TrustManager, HostnameVerifier, SSLContext, ohne Zertifikat, Java.

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.

Status
colourGrey
titleReferenz
Status
colourBlue
titleEntwickler
Status
colourGreen
titleStand: Jul 2026
Status
colourGrey
titlegilt fuer Nuclos 4.2026.x

Warnung
titleSicherheitshinweis

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

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

Codeblock
languagejava
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 →