Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

10.03.2010, 11:22

[JavaME] SSL/HTTPS: Could not parse validity information

Hi all,

ich versuche gerade die Server-Kommunikation von HTTP auf HTTPS umzustellen -

:!: Entwurf::

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public void run(String ip, String port, String additional) {

String url = "https://"+ip+":"+port+"/"+additional;

     try {

         HttpsConnection hc = (HttpsConnection)Connector.open(url);
         hc.setRequestMethod(HttpsConnection.GET);
         SecurityInfo si = hc.getSecurityInfo();
         Certificate c = si.getServerCertificate();
         String subject = c.getSubject();

         String s = "Server certificate subject: \n" + subject;
         Alert a = new Alert("Result", s, null, null);
         a.setTimeout(Alert.FOREVER);
         mDisplay.setCurrent(a, mForm);

         hc.close();
   }
   catch (RuntimeException re) {
       Alert a = new Alert("Exception", re.toString(), null, null);
       a.setTimeout(Alert.FOREVER);
       mDisplay.setCurrent(a, mForm);
     }
   catch (IOException ioe) {
     Alert a = new Alert("Exception", ioe.toString(), null, null);
     a.setTimeout(Alert.FOREVER);
     mDisplay.setCurrent(a, mForm);
   }
   catch (Exception e) {
       Alert a = new Alert("Exception", e.toString(), null, null);
       a.setTimeout(Alert.FOREVER);
       mDisplay.setCurrent(a, mForm);
     }
}


:!: Problem:
Die Zeile

Quellcode

1
"SecurityInfo si = hc.getSecurityInfo();"
wirft immer den Fehler "java.io.IOException: Could not parse validity information"

:!: Idee:
Das könnte daran liegen, dass das Zertifikat auf dem Server kein echtes ist / selbst unterschrieben.
Unter JavaEE braucht man in diesem Fall einen TrustManager, der dafür sorgt, dass alle Zertifikate akzeptiert werden.

:!: Google-Suche:
CertificateHandler, SSLHandler, TrustManager, disable certificate validation u.ä. - ergebnisse funktionieren nicht für J2ME

:?: Frage:
Wie macht man das in J2ME/MIDP 2.0?

Unter MIDP 2.0 gibt es meines Wissens keine Klassen wie TrustManager, X509TrustManager

2

11.03.2010, 10:18

um es etwas zu präzisieren - ich suche nach einer Möglichkeit für soetwas in J2ME:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllTrustManager = new TrustManager[] { new X509TrustManager()
        {
            public java.security.cert.X509Certificate[] getAcceptedIssuers()
            {
                return null;
            }

            public void checkClientTrusted(final X509Certificate[] certs, final String authType)
            {
                return;
            }

            public void checkServerTrusted(final X509Certificate[] certs, final String authType)
            {
                return;
            }
        }};

        // Install the all-trusting trust manager
        try
        {
            previousSSLContext = SSLContext.getDefault();
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllTrustManager, new java.security.SecureRandom());
            SSLContext.setDefault(sc);
        }
        catch (NoSuchAlgorithmException e){}
        catch (KeyManagementException e){}


...obiger Code funktioniert in J2EE aber nicht in J2ME[/code]