Package org.snmp4j.transport
Class TLSTM
java.lang.Object
org.snmp4j.transport.AbstractTransportMapping<TcpAddress>
org.snmp4j.transport.TcpTransportMapping
org.snmp4j.transport.TLSTM
- All Implemented Interfaces:
 ConnectionOrientedTransportMapping<TcpAddress>,TransportMapping<TcpAddress>
The 
TLSTM implements the Transport Layer Security
 Transport Mapping (TLS-TM) as defined by RFC 5953
 with the new IO API and SSLEngine.
 
 It uses a single thread for processing incoming and outgoing messages.
 The thread is started when the listen method is called, or
 when an outgoing request is sent using the sendMessage method.
- Since:
 - 2.0
 - Version:
 - 2.6.4
 - Author:
 - Frank Fock
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classstatic interface - 
Field Summary
FieldsFields inherited from class org.snmp4j.transport.TcpTransportMapping
openSocketOnSending, suspendedAddresses, tcpAddressFields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, maxInboundMessageSize, maxOutboundMessageSize, transportListener - 
Constructor Summary
ConstructorsConstructorDescriptionTLSTM()Creates a default TCP transport mapping with the server for incoming messages disabled.TLSTM(TlsAddress address) Creates a TLS transport mapping with the server for incoming messages bind to the given address.TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress) Creates a TLS transport mapping that binds to the given address (interface) on the local host.TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress, CounterSupport counterSupport) Creates a TLS transport mapping that binds to the given address (interface) on the local host. - 
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes all open sockets and stops the internal server thread that processes messages.booleanclose(TcpAddress remoteAddress) Closes a connection to the supplied remote address, if it is open.longGets the connection timeout.static OctetStringReturns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.intGets the inbound buffer size for incoming requests.Returns theMessageLengthDecoderused by this transport mapping.static ObjectgetSubjAltName(Collection<List<?>> subjAltNames, int type) Gets theAddressclass that is supported by this transport mapping.Returns the name of the listen thread.String[]protected static booleanisEngineClosed(SSLEngine engine) Check if aSSLEngineis fully closed.booleanReturnstrueif the transport mapping is listening for incoming messages.booleanChecks whether a server for incoming requests is enabled.voidlisten()Listen for incoming and outgoing requests.protected ObjectremoveSocketEntry(TcpAddress remoteAddress) voidsendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference) Sends a SNMP message to the supplied address.voidsetConnectionTimeout(long connectionTimeout) Sets the connection timeout.voidsetKeyStore(String keyStore) voidsetKeyStorePassword(String keyStorePassword) voidsetLocalCertificateAlias(String localCertificateAlias) Sets the certificate alias used for client and server authentication by this TLSTM.voidsetMaxInboundMessageSize(int maxInboundMessageSize) Sets the maximum buffer size for incoming requests.voidsetMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder) Sets theMessageLengthDecoderthat decodes the total message length from the header of a message.voidsetSecurityCallback(TlsTmSecurityCallback<X509Certificate> securityCallback) voidsetServerEnabled(boolean serverEnabled) Sets whether a server for incoming requests should be created when the transport is set into listen state.protected voidsetSocketOptions(ServerSocket serverSocket) Sets optional server socket options.voidsetThreadName(String name) Sets the name of the listen thread for this UDP transport mapping.voidsetTlsProtocols(String[] tlsProtocols) Sets the TLS protocols/versions that TLSTM should use during handshake.voidsetTrustManagerFactory(TLSTM.TLSTMTrustManagerFactory trustManagerFactory) Set the TLSTM trust manager factory.voidsetTrustStore(String trustStore) voidsetTrustStorePassword(String trustStorePassword) Methods inherited from class org.snmp4j.transport.TcpTransportMapping
addTransportStateListener, cancelNonServerSelectionKey, fireConnectionStateChanged, getAddress, handleDroppedMessageToSend, isOpenSocketOnSending, removeTransportStateListener, resumeAddress, setOpenSocketOnSending, suspendAddressMethods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, fireProcessMessage, getMaxOutboundMessageSize, isAsyncMsgProcessingSupported, removeAllTransportListeners, removeTransportListener, setAsyncMsgProcessingSupportedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.snmp4j.TransportMapping
addTransportListener, getMaxOutboundMessageSize, removeTransportListener 
- 
Field Details
- 
TLS_MAX_FRAGMENT_SIZE
public static final int TLS_MAX_FRAGMENT_SIZE- See Also:
 
 - 
DEFAULT_TLSTM_PROTOCOLS
- See Also:
 
 - 
