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