public class TLSTM extends TcpTransportMapping
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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
TLSTM.DefaultSSLEngineConfiguration |
static interface |
TLSTM.TLSTMTrustManagerFactory |
protected class |
TLSTM.TlsTrustManager |
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_TLSTM_PROTOCOLS |
static int |
MAX_TLS_PAYLOAD_SIZE |
tcpAddressasyncMsgProcessingSupported, maxInboundMessageSize, transportListener| Constructor and Description |
|---|
TLSTM()
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all open sockets and stops the internal server thread that
processes messages.
|
boolean |
close(TcpAddress remoteAddress)
Closes a connection to the supplied remote address, if it is open.
|
long |
getConnectionTimeout()
Gets the connection timeout.
|
CounterSupport |
getCounterSupport() |
static OctetString |
getFingerprint(X509Certificate cert) |
String |
getKeyStore() |
String |
getKeyStorePassword() |
String |
getLocalCertificateAlias() |
int |
getMaxInboundMessageSize()
Gets the inbound buffer size for incoming requests.
|
MessageLengthDecoder |
getMessageLengthDecoder()
Returns the
MessageLengthDecoder used by this transport
mapping. |
TlsTmSecurityCallback<X509Certificate> |
getSecurityCallback() |
static Object |
getSubjAltName(Collection<List<?>> subjAltNames,
int type) |
Class<? extends Address> |
getSupportedAddressClass()
Gets the
Address class that is supported by this transport mapping. |
String |
getThreadName()
Returns the name of the listen thread.
|
String[] |
getTlsProtocols() |
TLSTM.TLSTMTrustManagerFactory |
getTrustManagerFactory() |
boolean |
isListening()
Returns
true if the transport mapping is listening for
incoming messages. |
boolean |
isServerEnabled()
Checks whether a server for incoming requests is enabled.
|
void |
listen()
Listen for incoming and outgoing requests.
|
void |
sendMessage(TcpAddress address,
byte[] message,
TransportStateReference tmStateReference)
Sends a SNMP message to the supplied address.
|
void |
setConnectionTimeout(long connectionTimeout)
Sets the connection timeout.
|
void |
setKeyStore(String keyStore) |
void |
setKeyStorePassword(String keyStorePassword) |
void |
setLocalCertificateAlias(String localCertificateAlias)
Sets the certificate alias used for client and server authentication
by this TLSTM.
|
void |
setMaxInboundMessageSize(int maxInboundMessageSize)
Sets the maximum buffer size for incoming requests.
|
void |
setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)
Sets the
MessageLengthDecoder that decodes the total
message length from the header of a message. |
void |
setSecurityCallback(TlsTmSecurityCallback<X509Certificate> securityCallback) |
void |
setServerEnabled(boolean serverEnabled)
Sets whether a server for incoming requests should be created when
the transport is set into listen state.
|
protected void |
setSocketOptions(ServerSocket serverSocket)
Sets optional server socket options.
|
void |
setThreadName(String name)
Sets the name of the listen thread for this UDP transport mapping.
|
void |
setTlsProtocols(String[] tlsProtocols)
Sets the TLS protocols/versions that TLSTM should use during handshake.
|
void |
setTrustManagerFactory(TLSTM.TLSTMTrustManagerFactory trustManagerFactory)
Set the TLSTM trust manager factory.
|
addTransportStateListener, fireConnectionStateChanged, getAddress, getListenAddress, removeTransportStateListeneraddTransportListener, fireProcessMessage, isAsyncMsgProcessingSupported, removeTransportListener, setAsyncMsgProcessingSupportedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddTransportListener, removeTransportListenerpublic static final String DEFAULT_TLSTM_PROTOCOLS
public static final int MAX_TLS_PAYLOAD_SIZE
public TLSTM()
throws UnknownHostException
UnknownHostException - if the local host cannot be determined.public TLSTM(TlsAddress address) throws IOException
securityCallback
needs to be specified before listen() is called.IOException - on failure of binding a local port.public TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress) throws IOException
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.IOException - if the given address cannot be bound.public TLSTM(TlsTmSecurityCallback<X509Certificate> securityCallback, TlsAddress serverAddress, CounterSupport counterSupport) throws IOException
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, use
CounterSupport.getInstance().IOException - if the given address cannot be bound.public String getLocalCertificateAlias()
public String[] getTlsProtocols()
public void setTlsProtocols(String[] tlsProtocols)
DEFAULT_TLSTM_PROTOCOLS.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.public String getKeyStore()
public void setKeyStore(String keyStore)
public String getKeyStorePassword()
public void setKeyStorePassword(String keyStorePassword)
public void setLocalCertificateAlias(String localCertificateAlias)
null
filters out any certificates which are not in the chain of the given
alias.localCertificateAlias - a certificate alias which filters a single certification chain from
the javax.net.ssl.keyStore key store to be used to
authenticate this TLS transport mapping. If null no
filtering appears, which could lead to more than a single chain
available for authentication by the peer, which would violate the
TLSTM standard requirements.public CounterSupport getCounterSupport()
public Class<? extends Address> getSupportedAddressClass()
TransportMappingAddress class that is supported by this transport mapping.getSupportedAddressClass in interface TransportMapping<TcpAddress>getSupportedAddressClass in class TcpTransportMappingAddress.public TlsTmSecurityCallback<X509Certificate> getSecurityCallback()
public void setSecurityCallback(TlsTmSecurityCallback<X509Certificate> securityCallback)
public TLSTM.TLSTMTrustManagerFactory getTrustManagerFactory()
public void setTrustManagerFactory(TLSTM.TLSTMTrustManagerFactory trustManagerFactory)
trustManagerFactory - a X.509 trust manager factory implementing the interface TLSTM.TLSTMTrustManagerFactory.public void listen()
throws IOException
serverEnabled
member is false the server for incoming requests is not
started. This starts the internal server thread that processes messages.listen in interface TransportMapping<TcpAddress>listen in class TcpTransportMappingSocketException - when the transport is already listening for incoming/outgoing messages.IOExceptionpublic void setThreadName(String name)
listen() has been
called for this transport mapping.name - the new thread name.public String getThreadName()
null.public void close()
close in interface TransportMapping<TcpAddress>close in class TcpTransportMappingpublic boolean close(TcpAddress remoteAddress) throws IOException
remoteAddress - the address of the peer socket.true if the connection has been closed and
false if there was nothing to close.IOException - if the remote address cannot be closed due to an IO exception.public void sendMessage(TcpAddress address, byte[] message, TransportStateReference tmStateReference) throws IOException
sendMessage in interface TransportMapping<TcpAddress>sendMessage in class TcpTransportMappingaddress - an TcpAddress. A ClassCastException is thrown
if address is not a TcpAddress instance.message - byte[]
the message to sent.tmStateReference - the (optional) transport model state reference as defined by
RFC 5590 section 6.1.IOExceptionpublic long getConnectionTimeout()
public void setConnectionTimeout(long connectionTimeout)
setConnectionTimeout in interface ConnectionOrientedTransportMapping<TcpAddress>setConnectionTimeout in class TcpTransportMappingconnectionTimeout - 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.public boolean isServerEnabled()
public MessageLengthDecoder getMessageLengthDecoder()
TcpTransportMappingMessageLengthDecoder used by this transport
mapping.getMessageLengthDecoder in interface ConnectionOrientedTransportMapping<TcpAddress>getMessageLengthDecoder in class TcpTransportMappingpublic void setServerEnabled(boolean serverEnabled)
listen() method is called (if the transport is already
listening, close() has to be called before).serverEnabled - if true if the transport will listens for incoming
requests after listen() has been called.public void setMessageLengthDecoder(MessageLengthDecoder messageLengthDecoder)
TcpTransportMappingMessageLengthDecoder that decodes the total
message length from the header of a message.setMessageLengthDecoder in interface ConnectionOrientedTransportMapping<TcpAddress>setMessageLengthDecoder in class TcpTransportMappingmessageLengthDecoder - a MessageLengthDecoder instance.public int getMaxInboundMessageSize()
getMaxInboundMessageSize in interface TransportMapping<TcpAddress>getMaxInboundMessageSize in class AbstractTransportMapping<TcpAddress>public void setMaxInboundMessageSize(int maxInboundMessageSize)
maxInboundMessageSize - the length of the inbound buffer in bytes.public boolean isListening()
TransportMappingtrue if 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.true if this transport mapping is listening for messages.public static OctetString getFingerprint(X509Certificate cert)
public static Object getSubjAltName(Collection<List<?>> subjAltNames, int type)
protected void setSocketOptions(ServerSocket serverSocket)
serverSocket - the ServerSocket to apply additional non-default options.Copyright © 2016 SNMP4J.org. All Rights Reserved.