org.snmp4j.security
Class SecurityProtocols

java.lang.Object
  extended by org.snmp4j.security.SecurityProtocols
All Implemented Interfaces:
java.io.Serializable

public class SecurityProtocols
extends java.lang.Object
implements java.io.Serializable

The SecurityProtocols class holds all authentication and privacy protocols for a SNMP entity.

To register security protocols other than the default, set the system property SECURITY_PROTOCOLS_PROPERTIES to a customized version of the SecurityProtocols.properties file. The path has to be specified relatively to this class.

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

Field Summary
static java.lang.String SECURITY_PROTOCOLS_PROPERTIES
           
 
Constructor Summary
protected SecurityProtocols()
           
 
Method Summary
 void addAuthenticationProtocol(AuthenticationProtocol auth)
          Add the given AuthenticationProtocol.
 void addDefaultProtocols()
          Add the default SecurityProtocols.
 void addPrivacyProtocol(PrivacyProtocol priv)
          Add the given PrivacyProtocol.
 AuthenticationProtocol getAuthenticationProtocol(OID id)
          Get the AuthenticationProtocol with the given ID.
static SecurityProtocols getInstance()
          Get an instance of class SecurityProtocols.
 int getMaxAuthDigestLength()
          Gets the maximum authentication key length of the all known authentication protocols.
 int getMaxPrivDecryptParamsLength()
          Gets the maximum privacy key length of the currently known privacy protocols.
 PrivacyProtocol getPrivacyProtocol(OID id)
          Get the PrivacyProtocol with the given ID.
 byte[] passwordToKey(OID authProtocolID, OctetString passwordString, byte[] engineID)
          Generates the localized key for the given password and engine id for the authentication protocol specified by the supplied OID.
 byte[] passwordToKey(OID privProtocolID, OID authProtocolID, OctetString passwordString, byte[] engineID)
          Generates the localized key for the given password and engine id for the privacy protocol specified by the supplied OID.
 void removeAuthenticationProtocol(AuthenticationProtocol auth)
          Remove the given AuthenticationProtocol.
 void removePrivacyProtocol(PrivacyProtocol priv)
          Remove the given PrivacyProtocol.
static void setSecurityProtocols(SecurityProtocols securityProtocols)
          Set the SecurityProtocols
 byte[] truncateKey(byte[] key, int maxKeyLength)
          Limits the supplied key value to the specified maximum length
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECURITY_PROTOCOLS_PROPERTIES

public static final java.lang.String SECURITY_PROTOCOLS_PROPERTIES
See Also:
Constant Field Values
Constructor Detail

SecurityProtocols

protected SecurityProtocols()
Method Detail

getInstance

public static SecurityProtocols getInstance()
Get an instance of class SecurityProtocols.

Returns:
the globally used SecurityProtocols object.

setSecurityProtocols

public static void setSecurityProtocols(SecurityProtocols securityProtocols)
Set the SecurityProtocols

Parameters:
securityProtocols - SecurityProtocols

addDefaultProtocols

public void addDefaultProtocols()
Add the default SecurityProtocols. The names of the SecurityProtocols to add are read from a properties file.

Throws:
java.lang.InternalError - if the properties file cannot be opened/read.

addAuthenticationProtocol

public void addAuthenticationProtocol(AuthenticationProtocol auth)
Add the given AuthenticationProtocol. If an authentication protocol with the supplied ID already exists, the supplied authentication protocol will not be added and the security protocols will not be unchang.

Parameters:
auth - the AuthenticationProtocol to add (an existing authentication protcol with auth's ID remains unchanged).

getAuthenticationProtocol

public AuthenticationProtocol getAuthenticationProtocol(OID id)
Get the AuthenticationProtocol with the given ID.

Parameters:
id - The unique ID (specified as OID) of the AuthenticationProtocol.
Returns:
the AuthenticationProtocol object if it was added before, or null if not.

removeAuthenticationProtocol

public void removeAuthenticationProtocol(AuthenticationProtocol auth)
Remove the given AuthenticationProtocol.

Parameters:
auth - The protocol to remove

addPrivacyProtocol

public void addPrivacyProtocol(PrivacyProtocol priv)
Add the given PrivacyProtocol. If a privacy protocol with the supplied ID already exists, the supplied privacy protocol will not be added and the security protocols will not be changed.

Parameters:
priv - the PrivacyProtocol to add (an existing privacy protcol with priv's ID remains unchanged).

getPrivacyProtocol

public PrivacyProtocol getPrivacyProtocol(OID id)
Get the PrivacyProtocol with the given ID.

Parameters:
id - The unique ID (specified as OID) of the PrivacyProtocol.
Returns:
the PrivacyProtocol object if it was added before, or null if not.

removePrivacyProtocol

public void removePrivacyProtocol(PrivacyProtocol priv)
Remove the given PrivacyProtocol.

Parameters:
priv - The protocol to remove

passwordToKey

public byte[] passwordToKey(OID authProtocolID,
                            OctetString passwordString,
                            byte[] engineID)
Generates the localized key for the given password and engine id for the authentication protocol specified by the supplied OID.

Parameters:
authProtocolID - an OID identifying the authentication protocol to use.
passwordString - the authentication pass phrase.
engineID - the engine ID of the authoritative engine.
Returns:
the localized authentication key.

passwordToKey

public byte[] passwordToKey(OID privProtocolID,
                            OID authProtocolID,
                            OctetString passwordString,
                            byte[] engineID)
Generates the localized key for the given password and engine id for the privacy protocol specified by the supplied OID.

Parameters:
privProtocolID - an OID identifying the privacy protocol the key should be created for.
authProtocolID - an OID identifying the authentication protocol to use.
passwordString - the authentication pass phrase.
engineID - the engine ID of the authoritative engine.
Returns:
the localized privacy key.

getMaxAuthDigestLength

public int getMaxAuthDigestLength()
Gets the maximum authentication key length of the all known authentication protocols.

Returns:
the maximum authentication key length of all authentication protocols that have been added to this SecurityProtocols instance.

getMaxPrivDecryptParamsLength

public int getMaxPrivDecryptParamsLength()
Gets the maximum privacy key length of the currently known privacy protocols.

Returns:
the maximum privacy key length of all privacy protocols that have been added to this SecurityProtocols instance.

truncateKey

public byte[] truncateKey(byte[] key,
                          int maxKeyLength)
Limits the supplied key value to the specified maximum length

Parameters:
key - the key to truncate.
maxKeyLength - the maximum length of the returned key.
Returns:
the truncated key with a length of min(key.length, maxKeyLength).
Since:
1.9

Copyright 2005-2010 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.