Search in sources :

Example 1 with MPv3

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;
}
Also used : OctetString(org.snmp4j.smi.OctetString) MessageDispatcher(org.snmp4j.MessageDispatcher) MPv3(org.snmp4j.mp.MPv3) MPv2c(org.snmp4j.mp.MPv2c) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) MessageDispatcherImpl(org.snmp4j.MessageDispatcherImpl) MPv1(org.snmp4j.mp.MPv1) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 2 with MPv3

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()");
    }
}
Also used : MPv3(org.snmp4j.mp.MPv3) MPv2c(org.snmp4j.mp.MPv2c) MessageDispatcherImpl(org.snmp4j.MessageDispatcherImpl) MPv1(org.snmp4j.mp.MPv1) USM(org.snmp4j.security.USM)

Aggregations

MessageDispatcherImpl (org.snmp4j.MessageDispatcherImpl)2 MPv1 (org.snmp4j.mp.MPv1)2 MPv2c (org.snmp4j.mp.MPv2c)2 MPv3 (org.snmp4j.mp.MPv3)2 USM (org.snmp4j.security.USM)2 MessageDispatcher (org.snmp4j.MessageDispatcher)1 Snmp (org.snmp4j.Snmp)1 UsmUser (org.snmp4j.security.UsmUser)1 OctetString (org.snmp4j.smi.OctetString)1 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)1