|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.adventnet.snmp.snmp2.usm.USMUtils
This class provides general USM related methods. All the methods in this class are static. There is no need to instantiate this class. The methods include password to key conversion, digest authentication keyChange routines. The init_v3_params provide a simple interface to set up a user configuration for communicating with a v3 entity.
| Field Summary | |
(package private) static java.util.Stack[] |
freePool
|
(package private) static int |
PASS_KEY_LENGTH
|
(package private) static java.util.Random |
rand
|
(package private) static java.lang.String[] |
securityLevels
|
| Constructor Summary | |
(package private) |
USMUtils()
|
| Method Summary | |
(package private) static void |
|
(package private) static void |
|
(package private) static void |
|
(package private) static boolean |
checkDigest(int authProtocol,
byte[] authKey,
byte[] data,
int authPos,
byte[] authParms)
Verifies the pdu digest |
(package private) static void |
debugLogging(java.lang.String methodName,
java.lang.String className,
java.lang.String debugStr)
|
(package private) static byte[] |
decrypt(byte[] data,
int offset,
byte[] key,
int protocol,
byte[] privParams,
int eb,
int et)
|
(package private) static int |
encrypt(byte[] data,
int offset,
byte[] key,
int privProtocol,
byte[] privParms,
int eb,
int et)
|
(package private) static int |
encrypt(byte[] data,
int offset,
byte[] key,
int privProtocol,
byte[] privParams,
int eb,
int et,
boolean DEBUG)
|
(package private) static void |
freeDigestImpl(int algo,
java.security.MessageDigest md)
|
(package private) static byte[] |
genSalt()
|
(package private) static byte[] |
getbyteArray(int i)
|
(package private) static byte[] |
getCryptKey(byte[] privateKey)
|
static byte[] |
getDigest(int authProtocol,
byte[] authKey,
byte[] data)
Returns the USMUserEntry.MD5_AUTH or USMUserEntry.SHA_AUTH Digest. |
static java.security.MessageDigest |
getDigestImpl(int algorithm)
Returns the MessageDigest Implementation. |
static int |
getHashLength(int protocol)
Returns the length of the hash associated with the protocol. |
(package private) static byte[] |
getIV(byte[] preIV,
byte[] salt)
|
(package private) static byte[] |
getIVForAES(byte[] eb,
byte[] et,
byte[] salt)
|
(package private) static int |
getJavaMajorVersion()
|
(package private) static int |
getJavaMinorVersion()
|
static byte[] |
getKey(int authProtocol,
boolean isFixedLen,
int keyLength,
int hashLength,
byte[] keyChange,
byte[] keyOld,
byte[] random)
Gives the new key corresponding to the keyChange value provided |
static java.lang.Object |
getKey(java.lang.String name,
int port,
byte[] userName)
Retrieves the Hash key associated with the given host, port and userName. |
static byte[] |
getKeyChange(int authProtocol,
boolean isFixedLen,
int keyLength,
int hashLength,
byte[] keyNew,
byte[] keyOld,
byte[] random)
Returns the keyChange value required for a key change operation. |
static int |
getKeyLength(int protocol)
Returns the key Length associated with the protocol |
(package private) static byte[] |
getpreIV(byte[] privateKey)
|
(package private) static byte[] |
getStoredPassword(byte[] encPass)
|
(package private) static int[] |
getUsmEntryOid(byte[] user,
byte[] id,
int col)
|
static void |
init_v3_parameters(java.lang.String userName,
byte[] engineID,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
ProtocolOptions po,
SnmpSession session,
boolean validateUser)
A comprehensive initialisation routine that creates new SNMPv3 user entries and performs time synchronization. |
static void |
init_v3_parameters(java.lang.String userName,
byte[] engineID,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
ProtocolOptions po,
SnmpSession session,
boolean validateUser,
int privProtocol)
|
static void |
init_v3_parameters(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String targetHost,
int port,
SnmpSession session)
A comprehensive initialization routine that creates new SnmpV3 entities and user entries and performs discovery and time synchronization. |
static void |
init_v3_parameters(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String engineName,
SnmpSession session)
A comprehensive initialization routine that creates new SnmpV3 entities and user entries and performs discovery and time synchronization. |
static void |
init_v3_params(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String targetHost,
int port,
SnmpSession session)
Deprecated. This method doesn't throw any Exception and hence doesn't inform the user, in case of any error. As of AdventNet SNMP API 4 SP2 ( Release 4.0.2 ), replaced by init_v3_parameters(String,int,String,String,String,int,SnmpSession) |
static void |
init_v3_params(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String engineName,
SnmpSession session)
Deprecated. This method doesn't throw any Exception and hence doesn't inform the user, in case of any error. As of AdventNet SNMP API 4 SP2 ( Release 4.0.2 ), replaced by init_v3_parameters(String,int,String,String,String,SnmpSession) |
(package private) static boolean |
isDebugLog(int level)
|
(package private) static boolean |
isPerformanceLog(int level)
|
(package private) static void |
logErrorMessage(java.lang.String error)
This method will log the message in the LogManager through the static "logErrorMessage(String)" method present in the LogManager class. |
(package private) static void |
logInfoMessage(java.lang.String info)
This method will log the message in the LogManager through the static "logInfoMessage(String)" method present in the LogManager class. |
(package private) static void |
logMessage(java.lang.String message)
This method will log the message in the LogManager through the static "logMessage(String)" method present in the LogManager class. |
(package private) static void |
logMessage(java.lang.String message,
int id)
This method will log the message in the LogManager through the static "logMessage(String, int)" method present in the LogManager class. |
static byte[] |
password_to_key(int authProtocol,
byte[] password,
int passwordlen,
byte[] id)
The password to key implementation. |
(package private) static void |
performanceLogging(java.lang.String methodName,
java.lang.String className,
long timeDiff)
|
static java.lang.String |
printOctets(byte[] data,
int length)
Prints the octet data in a more readable form. |
(package private) static void |
signPdu(int authProtocol,
byte[] authKey,
byte[] data,
int authPos)
Generates the digest and inserts it at the authPos specified. |
(package private) static byte[] |
storePassword(byte[] pass,
byte[] key,
boolean decodeFlag)
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
static java.lang.String[] securityLevels
static java.util.Stack[] freePool
static java.util.Random rand
static int PASS_KEY_LENGTH
| Constructor Detail |
USMUtils()
| Method Detail |
static void()
static int getJavaMajorVersion()
static int getJavaMinorVersion()
public static byte[] password_to_key(int authProtocol,
byte[] password,
int passwordlen,
byte[] id)
authProtocol - The authentication protocol. Right now only
MD5 and SHA is supported.password - The password to be used for converting to the
localized key.passwordlen - The length of the password.id - The engineID to be used for converting to the localized key.
static void signPdu(int authProtocol,
byte[] authKey,
byte[] data,
int authPos)
authProtocol - the authentication protocol to be used. Either
of MD5_AUTH,SHA,AUTH.authKey - the authentication key.data - the data to be signed.authPos - the position at which the digest needs
to be inserted.
static boolean checkDigest(int authProtocol,
byte[] authKey,
byte[] data,
int authPos,
byte[] authParms)
authProtocol - the authentication protocol to be used. Either
of MD5_AUTH,SHA,AUTH.authKey - the authentication key.data - the data to be signed.authPos - the position at which the digest is to start.authParams - the authentication digest to be compared to.static void()
public static java.security.MessageDigest getDigestImpl(int algorithm)
throws java.security.NoSuchAlgorithmException
algorithm - The protocol to be used. Right now it is only
MD5 or SHA.
static void freeDigestImpl(int algo,
java.security.MessageDigest md)
static void()
public static byte[] getKeyChange(int authProtocol,
boolean isFixedLen,
int keyLength,
int hashLength,
byte[] keyNew,
byte[] keyOld,
byte[] random)
authProtocol - The authentication scheme. USMUserEntry.MD5_AUTH or USMUserEntry.SHA_AUTHisFixedLen - fixed/variable. Both MD5 & SHA have fixed secret key length.keyLength - 16 for MD5 and 20 for SHA. This will be 16 for CBC-DES.hashLength - 16 for MD5 and 20 for SHA.
public static byte[] getKey(int authProtocol,
boolean isFixedLen,
int keyLength,
int hashLength,
byte[] keyChange,
byte[] keyOld,
byte[] random)
authProtocol - the authentication protocol.isFixedLen - indicates whether the length of the key is fixed
for the protocol. true for both MD5 and SHA.keyLength - the length of the key associated with this protocol.hashLength - the length of the hash associated with the protocol.keyChange - the key change value.keyOld - the original key value.
public static java.lang.String printOctets(byte[] data,
int length)
data - the byte array representing the data to be printed.length - the number of bytes of data to be printed in hex format.
public static byte[] getDigest(int authProtocol,
byte[] authKey,
byte[] data)
authProtocol - The authentication protocol. Right now only MD5
and SHA is supported.authKey - The localized authentication key.data - The pdu data over which the digest is to be computed.
static int[] getUsmEntryOid(byte[] user,
byte[] id,
int col)
public static int getKeyLength(int protocol)
public static int getHashLength(int protocol)
static int encrypt(byte[] data,
int offset,
byte[] key,
int privProtocol,
byte[] privParms,
int eb,
int et)
throws SnmpException
static int encrypt(byte[] data,
int offset,
byte[] key,
int privProtocol,
byte[] privParams,
int eb,
int et,
boolean DEBUG)
throws SnmpException
static byte[] getCryptKey(byte[] privateKey)
static byte[] getpreIV(byte[] privateKey)
static byte[] genSalt()
static byte[] getIV(byte[] preIV,
byte[] salt)
static byte[] decrypt(byte[] data,
int offset,
byte[] key,
int protocol,
byte[] privParams,
int eb,
int et)
public static void init_v3_params(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String targetHost,
int port,
SnmpSession session)
init_v3_parameters(String,int,String,String,String,int,SnmpSession)
userName - The string representing the SnmpV3 principal.authProtocol - The authentication protocol. Should be one of
the constants, MD5_AUTH, SHA_AUTH or NO_AUTH. These constants are
defined in USMUserEntry.authPassword - The authentication password, which is converted
to a localized key.privPassword - The privacy password, which is converted into a
localized private key. The only supported protocol is CBC_DES.targetHost - The hostName of the SNMP peer.port - The port of the SNMP peer.session - The SnmpSession instance. This should be in an open
state. The discovery and timeSync messages are sent over this session.
public static void init_v3_parameters(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String targetHost,
int port,
SnmpSession session)
throws SnmpException
userName - The string representing the SnmpV3 principal.authProtocol - The authentication protocol. Should be one of
the constants, MD5_AUTH, SHA_AUTH or NO_AUTH. These constants are
defined in USMUserEntry.authPassword - The authentication password which is converted
to a localized key.privPassword - The privacy password which is converted into a
localized private key. The only supported protocol is CBC_DES.targetHost - The hostName of the SNMP peer.port - The port of the SNMP peer.session - The SnmpSession instance. This should be in an open
state. The discovery and timeSync messages are sent over this session.
public static void init_v3_parameters(java.lang.String userName,
byte[] engineID,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
ProtocolOptions po,
SnmpSession session,
boolean validateUser)
throws SnmpException
After this method is called successfully ( without any exception ) with a proper engineID as the argument, then a valid USMUserEntry will be added to the USMUserTable and no entry will be added to the SnmpEngineTable. Thus whenever an SNMPv3 request is sent for this particular agent, this engineID should be specified in the request using the setEngineID method.
userName - The string representing the SnmpV3 principal.engineID - The engineID of the remote SNMPv3 entity ( the agent ).authProtocol - The authentication protocol. Should be one of
the constants, MD5_AUTH, SHA_AUTH or NO_AUTH. These constants are
defined in USMUserEntry.authPassword - The authentication password which is converted
to a localized key.privPassword - The privacy password which is converted into a
localized private key.po - The ProtocolOptions instance.session - The SnmpSession instance. This should be in open
state. The discovery and timeSync messages are sent over this session.validateUser - The boolean value. If this value is set to true,
and if this method is called for an
public static void init_v3_params(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String engineName,
SnmpSession session)
init_v3_parameters(String,int,String,String,String,SnmpSession)
userName - The string representing the SnmpV3 principal.authProtocol - The authentication protocol. Should be one of
the constants, MD5_AUTH, SHA_AUTH or NO_AUTH. These constants are
defined in USMUserEntry.authPassword - The authentication password which is converted
to a localized key.privPassword - The privacy password which is converted into a
localized private key. The only supported protocol is CBC_DES.engineName - The string value of the engine entry.session - The SnmpSession instance. This should be in an open
state. The discovery and timeSync messages are sent over this session.
public static void init_v3_parameters(java.lang.String userName,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
java.lang.String engineName,
SnmpSession session)
throws SnmpException
static byte[] storePassword(byte[] pass,
byte[] key,
boolean decodeFlag)
static byte[] getStoredPassword(byte[] encPass)
public static java.lang.Object getKey(java.lang.String name,
int port,
byte[] userName)
name - hostName or engineName for UDP/IP or Independent Transport
Protocol respectively.port - the remotePort. -1 in the case of Independent Transport Protocol.userName - the UserName set in the case of v3.static void logMessage(java.lang.String message)
static void logMessage(java.lang.String message,
int id)
static void logInfoMessage(java.lang.String info)
static void logErrorMessage(java.lang.String error)
static void performanceLogging(java.lang.String methodName,
java.lang.String className,
long timeDiff)
static void debugLogging(java.lang.String methodName,
java.lang.String className,
java.lang.String debugStr)
static boolean isPerformanceLog(int level)
static boolean isDebugLog(int level)
public static void init_v3_parameters(java.lang.String userName,
byte[] engineID,
int authProtocol,
java.lang.String authPassword,
java.lang.String privPassword,
ProtocolOptions po,
SnmpSession session,
boolean validateUser,
int privProtocol)
throws SnmpException
static byte[] getIVForAES(byte[] eb,
byte[] et,
byte[] salt)
static byte[] getbyteArray(int i)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||