Search in sources :

Example 1 with PrivAES192

use of org.snmp4j.security.PrivAES192 in project ovirt-engine by oVirt.

the class Snmp method createSnmp3.

private org.snmp4j.Snmp createSnmp3(Profile profile) {
    try {
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        org.snmp4j.Snmp snmp = new org.snmp4j.Snmp(transport);
        SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
        securityProtocols.addDefaultProtocols();
        securityProtocols.addAuthenticationProtocol(new AuthMD5());
        securityProtocols.addAuthenticationProtocol(new AuthSHA());
        securityProtocols.addPrivacyProtocol(new PrivAES128());
        securityProtocols.addPrivacyProtocol(new PrivAES192());
        securityProtocols.addPrivacyProtocol(new PrivAES256());
        USM usm = new USM(securityProtocols, profile.engineId, 0);
        ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)).setLocalEngineID(profile.engineId.getValue());
        ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)).getSecurityModels().addSecurityModel(usm);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();
        snmp.getUSM().addUser(profile.username, getUsmUser(profile));
        return snmp;
    } catch (IOException e) {
        throw new NotificationServiceException("error creating version 3 snmp " + getClass().getName());
    }
}
Also used : NotificationServiceException(org.ovirt.engine.core.notifier.NotificationServiceException) SecurityProtocols(org.snmp4j.security.SecurityProtocols) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) AuthSHA(org.snmp4j.security.AuthSHA) IOException(java.io.IOException) USM(org.snmp4j.security.USM) PrivAES192(org.snmp4j.security.PrivAES192) PrivAES128(org.snmp4j.security.PrivAES128) PrivAES256(org.snmp4j.security.PrivAES256) AuthMD5(org.snmp4j.security.AuthMD5)

Example 2 with PrivAES192

use of org.snmp4j.security.PrivAES192 in project LogHub by fbacchella.

the class SNMPTrapGeneratorClient2 method sendSnmpV3Trap.

/**
 * Sends the v3 trap
 */
private static void sendSnmpV3Trap() {
    try {
        Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        USM usm = new USM(SecurityProtocols.getInstance().addDefaultProtocols(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES192());
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();
        snmp.getUSM().addUser(new OctetString("MD5DES"), new UsmUser(new OctetString("MD5DES"), AuthMD5.ID, new OctetString("UserName"), PrivAES128.ID, new OctetString("UserName")));
        // Create Target
        UserTarget target = new UserTarget();
        target.setAddress(targetAddress);
        target.setRetries(1);
        target.setTimeout(11500);
        target.setVersion(SnmpConstants.version3);
        target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
        target.setSecurityName(new OctetString("MD5DES"));
        // 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(trapOid), new OctetString("Major")));
        // Send the PDU
        snmp.send(pdu, target);
        System.out.println("Sending Trap to (IP:Port)=> " + ipAddress + ":" + port);
        snmp.addCommandResponder(new CommandResponder() {

            public void processPdu(CommandResponderEvent arg0) {
                System.out.println(arg0);
            }
        });
        snmp.close();
    } catch (Exception e) {
        System.err.println("Error in Sending Trap to (IP:Port)=> " + ipAddress + ":" + port);
        System.err.println("Exception Message = " + e.getMessage());
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) Address(org.snmp4j.smi.Address) IpAddress(org.snmp4j.smi.IpAddress) UdpAddress(org.snmp4j.smi.UdpAddress) GenericAddress(org.snmp4j.smi.GenericAddress) ScopedPDU(org.snmp4j.ScopedPDU) CommandResponderEvent(org.snmp4j.CommandResponderEvent) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OID(org.snmp4j.smi.OID) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM) PrivAES192(org.snmp4j.security.PrivAES192) Snmp(org.snmp4j.Snmp) UserTarget(org.snmp4j.UserTarget) VariableBinding(org.snmp4j.smi.VariableBinding) CommandResponder(org.snmp4j.CommandResponder)

Aggregations

PrivAES192 (org.snmp4j.security.PrivAES192)2 USM (org.snmp4j.security.USM)2 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)2 IOException (java.io.IOException)1 NotificationServiceException (org.ovirt.engine.core.notifier.NotificationServiceException)1 CommandResponder (org.snmp4j.CommandResponder)1 CommandResponderEvent (org.snmp4j.CommandResponderEvent)1 ScopedPDU (org.snmp4j.ScopedPDU)1 Snmp (org.snmp4j.Snmp)1 UserTarget (org.snmp4j.UserTarget)1 AuthMD5 (org.snmp4j.security.AuthMD5)1 AuthSHA (org.snmp4j.security.AuthSHA)1 PrivAES128 (org.snmp4j.security.PrivAES128)1 PrivAES256 (org.snmp4j.security.PrivAES256)1 SecurityProtocols (org.snmp4j.security.SecurityProtocols)1 UsmUser (org.snmp4j.security.UsmUser)1 Address (org.snmp4j.smi.Address)1 GenericAddress (org.snmp4j.smi.GenericAddress)1 IpAddress (org.snmp4j.smi.IpAddress)1 OID (org.snmp4j.smi.OID)1