Hello,
I developed an agent that supports SNMPv3 and a client sending Get request. Very simple but I got errors :
- With engineId on client : Message processing model 3 returned error: Unknown security name
- Without engineId on client : an error on serverr side : Unknown engine ID
I looked for a solution to fix this issue but no success.
Can you help on that.
Thanks
With engine_id : client exception
org.snmp4j.MessageException: Message processing model 3 returned error: Unknown security name
at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:527)
at org.snmp4j.Snmp.sendMessage(Snmp.java:1088)
at org.snmp4j.Snmp.send(Snmp.java:981)
at org.snmp4j.Snmp.send(Snmp.java:961)
at org.snmp4j.Snmp.send(Snmp.java:926)
at MySnmpV3Test.sendSnmp(MySnmpV3Test.java:66)
at MySnmpV3Test.snmpGet(MySnmpV3Test.java:46)
at MySnmpV3Test.main(MySnmpV3Test.java:115)
Without engine_id : (server side) :
Without engine id
Received message from /127.0.0.1/40155 with length 60: 30:3a:02:01:03:30:10:02:03:00:e7:53:02:03:00:ff:ff:04:01:04:02:01:03:04:10:30:0e:04:00:02:01:00:02:01:00:04:00:04:00:04:00:30:11:04:00:04:00:a0:0b:02:01:00:02:01:00:02:01:00:30:00
RFC3414 ยŕ¸3.2.3 Unknown engine ID:
RFC3414 ยŕ¸3.1.4.b Outgoing message is not encrypted
Sending message to 127.0.0.1/40155 with length 103: 30:65:02:01:03:30:10:02:03:00:e7:53:02:03:00:ff:ff:04:01:00:02:01:03:04:1d:30:1b:04:0d:80:00:13:70:01:7f:00:00:01:65:6b:12:34:02:01:00:02:01:00:04:00:04:00:04:00:30:2f:04:0d:80:00:13:70:01:7f:00:00:01:65:6b:12:34:04:00:a8:1c:02:01:00:02:01:00:02:01:00:30:11:30:0f:06:0a:2b:06:01:06:03:0f:01:01:04:00:41:01:05
Message from 127.0.0.1/40155 not dispatched, reason: statusInfo=1.3.6.1.6.3.15.1.1.4.0 = 5, status=1410
Hereafter my code :
Agent SERVER :
*public class MyAgent extends BaseAgent {
public MyAgent() {
super(new File(CsdClusterHelper.getVarFolder(), "snmp-conf2.agent"),
new File(CsdClusterHelper.getVarFolder(), "snmp-bootCounter2.agent"),
new CommandProcessor(new OctetString(MPv3.createLocalEngineID())));
agent.setWorkerPool(ThreadPool.create("SnmpAgentRequestPool", 4));
...
}
protected void addUsmUser(USM usm) {
// the security name of the user (typically the user name).
OctetString securityName = new OctetString("snmpuser");
// Passphrase
OctetString securityPassphrase = new OctetString("snmpPassword");
UsmUser user = new UsmUser(securityName, AuthMD5.ID, securityPassphrase, PrivDES.ID, securityPassphrase);
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
System.out.println("engine id : " + usm.getLocalEngineID().toHexString());
}
@Override
protected void addViews(VacmMIB vacm) {
String securityName = "snmpuser";
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM, new OctetString(securityName), new OctetString(GROUP_V3),
StorageType.nonVolatile);
vacm.addAccess(new OctetString(GROUP_V3), new OctetString(), SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadViewPublic"),
new OctetString("fullWriteViewPublic"), new OctetString("fullNotifyViewPublic"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadViewPublic"), new OID("1.3.6.1.4.1.35003"), new OctetString(),
VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyViewPublic"), new OID("1.3.6.1.4.1.35003"), new OctetString(),
VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
}
}
*
Snmp Client for test (Get request)
-
public class MySnmpV3Test {
protected Snmp snmp;
protected String address = â127.0.0.1/16002â;
protected String PROTOCOL = âudp:â;
private static OctetString securityName = new OctetString(âsnmpuserâ);
private static OID authProtocol = AuthMD5.ID;
private static OctetString passPhrase = new OctetString(âsnmpPasswordâ);
private static OID privProtocol = PrivDES.ID;
private static int securityLevel = SecurityLevel.AUTH_PRIV;
OctetString engineId = OctetString.fromHexString(â80:00:13:70:01:7f:00:00:01:9f:68:66:06â, â:â);protected USM usm = null;
public void snmpGet() {
usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
createSNMPsession();
addSnmpUser();
sendSnmp();
}private void sendSnmp() {
// send the PDU
ResponseEvent response;
try {
// Target
UserTarget target = new UserTarget();
Address targetAddress = GenericAddress.parse(PROTOCOL + address);
target.setAddress(targetAddress);
target.setRetries(0);
target.setTimeout(5000);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(securityLevel);
target.setSecurityName(securityName);// PDU ScopedPDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.35003.2.1.0"))); response = snmp.send(pdu, target); // extract the response PDU (could be null if timed out) PDU responsePDU = response.getResponse(); if (responsePDU == null) { System.out.println("No response, timeOut..."); } else if (responsePDU.getErrorStatus() == PDU.noError) { Vector<? extends VariableBinding> vbs = responsePDU.getVariableBindings(); for (VariableBinding vb : vbs) { System.out.println("RESPONSE: " + vb + " ," + vb.getVariable().getSyntaxString()); System.out.println("pdu: " + responsePDU.toString()); } } else { System.out.println("ERROR:" + responsePDU.getErrorStatusText() + ":" + responsePDU.getErrorStatus()); System.out.println("ERROR:" + responsePDU); } } catch (IOException e) { e.printStackTrace(); } finally { try { snmp.close(); } catch (IOException e) { e.printStackTrace(); } }
}
protected void createSNMPsession() {
TransportMapping<? extends Address> transport;
try {
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
snmp.setLocalEngine(engineId.getValue(), 0, 0);// OctetString(usm.getLocalEngineID()).getValue(), 0, 0);
transport.listen();
} catch (IOException e) {
e.printStackTrace();
}
}protected void addSnmpUser() {
UsmUser usmUser = new UsmUser(securityName, authProtocol, passPhrase, privProtocol, passPhrase);
System.out.println("engine id : " + usm.getLocalEngineID());
// snmp.getUSM().addUser(securityName, usm.getLocalEngineID(), usmUser);
snmp.getUSM().addUser(securityName, usmUser);
}public static void main(String[] args) {
new MySnmpV3Test().snmpGet();
}
}*