Package com.sun.mail.util

# Class MailSSLSocketFactory

java.lang.Object
javax.net.SocketFactory
javax.net.ssl.SSLSocketFactory
com.sun.mail.util.MailSSLSocketFactory

public class MailSSLSocketFactory extends SSLSocketFactory
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.

Since:
  JavaMail 1.4.2
Author:
  Stephan Sann, Bill Shannon

## Constructor Summary

Constructors
Constructor
Description
`MailSSLSocketFactory()`
Initializes a new MailSSLSocketFactory.
`MailSSLSocketFactory(String protocol)`
Initializes a new MailSSLSocketFactory with a given protocol.

## Method Summary

Modifier and Type
Method
Description
`Socket`
`createSocket()`
`Socket`
`createSocket(String s, int i)`
`Socket`
`createSocket(String s, int i, InetAddress inetaddress, int j)`
`Socket`
`createSocket(InetAddress inetaddress, int i)`
`Socket`
`createSocket(InetAddress inetaddress, int i, InetAddress inetaddress1, int j)`
`Socket`
`createSocket(Socket socket, String s, int i, boolean flag)`
`String[]`
`getDefaultCipherSuites()`
`KeyManager[]`
`getKeyManagers()`
`SecureRandom`
`getSecureRandom()`
`String[]`
`getSupportedCipherSuites()`
`String[]`
`getTrustedHosts()`
`TrustManager[]`
`getTrustManagers()`
`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.
`boolean`
`isTrustAllHosts()`
`void`
`setKeyManagers(KeyManager... keyManagers)`
`void`
`setSecureRandom(SecureRandom secureRandom)`
`void`
`setTrustAllHosts(boolean trustAllHosts)`
`void`
`setTrustedHosts(String... trustedHosts)`
`void`
`setTrustManagers(TrustManager... trustManagers)`

### Methods inherited from class javax.net.ssl.SSLSocketFactory

`createSocket, getDefault`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MailSSLSocketFactory

public MailSSLSocketFactory() throws GeneralSecurityException
Initializes a new MailSSLSocketFactory.

Throws:
  `GeneralSecurityException` - for security errors

### MailSSLSocketFactory

public MailSSLSocketFactory(String protocol) throws GeneralSecurityException
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` - for security errors

## Method Details

### getKeyManagers

public KeyManager[] getKeyManagers()

Returns:
  the keyManagers

### setKeyManagers

public void setKeyManagers(KeyManager... keyManagers) throws GeneralSecurityException

Parameters:
  `keyManagers` - the keyManagers to set
Throws:
  `GeneralSecurityException` - for security errors

### getSecureRandom

public SecureRandom getSecureRandom()

Returns:
  the secureRandom

### setSecureRandom

public void setSecureRandom(SecureRandom secureRandom) throws GeneralSecurityException

Parameters:
  `secureRandom` - the secureRandom to set
Throws:
  `GeneralSecurityException` - for security errors

### getTrustManagers

public TrustManager[] getTrustManagers()

Returns:
  the trustManagers

### setTrustManagers

public void setTrustManagers(TrustManager... trustManagers) throws GeneralSecurityException

Parameters:
  `trustManagers` - the trustManagers to set
Throws:
  `GeneralSecurityException` - for security errors

### isTrustAllHosts

public boolean isTrustAllHosts()

Returns:
  true if all hosts should be trusted

### setTrustAllHosts

public void setTrustAllHosts(boolean trustAllHosts)

Parameters:
  `trustAllHosts` - should all hosts be trusted?

### getTrustedHosts

public String[] getTrustedHosts()

Returns:
  the trusted hosts

### setTrustedHosts

public void setTrustedHosts(String... trustedHosts)

Parameters:
  `trustedHosts` - the hosts to trust

### isServerTrusted

public 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;

### createSocket

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

Specified by:
  `createSocket` in class `SSLSocketFactory`
Throws:
  `IOException`

### getDefaultCipherSuites

public String[] getDefaultCipherSuites()

Specified by:
  `getDefaultCipherSuites` in class `SSLSocketFactory`

### getSupportedCipherSuites

public String[] getSupportedCipherSuites()

Specified by:
  `getSupportedCipherSuites` in class `SSLSocketFactory`

### createSocket

public Socket createSocket() throws IOException

Overrides:
  `createSocket` in class `SocketFactory`
Throws:
  `IOException`

### createSocket

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

Specified by:
  `createSocket` in class `SocketFactory`
Throws:
  `IOException`

### createSocket

public Socket createSocket(InetAddress inetaddress, int i) throws IOException

Specified by:
  `createSocket` in class `SocketFactory`
Throws:
  `IOException`

### createSocket

public Socket createSocket(String s, int i, InetAddress inetaddress, int j) throws IOException, UnknownHostException

Specified by:
  `createSocket` in class `SocketFactory`
Throws:
  `IOException`
  `UnknownHostException`

### createSocket

public Socket createSocket(String s, int i) throws IOException, UnknownHostException

Specified by:
  `createSocket` in class `SocketFactory`
Throws:
  `IOException`
  `UnknownHostException`