public class

MailSSLSocketFactory

extends SSLSocketFactory
java.lang.Object
   ↳ javax.net.SocketFactory
     ↳ javax.net.ssl.SSLSocketFactory
       ↳ com.google.code.com.sun.mail.util.MailSSLSocketFactory

Class Overview

An SSL socket factory that makes it easier to specify trust. This socket factory can be configured to trust all hosts or trust a specific set of hosts, in which case the server's certificate isn't verified. Alternatively, a custom TrustManager can be supplied.

An instance of this factory can be set as the value of the mail.<protocol>.ssl.socketFactory property.

Summary

Fields
private SSLSocketFactory adapteeFactory Holds a SSLSocketFactory to pass all API-method-calls to
private KeyManager[] keyManagers Holds the KeyManager array to use
private SecureRandom secureRandom Holds the SecureRandom to use
private SSLContext sslcontext Holds a SSLContext to get SSLSocketFactories from
private boolean trustAllHosts Should all hosts be trusted?
private TrustManager[] trustManagers Holds the TrustManager array to use
private String[] trustedHosts String-array of trusted hosts
[Expand]
Inherited Fields
From class javax.net.ssl.SSLSocketFactory
From class javax.net.SocketFactory
Public Constructors
MailSSLSocketFactory()
Initializes a new MailSSLSocketFactory.
MailSSLSocketFactory(String protocol)
Initializes a new MailSSLSocketFactory with a given protocol.
Public Methods
synchronized Socket createSocket(String s, int i)
synchronized Socket createSocket(String s, int i, InetAddress inetaddress, int j)
synchronized Socket createSocket(InetAddress inetaddress, int i, InetAddress inetaddress1, int j)
synchronized Socket createSocket(InetAddress inetaddress, int i)
synchronized Socket createSocket(Socket socket, String s, int i, boolean flag)
synchronized Socket createSocket()
synchronized String[] getDefaultCipherSuites()
synchronized KeyManager[] getKeyManagers()
synchronized SecureRandom getSecureRandom()
synchronized String[] getSupportedCipherSuites()
synchronized TrustManager[] getTrustManagers()
synchronized String[] getTrustedHosts()
synchronized boolean isServerTrusted(String server, SSLSocket sslSocket)
After a successful conection to the server, this method is called to ensure that the server should be trusted.
synchronized boolean isTrustAllHosts()
synchronized void setKeyManagers(KeyManager[] keyManagers)
synchronized void setSecureRandom(SecureRandom secureRandom)
synchronized void setTrustAllHosts(boolean trustAllHosts)
synchronized void setTrustManagers(TrustManager[] trustManagers)
synchronized void setTrustedHosts(String[] trustedHosts)
[Expand]
Inherited Methods
From class javax.net.ssl.SSLSocketFactory
From class javax.net.SocketFactory
From class java.lang.Object

Fields

private SSLSocketFactory adapteeFactory

Holds a SSLSocketFactory to pass all API-method-calls to

private KeyManager[] keyManagers

Holds the KeyManager array to use

private SecureRandom secureRandom

Holds the SecureRandom to use

private SSLContext sslcontext

Holds a SSLContext to get SSLSocketFactories from

private boolean trustAllHosts

Should all hosts be trusted?

private TrustManager[] trustManagers

Holds the TrustManager array to use

private String[] trustedHosts

String-array of trusted hosts

Public Constructors

public MailSSLSocketFactory ()

Initializes a new MailSSLSocketFactory.

Throws
GeneralSecurityException

public MailSSLSocketFactory (String protocol)

Initializes a new MailSSLSocketFactory with a given protocol. Normally the protocol will be specified as "TLS".

Parameters
protocol The protocol to use
Throws
NoSuchAlgorithmException if given protocol is not supported
GeneralSecurityException

Public Methods

public synchronized Socket createSocket (String s, int i)

Parameters
s
i
Throws
IOException
UnknownHostException

public synchronized Socket createSocket (String s, int i, InetAddress inetaddress, int j)

Parameters
s
i
inetaddress
j
Throws
IOException
UnknownHostException

public synchronized Socket createSocket (InetAddress inetaddress, int i, InetAddress inetaddress1, int j)

Parameters
inetaddress
i
inetaddress1
j
Throws
IOException

public synchronized Socket createSocket (InetAddress inetaddress, int i)

Parameters
inetaddress
i
Throws
IOException

public synchronized Socket createSocket (Socket socket, String s, int i, boolean flag)

Parameters
socket
s
i
flag
Throws
IOException

public synchronized Socket createSocket ()

Throws
IOException

public synchronized String[] getDefaultCipherSuites ()

public synchronized KeyManager[] getKeyManagers ()

Returns
  • the keyManagers

public synchronized SecureRandom getSecureRandom ()

Returns
  • the secureRandom

public synchronized String[] getSupportedCipherSuites ()

public synchronized TrustManager[] getTrustManagers ()

Returns
  • the trustManagers

public synchronized String[] getTrustedHosts ()

Returns
  • the trusted hosts

public synchronized boolean isServerTrusted (String server, SSLSocket sslSocket)

After a successful conection to the server, this method is called to ensure that the server should be trusted.

Parameters
server Name of the server we connected to
sslSocket SSLSocket connected to the server
Returns
  • true if "trustAllHosts" is set to true OR the server is contained in the "trustedHosts" array;

public synchronized boolean isTrustAllHosts ()

Returns
  • true if all hosts should be trusted

public synchronized void setKeyManagers (KeyManager[] keyManagers)

Parameters
keyManagers The keyManagers to set
Throws
GeneralSecurityException

public synchronized void setSecureRandom (SecureRandom secureRandom)

Parameters
secureRandom The secureRandom to set
Throws
GeneralSecurityException

public synchronized void setTrustAllHosts (boolean trustAllHosts)

Parameters
trustAllHosts Should all hosts be trusted?

public synchronized void setTrustManagers (TrustManager[] trustManagers)

Parameters
trustManagers The trustManagers to set
Throws
GeneralSecurityException

public synchronized void setTrustedHosts (String[] trustedHosts)

Parameters
trustedHosts The hosts to trust