RFC3414 \u00a73.2.4 Unknown security name:

Hi,
I am using SNMP-4J agent library(SNMP4j-2.7.0) for running my agent. I have implemented my agent in a runnable thread and invoking this thread from another startup bean.
My agent thread starts perfectly on the given port 20100 but returns error when make discovery of the same on agents returns error “RFC3414 §3.2.4 Unknown security name:” same code runs absolutely fine when running in a stand alone package but throws error when running in EJB container.
One more observation after shutting down the agent I am unable to locate file “AgentConfig.cfg” .
Please help me out
Thanks and regards

//Startup bean code
@Singleton
@Startup
public class StartupBean {

    TestAgentWithRunThread snmpAgentConsumerThread;

    Thread snmpagentthread;

    @PostConstruct
public void onStartup() {
File bootCounterFile = null; File configfile = null;
    try {
                    snmpAgentConsumerThread = new TestAgentWithRunThread(bootCounterFile, configfile);
            } catch (IOException e) {
                    // TODO Auto-generated catch block 
            }
    snmpagentthread = new Thread(snmpAgentConsumerThread, "snmpAgentThread");
    snmpagentthread.start();  //<<<<--Starting thread
}

//Below is the code snippet of my agent implementation

public class TestAgentWithRunThread extends BaseAgent implements Runnable{

protected String address;
private Snmp4jHeartbeatMib heartbeatMIB;
private AgentppSimulationMib agentppSimulationMIB;
private Snmp4jDemoMib snmp4jDemoMib;
private SortedMap<OID, List> sparseTableData = new TreeMap<OID, List>();
private static String cAGENTIP=“”;
private static String cSNMPPORT=“20100”;
private static String cSNMPSECLEVEL=“AuthNoPriv”;
private static String cSNMPUSERNAME=“authUser”;
private static String cSNMPAUTHPROTOCOL=“MD5”;
private static String cSNMPAUTHPASSWD=“authUser”;
private static String cSNMPCONTEXTNAME=“auth”;
private static String cENGINEID=“”;
private static int mysecuritylevel=SecurityLevel.AUTH_NOPRIV; //Default

/**

  • Creates the test agent with a file to read and store the boot counter and
  • a file to read and store its configuration.
  • @param bootCounterFile
  • a file containing the boot counter in serialized form (as expected by
  • BaseAgent).
  • @param configFile
  • a configuration file with serialized management information.
  • @throws IOException
  • if the boot counter or config file cannot be read properly.
    */

public TestAgentWithRunThread(File bootCounterFile, File configFile) throws IOException {
super(bootCounterFile, configFile,
new CommandProcessor(new OctetString(OctetString.fromHexString(cENGINEID, ‘:’))));

agent.setWorkerPool(ThreadPool.create("RequestPool", 4));
// Uncomment the following if you want to use AES 192 or 256 with 3DES like key extension.
SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES256With3DESKeyExtension());

}

protected void registerManagedObjects() {
try {
// server.register(createStaticIfTable(), null);
agentppSimulationMIB.registerMOs(server, null);
heartbeatMIB.registerMOs(server, null);
snmp4jDemoMib.registerMOs(server, null);

}
catch (DuplicateRegistrationException ex) {
  ex.printStackTrace();
}

}

protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
targetMIB.addDefaultTDomains();

targetMIB.addTargetAddress(new OctetString("notificationV2c"),
                           TransportDomains.transportDomainUdpIpv4,
                           new OctetString(new UdpAddress("127.0.0.1/162").getValue()),
                           200, 1,
                           new OctetString("notify"),
                           new OctetString("v2c"),
                           StorageType.permanent);
targetMIB.addTargetAddress(new OctetString("notificationV3"),
                           TransportDomains.transportDomainUdpIpv4,
                           new OctetString(new UdpAddress("127.0.0.1/1162").getValue()),
                           200, 1,
                           new OctetString("notify"),
                           new OctetString("v3notify"),
                           StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v2c"),
                          MessageProcessingModel.MPv2c,
                          SecurityModel.SECURITY_MODEL_SNMPv2c,
                          new OctetString("cpublic"),
                          SecurityLevel.AUTH_PRIV,
                          StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v3notify"),
                          MessageProcessingModel.MPv3,
                          SecurityModel.SECURITY_MODEL_USM,
                          new OctetString("v3notify"),
                          SecurityLevel.NOAUTH_NOPRIV,
                          StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("default"),
                               new OctetString("notify"),
                               SnmpNotificationMIB.SnmpNotifyTypeEnum.inform,
                               StorageType.permanent);

}

protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString(“cpublic”),
new OctetString(“v1v2group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString(“cpublic”),
new OctetString(“v1v2group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString(“MD5DES”),
new OctetString(“v3group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString(cSNMPUSERNAME),
new OctetString(“v3group”),
StorageType.nonVolatile);

vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
              new OctetString("v3notify"),
              new OctetString("v3group"),
              StorageType.nonVolatile);

vacm.addAccess(new OctetString("v1v2group"), new OctetString("public"),
               SecurityModel.SECURITY_MODEL_ANY,
               SecurityLevel.NOAUTH_NOPRIV,
               MutableVACM.VACM_MATCH_EXACT,
               new OctetString("fullReadView"),
               new OctetString("fullWriteView"),
               new OctetString("fullNotifyView"),
               StorageType.nonVolatile);

			
vacm.addAccess(new OctetString("v3group"), new OctetString(cSNMPCONTEXTNAME),
               SecurityModel.SECURITY_MODEL_USM,
               mysecuritylevel,
               MutableVACM.VACM_MATCH_EXACT,
               new OctetString("fullReadView"),
               new OctetString("fullWriteView"),
               new OctetString("fullNotifyView"),
               StorageType.nonVolatile);

vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
                       new OctetString(), VacmMIB.vacmViewIncluded,
                       StorageType.nonVolatile);

vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
                       new OctetString(), VacmMIB.vacmViewIncluded,
                       StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyView"), new OID("1.3"),
                       new OctetString(), VacmMIB.vacmViewIncluded,
                       StorageType.nonVolatile);

}

protected void addUsmUser(USM usm) {
usm.setEngineDiscoveryEnabled(true);
UsmUser user = new UsmUser(new OctetString(“MD5DES”),
AuthMD5.ID,
new OctetString(“MD5DESAuthPassword”),
PrivDES.ID,
new OctetString(“MD5DESPrivPassword”));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);

user = new UsmUser(new OctetString(cSNMPUSERNAME),
        AuthMD5.ID,
        new OctetString(cSNMPAUTHPASSWD),
        PrivDES.ID,
        new OctetString(cSNMPAUTHPASSWD));

usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);

usm.getUserTable();

user = new UsmUser(new OctetString("v3notify"),
                           null,
                           null,
                           null,
                           null);
usm.addUser(user.getSecurityName(), null, user);

}

protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping<?>[1];
Address addr = GenericAddress.parse(address);
TransportMapping<? extends Address> tm =
TransportMappings.getInstance().createTransportMapping(addr);
transportMappings[0] = tm;
}

