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