Package org.snmp4j.security
Class AuthGeneric
java.lang.Object
org.snmp4j.security.AuthGeneric
- All Implemented Interfaces:
 Serializable,AuthenticationProtocol,SecurityProtocol
The abstract class AuthGeneric implements common operations for SNMP authentication protocols, such as MD5 and SHA.
- Version:
 - 1.0
 - Author:
 - Frank Fock, Jochen Katz
 - See Also:
 
- 
Field Summary
Fields - 
Constructor Summary
ConstructorsConstructorDescriptionAuthGeneric(String protoName, int digestLength) Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length.AuthGeneric(String protoName, int digestLength, int authenticationCodeLength) Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length.AuthGeneric(String protoName, int digestLength, int authenticationCodeLength, int hmacBlockSize) Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanauthenticate(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.intThe length of the authentication code (the hashing output length) in octets.intGets the length of the message digest used by this authentication protocol.protected MessageDigestGet a fresh MessageDigest object of the Algorithm specified in the constructor.intGet the maximum length of the key in bytes for this security protocol.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.booleanisAuthentic(byte[] authenticationKey, byte[] message, int messageOffset, int messageLength, ByteArrayWindow digest) Authenticates an incoming message.booleanChecks whether this security protocol is actually supported by this Java runtime environment.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, waitMethods inherited from interface org.snmp4j.security.AuthenticationProtocol
getID 
- 
Field Details
- 
HMAC_BLOCK_SIZE
public static int HMAC_BLOCK_SIZE - 
hmacBlockSize
protected int hmacBlockSize 
 - 
 - 
Constructor Details
- 
AuthGeneric
Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length.- Parameters:
 protoName- the name (ID) of the authentication protocol. Only names that are supported by the used security provider can be used.digestLength- the digest length.
 - 
AuthGeneric
Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length.- Parameters:
 protoName- the name (ID) of the authentication protocol. Only names that are supported by the used security provider can be used.digestLength- the digest length.authenticationCodeLength- the length of the hash output (i.e., the authentication code length).- Since:
 - 2.4.0
 
 - 
AuthGeneric
public AuthGeneric(String protoName, int digestLength, int authenticationCodeLength, int hmacBlockSize) Creates an authentication protocol with the specified name (ID) and digest length and using theDEFAULT_AUTHENTICATION_CODE_LENGTHdefault code length.- Parameters:
 protoName- the name (ID) of the authentication protocol. Only names that are supported by the used security provider can be used.digestLength- the digest length.authenticationCodeLength- the length of the hash output (i.e., the authentication code length).hmacBlockSize- the HMAC block size of the authentication protocol.- Since:
 - 2.5.4
 
 
 - 
 - 
Method Details
- 
getDigestLength
public int getDigestLength()Gets the length of the message digest used by this authentication protocol.- Specified by:
 getDigestLengthin interfaceAuthenticationProtocol- Returns:
 - the number of octets in the digest.
 
 - 
getMaxKeyLength
public int getMaxKeyLength()Description copied from interface:SecurityProtocolGet the maximum length of the key in bytes for this security protocol.- Specified by:
 getMaxKeyLengthin interfaceSecurityProtocol- Returns:
 - the (maximum) length of the security protocols key.
 
 - 
getAuthenticationCodeLength
public int getAuthenticationCodeLength()The length of the authentication code (the hashing output length) in octets.- Specified by:
 getAuthenticationCodeLengthin interfaceAuthenticationProtocol- Returns:
 - the length of the authentication code.
 - Since:
 - 2.4.0
 
 - 
getDigestObject
Get a fresh MessageDigest object of the Algorithm specified in the constructor.- Returns:
 - a new, fresh Message Digest object.
 
 - 
isSupported
public boolean isSupported()Description copied from interface:SecurityProtocolChecks whether this security protocol is actually supported by this Java runtime environment.- Specified by:
 isSupportedin interfaceSecurityProtocol- Returns:
 trueif this security protocol is supported,falseotherwise.
 - 
authenticate
public boolean authenticate(byte[] authenticationKey, byte[] message, int messageOffset, int messageLength, ByteArrayWindow digest) Description copied from interface:AuthenticationProtocolAuthenticates an outgoing message. This method fills the authentication parameters field of the given message. The parameterdigestOffsetoffset is pointing inside the message buffer and must be zeroed before the authentication value is computed.- Specified by:
 authenticatein interfaceAuthenticationProtocol- 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 inmessagewhere the message actually starts.messageLength- the actual message length (may be smaller thanmessage.length).digest- the offset inmessagewhere to store the digest.- Returns:
 trueif the message digest has been successfully computed and set,falseotherwise.
 - 
isAuthentic
public boolean isAuthentic(byte[] authenticationKey, byte[] message, int messageOffset, int messageLength, ByteArrayWindow digest) Description copied from interface:AuthenticationProtocolAuthenticates 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- copy the authentication value to a temp buffer
 - zero the auth field
 - recalculate the authenthication value
 - compare the two authentcation values
 - write back the received authentication value
 
- Specified by:
 isAuthenticin interfaceAuthenticationProtocol- 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 inmessagewhere the message actually starts.messageLength- the actual message length (may be smaller thanmessage.length).digest- the digest of themessage.- Returns:
 trueif the message is authentic,falseotherwise.
 - 
changeDelta
public byte[] changeDelta(byte[] oldKey, byte[] newKey, byte[] random) Description copied from interface:AuthenticationProtocolComputes 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:
 changeDeltain interfaceAuthenticationProtocol- 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
   
randomarray. 
 - 
passwordToKey
Description copied from interface:AuthenticationProtocolGenerates the localized key for the given password and engine id.- Specified by:
 passwordToKeyin interfaceAuthenticationProtocol- 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:AuthenticationProtocolGenerates a hash value for the given data.- Specified by:
 hashin interfaceAuthenticationProtocol- Parameters:
 data- the data- Returns:
 - the generated hash.
 
 - 
hash
public byte[] hash(byte[] data, int offset, int length) Description copied from interface:AuthenticationProtocolGenerates a hash value for the given data.- Specified by:
 hashin interfaceAuthenticationProtocol- Parameters:
 data- the dataoffset- offset into datalength- length of data to hash- Returns:
 - the generated hash.
 
 
 -