1 package SnowMailClient.MailEngine; 2 3 import java.net.Socket ; 4 import java.security.*; 5 import java.security.cert.*; 6 7 import javax.net.ssl.*; 8 9 11 public final class MyX509TrustManager implements X509TrustManager 12 { 13 14 public MyX509TrustManager() 15 { 16 } 17 18 public void checkClientTrusted(X509Certificate[] chain, 19 String authType) 20 { 21 System.out.println("checkClientTrusted()"); 22 System.out.println("Auth type="+authType); 23 24 } 25 26 public void checkServerTrusted(X509Certificate[] chain, 27 String authType) 28 throws CertificateException 29 { 30 System.out.println("checkServerTrusted()"); 31 System.out.println("Auth type="+authType); 32 } 33 34 public X509Certificate[] getAcceptedIssuers() { 35 return new X509Certificate[]{}; 36 } 37 38 public static void main(String [] arguments) 39 { 40 try 41 { 42 String host = "pop.gmail.com"; 43 int port= 995; 44 Socket s0 = new Socket (host, port); 45 SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault(); 46 SSLSocket sconnection = (SSLSocket) ssf.createSocket(s0, host,port, true); 47 sconnection.setSoTimeout(1000*60); 48 49 sconnection.setEnabledProtocols(sconnection.getEnabledProtocols()); 50 sconnection.setEnabledCipherSuites(sconnection.getEnabledCipherSuites()); 51 52 sconnection.setUseClientMode(true); 53 sconnection.setNeedClientAuth(false); 54 sconnection.setWantClientAuth(false); 55 sconnection.setEnableSessionCreation(true); 56 57 System.out.println("Connecting..."); 59 sconnection.startHandshake(); 60 61 System.out.println("Connected !"); 62 } 63 catch(Exception e) 64 { 65 e.printStackTrace(); 66 } 67 } 68 } 69 70 | Popular Tags |