java.lang.Object
org.snmp4j.transport.AbstractTransportMapping<TcpAddress>
org.snmp4j.transport.AbstractConnectionOrientedTransportMapping<TcpAddress,org.snmp4j.transport.TLSTM.SocketEntry>
org.snmp4j.transport.TcpTransportMapping<org.snmp4j.transport.TLSTM.SocketEntry>
org.snmp4j.transport.TLSTM
- All Implemented Interfaces:
Closeable,AutoCloseable,ConnectionOrientedTransportMapping<TcpAddress>,TlsTransportMappingConfig<X509Certificate>,X509TlsTransportMappingConfig,TransportMapping<TcpAddress>
public class TLSTM
extends TcpTransportMapping<org.snmp4j.transport.TLSTM.SocketEntry>
implements X509TlsTransportMappingConfig
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:
- 3.5.0
- Author:
- Frank Fock
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default supported TLS protocol versions.static final intstatic final intFields inherited from class org.snmp4j.transport.TcpTransportMapping
openSocketOnSending, tcpAddressFields inherited from class org.snmp4j.transport.AbstractConnectionOrientedTransportMapping
serverEnabled, socketsFields inherited from class org.snmp4j.transport.AbstractTransportMapping
asyncMsgProcessingSupported, connectionTimeout, listenWorkerTask, maxInboundMessageSize, socketCleaner, suspendedAddresses, transportListener, transportStateListeners -
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(TlsAddress address, boolean serverEnabled) 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.TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress, CounterSupport counterSupport, boolean serverEnabled) Creates a TLS transport mapping that binds to the given address (interface) on the local host. -
Method Summary
Modifier and TypeMethodDescriptionprotected SSLEngineConfiguratorReturns the configuredsetSslEngineConfigurator(SSLEngineConfigurator)or theDefaultSSLEngineConfigurationwhich will then become the configured SSL engine configurator.longGets the connection timeout.Returns the address that represents the actual incoming address this transport mapping uses to listen for incoming packets.Gets theWorkerTaskthat is responsible for receiving new messages.Gets the certificate alias used for client and server authentication.Returns theMessageLengthDecoderused by this transport mapping.Gets the (optional and possiblynull) revocation checker for the cert path validation of X509 certificates.Returns the property name that is used by this transport mapping to determine the protocol versions from system properties.String[]Return the (D)TLS protocol versions used by this transport mapping.Gets theTlsTmSecurityCallbackassociated with thisTransportMappinghook which is called by the transport mapping to lookup TLS security parameters from external configuration.Gets the primaryAddressclass that is supported by this transport mapping.Gets theTransportTypethisTransportMappingsupports depending onAbstractConnectionOrientedTransportMapping.isServerEnabled().intGets the maximum fragment size of supported for this transport mapping when acting as TLS server.String[]Deprecated.Gets the X509 certificate revocation list (CRL) URI, if defined.protected static booleanisEngineClosed(SSLEngine engine) Check if aSSLEngineis fully closed.booleanReturnstrueif the transport mapping is listening for incoming messages.voidlisten()Listen for incoming and outgoing requests.voidsendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) Sends an 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.voidsetPKIXRevocationChecker(PKIXRevocationChecker pkixRevocationChecker) Sets the (optional and possiblynull) revocation checker for the cert path validation of X509 certificates.voidsetProtocolVersions(String[] protocolVersions) Sets the TLS protocols/versions that TLSTM should use during handshake.voidsetSecurityCallback(TlsTmSecurityCallback<X509Certificate> securityCallback) Sets theTlsTmSecurityCallbackassociated with thisTransportMappinghook.voidsetSslEngineConfigurator(SSLEngineConfigurator sslEngineConfigurator) Sets the configurator for theSSLEngineinternally used to run the TLS communication.voidsetTlsMaxFragmentSize(int tlsMaxFragmentSize) Sets the maximum TLS fragment size that this transport mapping should support as server.voidsetTlsProtocols(String[] tlsProtocols) Deprecated.UsesetProtocolVersions(String[])instead.voidsetTrustManagerFactory(TLSTMTrustManagerFactory trustManagerFactory) Set the TLSTM trust manager factory.voidsetTrustStore(String trustStore) voidsetTrustStorePassword(String trustStorePassword) voidSets the X509 certificate revocation list (CRL) URI, to enable CRL checking.voidMethods inherited from class org.snmp4j.transport.TcpTransportMapping
getAddress, isOpenSocketOnSending, setOpenSocketOnSendingMethods inherited from class org.snmp4j.transport.AbstractConnectionOrientedTransportMapping
cancelNonServerSelectionKey, close, close, closeSockets, getMaxBusyLoops, getSockets, isServerEnabled, setMaxBusyLoops, setServerEnabled, setSocketOptions, timeoutSocketMethods inherited from class org.snmp4j.transport.AbstractTransportMapping
addTransportListener, addTransportStateListener, fireConnectionStateChanged, fireProcessMessage, getMaxInboundMessageSize, getPriority, getSocketCleaner, getSuspendedAddresses, getThreadName, handleDroppedMessageToSend, isAsyncMsgProcessingSupported, removeAllTransportListeners, removeTransportListener, removeTransportStateListener, resumeAddress, setAsyncMsgProcessingSupported, setPriority, setThreadName, suspendAddressMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.snmp4j.transport.ConnectionOrientedTransportMapping
addTransportStateListener, close, getSocketCleaner, isServerEnabled, removeTransportStateListener, resumeAddress, setServerEnabled, suspendAddressMethods inherited from interface org.snmp4j.TransportMapping
addTransportListener, close, getMaxInboundMessageSize, getMaxOutboundMessageSize, getSupportedAddressClasses, isAddressSupported, isAddressSupported, removeTransportListener
-
Field Details
-
TLS_MAX_FRAGMENT_SIZE
public static final int TLS_MAX_FRAGMENT_SIZE- See Also:
-
DEFAULT_TLSTM_PROTOCOLS
The default supported TLS protocol versions.- 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
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.serverEnabled- defines the role of the underlyingSSLEngine. Setting this tofalseenables theSSLEngine.setUseClientMode(boolean).- Throws:
IOException- on failure of binding a local port.- Since:
- 3.2.0
-
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.
-
TLSTM
public TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress, CounterSupport counterSupport, boolean serverEnabled) 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().serverEnabled- defines the role of the underlyingSSLEngine. Setting this tofalseenables theSSLEngine.setUseClientMode(boolean).- Throws:
IOException- if the given address cannot be bound.- Since:
- 3.2.0
-
-
Method Details
-
getLocalCertificateAlias
Description copied from interface:TlsTransportMappingConfigGets the certificate alias used for client and server authentication. See alsoTlsTransportMappingConfig.setLocalCertificateAlias(java.lang.String)- Specified by:
getLocalCertificateAliasin interfaceTlsTransportMappingConfig<X509Certificate>- Returns:
- the certificate alias selecting the local certificate.
-
getSupportedTransportType
Gets theTransportTypethisTransportMappingsupports depending onAbstractConnectionOrientedTransportMapping.isServerEnabled().- Specified by:
getSupportedTransportTypein interfaceTransportMapping<TcpAddress>- Returns:
TransportType.anyifAbstractConnectionOrientedTransportMapping.isServerEnabled()istrueandTransportType.senderotherwise.- Since:
- 3.2.0
-
getTlsMaxFragmentSize
public int getTlsMaxFragmentSize()Gets the maximum fragment size of supported for this transport mapping when acting as TLS server.- Returns:
- the maximum TLS fragment size as defined by RFC 6066 section 4.
-
setTlsMaxFragmentSize
public void setTlsMaxFragmentSize(int tlsMaxFragmentSize) Sets the maximum TLS fragment size that this transport mapping should support as server. There is no need to change that from the defaultTLS_MAX_FRAGMENT_SIZEunless, a new Java version allows to set the maximum fragment size to a lower value.- Parameters:
tlsMaxFragmentSize- a value as defined by RFC 6066 section 4.- Since:
- 3.0.5
-
getTlsProtocols
Deprecated.UsegetProtocolVersions()instead.Gets the TLS protocols supported by this transport mapping.- Returns:
- an array of TLS protocol (version) names supported by the SunJSSE provider.
-
setTlsProtocols
Deprecated.UsesetProtocolVersions(String[])instead.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
-
setProtocolVersions
Sets the TLS protocols/versions that TLSTM should use during handshake. The default is defined byDEFAULT_TLSTM_PROTOCOLS.- Specified by:
setProtocolVersionsin interfaceTlsTransportMappingConfig<X509Certificate>- Parameters:
protocolVersions- 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:
- 3.0
-
getProtocolVersions
Description copied from interface:TlsTransportMappingConfigReturn the (D)TLS protocol versions used by this transport mapping.- Specified by:
getProtocolVersionsin interfaceTlsTransportMappingConfig<X509Certificate>- Returns:
- an array of SunJSSE TLS/DTLS provider (depending on the transport mapping type).
-
getProtocolVersionPropertyName
Returns the property name that is used by this transport mapping to determine the protocol versions from system properties.- Specified by:
getProtocolVersionPropertyNamein interfaceTlsTransportMappingConfig<X509Certificate>- Returns:
- a property name like
SnmpConfigurator.P_TLS_VERSIONorSnmpConfigurator.P_DTLS_VERSION. - Since:
- 3.0
-
getKeyStore
- Specified by:
getKeyStorein interfaceTlsTransportMappingConfig<X509Certificate>
-
setKeyStore
- Specified by:
setKeyStorein interfaceTlsTransportMappingConfig<X509Certificate>
-
getKeyStorePassword
- Specified by:
getKeyStorePasswordin interfaceTlsTransportMappingConfig<X509Certificate>
-
setKeyStorePassword
- Specified by:
setKeyStorePasswordin interfaceTlsTransportMappingConfig<X509Certificate>
-
getTrustStore
- Specified by:
getTrustStorein interfaceTlsTransportMappingConfig<X509Certificate>
-
setTrustStore
- Specified by:
setTrustStorein interfaceTlsTransportMappingConfig<X509Certificate>
-
getTrustStorePassword
- Specified by:
getTrustStorePasswordin interfaceTlsTransportMappingConfig<X509Certificate>
-
setTrustStorePassword
- Specified by:
setTrustStorePasswordin interfaceTlsTransportMappingConfig<X509Certificate>
-
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.- Specified by:
setLocalCertificateAliasin interfaceTlsTransportMappingConfig<X509Certificate>- 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 the primaryAddressclass that is supported by this transport mapping.- Specified by:
getSupportedAddressClassin interfaceTransportMapping<TcpAddress>- Overrides:
getSupportedAddressClassin classTcpTransportMapping<org.snmp4j.transport.TLSTM.SocketEntry>- Returns:
- a subclass of
Address.
-
getSecurityCallback
Description copied from interface:TlsTransportMappingConfigGets theTlsTmSecurityCallbackassociated with thisTransportMappinghook which is called by the transport mapping to lookup TLS security parameters from external configuration.- Specified by:
getSecurityCallbackin interfaceTlsTransportMappingConfig<X509Certificate>- Returns:
- a
TlsTmSecurityCallbackinstance.
-
setSecurityCallback
Description copied from interface:TlsTransportMappingConfigSets theTlsTmSecurityCallbackassociated with thisTransportMappinghook. This hook will be called to lookup the security name based on the TLS peer certificate, for example. SeeTlsTmSecurityCallbackfor details.- Specified by:
setSecurityCallbackin interfaceTlsTransportMappingConfig<X509Certificate>- Parameters:
securityCallback- aTlsTmSecurityCallbackinstance. Setting this hook tonullwill disable incoming request processing because these request will be rejected due to an authorization error (no mathing SNMPv3 view).
-
getSslEngineConfigurator
-
setSslEngineConfigurator
Sets the configurator for theSSLEngineinternally used to run the TLS communication. This method should be called before any new connection is established that should use this configurator/configuration.- Parameters:
sslEngineConfigurator- aSSLEngineConfiguratorinstance likeDefaultSSLEngineConfiguration.- Since:
- 3.0.5
-
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 interfaceTLSTMTrustManagerFactory.- 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<org.snmp4j.transport.TLSTM.SocketEntry>- 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.
-
getListenWorkerTask
Description copied from class:AbstractTransportMappingGets theWorkerTaskthat is responsible for receiving new messages.- Overrides:
getListenWorkerTaskin classAbstractTransportMapping<TcpAddress>- Returns:
- a
WorkerTaskinstance which is most likely aDefaultThreadFactory.WorkerThread.
-
sendMessage
public void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) throws IOException Sends an SNMP message to the supplied address.- Specified by:
sendMessagein interfaceTransportMapping<TcpAddress>- Specified by:
sendMessagein classTcpTransportMapping<org.snmp4j.transport.TLSTM.SocketEntry>- 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.timeoutMillis- maximum number of milli seconds the connection creation might take (if connection based).maxRetries- maximum retries during connection creation.- 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.- Specified by:
getConnectionTimeoutin interfaceConnectionOrientedTransportMapping<TcpAddress>- Overrides:
getConnectionTimeoutin classAbstractConnectionOrientedTransportMapping<TcpAddress,org.snmp4j.transport.TLSTM.SocketEntry> - 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>- Overrides:
setConnectionTimeoutin classAbstractConnectionOrientedTransportMapping<TcpAddress,org.snmp4j.transport.TLSTM.SocketEntry> - 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.
-
wakeupServerSelector
public void wakeupServerSelector()- Specified by:
wakeupServerSelectorin classAbstractConnectionOrientedTransportMapping<TcpAddress,org.snmp4j.transport.TLSTM.SocketEntry>
-
getMessageLengthDecoder
Description copied from class:TcpTransportMappingReturns theMessageLengthDecoderused by this transport mapping.- Specified by:
getMessageLengthDecoderin interfaceConnectionOrientedTransportMapping<TcpAddress>- Specified by:
getMessageLengthDecoderin classTcpTransportMapping<org.snmp4j.transport.TLSTM.SocketEntry>- Returns:
- a MessageLengthDecoder instance.
-
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<org.snmp4j.transport.TLSTM.SocketEntry>- Parameters:
messageLengthDecoder- a MessageLengthDecoder instance.
-
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.
-
getPKIXRevocationChecker
Description copied from interface:X509TlsTransportMappingConfigGets the (optional and possiblynull) revocation checker for the cert path validation of X509 certificates.- Specified by:
getPKIXRevocationCheckerin interfaceX509TlsTransportMappingConfig- Returns:
nullto disable cert path validation with CLR checking or a properly configured cert path checker instance.
-
setPKIXRevocationChecker
Description copied from interface:X509TlsTransportMappingConfigSets the (optional and possiblynull) revocation checker for the cert path validation of X509 certificates.- Specified by:
setPKIXRevocationCheckerin interfaceX509TlsTransportMappingConfig- Parameters:
pkixRevocationChecker-nullto disable cert path validation with CLR checking or a properly configured cert path checker instance.
-
getX509CertificateRevocationListURI
Description copied from interface:X509TlsTransportMappingConfigGets the X509 certificate revocation list (CRL) URI, if defined.- Specified by:
getX509CertificateRevocationListURIin interfaceX509TlsTransportMappingConfig- Returns:
nullif there is no CRL available/necessary or a URI string that points to a CRL file.
-
setX09CertificateRevocationListURI
Description copied from interface:X509TlsTransportMappingConfigSets the X509 certificate revocation list (CRL) URI, to enable CRL checking.- Specified by:
setX09CertificateRevocationListURIin interfaceX509TlsTransportMappingConfig- Parameters:
crlURI-nullif there is no CRL available/necessary or a URI string that points to a CRL file.
-
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.- Specified by:
isListeningin interfaceTransportMapping<TcpAddress>- Overrides:
isListeningin classAbstractTransportMapping<TcpAddress>- Returns:
trueif this transport mapping is listening for messages.
-
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<org.snmp4j.transport.TLSTM.SocketEntry>- Returns:
- the address for incoming packets or
nullthis transport mapping is not configured to listen for incoming packets.
-
isEngineClosed
Check if aSSLEngineis fully closed.- Parameters:
engine- an SSL engine.- Returns:
trueif inbound and outbound is done and .
-
ensureSslEngineConfigurator
Returns the configuredsetSslEngineConfigurator(SSLEngineConfigurator)or theDefaultSSLEngineConfigurationwhich will then become the configured SSL engine configurator. This method is not synchronized against concurrent execution ofsetSslEngineConfigurator(SSLEngineConfigurator).- Returns:
- a non-null
SSLEngineConfigurator. - Since:
- 3.0.5
-
getProtocolVersions()instead.