com.adventnet.snmp.snmp2
Class SecurityModelEntry

java.lang.Object
  extended by com.adventnet.snmp.snmp2.SecurityModelEntry
Direct Known Subclasses:
SnmpCommunityEntry, USMUserEntry

public abstract class SecurityModelEntry
extends java.lang.Object

This is an abstract class which is used to define a new security model. API users should extend this class to implement their own security model. This class has a security model number, a model independent securityName, a model dependent securityID and the securityLevel of the model independent securityName. This class has to be extended to provide the securityModel specific parameters (In case of the USM, the parameters are engineID, engineBoots, engineTime, authentication and privacy parameters). In addition this class also has the abstract methods to encode/decode the messageSecurityParameters and authenticate the message to be sent/received.

To implement a securityModel, the securityModel has to be registered with the securityProvider. And it is for this purpose a security provider class is given.

See Also:
SecurityProvider

Constructor Summary
SecurityModelEntry()
           
 
Method Summary
abstract  void authenticateMessageToSend(Snmp3Message msg, SnmpSession session)
          Prepares the outgoing message as per security model and message security level etc.
abstract  int authenticateReceivedMessage(Snmp3Message msg, SnmpSession session)
          Performs authentication of the received message as per the security model.
abstract  SecurityModelEntry copy()
          This returns the copy of this Security Entry object.
abstract  void decodeMsgSecurityParams(Snmp3Message msg, SnmpSession session, ASN1Parser parser)
          This method will decode the securityModel dependent security parameters.
abstract  byte[] decrypt(byte[] data, int offset, byte[] key, int protocol, byte[] privParams)
          This method is called to decrypt the data.
abstract  boolean encodeMsgSecurityParams(Snmp3Message msg, SnmpAPI API, ASN1Parser asnParser)
          This method will encode the securityModel dependent security parameters.
abstract  int encrypt(byte[] data, int spaceLeft, byte[] key, int protocol, byte[] privParams)
          This method is called to encrypt the data.
abstract  byte[] getEngineID()
          Returns the engineID of this SnmpEngine.
abstract  java.lang.Object getKey()
          Returns an Object which is interpretted as a key to uniquely identify this entry in the SecurityModelTable.
abstract  byte[] getSecurityID(byte[] securityName)
          Returns a security model dependent securityID, using the security model independent security name.
abstract  byte getSecurityLevel()
          Returns the security level associated with this securityEntry.
abstract  int getSecurityModel()
          Returns the security model.
abstract  byte[] getSecurityName()
          Returns the security model independent security name.
abstract  byte[] getSecurityName(byte[] securityID)
          Returns a security model independent security name, using the security model dependent securityID.
abstract  void init(SnmpSession session, ProtocolOptions po)
           
abstract  void processEncodedMsg(Snmp3Message msg, ASN1Parser parser)
          This method is called after encoding the message version.
abstract  void setSecurityLevel(byte level)
          Sets the security level associated with this securityEntry.
abstract  void setSecurityName(byte[] name)
          Sets the security name by taking in the security model independent security name as the argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecurityModelEntry

public SecurityModelEntry()
Method Detail

getSecurityModel

public abstract int getSecurityModel()
Returns the security model.


getEngineID

public abstract byte[] getEngineID()
Returns the engineID of this SnmpEngine.


getSecurityName

public abstract byte[] getSecurityName()
Returns the security model independent security name.


getSecurityName

public abstract byte[] getSecurityName(byte[] securityID)
Returns a security model independent security name, using the security model dependent securityID.


getSecurityID

public abstract byte[] getSecurityID(byte[] securityName)
Returns a security model dependent securityID, using the security model independent security name.


setSecurityName

public abstract void setSecurityName(byte[] name)
Sets the security name by taking in the security model independent security name as the argument. The model dependent securityID should also be set as a result of this operation.


getSecurityLevel

public abstract byte getSecurityLevel()
Returns the security level associated with this securityEntry.


setSecurityLevel

public abstract void setSecurityLevel(byte level)
Sets the security level associated with this securityEntry.


getKey

public abstract java.lang.Object getKey()
Returns an Object which is interpretted as a key to uniquely identify this entry in the SecurityModelTable. Generally the returned Object is a function of the index values in the MIB which defines the security model.


authenticateReceivedMessage

public abstract int authenticateReceivedMessage(Snmp3Message msg,
                                                SnmpSession session)