MAX_TLS_PAYLOAD_SIZE
public static final int MAX_TLS_PAYLOAD_SIZE- See Also:
 
 
 - 
 - 
Constructor Details
- 
TLSTM
Creates a default TCP transport mapping with the server for incoming messages disabled.- Throws:
 UnknownHostException- if the local host cannot be determined.
 - 
TLSTM
Creates a TLS transport mapping with the server for incoming messages bind to the given address. ThesecurityCallbackneeds to be specified beforelisten()is called.- Parameters:
 address- the address to bind for incoming requests.- Throws:
 IOException- on failure of binding a local port.
 - 
TLSTM
public TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress) throws IOException Creates a TLS transport mapping that binds to the given address (interface) on the local host.- Parameters:
 securityCallback- a security name callback to resolve X509 certificates to tmSecurityNames.serverAddress- the TcpAddress instance that describes the server address to listen on incoming connection requests.- Throws:
 IOException- if the given address cannot be bound.
 - 
TLSTM
public TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress, CounterSupport counterSupport) throws IOException Creates a TLS transport mapping that binds to the given address (interface) on the local host.- Parameters:
 securityCallback- a security name callback to resolve X509 certificates to tmSecurityNames.serverAddress- the TcpAddress instance that describes the server address to listen on incoming connection requests.counterSupport- The CounterSupport instance to be used to count events created by this TLSTM instance. To get a default instance, useCounterSupport.getInstance().- Throws:
 IOException- if the given address cannot be bound.
 
 - 
 - 
Method Details
- 
getLocalCertificateAlias
 - 
getTlsProtocols
 - 
setTlsProtocols
Sets the TLS protocols/versions that TLSTM should use during handshake. The default is defined byDEFAULT_TLSTM_PROTOCOLS.- Parameters:
 tlsProtocols- an array of TLS protocol (version) names supported by the SunJSSE provider. The order in the array defines which protocol is tried during handshake first.- Since:
 - 2.0.3
 
 - 
getKeyStore
 - 
setKeyStore
 - 
getKeyStorePassword
 - 
setKeyStorePassword
 - 
setLocalCertificateAlias
Sets the certificate alias used for client and server authentication by this TLSTM. Setting this property to a value other thannullfilters out any certificates which are not in the chain of the given alias.- Parameters:
 localCertificateAlias- a certificate alias which filters a single certification chain from thejavax.net.ssl.keyStorekey store to be used to authenticate this TLS transport mapping. Ifnullno filtering appears, which could lead to more than a single chain available for authentication by the peer, which would violate the TLSTM standard requirements.
 - 
getCounterSupport
 - 
getSupportedAddressClass
Description copied from interface:TransportMappingGets theAddressclass that is supported by this transport mapping.- Specified by:
 getSupportedAddressClassin interfaceTransportMapping<TcpAddress>- Overrides:
 getSupportedAddressClassin classTcpTransportMapping- Returns:
 - a subclass of 
Address. 
 - 
getSecurityCallback
 - 
setSecurityCallback
 - 
getTrustManagerFactory
 - 
setTrustManagerFactory
Set the TLSTM trust manager factory. Using a trust manager factory other than the default allows to add support for Java 1.7 X509ExtendedTrustManager.- Parameters:
 trustManagerFactory- a X.509 trust manager factory implementing the interfaceTLSTM.TLSTMTrustManagerFactory.- Since:
 - 2.0.3
 
 - 
listen
Listen for incoming and outgoing requests. If theserverEnabledmember isfalsethe server for incoming requests is not started. This starts the internal server thread that processes messages.- Specified by:
 listenin interfaceTransportMapping<TcpAddress>- Specified by:
 listenin classTcpTransportMapping- Throws:
 SocketException- when the transport is already listening for incoming/outgoing messages.IOException- if the listen port could not be bound to the server thread.
 - 
setThreadName
Sets the name of the listen thread for this UDP transport mapping. This method has no effect, if called beforelisten()has been called for this transport mapping.- Parameters:
 name- the new thread name.- Since:
 - 1.6
 
 - 
getThreadName
Returns the name of the listen thread.- Returns:
 - the thread name if in listening mode, otherwise 
null. - Since:
 - 1.6
 
 - 
close
public void close()Closes all open sockets and stops the internal server thread that processes messages.- Specified by:
 closein interfaceTransportMapping<TcpAddress>- Specified by:
 closein classTcpTransportMapping
 - 
