本文整理汇总了Java中org.snmp4j.security.PrivDES类的典型用法代码示例。如果您正苦于以下问题:Java PrivDES类的具体用法?Java PrivDES怎么用?Java PrivDES使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrivDES类属于org.snmp4j.security包,在下文中一共展示了PrivDES类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertPrivacyProtocol
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private OID convertPrivacyProtocol(String privacyProtocol) {
if (privacyProtocol == null) {
return null;
}
if ("DES".equals(privacyProtocol)) {
return PrivDES.ID;
} else if ("TRIDES".equals(privacyProtocol)) {
return Priv3DES.ID;
} else if ("AES128".equals(privacyProtocol)) {
return PrivAES128.ID;
} else if ("AES192".equals(privacyProtocol)) {
return PrivAES192.ID;
} else if ("AES256".equals(privacyProtocol)) {
return PrivAES256.ID;
} else {
throw new IllegalArgumentException("Unknown privacy protocol: " + privacyProtocol);
}
}
示例2: privType
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private OID privType(SnmpV3Target v3Target) {
switch (v3Target.getPrivType()) {
case DES:
return PrivDES.ID;
case DES3:
return Priv3DES.ID;
case AES128:
return PrivAES128.ID;
case AES192:
return PrivAES192.ID;
case AES256:
return PrivAES256.ID;
default:
throw new IllegalArgumentException("unrecognized privacy type");
}
}
示例3: getTargetV3
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private Target getTargetV3() {
//logger.info("Use SNMP v3, "+this.privacyprotocol +"="+this.password+", "+this.privacyprotocol+"="+this.privacypassphrase);
OID authOID = AuthMD5.ID;
if("SHA".equals(this.authprotocol))
authOID = AuthSHA.ID;
OID privOID = PrivDES.ID;
if(this.privacyprotocol == null || this.privacyprotocol.isEmpty())
privOID = null;
UsmUser user = new UsmUser(new OctetString(this.username),
authOID, new OctetString(this.password), //auth
privOID, this.privacypassphrase!=null?new OctetString(this.privacypassphrase):null); //enc
snmp.getUSM().addUser(new OctetString(this.username), user);
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(this.getVersionInt());
if(privOID != null)
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
else
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString(this.username));
return target;
}
示例4: convertPrivProtocol
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private OID convertPrivProtocol(String privProtocol) {
/*
* Returning null here is okay because the SNMP4J library supports
* this value as null when creating the SNMP session.
*/
if (StringUtils.isBlank(privProtocol)) {
return null;
}
if (privProtocol.equals("DES")) {
return PrivDES.ID;
} else if ((privProtocol.equals("AES128")) || (privProtocol.equals("AES"))) {
return PrivAES128.ID;
} else if (privProtocol.equals("AES192")) {
return PrivAES192.ID;
} else if (privProtocol.equals("AES256")) {
return PrivAES256.ID;
} else {
throw new IllegalArgumentException("Privacy protocol " + privProtocol + " not supported");
}
}
示例5: testTrapReceiverWithoutOpenNMS
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
public void testTrapReceiverWithoutOpenNMS() throws Exception {
System.out.println("SNMP4J: Register for Traps");
trapCount = 0;
Snmp snmp = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(9162)));
snmp.addCommandResponder(this);
snmp.getUSM().addUser(
new OctetString("opennmsUser"),
new UsmUser(new OctetString("opennmsUser"), AuthMD5.ID, new OctetString("0p3nNMSv3"), PrivDES.ID, new OctetString("0p3nNMSv3")));
snmp.listen();
sendTraps();
System.out.println("SNMP4J: Unregister for Traps");
snmp.close();
System.out.println("SNMP4J: Checking Trap status");
assertEquals(2, trapCount);
}
示例6: convertPrivProtocol
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private OID convertPrivProtocol(String privProtocol) {
/*
* Returning null here is okay because the SNMP4J library supports
* this value as null when creating the SNMP session.
*/
if (privProtocol == null) {
return null;
}
if (privProtocol.equals("DES")) {
return PrivDES.ID;
} else if ((privProtocol.equals("AES128")) || (privProtocol.equals("AES"))) {
return PrivAES128.ID;
} else if (privProtocol.equals("AES192")) {
return PrivAES192.ID;
} else if (privProtocol.equals("AES256")) {
return PrivAES256.ID;
} else {
throw new IllegalArgumentException("Privacy protocol " + privProtocol + " not supported");
}
}
示例7: privProtocol
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
private OID privProtocol() {
PrivProtocol pp = PrivProtocol.valueOf(conf("privProtocol", PrivProtocol.NONE));
switch (pp) {
case DES: return PrivDES.ID;
case AES128: return PrivAES128.ID;
case AES192: return PrivAES192.ID;
case AES256: return PrivAES256.ID;
case _3DES: return Priv3DES.ID;
default: return null;
}
}
示例8: setUpTarget
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
/**
* Helper method that initializes the snmp target to listening mode. This
* method is explicitly for V3 messages. This method will create and set up
* the TransportMapping and target for SNMP V3. It creates a
* TransportMapping and puts it in the listening mode. Also Creates
* CommunityTarget object and sets SNMP target properties.
*
* @param targetIP
* IP address of Target machine
* @param portNumber
* Port number
* @param userName
* The security name of the user
* @param authenticatePassword
* The authentication password
* @param privacyPassword
* The privacy password
* @return The created UserTarget
* @throws IOException
* IOException
*/
private UserTarget setUpTarget( final String targetIP, final int portNumber, final String userName,
final String authenticatePassword, final String privacyPassword ) throws IOException
{
// Creates a TransportMapping and puts the transport mapping in to
// listen mode
final TransportMapping transportMapping = new DefaultUdpTransportMapping();
snmp = new Snmp( transportMapping );
transportMapping.listen();
// Creating a USM with the support for the supplied security protocols
final SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
securityProtocols.addDefaultProtocols();
final OctetString engineId = new OctetString( MPv3.createLocalEngineID() );
final USM usm = new USM( securityProtocols, engineId, DEFAULT_ENGINE_REBOOTS );
SecurityModels.getInstance().addSecurityModel( usm );
final OctetString username = new OctetString( userName );
final OctetString authenticationPassphrase = new OctetString( authenticatePassword );
final OctetString privacyPassphrase = new OctetString( privacyPassword );
// Creating UsmUser and adds the UsmUser to the internal user name table
// TODO Need to confirm, whether AuthMD5 and PrivDES needs to be changed
final UsmUser usmuser = new UsmUser( username, AuthMD5.ID, authenticationPassphrase, PrivDES.ID,
privacyPassphrase );
snmp.getUSM().addUser( username, usmuser );
// Create a target for a user based security model target and setting
// its properties
final UserTarget userTarget = new UserTarget();
final InetAddress inetAddress = InetAddress.getByName( targetIP );
final Address address = new UdpAddress( inetAddress, portNumber );
userTarget.setAddress( address );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
userTarget.setVersion( SnmpConstants.version3 );
// TODO Need to confirm, whether this value needs to be configures
userTarget.setSecurityLevel( SecurityLevel.AUTH_PRIV );
userTarget.setSecurityName( username );
return userTarget;
}
示例9: sendTrapV3AuthPriv
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
public static void sendTrapV3AuthPriv(String port) throws IOException {
try {
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
TransportMapping<?> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
snmp.getUSM().addUser(
new OctetString("user"),
new UsmUser(new OctetString("user"), AuthMD5.ID, new OctetString("12345678"),
PrivDES.ID, new OctetString("passphrase")));
// Create Target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(11500);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString("user"));
// Create PDU for V3
ScopedPDU pdu = new ScopedPDU();
pdu.setType(ScopedPDU.NOTIFICATION);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));
// Send the PDU
snmp.send(pdu, target);
transport.close();
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例10: SnmpClient
import org.snmp4j.security.PrivDES; //导入依赖的package包/类
/**
* Create a new SnmpClient for the passed NetworkDevice.
*
* @param targetDevice
* NetworkDevice that will be used for SNMP message exchange.
*/
public SnmpClient(NetworkDevice targetDevice) {
this.targetDevice = targetDevice;
// Create a new logger with name jnetman.snmp.device_name
logger = Logger.getLogger("snmp.snmpClient." + targetDevice.getName());
// If activated SNMP4J will show a huge amount of low level debug info
if (SnmpPref.isSnmp4jLogEnabled())
LogFactory.setLogFactory(new Log4jLogFactory());
try {
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
// Creates Snmp istance for that transport channel
snmpInstance = new Snmp(transport);
logger.debug("New SNMP Client crated");
// Creates v3 SNMP USM
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// Adds 'jnetman' usm using MD5 authentication and DES encryption
UsmUser jnetmanUser = new UsmUser(
new OctetString(SnmpPref.getUser()), AuthMD5.ID,
new OctetString(SnmpPref.getPassword()), PrivDES.ID,
new OctetString(SnmpPref.getPassword()));
snmpInstance.getUSM().addUser(new OctetString(SnmpPref.getUser()),
jnetmanUser);
logger.debug("New USM User added >> " + jnetmanUser.getSecurityName());
// Enables listening for incoming SNMP packet
transport.listen();
} catch (IOException e) {
logger.fatal(
"IOException while creating a new DefaultUdpTransportMapping()",
e);
System.exit(-1);
}
}