[SNMP4J] null in authPassPhrase..even though initialized user to "authUser"

Rajesh Reddy rajeshreddy at tataelxsi.co.in
Fri May 12 08:17:39 CEST 2006


Hi,

I have configured the agent simulator with

Username : authUser
ContextName :auth
Authpassword: authUser
Authprotocol :MD5
Priv protocol :null
priv pass:null


is the below code wrong for a get operation .
Please let me know the wrong step i have made with this.

import java.io.IOException;
import java.util.Vector;

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.mp.MessageProcessingModel;
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 snmpget
{
  private String ip;
  private Snmp snmp;
  private ScopedPDU request = null;
  private UserTarget uTarget;

  public static void main(String args[]){
  	snmpget get=new snmpget("10.9.10.158");
  	Vector v=get.get();
  	System.out.println("Received response");
  }

  public snmpget(String ipAddress)
  {
    this.ip = ipAddress;

    // simplified here
    OctetString securityName = new OctetString("authUser");
    OctetString authPassphrase = new OctetString("authUser");
   // OctetString privPassphrase = new OctetString("snmpPrivPassphrase");
    int timeout = Integer.parseInt("1000");
    int version = Integer.parseInt("3");

    OID authProtocol = AuthMD5.ID;
    OID privProtocol = PrivDES.ID;
    int retries = 1;
    int pduType = PDU.GET;

    uTarget = new UserTarget();
    uTarget.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
    uTarget.setSecurityName(securityName);
    uTarget.setVersion(version);
    uTarget.setRetries(retries);
    uTarget.setTimeout(timeout);
    uTarget.setAddress(new UdpAddress(ipAddress + "/8001"));

    request = new ScopedPDU();
    request.setType(pduType);
    request.setContextName(new OctetString("auth"));
    request.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.1.0")));
    DefaultUdpTransportMapping dutm = null;
    try
    {
      dutm = new DefaultUdpTransportMapping();
    } catch (IOException e)
    {
      e.printStackTrace();
    }

    dutm.setAsyncMsgProcessingSupported(false);
    TransportMapping transport = dutm;
    snmp = new Snmp(transport);
    USM usm = new USM(SecurityProtocols.getInstance(), new
    OctetString(((MPv3)
snmp.getMessageProcessingModel(MessageProcessingModel.MPv3)).createLocalEngi
neID()),0);
    SecurityModels.getInstance().addSecurityModel(usm);
    snmp.getUSM().addUser(securityName,
        new UsmUser(securityName, authProtocol, authPassphrase,null, null));
    try
    {
      snmp.listen();
    } catch (IOException e1)
    {
      e1.printStackTrace();
    }
  }
  public Vector get()
  {
    PDU response = null;
    try
    {
      response = snmp.sendPDU(request, uTarget);
    } catch (Exception e)
    {
      e.printStackTrace();
    }

    if (response == null)
    {
      // timeout case
      return null;
    } else if (response.getType() == PDU.REPORT)
    { System.out.println(response.get(0));
      // There is an error message from the device
      System.out.print("error from host: " + ip);
      return null;
    } else
    {
      return response.getVariableBindings();
    } // if response

  }

  protected void finalize() throws Throwable
  {
    snmp.close();
    super.finalize();
  }

}



i am getting the output as 1.3.6.1.6.3.15.1.1.3.0 = 187
(unknown user)

Regards,
Rajesh.





-----Original Message-----
From: Frank Fock [mailto:fock at agentpp.com]
Sent: Friday, May 12, 2006 4:55 AM
To: Rajesh Reddy
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] null in authPassPhrase..even though initialized
user to "authUser"


Hi Rajesh,

The behavior is intended. The returned UsmUserEntry
represents a localized user. Therefore the contained
UsmUser class does not contain any passphrases.

Why do you think that you need any help here?
In other words, what are you trying to accomplish?

Best regards,
Frank

Rajesh Reddy wrote:
> Hi,
>
> I am getting null while displaying the UsmUSer object in the
authPassPhrase
> and PrivPassPhrase..
>
> please see the sample code
>
> TransportMapping transport = new DefaultUdpTransportMapping();
>      Snmp snmp = new Snmp(transport);
>      byte[] b=MPv3.createLocalEngineID();
>      MPv3 mpv3 =
>
(MPv3)snmp.getMessageProcessingModel(MessageProcessingModel.MPv3);
>
> USM usm = new USM(mpv3.getSecurityProtocols().getInstance(),
>                 new OctetString(b), 1);
>
>      SecurityModels.getInstance().addSecurityModel(usm);
>
> UsmUser user1=new UsmUser(new OctetString("privUser"),
>           AuthMD5.ID,
>           new OctetString("authUser".getBytes()),
>           PrivDES.ID,
>           new OctetString("privUser")
>     );
>
>      System.out.println("passphrase:"+user1.getPrivacyPassphrase());
> //////Output:passphrase:privUser
>
>      snmp.getUSM().addUser(new OctetString("privUser"),user1);
> System.out.println(snmp.getUSM().getUser(new OctetString(b),new
> OctetString("privUser")));
> /////Output:
>
UsmUserEntry[userName=privUser,usmUser=UsmUser[secName=privUser,authProtocol
>
=1.3.6.1.6.3.10.1.1.2,authPassphrase=null,privProtocol=1.3.6.1.6.3.10.1.2.2,
> privPassphrase=null]]
>
> UsmUserEntry user=snmp.getUSM().getUser(new OctetString(b),new
> OctetString("privUser"));
>
> UsmUser user2=user.getUsmUser();
> System.out.println("pass:"+user2.getPrivacyPassphrase());  /////////Output
> is :        pass:null
>
>
> Help me to get out of it
> Thanks in Advance
>
> regards,
> Rajesh.
>
>
> ------------------------------------------------------------------------
>
> The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)and
may contain confidential or privileged information. If you are not the
intended recipient, please notify the sender or
administrator at tataelxsi.co.in
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

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

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender or administrator at tataelxsi.co.in



More information about the SNMP4J mailing list