use of org.snmp4j.mp.MPv3 in project opennms by OpenNMS.
the class Snmp4JAgentConfig method createSnmpSession.
public Snmp createSnmpSession() throws IOException {
final TransportMapping<?> transport = new DefaultUdpTransportMapping();
final MessageDispatcher disp = new MessageDispatcherImpl();
final Snmp session;
// models we need for the specific agent
if (!isSnmpV3()) {
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
session = new Snmp(disp, transport);
} else {
// Make a new USM
final USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
// Add the specified user to the USM
usm.addUser(getSecurityName(), new UsmUser(getSecurityName(), getAuthProtocol(), getAuthPassPhrase(), getPrivProtocol(), getPrivPassPhrase()));
disp.addMessageProcessingModel(new MPv3(usm));
session = new Snmp(disp, transport);
}
return session;
}
use of org.snmp4j.mp.MPv3 in project opennms by OpenNMS.
the class MockSnmpAgent method initMessageDispatcher.
/**
* <p>
* Note that this method can hang if your system entropy is not high enough.
* Here is a stack trace from a test running on JDK 1.8u40:</p>
*
* <pre>
* Thread [MockSnmpAgent-1657048932] (Suspended)
* owns: SecureRandom (id=26)
* owns: SecureRandom (id=27)
* owns: SecurityProtocols (id=28)
* FileInputStream.readBytes(byte[], int, int) line: not available [native method]
* FileInputStream.read(byte[], int, int) line: 255
* NativeSeedGenerator(SeedGenerator$URLSeedGenerator).getSeedBytes(byte[]) line: 539
* SeedGenerator.generateSeed(byte[]) line: 144
* SecureRandom$SeederHolder.<clinit>() line: 203 [local variables unavailable]
* SecureRandom.engineNextBytes(byte[]) line: 221
* SecureRandom.nextBytes(byte[]) line: 468
* Salt.<init>() line: 54
* Salt.getInstance() line: 79
* PrivDES.<init>() line: 57
* SecurityProtocols.addDefaultProtocols() line: 155
* MockSnmpAgent.initMessageDispatcher() line: 306
* MockSnmpAgent(BaseAgent).init() line: 145
* MockSnmpAgent.run() line: 380
* Thread.run() line: 745
* </pre>
*/
@Override
protected void initMessageDispatcher() {
s_log.info("MockSnmpAgent: starting initMessageDispatcher()");
try {
dispatcher = new MessageDispatcherImpl();
usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots());
mpv3 = new MPv3(usm);
SecurityProtocols.getInstance().addDefaultProtocols();
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
initSnmpSession();
} finally {
s_log.info("MockSnmpAgent: finished initMessageDispatcher()");
}
}
Aggregations