@Override
public void run() {

  //LogFactory.setLogFactory(new ConsoleLogFactory());
  //ConsoleLogAdapter.setDebugEnabled(true);
 // readServerinfo();
  
  cAGENTIP="182.4.1.221";
	cSNMPPORT="20100";
	 cSNMPSECLEVEL="AuthNoPriv";
	 cSNMPUSERNAME="myUser";
	  cSNMPAUTHPROTOCOL="MD5";
	  cSNMPAUTHPASSWD="myUser";
	  cSNMPCONTEXTNAME="auth";
	  cENGINEID="31:36:38:2e:34:2e:38:35:23:32:30:31:30:30";
	
  
  if(cSNMPSECLEVEL.equalsIgnoreCase("NoAuthNoPriv"))
  {
	  mysecuritylevel = SecurityLevel.NOAUTH_NOPRIV;
  }
  if(cSNMPSECLEVEL.equalsIgnoreCase("AuthNoPriv"))
  {
	 mysecuritylevel = SecurityLevel.AUTH_NOPRIV;
  }
  if(cSNMPSECLEVEL.equalsIgnoreCase("AuthPriv"))
  {
	  mysecuritylevel = SecurityLevel.AUTH_PRIV;
  }
  
String address;
	 address = cAGENTIP+"/"+cSNMPPORT;
	    
BasicConfigurator.configure();
try {
  TestAgentWithRunThread testAgent1 = new TestAgentWithRunThread(new File("BC.cfg"),
	new File("AgentConfig.cfg"));
  testAgent1.address = address;
  testAgent1.init();
  testAgent1.loadConfig(ImportModes.REPLACE_CREATE);
  testAgent1.addShutdownHook();
  testAgent1.getServer().addContext(new OctetString(cSNMPCONTEXTNAME));
  testAgent1.finishInit();
 testAgent1.running();

  testAgent1.sendColdStartNotification();
  
  
  while (true) {
    try {
      Thread.sleep(1);
      //LOGGER.log(Level.DEBUG, "TestAgent.main() sleep");
      //myprintf();
    }
    catch (InterruptedException ex1) {
      break;
    }
  }
}
catch (IOException ex) {
  ex.printStackTrace();
}

}

protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered…
}

protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] {
new OctetString(cSNMPCONTEXTNAME), // community name
new OctetString(“cpublic”), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString(cSNMPCONTEXTNAME), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
SnmpCommunityMIB.SnmpCommunityEntryRow row =
communityMIB.getSnmpCommunityEntry().createRow(
new OctetString(“public2public”).toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
// snmpCommunityMIB.setSourceAddressFiltering(true);
}

protected void registerSnmpMIBs() {
heartbeatMIB = new Snmp4jHeartbeatMib(super.getNotificationOriginator(),
new OctetString(),
super.snmpv2MIB.getSysUpTime());
agentppSimulationMIB = new AgentppSimulationMib();
snmp4jDemoMib = new Snmp4jDemoMib(DefaultMOFactory.getInstance());
/*
*/
super.registerSnmpMIBs();
}

}

I think you have to check if the USM configuration is correctly done in your EJB implementation.

Thanks!
After analysis of my EJB found a Snmp4jSmiUtil.java class using for manager functionality, in this class following code is implemented

USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
usmObj = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usmObj);

When my agent is initialising in the same EJB and in BaseAgent.java class, it is done like
protected void initMessageDispatcher() {
dispatcher = new MessageDispatcherImpl();
mpv3 = new MPv3(agent.getContextEngineID().getValue());
usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots()); <<-----
SecurityModels.getInstance().addSecurityModel(usm); <<—
SecurityProtocols.getInstance().addDefaultProtocols();
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
dispatcher.addMessageProcessingModel(mpv3);
initSnmpSession();
}

Since, my agent initialises first then SmiUtil code , the later re-initialises the usm (i guess), SecurityModels.getInstance() being a singleton instance.
when I commented the first code (Snmp4jSmiUtil.java) , agent worked fine.

One more query in this case I have to use

usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots());
SecurityModels.getInstance().addSecurityModel(usm);

Only once in single JVM and can i do “usm.addUser()” from different classes. If same user with difference credentials is created in different classes will the only latest will be effective.

thanks and regards,

Yes, the a single USM instance can be registered as singleton with the SecurityProtocols singleton. The USM.addUser overwrites any previous entries with same engineID and securityName.

Nevertheless, you can work with several USM instances too. See How to configure SNMPv3 users with same name but different passphrases? - SNMP4J - AGENTPP for details.

1 Like