close
Closes a connection to the supplied remote address, if it is open. This method is particularly useful when not using a timeout for remote connections.- Parameters:
 remoteAddress- the address of the peer socket.- Returns:
 trueif the connection has been closed andfalseif there was nothing to close.- Throws:
 IOException- if the remote address cannot be closed due to an IO exception.- Since:
 - 1.7.1
 
 - 
removeSocketEntry
 - 
sendMessage
public void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference) throws IOException Sends a SNMP message to the supplied address.- Specified by:
 sendMessagein interfaceTransportMapping<TcpAddress>- Specified by:
 sendMessagein classTcpTransportMapping- Parameters:
 address- anTcpAddress. AClassCastExceptionis thrown ifaddressis not aTcpAddressinstance.message- byte[] the message to sent.tmStateReference- the (optional) transport model state reference as defined by RFC 5590 section 6.1.- Throws:
 IOException- if an IO exception occurs while trying to send the message.
 - 
getConnectionTimeout
public long getConnectionTimeout()Gets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Returns:
 - long the idle timeout in milliseconds.
 
 - 
setConnectionTimeout
public void setConnectionTimeout(long connectionTimeout) Sets the connection timeout. This timeout specifies the time a connection may be idle before it is closed.- Specified by:
 setConnectionTimeoutin interfaceConnectionOrientedTransportMapping<TcpAddress>- Specified by:
 setConnectionTimeoutin classTcpTransportMapping- Parameters:
 connectionTimeout- the idle timeout in milliseconds. A zero or negative value will disable any timeout and connections opened by this transport mapping will stay opened until they are explicitly closed.
 - 
isServerEnabled
public boolean isServerEnabled()Checks whether a server for incoming requests is enabled.- Returns:
 - boolean
 
 - 
getMessageLengthDecoder
Description copied from class:TcpTransportMappingReturns theMessageLengthDecoderused by this transport mapping.- Specified by:
 getMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<TcpAddress>- Specified by:
 getMessageLengthDecoderin classTcpTransportMapping- Returns:
 - a MessageLengthDecoder instance.
 
 - 
setServerEnabled
public void setServerEnabled(boolean serverEnabled) Sets whether a server for incoming requests should be created when the transport is set into listen state. Setting this value has no effect until thelisten()method is called (if the transport is already listening,close()has to be called before).- Parameters:
 serverEnabled- iftrueif the transport will listens for incoming requests afterlisten()has been called.
 - 
setMessageLengthDecoder
Description copied from class:TcpTransportMappingSets theMessageLengthDecoderthat decodes the total message length from the header of a message.- Specified by:
 setMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<TcpAddress>- Specified by:
 setMessageLengthDecoderin classTcpTransportMapping- Parameters:
 messageLengthDecoder- a MessageLengthDecoder instance.
 - 
getMaxInboundMessageSize
public int getMaxInboundMessageSize()Gets the inbound buffer size for incoming requests. When SNMP packets are received that are longer than this maximum size, the messages will be silently dropped and the connection will be closed.- Specified by:
 getMaxInboundMessageSizein interfaceTransportMapping<TcpAddress>- Overrides:
 getMaxInboundMessageSizein classAbstractTransportMapping<TcpAddress>- Returns:
 - the maximum inbound buffer size in bytes.
 
 - 
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int maxInboundMessageSize) Sets the maximum buffer size for incoming requests. When SNMP packets are received that are longer than this maximum size, the messages will be silently dropped and the connection will be closed.- Parameters:
 maxInboundMessageSize- the length of the inbound buffer in bytes.
 - 
isListening
public boolean isListening()Description copied from interface:TransportMappingReturnstrueif the transport mapping is listening for incoming messages. For connection oriented transport mappings this is a prerequisite to be able to send SNMP messages. For connectionless transport mappings it is a prerequisite to be able to receive responses.- Returns:
 trueif this transport mapping is listening for messages.
 - 
getFingerprint
 - 
getSubjAltName
 - 
getListenAddress
Description copied from interface:TransportMappingReturns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.- Specified by:
 getListenAddressin interfaceTransportMapping<TcpAddress>- Overrides:
 getListenAddressin classTcpTransportMapping- Returns:
 - the address for incoming packets or 
nullthis transport mapping is not configured to listen for incoming packets. 
 - 
setSocketOptions
Sets optional server socket options. The default implementation does nothing.- Parameters:
 serverSocket- theServerSocketto apply additional non-default options.
 - 
isEngineClosed
Check if aSSLEngineis fully closed.- Parameters:
 engine- an SSL engine.- Returns:
 trueif inbound and outbound is done.
 - 
getTrustStore
 - 
setTrustStore
 - 
getTrustStorePassword
 - 
setTrustStorePassword
 
 -