Search in sources :

Example 6 with USM

use of org.snmp4j.security.USM in project ovirt-engine by oVirt.

the class Snmp method createSnmp3.

private org.snmp4j.Snmp createSnmp3(Profile profile) {
    try {
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        org.snmp4j.Snmp snmp = new org.snmp4j.Snmp(transport);
        SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
        securityProtocols.addDefaultProtocols();
        securityProtocols.addAuthenticationProtocol(new AuthMD5());
        securityProtocols.addAuthenticationProtocol(new AuthSHA());
        securityProtocols.addPrivacyProtocol(new PrivAES128());
        securityProtocols.addPrivacyProtocol(new PrivAES192());
        securityProtocols.addPrivacyProtocol(new PrivAES256());
        USM usm = new USM(securityProtocols, profile.engineId, 0);
        ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)).setLocalEngineID(profile.engineId.getValue());
        ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)).getSecurityModels().addSecurityModel(usm);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();
        snmp.getUSM().addUser(profile.username, getUsmUser(profile));
        return snmp;
    } catch (IOException e) {
        throw new NotificationServiceException("error creating version 3 snmp " + getClass().getName());
    }
}
Also used : NotificationServiceException(org.ovirt.engine.core.notifier.NotificationServiceException) SecurityProtocols(org.snmp4j.security.SecurityProtocols) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) AuthSHA(org.snmp4j.security.AuthSHA) IOException(java.io.IOException) USM(org.snmp4j.security.USM) PrivAES192(org.snmp4j.security.PrivAES192) PrivAES128(org.snmp4j.security.PrivAES128) PrivAES256(org.snmp4j.security.PrivAES256) AuthMD5(org.snmp4j.security.AuthMD5)

Example 7 with USM

use of org.snmp4j.security.USM in project mysql_perf_analyzer by yahoo.

the class SNMPClient method start.

/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
public void start() throws IOException {
    TransportMapping transport = new DefaultUdpTransportMapping();
    snmp = new Snmp(transport);
    if (// add v3 support
    "3".equals(this.version)) {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
    }
    // Do not forget this line!
    transport.listen();
}
Also used : OctetString(org.snmp4j.smi.OctetString) TransportMapping(org.snmp4j.TransportMapping) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) USM(org.snmp4j.security.USM)

Example 8 with USM

use of org.snmp4j.security.USM in project opennms by OpenNMS.

the class MockSnmpAgentIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) {
    PDU response = null;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(InetAddressUtils.addr("127.0.0.1"), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    target.setTimeout(DEFAULT_TIMEOUT);
    TransportMapping<UdpAddress> transport = null;
    Snmp snmp = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        if (snmp != null) {
            try {
                snmp.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
        if (transport != null) {
            try {
                transport.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) IOException(java.io.IOException) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 9 with USM

use of org.snmp4j.security.USM in project opennms by OpenNMS.

the class BrocadeMibIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    target.setTimeout(5000);
    TransportMapping<UdpAddress> transport = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 10 with USM

use of org.snmp4j.security.USM in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    } else {
        target.setTimeout(5000);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

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