[SNMP4J] reg: USM and MPV3

Frank Fock fock at agentpp.com
Tue Apr 20 22:38:36 CEST 2010


Tomek,

The code snippet below is hard to understand. It seems
to be incorrect because its algorithm depends on the state of
the USM.

With correct key localization, using two targets with the
same user name but different keys and a single USM should
not be any problem.

Best regards,
Frank

On 20.04.2010 18:04, Tomasz Kaczmarek wrote:
> Frank,
> I have the similar problem. I'm using snmp4j 1.11
> I'm using one MPV3 and USM. Snmp4j is utilized in tomcat6 container.
> Everything is working pretty fine for only one remote device. I have a
> problem with talking via snmp to 2 network devices. My configuration
> is the same name but different passwords.
> I'm getting an exception:
> org.snmp4j.Message Exception: "Message processing model 3 returned
> error: Unknown security name"
> I've debugged that engineId discovery succeed and and user is added to
> USM's user's table before send operation.
>
> Thanks,
> Tomek
>
> Here is my code (This is a part of bigger one. I've just cut a part
> responsible for communication with one snmp device):
> ------------------------------------------------
> OctetString localEngineID = new OctetString(MPv3.createLocalEngineID());
> USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
> SecurityModels.getInstance().addSecurityModel(usm);
>
> TransportMapping transport = new DefaultUdpTransportMapping();
> transport.listen();
>
> Snmp snmp = new Snmp(transport);
> ((MPv3) snmp.getMessageProcessingModel(MPv3.ID)).setLocalEngineID(localEngineID.getValue());
> snmp.listen();
>
> UserTarget target = fillTarget(new UserTarget(), agent);
> target.setVersion(SnmpConstants.version3);
> //target.setSecurityLevel(securityLevel);
> target.setSecurityLevel(((UserBasedModel)
> agent.getSecurityModel()).getSecurityLevel());
>
> UsmUser user = Snmp4JTranslator.to(((UserBasedModel)
> agent.getSecurityModel()).getUser());
> target.setSecurityName(user.getSecurityName());
>
> byte[] engineIdDisc = null;
> if (((MPv3) snmp.getMessageProcessingModel(MPv3.ID)).getEngineID(target.getAddress())
> == null) {
>   usm.setEngineDiscoveryEnabled(true);
>   engineIdDisc =
> snmp.discoverAuthoritativeEngineID(target.getAddress(),
> target.getTimeout());
> } else {
>   engineIdDisc = ((MPv3)
> snmp.getMessageProcessingModel(MPv3.ID)).getEngineID(target.getAddress()).toByteArray();
> }
>
> if(engineIdDisc != null) {
>   target.setAuthoritativeEngineID(engineIdDisc);
>   usm.addUser(new OctetString(user.getSecurityName()), new
> OctetString(engineIdDisc), user);
> } else {
>   throw new SessionTimeoutException("Timeout exception");
> }
>
> try {
>      return snmp.send(pdu, target);
> } catch (IOException ex) {
>   ....
> }
> ------------------------------------------------

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list