Child pages
  • How to configure SNMP4J for TLS usage?
Skip to end of metadata
Go to start of metadata

Since version 3.0, SNMP4J and SNMP4J-Agent support TLS. This How-To describes how those SNMP4J APIs are configured to use TLS.

How to configure SNMP4J to use TLS?

Before you can start using TLS (or DTLS), you need a key pair. You can generate a self signed one for testing purposes as follows:

keytool -keystore dtls-cert.ks -alias dtls-snmp4j-test -storepass snmp4j -keypass snmp4j -genkeypair -keyalg DSA -keysize 2048 -validity 5000 -dname ", OU=Unit-Test, O=AGENTPP, L=Stuttgart, S=Baden-Wuerttemberg, C=DE" -ext "san=dns:localhost,ip:"

 The following steps then prepare the SNMP4J API for TLS usage: 

  • The SNMP TLS Transport Model (TLSTM) uses certificate based authentication, thus we need to configure a trust store for client authentication (SNMP command generator) and a key store (SNMP command responder):<trustStoreFilePath><trustStorePassword><keyStoreFilePath><keyStorePassword>
  • Create the TLSTM TransportMapping (which may be used with TlsAddress classes only) and set its SecurityCallback for authentication of remote certificates and selecting the local certificate to be used by the TLSTM for client authentication:
// create the TLS transport mapping:
AbstractTransportMapping transport = new TLSTM();

// set the security callback (only required for command responder, 
// but also recommended for command generators) - 
// the callback will be configured later:
DefaultTlsTmSecurityCallback securityCallback = new DefaultTlsTmSecurityCallback();
MessageDispatcher md = new MessageDispatcherImpl();
// we need MPv3 for TLSTM:
md.addMessageProcessingModel(new MPv3());

Snmp snmp = new Snmp(md, transport);

// create and initialize the TransportSecurityModel TSM:
SecurityModels.getInstance().addSecurityModel(new TSM(new OctetString(mpv3.getLocalEngineID()), false));

// do not forget to listen for responses:

  • Create a target and set its address if the SNMP instance is command generator:
String sn = "myTlsSecurityName";
CertifiedTarget ct = new CertifiedTarget(GenericAddress.parse("tls:"), new OctetString(sn), 
	// server fingerprint (replace with the fingerprint of the server's certificate):
	// Client fingerprint could be empty string (no check)
	new OctetString());
// add the distinguished name (DN) of the certificates we want to accept as peer:
securityCallback.addAcceptedSubjectDN(", C=US, CN=Foo Bar");

  • No labels