Performs authentication of the received message as per the security model. The authenticateReceivedMessage of the security Model will actually check whether the received message is any of the following ones ,such as 1. Discovery or timeSysnc message and respond appropriately. 2. Response to a discovery or timeSync message. i.e discovery/timeSync report message. It will update the security info. 3. Response to an SNMP request. Here it will authenticate the message. The SnmpSession is also passed so that if this module requires the message to be replied(e.g respond to a discovery/timeSync) appropriately.

Parameters:
msg - The Smp3Message instance.
session - The SnmpSession instance, incase this module requires to reply appropriately.
Returns:
The approptiate negative value in case the authentication fails and a positive value if it is successful. Returns 0 if authentication is successful and pdu is stored in the queue. Returns 1 if authentication is successful and no need to queue the pdu.

authenticateMessageToSend

public abstract void authenticateMessageToSend(Snmp3Message msg,
                                               SnmpSession session)
                                        throws SnmpException
Prepares the outgoing message as per security model and message security level etc. This method is called on the SecurityModelEntry instance of Snmp3Message before emcoding the PDU. This method will fill up the security parameters in the securityModelEntry to prepare for an outgoing message.

Parameters:
msg - The Snmp3Message instance.
session - The SnmpSession instance.
Throws:
SnmpException - If the message could not be authenticated properly or the particular entry is not available.

copy

public abstract SecurityModelEntry copy()
This returns the copy of this Security Entry object.


encodeMsgSecurityParams

public abstract boolean encodeMsgSecurityParams(Snmp3Message msg,
                                                SnmpAPI API,
                                                ASN1Parser asnParser)
This method will encode the securityModel dependent security parameters. This will encode the message security params. The message security params is security model independent and hence the securityModelEntry should take of this. It will also encrypt the scoped pdu if it is an authpriv user. This method should also set the message flags in Snmp3Message.

Parameters:
msg - The Snmp3Message instance.
API - The SnmpAPI Instance.
asnParser - The reference to ASN1Parser which has the methods to encode the SnmpPDU.

decodeMsgSecurityParams

public abstract void decodeMsgSecurityParams(Snmp3Message msg,
                                             SnmpSession session,
                                             ASN1Parser parser)
                                      throws SnmpException,
                                             java.lang.ArrayIndexOutOfBoundsException
This method will decode the securityModel dependent security parameters. The msgSecurityParameters are securityModel dependent. i.e the engineID, boots time, auth and priv params used in USM may not be used in other securityModels. This method will also have to decrypt if a message with privacy is received. This method is called by the securityModelEntry instance of Snmp3Mesage. While decoding, the API user will have to set the security parameters in this securityModelEntry.

Parameters:
msg - The Snmp3Message instance.
asnParser - The reference to ASN1Parser which has the data and methods to encode/decode the SnmpPDU.
Throws:
SnmpException - If the security parameters could not be decoded properly.
java.lang.ArrayIndexOutOfBoundsException - If an unrecognized snmp message

processEncodedMsg

public abstract void processEncodedMsg(Snmp3Message msg,
                                       ASN1Parser parser)
This method is called after encoding the message version. It is useful when the API user needs to calculate the digest over the message. Eg. in the USM, the message authentication parameters (authParams) need to be calculated over the entire message. This method is called on the SecurityModelEntry instance of Snmp3Mesage.

Parameters:
msg - Snmp3Messgage instance.
asnParser - The reference to ASN1Parser which has the encoded data and methods to encode the SnmpPDU.

encrypt

public abstract int encrypt(byte[] data,
                            int spaceLeft,
                            byte[] key,
                            int protocol,
                            byte[] privParams)
                     throws SnmpException
This method is called to encrypt the data.

Parameters:
data - The data to be encrypt.
spaceleft - The space left in the buffer while encoding.
key - The key value used in encryption.
protocol - The protocol used for encryption.
privParams - The privacy params used in encryption.
Throws:
SnmpException

decrypt

public abstract byte[] decrypt(byte[] data,
                               int offset,
                               byte[] key,
                               int protocol,
                               byte[] privParams)
This method is called to decrypt the data.

Parameters:
data - The data to be decrypt.
offset - The offset value to be used in decrypt.
key - The key value to be used in decryption.
protocol - The protocol used for decryption.
privParams - The privacy params used in decryption.
Returns:
data The decrypted data.

init

public abstract void init(SnmpSession session,
                          ProtocolOptions po)
                   throws SnmpException
Throws:
SnmpException