public class SocketFetcher
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static MailLogger |
logger |
Modifier | Constructor and Description |
---|---|
private |
SocketFetcher() |
Modifier and Type | Method and Description |
---|---|
private static void |
checkServerIdentity(java.lang.String server,
javax.net.ssl.SSLSocket sslSocket)
Check the server from the Socket connection against the server name(s)
as expressed in the server certificate (RFC 2595 check).
|
private static void |
configureSSLSocket(java.net.Socket socket,
java.lang.String host,
java.util.Properties props,
java.lang.String prefix,
javax.net.SocketFactory sf)
Configure the SSL options for the socket (if it's an SSL socket),
based on the mail.
|
private static java.net.Socket |
createSocket(java.net.InetAddress localaddr,
int localport,
java.lang.String host,
int port,
int cto,
int to,
java.util.Properties props,
java.lang.String prefix,
javax.net.SocketFactory sf,
boolean useSSL)
Create a socket with the given local address and connected to
the given host and port.
|
private static java.lang.ClassLoader |
getContextClassLoader()
Convenience method to get our context class loader.
|
static java.net.Socket |
getSocket(java.lang.String host,
int port,
java.util.Properties props,
java.lang.String prefix) |
static java.net.Socket |
getSocket(java.lang.String host,
int port,
java.util.Properties props,
java.lang.String prefix,
boolean useSSL)
This method returns a Socket.
|
private static javax.net.SocketFactory |
getSocketFactory(java.lang.String sfClass)
Return a socket factory of the specified class.
|
private static boolean |
matchCert(java.lang.String server,
java.security.cert.X509Certificate cert)
Do any of the names in the cert match the server name?
|
private static boolean |
matchServer(java.lang.String server,
java.lang.String name)
Does the server we're expecting to connect to match the
given name from the server's certificate?
|
static java.net.Socket |
startTLS(java.net.Socket socket)
Start TLS on an existing socket.
|
static java.net.Socket |
startTLS(java.net.Socket socket,
java.util.Properties props,
java.lang.String prefix)
Start TLS on an existing socket.
|
static java.net.Socket |
startTLS(java.net.Socket socket,
java.lang.String host,
java.util.Properties props,
java.lang.String prefix)
Start TLS on an existing socket.
|
private static java.lang.String[] |
stringArray(java.lang.String s)
Parse a string into whitespace separated tokens
and return the tokens in an array.
|
private static MailLogger logger
public static java.net.Socket getSocket(java.lang.String host, int port, java.util.Properties props, java.lang.String prefix, boolean useSSL) throws java.io.IOException
If we're making an SSL connection, the ssl.socketFactory properties are used first, if set.
If the socketFactory property is set, the value is an
instance of a SocketFactory class, not a string. The
instance is used directly. If the socketFactory property
is not set, the socketFactory.class property is considered.
(Note that the SocketFactory property must be set using the
put
method, not the setProperty
method.)
If the socketFactory.class property isn't set, the socket returned is an instance of java.net.Socket connected to the given host and port. If the socketFactory.class property is set, it is expected to contain a fully qualified classname of a javax.net.SocketFactory subclass. In this case, the class is dynamically instantiated and a socket created by that SocketFactory is returned.
If the socketFactory.fallback property is set to false, don't fall back to using regular sockets if the socket factory fails.
The socketFactory.port specifies a port to use when connecting through the socket factory. If unset, the port argument will be used.
If the connectiontimeout property is set, the timeout is passed to the socket connect method.
If the timeout property is set, it is used to set the socket timeout.
If the localaddress property is set, it's used as the local address to bind to. If the localport property is also set, it's used as the local port number to bind to.
If the usesocketchannels property is set, and we create the Socket ourself, and the selection of other properties allows, create a SocketChannel and get the Socket from it. This allows us to later retrieve the SocketChannel from the Socket and use it with Select.
host
- The host to connect toport
- The port to connect to at the hostprops
- Properties object containing socket propertiesprefix
- Property name prefix, e.g., "mail.imap"useSSL
- use the SSL socket factory as the defaultjava.io.IOException
public static java.net.Socket getSocket(java.lang.String host, int port, java.util.Properties props, java.lang.String prefix) throws java.io.IOException
java.io.IOException
private static java.net.Socket createSocket(java.net.InetAddress localaddr, int localport, java.lang.String host, int port, int cto, int to, java.util.Properties props, java.lang.String prefix, javax.net.SocketFactory sf, boolean useSSL) throws java.io.IOException
java.io.IOException
private static javax.net.SocketFactory getSocketFactory(java.lang.String sfClass) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.net.Socket startTLS(java.net.Socket socket) throws java.io.IOException
java.io.IOException
public static java.net.Socket startTLS(java.net.Socket socket, java.util.Properties props, java.lang.String prefix) throws java.io.IOException
java.io.IOException
public static java.net.Socket startTLS(java.net.Socket socket, java.lang.String host, java.util.Properties props, java.lang.String prefix) throws java.io.IOException
java.io.IOException
private static void configureSSLSocket(java.net.Socket socket, java.lang.String host, java.util.Properties props, java.lang.String prefix, javax.net.SocketFactory sf) throws java.io.IOException
java.io.IOException
private static void checkServerIdentity(java.lang.String server, javax.net.ssl.SSLSocket sslSocket) throws java.io.IOException
server
- name of the server expectedsslSocket
- SSLSocket connected to the serverjava.io.IOException
private static boolean matchCert(java.lang.String server, java.security.cert.X509Certificate cert)
server
- name of the server expectedcert
- X509Certificate to get the subject's name fromprivate static boolean matchServer(java.lang.String server, java.lang.String name)
server
- name of the server expectedname
- name from the server's certificateprivate static java.lang.String[] stringArray(java.lang.String s)
private static java.lang.ClassLoader getContextClassLoader()