use of org.snmp4j.security.UsmUser in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getTargetV3.
private Target getTargetV3() {
//logger.info("Use SNMP v3, "+this.privacyprotocol +"="+this.password+", "+this.privacyprotocol+"="+this.privacypassphrase);
OID authOID = AuthMD5.ID;
if ("SHA".equals(this.authprotocol))
authOID = AuthSHA.ID;
OID privOID = PrivDES.ID;
if (this.privacyprotocol == null || this.privacyprotocol.isEmpty())
privOID = null;
UsmUser user = new UsmUser(new OctetString(this.username), //auth
authOID, //auth
new OctetString(this.password), privOID, //enc
this.privacypassphrase != null ? new OctetString(this.privacypassphrase) : null);
snmp.getUSM().addUser(new OctetString(this.username), user);
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(this.getVersionInt());
if (privOID != null)
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
else
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString(this.username));
return target;
}
use of org.snmp4j.security.UsmUser 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.UsmUser in project opennms by OpenNMS.
the class MockSnmpAgent method addUsmUser.
/** {@inheritDoc} */
@Override
protected void addUsmUser(USM usm) {
UsmUser user = new UsmUser(new OctetString("SHADES"), AuthSHA.ID, new OctetString("SHADESAuthPassword"), PrivDES.ID, new OctetString("SHADESPrivPassword"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString("TEST"), AuthSHA.ID, new OctetString("maplesyrup"), PrivDES.ID, new OctetString("maplesyrup"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString("opennmsUser"), AuthMD5.ID, new OctetString("0p3nNMSv3"), PrivDES.ID, new OctetString("0p3nNMSv3"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString("SHA"), AuthSHA.ID, new OctetString("SHAAuthPassword"), null, null);
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
}
use of org.snmp4j.security.UsmUser in project camel by apache.
the class SnmpOIDPoller method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
// either tcp or udp
if ("tcp".equals(endpoint.getProtocol())) {
this.transport = new DefaultTcpTransportMapping();
} else if ("udp".equals(endpoint.getProtocol())) {
this.transport = new DefaultUdpTransportMapping();
} else {
throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
}
this.snmp = new Snmp(this.transport);
if (SnmpConstants.version3 == endpoint.getSnmpVersion()) {
UserTarget userTarget = new UserTarget();
userTarget.setSecurityLevel(endpoint.getSecurityLevel());
userTarget.setSecurityName(convertToOctetString(endpoint.getSecurityName()));
userTarget.setAddress(targetAddress);
userTarget.setRetries(endpoint.getRetries());
userTarget.setTimeout(endpoint.getTimeout());
userTarget.setVersion(endpoint.getSnmpVersion());
this.target = userTarget;
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
OID authProtocol = convertAuthenticationProtocol(endpoint.getAuthenticationProtocol());
OctetString authPwd = convertToOctetString(endpoint.getAuthenticationPassphrase());
OID privProtocol = convertPrivacyProtocol(endpoint.getPrivacyProtocol());
OctetString privPwd = convertToOctetString(endpoint.getPrivacyPassphrase());
UsmUser user = new UsmUser(convertToOctetString(endpoint.getSecurityName()), authProtocol, authPwd, privProtocol, privPwd);
usm.addUser(convertToOctetString(endpoint.getSecurityName()), user);
ScopedPDU scopedPDU = new ScopedPDU();
if (endpoint.getSnmpContextEngineId() != null) {
scopedPDU.setContextEngineID(new OctetString(endpoint.getSnmpContextEngineId()));
}
if (endpoint.getSnmpContextName() != null) {
scopedPDU.setContextName(new OctetString(endpoint.getSnmpContextName()));
}
this.pdu = scopedPDU;
} else {
CommunityTarget communityTarget = new CommunityTarget();
communityTarget.setCommunity(convertToOctetString(endpoint.getSnmpCommunity()));
communityTarget.setAddress(targetAddress);
communityTarget.setRetries(endpoint.getRetries());
communityTarget.setTimeout(endpoint.getTimeout());
communityTarget.setVersion(endpoint.getSnmpVersion());
this.target = communityTarget;
this.pdu = new PDU();
}
// listen to the transport
if (LOG.isDebugEnabled()) {
LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
this.transport.listen();
if (LOG.isInfoEnabled()) {
LOG.info("Started OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
}
use of org.snmp4j.security.UsmUser in project opennms by OpenNMS.
the class Snmp4JStrategy method registerForTraps.
@Override
public void registerForTraps(final TrapNotificationListener listener, InetAddress address, int snmpTrapPort, List<SnmpV3User> snmpUsers) throws IOException {
final RegistrationInfo info = new RegistrationInfo(listener, address, snmpTrapPort);
final Snmp4JTrapNotifier trapNotifier = new Snmp4JTrapNotifier(listener);
info.setHandler(trapNotifier);
final UdpAddress udpAddress;
if (address == null) {
udpAddress = new UdpAddress(snmpTrapPort);
} else {
udpAddress = new UdpAddress(address, snmpTrapPort);
}
// Set socket option SO_REUSEADDR so that we can bind to the port even if it
// has recently been closed by passing 'true' as the second argument here.
final DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(udpAddress, true);
// Increase the receive buffer for the socket
LOG.debug("Attempting to set receive buffer size to {}", Integer.MAX_VALUE);
transport.setReceiveBufferSize(Integer.MAX_VALUE);
LOG.debug("Actual receive buffer size is {}", transport.getReceiveBufferSize());
info.setTransportMapping(transport);
Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(trapNotifier);
if (snmpUsers != null) {
for (SnmpV3User user : snmpUsers) {
SnmpAgentConfig config = new SnmpAgentConfig();
config.setVersion(SnmpConfiguration.VERSION3);
config.setSecurityName(user.getSecurityName());
config.setAuthProtocol(user.getAuthProtocol());
config.setAuthPassPhrase(user.getAuthPassPhrase());
config.setPrivProtocol(user.getPrivProtocol());
config.setPrivPassPhrase(user.getPrivPassPhrase());
Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(config);
UsmUser usmUser = new UsmUser(agentConfig.getSecurityName(), agentConfig.getAuthProtocol(), agentConfig.getAuthPassPhrase(), agentConfig.getPrivProtocol(), agentConfig.getPrivPassPhrase());
/* This doesn't work as expected. Basically SNMP4J is ignoring the engineId
if (user.getEngineId() == null) {
snmp.getUSM().addUser(agentConfig.getSecurityName(), usmUser);
} else {
snmp.getUSM().addUser(agentConfig.getSecurityName(), new OctetString(user.getEngineId()), usmUser);
}
*/
snmp.getUSM().addUser(agentConfig.getSecurityName(), usmUser);
}
}
info.setSession(snmp);
s_registrations.put(listener, info);
snmp.listen();
}
Aggregations