1 package SnowMailClient.MailEngine; 2 3 import SnowMailClient.Language.Language; 4 import java.util.*; 5 import javax.net.ssl.*; 6 import java.net.*; 7 8 public final class SSLConnection 9 { 10 private SSLConnection() {} 11 12 14 public static Socket createSSLConnection(String host, int port) throws Exception 15 { 16 boolean debug = false; 17 18 Socket s0 = null; 19 try 20 { 21 s0 = new Socket(host, port); 22 s0.setSoTimeout(1000*60); 23 } 24 catch(Exception e) 25 { 26 throw new Exception (Language.translate("Cannot connect to %1 on port %2", host, ""+port), e); 27 } 28 29 try 30 { 31 SSLSocketFactory ssf = VerifiedSSLSocketFactory.getInstance().getSocketFactory(); 32 SSLSocket sconnection = (SSLSocket) ssf.createSocket(s0, host, port, true); 34 sconnection.setSoTimeout(1000*60); 35 36 sconnection.setEnabledProtocols(sconnection.getEnabledProtocols()); 37 sconnection.setEnabledCipherSuites(sconnection.getEnabledCipherSuites()); 38 39 sconnection.setUseClientMode(true); 40 sconnection.setNeedClientAuth(false); 41 sconnection.setWantClientAuth(false); 42 sconnection.setEnableSessionCreation(true); 43 44 sconnection.startHandshake(); 46 47 SSLSession sSLSession = sconnection.getSession(); 48 49 if(debug && sSLSession!=null) 50 { 51 String cipherSuite = sSLSession.getCipherSuite(); 52 System.out.println("Cipher suite used = "+cipherSuite); 53 54 String proto = sSLSession.getProtocol(); 55 System.out.println("Protocol = "+proto); 56 } 57 58 return sconnection; 59 } 60 catch(Exception e) 61 { 62 e.printStackTrace(); 63 throw new Exception (Language.translate("Cannot initiale SSL connection to %1 on port %2", host, ""+port), e); 64 } 65 66 } 68 69 70 71 72 } | Popular Tags |