[SNMP4J] Problem in KeyChange.

ravi kumar ravikumar1984 at gmail.com
Mon Dec 24 08:45:02 CET 2007


Hi Frank Fock,

 I just go through the API docs and write an application to genarate the
AuthKeyChange and privKeyChange value. But I facing
ArrayIndexoutOfBoundsException. Herewith I have attached the code snippet,
you help me to come out from this issue.

The exception I am facing is

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
        at org.snmp4j.security.AuthGeneric.changeDelta(Unknown Source)
        at KeyChangeManager.main(KeyChangeManager.java:51)

Your helps really appreciated.

Look forward your response.

  code snippet is :-

import java.io.*;
import java.util.*;
import org.snmp4j.*;
import org.snmp4j.smi.*;
import org.snmp4j.Snmp.*;
import org.snmp4j.security.*;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.Snmp;

public class KeyChangeManager
{
    public static void main(String args[])
    {
        OID authProtocol= AuthSHA.ID;
        OID privProtocol= PrivAES256.ID;
        String oldPass="maplesyrup";
        String newPass="newsyrup";

        //'00000000 00000000 00000002'H
        byte engineID[] = new byte[] {(byte)0x00, (byte)0x00 , (byte)0x00 ,
(byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00
, (byte)0x00 , (byte)0x00 , (byte)0x02};

        //'00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000'H
        byte random[] = new byte[] { (byte)0x00, (byte)0x00,
(byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };


               //'00000000 00000000 00000000 00000000 00000000 'H
        byte randomForAuth[] = new byte[] { (byte)0x00, (byte)0x00,
(byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00,(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };


        SecurityProtocols protocols = SecurityProtocols.getInstance();
               protocols.addDefaultProtocols();

               /********************** For AuthKey
*******************************/

              //Generate Localized keys.
        byte oldAuthkey[] = protocols.passwordToKey(authProtocol , new
OctetString(oldPass), engineID );
            byte newAuthkey[] = protocols.passwordToKey(authProtocol , new
OctetString(oldPass), engineID );

         // AuthKey Change.
            AuthSHA sha = new AuthSHA();
            byte keyChange[] = sha.changeDelta(oldAuthkey, newAuthkey,
randomForAuth);
                   System.out.println(" authkey Changeis " + new
OctetString( keyChange ).toHexString() );


           /******************* For PrivKey
*************************************/

        //Generate Localized keys.   - For privacy.
            byte oldPrivkey[] = protocols.passwordToKey(privProtocol,
authProtocol , new OctetString(oldPass), engineID );
            byte newPrivkey[] = protocols.passwordToKey(privProtocol,
authProtocol , new OctetString(oldPass), engineID );

         // PrivKey Change.
            byte privKeyChange[] = sha.changeDelta(oldPrivkey, newPrivkey,
random);
                   System.out.println(" privKeyChange is " + new
OctetString( privKeyChange ).toHexString() );

    }
}

Cheers
Ravi.


On Dec 23, 2007 1:05 AM, Frank Fock <fock at agentpp.com> wrote:

> Hi Ravi,
>
> SNMP4J of course supports key changes. See the passwordToKey
> and changeDelta methods of
>
> http://www.snmp4j.org/doc/org/snmp4j/security/AuthenticationProtocol.html
>
> For AES256 key expansion is needed, for convenience you can use
>
>
> http://www.snmp4j.org/doc/org/snmp4j/security/SecurityProtocols.html#passwordToKey(org.snmp4j.smi.OID<http://www.snmp4j.org/doc/org/snmp4j/security/SecurityProtocols.html#passwordToKey%28org.snmp4j.smi.OID>
> ,
> org.snmp4j.smi.OID, org.snmp4j.smi.OctetString, byte[])
>
> which does the key expansion for you according to the auth
> protocol you are using.
>
> Best regards,
> Frank
>
> ravi kumar wrote:
> > Hi,
> >
> >  Thanks for your response. I would like to know Snmp4j supports
> KeyChange
> > process. If so, I will use this one. Is there any help documentation or
> > examples are available?.
> >
> > Thanks
> > Ravi
> >
> > On Dec 22, 2007 5:34 AM, Eugene R. Snider <gene at cvtt.net> wrote:
> >
> >> Personally I think you should use the SNMP4j API since that will
> greatly
> >> improve the liklihood of getting support on the SNMP4j mailing list.
> >> Gene
> >>
> >> ravi kumar wrote:
> >>> Hi All,
> >>>
> >>>  I am using AdventNet SNMP API.
> >>>
> >>> ....
> >>> ---- Look forward your thoughts. ----------
> >>> Cheers
> >>> Ravikumar
> >>> _______________________________________________
> >>> SNMP4J mailing list
> >>> SNMP4J at agentpp.org
> >>> http://lists.agentpp.org/mailman/listinfo/snmp4j
> >>>
> > _______________________________________________
> > 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
>
>



More information about the SNMP4J mailing list