org.snmp4j.security
Class AuthGeneric

java.lang.Object
  extended by org.snmp4j.security.AuthGeneric
All Implemented Interfaces:
java.io.Serializable, AuthenticationProtocol, SecurityProtocol
Direct Known Subclasses:
AuthMD5, AuthSHA

public abstract class AuthGeneric
extends java.lang.Object
implements AuthenticationProtocol

The abstract class AuthGeneric implements common operations for SNMP authentication protocols, such as MD5 and SHA.

Version:
1.0
Author:
Jochen Katz & Frank Fock
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.snmp4j.security.AuthenticationProtocol
MESSAGE_AUTHENTICATION_CODE_LENGTH
 
Constructor Summary
AuthGeneric(java.lang.String protoName, int digestLength)
           
 
Method Summary
 boolean authenticate(byte[] authenticationKey, byte[] message, int messageOffset, int messageLength, ByteArrayWindow digest)
          Authenticates an outgoing message.
 byte[] changeDelta(byte[] oldKey, byte[] newKey, byte[] random)
          Computes the delta digest needed to remotely change an user's authenitcation key.
 int getDigestLength()
          Gets the length of the digest generated by this authentication protocol.
protected  java.security.MessageDigest getDigestObject()
          Get a fresh MessageDigest object of the Algorithm specified in the constructor.
 byte[] hash(byte[] data)
          Generates a hash value for the given data.
 byte[] hash(byte[] data, int offset, int length)
          Generates a hash value for the given data.
 boolean isAuthentic(byte[] authenticationKey, byte[] message, int messageOffset, int messageLength, ByteArrayWindow digest)
          Authenticates an incoming message.
 byte[] passwordToKey(OctetString passwordString, byte[] engineID)
          Generates the localized key for the given password and engine id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.snmp4j.security.AuthenticationProtocol
getID
 

Constructor Detail

AuthGeneric

public AuthGeneric(java.lang.String protoName,
                   int digestLength)
Method Detail

getDigestLength

public int getDigestLength()
Description copied from interface: AuthenticationProtocol
Gets the length of the digest generated by this authentication protocol. This value can be used to compute the BER encoded length of the security parameters for authentication.

Specified by:
getDigestLength in interface AuthenticationProtocol
Returns:
the number of bytes of digests generated by this authentication procotol.

getDigestObject

protected java.security.MessageDigest getDigestObject()
Get a fresh MessageDigest object of the Algorithm specified in the constructor.

Returns:
a new, fresh Message Digest object.

authenticate

public boolean authenticate(byte[] authenticationKey,
                            byte[] message,
                            int messageOffset,
                            int messageLength,
                            ByteArrayWindow digest)
Description copied from interface: AuthenticationProtocol
Authenticates an outgoing message. This method fills the authentication parameters field of the given message. The parameter digestOffset offset is pointing inside the message buffer and must be zeroed before the authentication value is computed.

Specified by:
authenticate in interface AuthenticationProtocol
Parameters:
authenticationKey - the authentication key to be used for authenticating the message.
message - the entire message for which the digest should be determined.
messageOffset - the offset in message where the message actually starts.
messageLength - the actual message length (may be smaller than message.length).
digest - the offset in message where to store the digest.
Returns:
true if the message digest has been successfully computed and set, false otherwise.

isAuthentic

public boolean isAuthentic(byte[] authenticationKey,
                           byte[] message,
                           int messageOffset,
                           int messageLength,
                           ByteArrayWindow digest)
Description copied from interface: AuthenticationProtocol
Authenticates an incoming message. This method checks if the value in the authentication parameters field of the message is valid. The following procedure is used to verify the authenitcation value

Specified by:
isAuthentic in interface AuthenticationProtocol
Parameters:
authenticationKey - the authentication key to be used for authenticating the message.
message - the entire message for which the digest should be determined.
messageOffset - the offset in message where the message actually starts.
messageLength - the actual message length (may be smaller than message.length).
digest - the digest of the message.
Returns:
true if the message is authentic, false otherwise.

changeDelta

public byte[] changeDelta(byte[] oldKey,
                          byte[] newKey,
                          byte[] random)
Description copied from interface: AuthenticationProtocol
Computes the delta digest needed to remotely change an user's authenitcation key. The length of the old key (e.g. 16 for MD5, 20 for SHA) must match the length of the new key.

Specified by:
changeDelta in interface AuthenticationProtocol
Parameters:
oldKey - the old authentication/privacy key.
newKey - the new authentication/privacy key.
random - the random 'seed' to be used to produce the digest.
Returns:
the byte array representing the delta for key change operations. To obtain the key change value, append this delta to the random array.

passwordToKey

public byte[] passwordToKey(OctetString passwordString,
                            byte[] engineID)
Description copied from interface: AuthenticationProtocol
Generates the localized key for the given password and engine id.

Specified by:
passwordToKey in interface AuthenticationProtocol
Parameters:
passwordString - the authentication pass phrase.
engineID - the engine ID of the authoritative engine.
Returns:
the localized authentication key.

hash

public byte[] hash(byte[] data)
Description copied from interface: AuthenticationProtocol
Generates a hash value for the given data.

Specified by:
hash in interface AuthenticationProtocol
Parameters:
data - the data
Returns:
the generated hash.

hash

public byte[] hash(byte[] data,
                   int offset,
                   int length)
Description copied from interface: AuthenticationProtocol
Generates a hash value for the given data.

Specified by:
hash in interface AuthenticationProtocol
Parameters:
data - the data
offset - offset into data
length - length of data to hash
Returns:
the generated hash.

Copyright 2005-2010 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.