[SNMP4J] [snmp4j] USM.removeUser not really working
Kelsey Abe
kabe at referentia.com
Wed Jul 13 05:16:43 CEST 2011
Hello,
I was running some tests on a userTarget by adding and removing the USM
users to ensure that we had correctly set up a list of
Users/passwords/authentication on the router.
1. Adding a single user worked as expected, but when placing a
snmp.getUSM().removeUser() [or .getUSM().getUserTable().removeUser()] in
between two snmp.getBulk requests, both requests were successful.
(unexpected behavior)
2. However, after using a removeUser, when using the getUser/removeUser
functions, they return null, indicating that the user should have been
removed from the USM. (expected behavior)
3. As a side note, the removeAllUsers() caused the program to throw a
MessageException, which showed that the user was actually removed. (expected
behavior)
I have a feeling that the problem lies within the removeUser function.
thanks for your help!
Kelsey
Code:
package temp;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.ScopedPDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.UserTarget;
import org.snmp4j.mp.MPv3;
import org.snmp4j.security.AuthMD5;
import org.snmp4j.security.PrivDES;
import org.snmp4j.security.SecurityLevel;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.security.USM;
import org.snmp4j.security.UsmUser;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
public class Main {
public static int printoutNumber;
private static OctetString authEngineID = OctetString
.fromHexString("80:00:00:09:03:00:54:75:D0:6D:3B:80");
private static OctetString localEngineID = new
OctetString(MPv3.createLocalEngineID());
public static void main(String[] args) {
try {
OctetString securityName = new OctetString("authNoPrivMd5");
UserTarget utarget = Build.craftTarget("192.168.1.197/161",
securityName,
authEngineID.toByteArray(), SecurityLevel.AUTH_NOPRIV);
/* where Build.craftTarget does the following:
* UdpAddress uAdd = new UdpAddress(address);
* UserTarget utarget = new UserTarget(uAdd, securityName,
authEngineID, securityLevel);
* utarget.setRetries(1);
* utarget.setTimeout(1000);
* utarget.setVersion(SnmpConstants.version3);
*/
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
SecurityModels.getInstance().addSecurityModel(usm);
TransportMapping transport = Build.craftTransport(8088);
Snmp snmp = new Snmp(transport);
/*where Build.craftTransport(i) does the following:
*trans = new DefaultUdpTransportMapping(new UdpAddress("172.16.67.76/"
+i));
* trans.listen();
*/
ScopedPDU sPdu = Build.craftSPDU();
/*where Build.craftSPDU does the following
*ScopedPDU sPdu = new ScopedPDU();
* List<VariableBinding> list = Arrays.asList(new VariableBinding(new
OID("1.3.6.1.2.1.2.1")),
* new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.10")),
* new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.16")));
* sPdu = craftSPDU(list);
* sPdu.setType(PDU.GETBULK);
* sPdu.setMaxRepetitions(50);
* sPdu.setNonRepeaters(1);
*/
// add user to the USM
snmp.getUSM().addUser(
new OctetString("authNoPrivMd5"),
new UsmUser(new OctetString("authNoPrivMd5"), AuthMD5.ID,
new OctetString("ImpressivePassword"), PrivDES.ID, new
OctetString("ImpressivePassword")));
Test.sendAndPrintResponse(snmp, sPdu, utarget);
System.out.println(snmp.getUSM().removeUser(authEngineID, new
OctetString("authNoPrivMd5")));
//
System.out.println(snmp.getUSM().getUserTable().removeUser(authEngineID, new
OctetString("authNoPrivMd5")));
// System.out.println(snmp.getUSM().removeUser(authEngineID, new
OctetString("authNoPrivMd5")));
// System.out.println(snmp.getUSM().getUserTable().getUser(authEngineID,
new OctetString("authNoPrivMd5")));
// snmp.getUSM().removeAllUsers();
Test.sendAndPrintResponse(snmp, sPdu, utarget);
}
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}// end main
More information about the SNMP4J
mailing list