Package org.apache.commons.net.pop3
Class POP3SClient
- java.lang.Object
-
- org.apache.commons.net.SocketClient
-
- org.apache.commons.net.pop3.POP3
-
- org.apache.commons.net.pop3.POP3Client
-
- org.apache.commons.net.pop3.POP3SClient
-
- Direct Known Subclasses:
ExtendedPOP3Client
public class POP3SClient extends POP3Client
POP3 over SSL processing. Copied from FTPSClient.java and modified to suit POP3. If implicit mode is selected (NOT the default), SSL/TLS negotiation starts right after the connection has been established. In explicit mode (the default), SSL/TLS negotiation starts when the user calls execTLS() and the server accepts the command. Implicit usage: POP3SClient c = new POP3SClient(true); c.connect("127.0.0.1", 995); Explicit usage: POP3SClient c = new POP3SClient(); c.connect("127.0.0.1", 110); if (c.execTLS()) { /rest of the commands here/ } Warning: the hostname is not verified against the certificate by default, usesetHostnameVerifier(HostnameVerifier)orsetEndpointCheckingEnabled(boolean)(on Java 1.7+) to enable verification.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description private javax.net.ssl.SSLContextcontextThe context object.private static intDEFAULT_POP3S_PORTprivate static java.lang.StringDEFAULT_PROTOCOLDefault secure socket protocol name, like TLSprivate javax.net.ssl.HostnameVerifierhostnameVerifierTheHostnameVerifierto use post-TLS, default null (i.e.private booleanisImplicitThe security mode.private javax.net.ssl.KeyManagerkeyManagerTheKeyManager, default null.private java.lang.StringprotocolThe secure socket protocol to be used, like SSL/TLS.private java.lang.String[]protocolsThe protocol versions.private java.lang.String[]suitesThe cipher suites.private booleantlsEndpointCheckingUse Java 1.7+ HTTPS Endpoint Identification Algorithm.private javax.net.ssl.TrustManagertrustManagerThe FTPSTrustManagerimplementation, default null.-
Fields inherited from class org.apache.commons.net.pop3.POP3
_commandSupport_, AUTHORIZATION_STATE, DEFAULT_ENCODING, DEFAULT_PORT, DISCONNECTED_STATE, ERROR, lastReplyLine, OK, OK_INT, reader, replyCode, replyLines, TRANSACTION_STATE, UPDATE_STATE, writer
-
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
-
-
Constructor Summary
Constructors Constructor Description POP3SClient()Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e.POP3SClient(boolean implicit)Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e.POP3SClient(boolean implicit, javax.net.ssl.SSLContext ctx)Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e.POP3SClient(java.lang.String proto)Constructor for POP3SClient.POP3SClient(java.lang.String proto, boolean implicit)Constructor for POP3SClient.POP3SClient(java.lang.String proto, boolean implicit, javax.net.ssl.SSLContext ctx)Constructor for POP3SClient.POP3SClient(javax.net.ssl.SSLContext context)Constructor for POP3SClient, usingDEFAULT_PROTOCOL- TLS - and isImplicit = false
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_connectAction_()Because there are so many connect() methods, the _connectAction_() method is provided as a means of performing some action immediately after establishing a connection, rather than reimplementing all the connect() methods.booleanexecTLS()The TLS command execution.java.lang.String[]getEnabledCipherSuites()Gets the names of the cipher suites which could be enabled for use on this connection.java.lang.String[]getEnabledProtocols()Gets the names of the protocol versions which are currently enabled for use on this connection.javax.net.ssl.HostnameVerifiergetHostnameVerifier()Gets the currently configuredHostnameVerifier.private javax.net.ssl.KeyManagergetKeyManager()Gets theKeyManagerinstance.javax.net.ssl.TrustManagergetTrustManager()Gets the currently configuredTrustManager.private voidinitSSLContext()Performs a lazy init of the SSL context.booleanisEndpointCheckingEnabled()Tests whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled.private voidperformSSLNegotiation()SSL/TLS negotiation.voidsetEnabledCipherSuites(java.lang.String[] cipherSuites)Sets which particular cipher suites are enabled for use on this connection.voidsetEnabledProtocols(java.lang.String[] protocolVersions)Sets which particular protocol versions are enabled for use on this connection.voidsetEndpointCheckingEnabled(boolean enable)Sets automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+.voidsetHostnameVerifier(javax.net.ssl.HostnameVerifier newHostnameVerifier)Sets to override the defaultHostnameVerifierto use.voidsetKeyManager(javax.net.ssl.KeyManager newKeyManager)Sets aKeyManagerto use.voidsetTrustManager(javax.net.ssl.TrustManager newTrustManager)Sets to override the defaultTrustManagerto use.-
Methods inherited from class org.apache.commons.net.pop3.POP3Client
capa, deleteMessage, listMessage, listMessages, listUniqueIdentifier, listUniqueIdentifiers, login, login, logout, noop, reset, retrieveMessage, retrieveMessageTop, status
-
Methods inherited from class org.apache.commons.net.pop3.POP3
disconnect, getAdditionalReply, getCommandSupport, getReplyString, getReplyStrings, getState, removeProtocolCommandistener, sendCommand, sendCommand, sendCommand, sendCommand, setState
-
Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getHostAddress, getHostAddress, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
-
-
-
-
Field Detail
-
DEFAULT_POP3S_PORT
private static final int DEFAULT_POP3S_PORT
- See Also:
- Constant Field Values
-
DEFAULT_PROTOCOL
private static final java.lang.String DEFAULT_PROTOCOL
Default secure socket protocol name, like TLS- See Also:
- Constant Field Values
-
isImplicit
private final boolean isImplicit
The security mode. True - Implicit Mode / False - Explicit Mode.
-
protocol
private final java.lang.String protocol
The secure socket protocol to be used, like SSL/TLS.
-
context
private javax.net.ssl.SSLContext context
The context object.
-
suites
private java.lang.String[] suites
The cipher suites. SSLSockets have a default set of these anyway, so no initialization required.
-
protocols
private java.lang.String[] protocols
The protocol versions.
-
trustManager
private javax.net.ssl.TrustManager trustManager
The FTPSTrustManagerimplementation, default null.
-
keyManager
private javax.net.ssl.KeyManager keyManager
TheKeyManager, default null.
-
hostnameVerifier
private javax.net.ssl.HostnameVerifier hostnameVerifier
TheHostnameVerifierto use post-TLS, default null (i.e. no verification).
-
tlsEndpointChecking
private boolean tlsEndpointChecking
Use Java 1.7+ HTTPS Endpoint Identification Algorithm.
-
-
Constructor Detail
-
POP3SClient
public POP3SClient()
Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e. TLS Sets security mode to explicit.
-
POP3SClient
public POP3SClient(boolean implicit)
Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e. TLS- Parameters:
implicit- The security mode,truefor implicit,falsefor explicit
-
POP3SClient
public POP3SClient(boolean implicit, javax.net.ssl.SSLContext ctx)Constructor for POP3SClient, usingDEFAULT_PROTOCOLi.e. TLS- Parameters:
implicit- The security mode,truefor implicit,falsefor explicitctx- A pre-configured SSL Context.
-
POP3SClient
public POP3SClient(javax.net.ssl.SSLContext context)
Constructor for POP3SClient, usingDEFAULT_PROTOCOL- TLS - and isImplicit = false- Parameters:
context- A pre-configured SSL Context.- See Also:
POP3SClient(boolean, SSLContext)
-
POP3SClient
public POP3SClient(java.lang.String proto)
Constructor for POP3SClient. Sets security mode to explicit.- Parameters:
proto- the protocol.
-
POP3SClient
public POP3SClient(java.lang.String proto, boolean implicit)Constructor for POP3SClient.- Parameters:
proto- the protocol.implicit- The security mode,truefor implicit,falsefor explicit
-
POP3SClient
public POP3SClient(java.lang.String proto, boolean implicit, javax.net.ssl.SSLContext ctx)Constructor for POP3SClient. Sets the default port toDEFAULT_POP3S_PORT- 995 - if using implicit mode- Parameters:
proto- the protocol.implicit- The security mode,truefor implicit,falsefor explicitctx- the context to be used
-
-
Method Detail
-
_connectAction_
protected void _connectAction_() throws java.io.IOExceptionBecause there are so many connect() methods, the _connectAction_() method is provided as a means of performing some action immediately after establishing a connection, rather than reimplementing all the connect() methods.- Overrides:
_connectAction_in classPOP3- Throws:
java.io.IOException- If it is thrown by _connectAction_().- See Also:
SocketClient._connectAction_()
-
execTLS
public boolean execTLS() throws javax.net.ssl.SSLException, java.io.IOExceptionThe TLS command execution.- Returns:
- TRUE if the command and negotiation succeeded.
- Throws:
javax.net.ssl.SSLException- If the server reply code is not positive.java.io.IOException- If an I/O error occurs while sending the command or performing the negotiation.
-
getEnabledCipherSuites
public java.lang.String[] getEnabledCipherSuites()
Gets the names of the cipher suites which could be enabled for use on this connection. When the underlyingSocketis not anSSLSocketinstance, returns null.- Returns:
- An array of cipher suite names, or
null.
-
getEnabledProtocols
public java.lang.String[] getEnabledProtocols()
Gets the names of the protocol versions which are currently enabled for use on this connection. When the underlyingSocketis not anSSLSocketinstance, returns null.- Returns:
- An array of protocols, or
null.
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
Gets the currently configuredHostnameVerifier.- Returns:
- A HostnameVerifier instance.
- Since:
- 3.4
-
getKeyManager
private javax.net.ssl.KeyManager getKeyManager()
Gets theKeyManagerinstance.- Returns:
- The current
KeyManagerinstance.
-
getTrustManager
public javax.net.ssl.TrustManager getTrustManager()
Gets the currently configuredTrustManager.- Returns:
- A TrustManager instance.
-
initSSLContext
private void initSSLContext() throws java.io.IOExceptionPerforms a lazy init of the SSL context.- Throws:
java.io.IOException- When could not initialize the SSL context.
-
isEndpointCheckingEnabled
public boolean isEndpointCheckingEnabled()
Tests whether or not endpoint identification using the HTTPS algorithm on Java 1.7+ is enabled. The default behavior is for this to be disabled.- Returns:
- True if enabled, false if not.
- Since:
- 3.4
-
performSSLNegotiation
private void performSSLNegotiation() throws java.io.IOExceptionSSL/TLS negotiation. Acquires an SSL socket of a connection and carries out handshake processing.- Throws:
java.io.IOException- If server negotiation fails.
-
setEnabledCipherSuites
public void setEnabledCipherSuites(java.lang.String[] cipherSuites)
Sets which particular cipher suites are enabled for use on this connection. Called before server negotiation.- Parameters:
cipherSuites- The cipher suites.
-
setEnabledProtocols
public void setEnabledProtocols(java.lang.String[] protocolVersions)
Sets which particular protocol versions are enabled for use on this connection. I perform setting before a server negotiation.- Parameters:
protocolVersions- The protocol versions.
-
setEndpointCheckingEnabled
public void setEndpointCheckingEnabled(boolean enable)
Sets automatic endpoint identification checking using the HTTPS algorithm is supported on Java 1.7+. The default behavior is for this to be disabled.- Parameters:
enable- Enable automatic endpoint identification checking using the HTTPS algorithm on Java 1.7+.- Since:
- 3.4
-
setHostnameVerifier
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier newHostnameVerifier)
Sets to override the defaultHostnameVerifierto use.- Parameters:
newHostnameVerifier- The HostnameVerifier implementation to set ornullto disable.- Since:
- 3.4
-
setKeyManager
public void setKeyManager(javax.net.ssl.KeyManager newKeyManager)
Sets aKeyManagerto use.- Parameters:
newKeyManager- The KeyManager implementation to set.- See Also:
KeyManagerUtils
-
setTrustManager
public void setTrustManager(javax.net.ssl.TrustManager newTrustManager)
Sets to override the defaultTrustManagerto use.- Parameters:
newTrustManager- The TrustManager implementation to set.- See Also:
TrustManagerUtils
-
-