Unable to get SampleAgent working with md5des

Hello, I am not very familiar with SNMP4J nor SNMP in general so I might ask dumb questions. I was able to get a SNMP Agent working for SHA256DES with the following sampleAgentConfig.properties:

Note: copied and adapted from PropertyMOInput.html documentation

snmp4j.agent.cfg.contexts=
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.2.0={o}1.3.6.1.4.1.4976
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.4.0={s}System Administrator
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.6.0={s}
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.7.0={i}10
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.9.1=1:2
snmp4j.agent.cfg.index.1.3.6.1.2.1.1.9.1.0={o}1
snmp4j.agent.cfg.value.1.3.6.1.2.1.1.9.1.0.0={o}1.3.6.1.4.1.4976.10.1.1.100.4.1
snmp4j.agent.cfg.value.1.3.6.1.2.1.1.9.1.0.1=
## VACM MIB
# security2Group
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.2.1=2:3
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.2.1.0={o}3.9.'SHA256DES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.0={s}v3group
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.1={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.2={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.2.1.1={o}3.4.'MD5DES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.0={s}v3group
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.1={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.2={i}1

# access
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.4.1=1:6
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.4.1.0={o}7.'v3group'.0.3.3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.0={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.1={s}unrestrictedReadView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.2={s}unrestrictedWriteView
#snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.3={s}unrestrictedNotifyView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.4={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.5={i}1
# view trees
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.5.2.1=2:4
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.0={o}20.'unrestrictedReadView'.3.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.2={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.3={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.1={o}21.'unrestrictedWriteView'.3.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.2={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.3={i}1
#snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.2={o}22.'unrestrictedNotifyView'.3.1.3.6
#snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.0={s}
#snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.1={i}1
#snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.2={i}3
#snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.3={i}1
## SNMP community MIB
## USM MIB
snmp4j.agent.cfg.oid.1.3.6.1.6.3.15.1.2.2.1=2:16
snmp4j.agent.cfg.index.1.3.6.1.6.3.15.1.2.2.1.0={o}$#{1.3.6.1.6.3.10.2.1.1.0}.9.'SHA256DES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.0={s}SHA256DES
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.1={o}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.2={o}1.3.6.1.6.3.10.1.1.5
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.3={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.4={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.5={o}1.3.6.1.6.3.10.1.2.2
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.6={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.7={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.8={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.9={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.10={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.11={s}SHA256DESAuthPassword
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.12={s}SHA256DESPrivPassword
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.13=
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.14=
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.15=
snmp4j.agent.cfg.index.1.3.6.1.6.3.15.1.2.2.1.1={o}$#{1.3.6.1.6.3.10.2.1.1.0}.4.'MD5DES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.0={s}MD5DES
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.1={o}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.2={o}1.3.6.1.6.3.10.1.1.2
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.3={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.4={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.5={o}1.3.6.1.6.3.10.1.2.2
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.6={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.7={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.8={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.9={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.10={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.11={s}MD5DESAuthPassword
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.12={s}MD5DESPrivPassword
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.13=
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.14=
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.1.15=

# parameters
snmp4j.agent.cfg.oid.1.3.6.1.6.3.12.1.3.1=1:6
snmp4j.agent.cfg.index.1.3.6.1.6.3.12.1.3.1.0={o}'SNMPv3'
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.0={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.1={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.2={s}MD5DES
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.3={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.4={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.0.5={i}1
#
#snmp4j.agent.cfg.index.1.3.6.1.6.3.12.1.3.1.1={o}'SNMPv3'
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.0={i}3
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.1={i}3
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.2={s}MD5DES
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.3={i}3
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.4={i}3
#snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.3.1.1.5={i}1

I have a few questions and problems:

Problem: When I try to connect to my MD5DES access it gives me “Unknown UserName: -33” but when I connect to SHA256DES it authenticates successfully.

example: snmpwalk -v3 -l authPriv -u MD5DES -a MD5 -A “MD5DESAuthPassword” -x DES -X “MD5DESPrivPassword” 127.0.0.1:10030 .1.3.6

Question 1: Why does the index need to be prefixed with 3.9 before specifying SHA256DES? I assumed it had something to do with index of USM mibs so I replicated it for MD5DES.

Question 2: Why is my MIB filled with so much stuff? Is it snmp4jDemoMib doing it?

Question 3: I haven’t looked into this yet but how would you go about adding entries<OID, value> to the MIB?

Question 4: Is sampleAgent bloated? Should I use make my own Agent that extends AgentConfigManager? I only need this as a simulated Agent to verify that my manager is working (I’m trying to connect to someone else’s agent) so it being bloated is not that much of an issue.

Sorry for the question spam, I just have so many doubts which I’ve been having trouble answering through documentation.

Thank you.

Q1: The „prefix“ is part of the INDEX definition of the MIB for that table. In this case, the security model (3) and the length of the security name (9). Therefore, your prefix for MD5DES is wrong (should be 3.6 instead 3.4).
Q2: No, the MIB objects are mostly related to SNMP standard MIBs. If you do not implement it, you might lose some important functionality, but that is your decision.
Q3: OID/Value pairs can be added too and easily, but that is probably only useful for simulation agents. For example, you can use the StaticMOGroup class for that.
Q4: I always recommend to write your own agent based on AgentConfigManager.

Would also like to ask, how would I go about using GETBULK, I’ve debugged the code until I reach GetBulkHandler and I see that the ScopedPDU that I created in the manager:

// Create PDU for V3
            PDU pdu = new ScopedPDU();
            pdu.setType(PDU.GETBULK);
            pdu.setMaxRepetitions(9);
            pdu.setNonRepeaters(0);
            pdu.setErrorIndex(0);
            pdu.setErrorStatus(0);
            pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1")));

Was supposed be handled by the agent and enter inside the code block covered by (CommandProcessor@GetBulkHandler:line:1153):

if (request.getMaxRepetitions() > 0)

But these MaxRepetitions are coming at 0 when in the manager I set them to 9.

Is there any additional setup in sampleAgent that I’m missing?

Thank you for the quick reply! I was able to get it working with your help and I used your suggestion of StaticMOGroup to register my own values, I am however only now realizing that, unless I delete the files persistance.out and bootCounter.out, I can’t connect after an agent restart.

My properties are the ones above with your suggestions.

Here is my code:

package private;

import org.snmp4j.agent.AgentConfigManager;
import org.snmp4j.agent.DuplicateRegistrationException;
import org.snmp4j.agent.MOServer;
import org.snmp4j.agent.example.SampleAgent;
import org.snmp4j.agent.mo.ext.StaticMOGroup;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimuAgent{

    private final SampleAgent agent;

    public SimuAgent(SampleAgent agent) {
        this.agent = agent;
    }


    public static void main(String[] args) throws DuplicateRegistrationException {
        Map<String, List<Object>> argsMap = new HashMap<>();
        argsMap.put("c", Collections.singletonList("src/test/resources/persistance.out"));
        argsMap.put("bc", Collections.singletonList("src/test/resources/bootCounter.out"));
        argsMap.put("address", Collections.singletonList("udp:127.0.0.1/10030"));
        argsMap.put("cfg", Collections.singletonList("src/test/resources/SampleAgentConfigDemo.properties"));
        SampleAgentPublic agent = new SampleAgentPublic(argsMap);


        VariableBinding[] vbs = new VariableBinding[5];
        vbs[0] = new VariableBinding(new OID("1.3.6.1.2.1.1.0.0"), new Integer32(0));
        vbs[1] = new VariableBinding(new OID("1.3.6.1.2.1.1.1.0"), new Integer32(0));
        vbs[2] = new VariableBinding(new OID("1.3.6.1.2.1.1.2.0"), new Integer32(1));
        vbs[3] = new VariableBinding(new OID("1.3.6.1.2.1.1.3.0"), new Integer32(0));
        vbs[4] = new VariableBinding(new OID("1.3.6.1.2.1.1.4.0"), new Integer32(0));
        StaticMOGroup moGroup = new StaticMOGroup(new OID("1.3.6.1.2.1.1"), vbs);
        agent.run();
        agent.getAgent().getSNMPv2MIB().unregisterMOs(agent.getServer(), new OctetString());
        moGroup.registerMOs(agent.getServer(), new OctetString());
        System.out.println("running");
    }
}

class SampleAgentPublic extends SampleAgent{

    public SampleAgentPublic(Map<String, List<Object>> args) {
        super(args);
    }


    public MOServer getServer(){
        return super.server;
    }

    public AgentConfigManager getAgent(){
        return super.agent;
    }
}

At my first clean run, everything works as expected, I was about to be done with this until I realized that upon restarting the agent I stop being able to connect.

Thank you for your help!