java.lang.Object
org.snmp4j.security.SecurityProtocols
- All Implemented Interfaces:
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:
- 3.5.0
- Author:
- Frank Fock, Jochen Katz
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSecurityProtocols(SecurityProtocols.SecurityProtocolSet initialSecurityProtocolSet) Create a newSecurityProtocolscollection to be used inMPv3(byte[], PDUFactory, SecurityProtocols, SecurityModels, CounterSupport)constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the givenAuthenticationProtocol.Add the default SecurityProtocols.voidaddPredefinedProtocolSet(SecurityProtocols.SecurityProtocolSet initialSecurityProtocolSet) Add a consistent, predefined, set of security protocols to this security protocol set.voidAdd the givenPrivacyProtocol.Get theAuthenticationProtocolwith the given ID.static SecurityProtocolsGet an instance of class SecurityProtocols.intGets the maximum authentication key length of the all known authentication protocols.intGets the maximum privacy key length of the currently known privacy protocols.Get the PrivacyProtocol with the given ID.getSecurityProtocol(OID protocolID) Get the security protocol (AuthenticationProtocolorPrivacyProtocol) for the specified protocol OID.getSecurityProtocolOIDs(SecurityProtocols.SecurityProtocolType securityProtocolType) Returns the object identifiers (OIDs) of theSecurityProtocols known to thisSecurityProtocolsinstance that have the specified type.static byte[]passwordToKey(PrivacyProtocol privProtocol, AuthenticationProtocol authProtocol, OctetString passwordString, byte[] engineID) Generates the localized key for the given password and engine id for the privacy protocol specified by the supplied OID.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.voidRemove all security protocols from this set.voidremoveAuthenticationProtocol(OID authOID) Remove the givenAuthenticationProtocol.voidremovePrivacyProtocol(OID privOID) Remove the givenPrivacyProtocol.static voidsetSecurityProtocols(SecurityProtocols securityProtocols) Set theSecurityProtocolsbyte[]truncateKey(byte[] key, int maxKeyLength) Limits the supplied key value to the specified maximum length
-
Field Details
-
SECURITY_PROTOCOLS_PROPERTIES
- See Also:
-
-
Constructor Details
-
SecurityProtocols
protected SecurityProtocols() -
SecurityProtocols
Create a newSecurityProtocolscollection to be used inMPv3(byte[], PDUFactory, SecurityProtocols, SecurityModels, CounterSupport)constructor. Using this constructor creates a non-default instance of a security protocols collections. You can set it as default instance by callingsetSecurityProtocols(SecurityProtocols)with this instance later to set it as default.- Parameters:
initialSecurityProtocolSet- defines the initial set of
-
-
Method Details
-
removeAll
public void removeAll()Remove all security protocols from this set.- Since:
- 3.5.0
-
addPredefinedProtocolSet
public void addPredefinedProtocolSet(SecurityProtocols.SecurityProtocolSet initialSecurityProtocolSet) Add a consistent, predefined, set of security protocols to this security protocol set.- Parameters:
initialSecurityProtocolSet- the set that defines the protocols to add.- Since:
- 3.5.0
-
getInstance
Get an instance of class SecurityProtocols.- Returns:
- the globally used SecurityProtocols object.
-
setSecurityProtocols
Set theSecurityProtocols- Parameters:
securityProtocols- SecurityProtocols
-
getSecurityProtocol
Get the security protocol (AuthenticationProtocolorPrivacyProtocol) for the specified protocol OID.- Parameters:
protocolID- an object identifier of the security protocol to return.- Returns:
- the security protocol or
nullif a protocol with such an ID has not been added yet. - Since:
- 2.6.0
-
addDefaultProtocols
Add the default SecurityProtocols.The names of the SecurityProtocols to add are read from a properties file.
- Returns:
- this SecurityProtocols instance for chaining configuration.
- Throws:
InternalError- ifSNMP4JSettings.isExtensibilityEnabled()istrueand corresponding properties file with the security protocols configuration cannot be opened/read.
-
addAuthenticationProtocol
Add the givenAuthenticationProtocol. 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 withauth's ID remains unchanged).
-
getAuthenticationProtocol
Get theAuthenticationProtocolwith the given ID.- Parameters:
id- The unique ID (specified asOID) of the AuthenticationProtocol.- Returns:
- the AuthenticationProtocol object if it was added before, or null if not.
-
removeAuthenticationProtocol
Remove the givenAuthenticationProtocol.- Parameters:
authOID- The object identifier of the protocol to remove
-
addPrivacyProtocol
Add the givenPrivacyProtocol. 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 protocol withpriv's ID remains unchanged).
-
getPrivacyProtocol
Get the PrivacyProtocol with the given ID.- Parameters:
id- The unique ID (specified asOID) of the PrivacyProtocol.- Returns:
- the
PrivacyProtocolobject if it was added before, or null if not.
-
removePrivacyProtocol
Remove the givenPrivacyProtocol.- Parameters:
privOID- The object identifier of the protocol to remove
-
passwordToKey
Generates the localized key for the given password and engine id for the authentication protocol specified by the supplied OID.- Parameters:
authProtocolID- anOIDidentifying 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- anOIDidentifying the privacy protocol the key should be created for.authProtocolID- anOIDidentifying the authentication protocol to use.passwordString- the authentication pass phrase.engineID- the engine ID of the authoritative engine.- Returns:
- the localized privacy key.
-
passwordToKey
public static byte[] passwordToKey(PrivacyProtocol privProtocol, AuthenticationProtocol authProtocol, 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:
privProtocol- the privacy protocol the key should be created for.authProtocol- the authentication protocol to use.passwordString- the authentication pass phrase.engineID- the engine ID of the authoritative engine.- Returns:
- the localized privacy key.
- Since:
- 3.9.3
-
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
SecurityProtocolsinstance.
-
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
SecurityProtocolsinstance.
-
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
-
getSecurityProtocolOIDs
public Collection<OID> getSecurityProtocolOIDs(SecurityProtocols.SecurityProtocolType securityProtocolType) Returns the object identifiers (OIDs) of theSecurityProtocols known to thisSecurityProtocolsinstance that have the specified type.- Parameters:
securityProtocolType- the security protocol type (authentication or privacy).- Returns:
- a collection of security protocol identifiers of the specified type or
nullif the type is not supported by this instance. - Since:
- 3.3.4
-