Search in sources :

Example 1 with USM

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;
}
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 USM

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);
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) USM(org.snmp4j.security.USM) ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException)

Example 3 with USM

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()");
    }
}
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)

Example 4 with USM

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<>();
}
Also used : OctetString(org.snmp4j.smi.OctetString) USM(org.snmp4j.security.USM) Before(org.junit.Before)

Example 5 with USM

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<>();
}
Also used : OctetString(org.snmp4j.smi.OctetString) USM(org.snmp4j.security.USM) Before(org.junit.Before)

Aggregations

USM (org.snmp4j.security.USM)17 OctetString (org.snmp4j.smi.OctetString)14 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)10 Snmp (org.snmp4j.Snmp)9 UsmUser (org.snmp4j.security.UsmUser)7 ScopedPDU (org.snmp4j.ScopedPDU)6 UserTarget (org.snmp4j.UserTarget)6 PDU (org.snmp4j.PDU)5 UdpAddress (org.snmp4j.smi.UdpAddress)5 CommunityTarget (org.snmp4j.CommunityTarget)4 ResponseEvent (org.snmp4j.event.ResponseEvent)4 OID (org.snmp4j.smi.OID)4 IOException (java.io.IOException)3 Before (org.junit.Before)3 VariableBinding (org.snmp4j.smi.VariableBinding)3 MessageDispatcherImpl (org.snmp4j.MessageDispatcherImpl)2 TransportMapping (org.snmp4j.TransportMapping)2 MPv1 (org.snmp4j.mp.MPv1)2 MPv2c (org.snmp4j.mp.MPv2c)2 MPv3 (org.snmp4j.mp.MPv3)2