use of org.snmp4j.security.USM 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.security.USM in project nifi by apache.
the class AbstractSNMPProcessor method buildTargetResource.
/**
* Builds target resource.
* @param context Process context
*/
private void buildTargetResource(ProcessContext context) {
if ((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) {
try {
this.transportMapping = new DefaultUdpTransportMapping();
this.snmp = new Snmp(this.transportMapping);
if ("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
this.transportMapping.listen();
} catch (Exception e) {
throw new IllegalStateException("Failed to initialize UDP transport mapping", e);
}
}
if (this.snmpTarget == null) {
this.snmpTarget = this.createSnmpTarget(context);
}
if (this.targetResource == null) {
this.targetResource = this.finishBuildingTargetResource(context);
}
}
use of org.snmp4j.security.USM 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()");
}
}
use of org.snmp4j.security.USM in project opennms by OpenNMS.
the class LLDPMibIT method setUp.
@Before
public void setUp() throws Exception {
// Create a global USM that all client calls will use
SNMP4JSettings.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
try {
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("penrose-lldp-mib.properties"), str(InetAddress.getLocalHost()) + "/0");
} catch (Throwable e) {
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("penrose-lldp-mib.properties"), str(InetAddressUtils.ONE_TWENTY_SEVEN) + "/0");
}
m_requestedVarbinds = new ArrayList<>();
}
use of org.snmp4j.security.USM in project opennms by OpenNMS.
the class MockSnmpAgentIT method setUp.
@Before
public void setUp() throws Exception {
// Create a global USM that all client calls will use
SNMP4JSettings.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("loadSnmpDataTest.properties"), "127.0.0.1/0");
Thread.sleep(200);
System.err.println("Started MockSnmpAgent on port " + m_agent.getPort());
m_requestedVarbinds = new ArrayList<>();
}
Aggregations