This product includes software developed by the KnownSpace Group for use in the KnownSpace Project (http://www.knownspace.org/).
-- Da ich keine Ahnung von Java habe, kann dies nur als Hack bezeichnet werden und nicht als sinnvolle Erweiterung von OX in einer Produktionsumgebung --
Die Anleitung bezieht sich auf die OX-Version 0.8.0-2
Um OpenXChange mit IMAPS auszustatten sind mehrere Schritte notwendig. Der Source-Code ist leider redundant und verwendet zweimal eine Funktion für den IMAP-Connect.
Wichtig ist, dass man eine neue javamail.jar verwendet und zwar in einer Version >= 1.3.2.
Man installiere unter src/com/openexchange/tools die beiden folgenden Dateien:
DummySSLSocketFactory.java : // For licensing, see: http://helium.knownspace.org/license.html package com.openexchange.tools;
import java.io.IOException;
import java.net.InetAddress; import java.net.Socket;
import javax.net.SocketFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager;
/** * A custom SSLSocketFactory for generating SSL sockets * used by JavaMail for access to secure IMAP stores. * * Taken from * http://www.javaworld.com/javatips/jw-javatip115.html * Java Tip 115: Secure JavaMail with JSSE * Add secure, SSL-based connections to JavaMail * By Eugen Kuleshov and Dmitry I. Platonoff * */ public class DummySSLSocketFactory extends SSLSocketFactory { private SSLSocketFactory factory;
public DummySSLSocketFactory() { System.out.println("DummySocketFactory instantiated");
try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, // No KeyManager required new TrustManager[] { new DummyTrustManager() }, new java.security.SecureRandom()); factory = (SSLSocketFactory) sslcontext.getSocketFactory(); } catch (Exception ex) { ex.printStackTrace(); } } public static SocketFactory getDefault() { return new DummySSLSocketFactory(); }
public Socket createSocket(Socket socket, String s, int i, boolean flag) throws IOException { return factory.createSocket(socket, s, i, flag); }
public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr1, int j) throws IOException { return factory.createSocket(inaddr, i, inaddr1, j); }
public Socket createSocket(InetAddress inaddr, int i) throws IOException { return factory.createSocket(inaddr, i); }
public Socket createSocket(String s, int i, InetAddress inaddr, int j) throws IOException { return factory.createSocket(s, i, inaddr, j); }
public Socket createSocket(String s, int i) throws IOException { return factory.createSocket(s, i); } public String[] getDefaultCipherSuites() { return factory.getSupportedCipherSuites(); }
public String[] getSupportedCipherSuites() { return factory.getSupportedCipherSuites(); } }
DummyTrustManager.java : // For licensing, see: http://helium.knownspace.org/license.html package com.openexchange.tools; import java.security.cert.X509Certificate; import javax.net.ssl.X509TrustManager;
/** * A simple TrustManager implementation that accepts * all certificates without validation. * * Taken from * http://www.javaworld.com/javatips/jw-javatip115.html * Java Tip 115: Secure JavaMail with JSSE * Add secure, SSL-based connections to JavaMail * By Eugen Kuleshov and Dmitry I. Platonoff * */ public class DummyTrustManager implements X509TrustManager { public boolean isClientTrusted(X509Certificate[] cert) { return true; }
public boolean isServerTrusted(X509Certificate[] cert) { return true; } public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
public void checkClientTrusted(X509Certificate[] p0, String p1) throws java.security.cert.CertificateException { }
public void checkServerTrusted(X509Certificate[] p0, String p1) throws java.security.cert.CertificateException { } }
Um beim Einloggen in OpenXChange zu prüfen, ob Mail da ist, wird die Datei /src/com/openexchange/tools/MailHandle.java angepasst.
Die DummySSLSocketFactory wird eingebunden am Anfang der Datei : import com.openexchange.tools.DummySSLSocketFactory;
Dann wird die Funktion initIMAPConnection verändert : public void initIMAPConnection(String user, String password) throws Exception {
String SSL_FACTORY = "com.openexchange.tools.DummySSLSocketFactory"; Properties props = (Properties)System.getProperties().clone(); props.put("mail.store.protocol", "imap"); props.put("mail.imap.port", String.valueOf(imapport)); props.put("mail.imap.socketFactory.class", SSL_FACTORY); props.put("mail.imap.socketFactory.fallback", "false"); props.put("mail.imap.socketFactory.port", "993"); java.security.Security.setProperty("ssl.SocketFactory.provider", SSL_FACTORY); Session session = Session.getDefaultInstance(props, null); this.store = session.getStore("imap"); this.store.connect(imap,user,password); }
Um den E-Mail Client mit IMAPS zu verwenden, muss zusätzlich die Datei /src/com/openexchange/webmail/imap/DefaultIMAPConnection.java angepasst werden.
Die DummySSLSocketFactory wird eingebunden am Anfang der Datei : import com.openexchange.tools.DummySSLSocketFactory;
Dann wird die Funktion connect() angepasst :
public Store connect() throws javax.mail.NoSuchProviderException, javax.mail.MessagingException {
String SSL_FACTORY = "com.openexchange.tools.DummySSLSocketFactory"; Properties imapProperties = (Properties)System.getProperties().clone(); imapProperties.put("mail.store.protocol", "imap"); imapProperties.put("mail.imap.port", String.valueOf(imapPort)); imapProperties.put("mail.imap.socketFactory.class", SSL_FACTORY); imapProperties.put("mail.imap.socketFactory.fallback", "false"); imapProperties.put("mail.imap.socketFactory.port", "993"); java.security.Security.setProperty("ssl.SocketFactory.provider", SSL_FACTORY);
Session imapSession = Session.getDefaultInstance(imapProperties, null); Store imapStore = imapSession.getStore("imap"); imapStore.connect(imapServer, imapUsername, imapPassword);
connections++; ComfireLogger.log("DEBUG: IMAP: Open connection: CONNECTIONS=" + connections, ComfireLogger.DEBUG); return imapStore; }
Danach sind die folgenden Schritte notwendig :
- *.war-Dateien neu deployen
- *.jar-Dateien nach /opt/ox/lib kopieren
- OX neu durchstarten
Jetzt wird auf den beim Benutzer eingetragenen IMAP-Server mittels IMAPS zugegriffen.
Fertig!
| |