From: <pn...@hy...> - 2010-01-21 08:53:15
|
Author: pnguyen Date: 2010-01-21 00:53:04 -0800 (Thu, 21 Jan 2010) New Revision: 14207 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14207 Modified: trunk/plugins/netservices/etc/hq-plugin.xml trunk/src/org/hyperic/snmp/SNMPClient.java trunk/src/org/hyperic/snmp/SNMPSession_v3.java Log: [HHQ-3665] Add support for noAuthNoPriv, authNoPriv, and authPriv authentication/privacy schemes Modified: trunk/plugins/netservices/etc/hq-plugin.xml =================================================================== --- trunk/plugins/netservices/etc/hq-plugin.xml 2010-01-21 05:27:58 UTC (rev 14206) +++ trunk/plugins/netservices/etc/hq-plugin.xml 2010-01-21 08:53:04 UTC (rev 14207) @@ -254,29 +254,30 @@ optional="true"/> <option name="snmpUser" - description="SNMP username (v3 only)" + description="SNMP Security Name (v3 only)" default="username" optional="true"/> - <option name="snmpPassword" - description="SNMP password (v3 only)" - type="secret" - default="password" - optional="true"/> + <option name="snmpSecurityContext" + description="SNMP Security Context Name (v3 only)" + optional="true"/> <option name="snmpAuthType" - description="SNMP auth type (v3 only)" + description="SNMP Authentication Protocol (v3 only)" type="enum" optional="true"> <include name="none" /> <include name="MD5"/> <include name="SHA"/> </option> - <option name="snmpAuthPassPhrase" - description="SNMP auth passphrase (v3 only)" - optional="true"/> + + <option name="snmpPassword" + description="SNMP Authentication Passphrase (v3 only)" + type="secret" + optional="true"/> + <option name="snmpPrivacyType" - description="SNMP privacy type (v3 only)" + description="SNMP Privacy Protocol (v3 only)" type="enum" optional="true"> <include name="none" /> @@ -286,12 +287,11 @@ <include name="AES-192" /> <include name="AES-256" /> </option> + <option name="snmpPrivacyPassPhrase" - description="SNMP privacy passphrase (v3 only)" - optional="true"/> - <option name="snmpSecurityContext" - description="SNMP security context (v3 only)" - optional="true"/> + description="SNMP Privacy Passphrase (v3 only)" + type="secret" + optional="true"/> </config> <!-- disabled by default, change to true for testing --> Modified: trunk/src/org/hyperic/snmp/SNMPClient.java =================================================================== --- trunk/src/org/hyperic/snmp/SNMPClient.java 2010-01-21 05:27:58 UTC (rev 14206) +++ trunk/src/org/hyperic/snmp/SNMPClient.java 2010-01-21 08:53:04 UTC (rev 14207) @@ -60,6 +60,9 @@ public static final String PROP_USER = "snmpUser"; public static final String PROP_PASSWORD = "snmpPassword"; public static final String PROP_AUTHTYPE = "snmpAuthType"; + public static final String PROP_PRIV_TYPE = "snmpPrivacyType"; + public static final String PROP_PRIV_PASSPHRASE = "snmpPrivacyPassPhrase"; + public static final String PROP_SECURITY_CONTEXT = "snmpSecurityContext"; private static Log log = LogFactory.getLog(SNMPClient.class); @@ -87,20 +90,6 @@ throw new IllegalArgumentException("unknown version: " + version); } - private static int parseAuthMethod(String authMethod) { - if (authMethod == null) { - throw new IllegalArgumentException("authMethod is null"); - } - - if (authMethod.equalsIgnoreCase("md5")) { - return AUTH_MD5; - } else if (authMethod.equalsIgnoreCase("sha")) { - return AUTH_SHA; - } - - throw new IllegalArgumentException("unknown authMethod: " + authMethod); - } - public SNMPClient() { } @@ -241,13 +230,14 @@ case SNMPClient.VERSION_3: String user = props.getProperty(PROP_USER, DEFAULT_USERNAME); + String pass = props.getProperty(PROP_PASSWORD); + String authtype = props.getProperty(PROP_AUTHTYPE); + String privtype = props.getProperty(PROP_PRIV_TYPE); + String privpass = props.getProperty(PROP_PRIV_PASSPHRASE); - String pass = props.getProperty(PROP_PASSWORD, DEFAULT_PASSWORD); + ((SNMPSession_v3) session).init(address, port, transport, user, + authtype, pass, privtype, privpass); - int authtype = parseAuthMethod(props.getProperty(PROP_AUTHTYPE, VALID_AUTHTYPES[0])); - - ((SNMPSession_v3) session).init(address, port, transport, user, pass, authtype); - break; default: Modified: trunk/src/org/hyperic/snmp/SNMPSession_v3.java =================================================================== --- trunk/src/org/hyperic/snmp/SNMPSession_v3.java 2010-01-21 05:27:58 UTC (rev 14206) +++ trunk/src/org/hyperic/snmp/SNMPSession_v3.java 2010-01-21 08:53:04 UTC (rev 14207) @@ -42,7 +42,7 @@ import org.snmp4j.smi.OID; import org.snmp4j.smi.OctetString; -/* +/** * Implements the SNMPSession interface for SNMPv3 sessions by extending the * SNMPSession_v2c implementation. SNMPv3 is only different from v1 or v2c in * the way that a session is initialized. @@ -70,10 +70,18 @@ return pdu; } - private OctetString getPrivPassphrase(String defVal) throws SNMPException { + private OctetString getAuthPassphrase(String val) { + if (val == null || val.length() == 0) { + return null; + } + + return new OctetString(val); + } + + private OctetString getPrivPassphrase(String defVal) { String val = System.getProperty("snmpPrivacyPassPhrase", defVal); - if (val == null) { + if (val == null || val.length() == 0) { return null; } @@ -83,7 +91,9 @@ private OID getPrivProtocol(String defVal) throws SNMPException { String val = System.getProperty("snmpPrivacyType", defVal); - if (val == null) { + if (val == null + || val.equalsIgnoreCase("none") + || val.length() == 0) { return null; } @@ -104,16 +114,31 @@ } } - void init(String host, String port, String transport, String user, String password, int authmethod) throws SNMPException - { - OID authProtocol = authmethod == SNMPClient.AUTH_SHA ? AuthSHA.ID : AuthMD5.ID; + private OID getAuthProtocol(String authMethod) { + if (authMethod == null + || authMethod.equalsIgnoreCase("none") + || authMethod.length() == 0) { + return null; + } else if (authMethod.equalsIgnoreCase("md5")) { + return AuthMD5.ID; + } else if (authMethod.equalsIgnoreCase("sha")) { + return AuthSHA.ID; + } else { + throw new IllegalArgumentException("unknown authentication protocol: " + authMethod); + } + } + + void init(String host, String port, String transport, String user, + String authType, String authPassword, + String privType, String privPassword) + throws SNMPException + { + OID authProtocol = getAuthProtocol(authType); + OID privProtocol = getPrivProtocol(privType); - OID privProtocol = getPrivProtocol(null); // Template option... - OctetString securityName = new OctetString(user); - OctetString authPassphrase = password == null ? null : new OctetString(password); - OctetString privPassphrase = getPrivPassphrase(null); // Template - // option... + OctetString authPassphrase = getAuthPassphrase(authPassword); + OctetString privPassphrase = getPrivPassphrase(privPassword); UserTarget target = new UserTarget(); |