/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be >= 5 and <= 32. * @param incomingPDUFactory * a {@link PDUFactory}. If <code>null</code> the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be greater or equal than 5 and less or equal than 32. * @param incomingPDUFactory * a {@link PDUFactory}. If {@code null} the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
/** * Creates a MPv3 with a supplied local engine ID and {@link PDUFactory} * for incoming messages. * @param localEngineID * the local engine ID. Its length must be greater or equal than 5 and less or equal than 32. * @param incomingPDUFactory * a {@link PDUFactory}. If {@code null} the default factory will be * used which creates {@link ScopedPDU} instances. * @since 1.9.1 */ public MPv3(byte[] localEngineID, PDUFactory incomingPDUFactory) { this(localEngineID, incomingPDUFactory, SecurityProtocols.getInstance(), SecurityModels.getInstance(), CounterSupport.getInstance()); }
protected void initSecurityModels(EngineBootsProvider engineBootsProvider) { usm = createUSM(); if (usm != null) { SecurityModels.getInstance().addSecurityModel(usm); } TSM tsm = createTSM(); if (tsm != null) { SecurityModels.getInstance().addSecurityModel(tsm); } frameworkMIB = new SnmpFrameworkMIB(usm, dispatcher.getTransportMappings()); }
@Override protected void doStop() throws Exception { super.doStop(); try { SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); } finally { this.targetAddress = null; this.usm = null; this.target = null; this.pdu = null; } }
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); if (ok) { SecurityModels secModels = SecurityModels.getInstance(); if (secModels.getSecurityModel(new Integer32(index.get(0))) == null) { return false; } } return ok; } };
protected void initSecurityModels(EngineBootsProvider engineBootsProvider) { usm = createUSM(); SecurityModels.getInstance().addSecurityModel(usm); frameworkMIB = new SnmpFrameworkMIB(usm, dispatcher.getTransportMappings()); }
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); int securityModel = index.get(0); if (ok && (securityModel > SecurityModel.SECURITY_MODEL_SNMPv2c)) { SecurityModels secModels = SecurityModels.getInstance(); if (secModels.getSecurityModel(new Integer32(securityModel)) == null) { return false; } } return ok; } };
@Override protected void doStop() throws Exception { super.doStop(); try { SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); } finally { this.targetAddress = null; this.usm = null; this.target = null; } }
public void validate(MOValueValidationEvent validationEvent) { //--AgentGen BEGIN=snmpTargetParamsSecurityModel::validate Variable newValue = validationEvent.getNewValue(); switch (((Integer32)newValue).getValue()) { case SecurityModel.SECURITY_MODEL_USM: { if (SecurityModels.getInstance(). getSecurityModel((Integer32) newValue) == null) { validationEvent.setValidationStatus(SnmpConstants. SNMP_ERROR_WRONG_VALUE); return; } break; } default: break; } //--AgentGen END } }
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); if (ok) { SecurityModels secModels = SecurityModels.getInstance(); Integer32 secModel = new Integer32(index.get(index.size()-2)); if ((secModel.getValue() != SecurityModel.SECURITY_MODEL_ANY) && (secModels.getSecurityModel(secModel) == null)) { return false; } int secLevel = index.get(index.size()-1); if ((secLevel < 1) || (secLevel > 3)) { return false; } } return ok; } };
public boolean isValidIndex(OID index) { boolean ok = super.isValidIndex(index); if (ok) { SecurityModels secModels = SecurityModels.getInstance(); Integer32 secModel = new Integer32(index.get(index.size()-2)); int secModelID = secModel.getValue(); if ((secModelID != SecurityModel.SECURITY_MODEL_ANY) && (secModelID > SecurityModel.SECURITY_MODEL_SNMPv2c) && (secModels.getSecurityModel(secModel) == null)) { return false; } int secLevel = index.get(index.size()-1); if ((secLevel < 1) || (secLevel > 3)) { return false; } } return ok; } };
public void start () throws IOException { this.address = GenericAddress.parse ( this.connectionInformation.getAddress () ); this.transport = new DefaultUdpTransportMapping (); this.snmp = new Snmp ( this.transport ); //MPv3 mpv3 = (MPv3)_snmp.getMessageProcessingModel ( MessageProcessingModel.MPv3 ); final USM usm = new USM ( SecurityProtocols.getInstance (), new OctetString ( MPv3.createLocalEngineID () ), 0 ); SecurityModels.getInstance ().addSecurityModel ( usm ); this.snmp.listen (); }
@Override protected void doStart() throws Exception { super.doStart(); this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); LOG.debug("targetAddress: {}", targetAddress); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(this.usm); // setting up target this.target = new CommunityTarget(); this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity())); this.target.setAddress(this.targetAddress); this.target.setRetries(this.endpoint.getRetries()); this.target.setTimeout(this.endpoint.getTimeout()); this.target.setVersion(this.endpoint.getSnmpVersion()); }
private void initMessageDispatcher(){ this.dispatcher = new MessageDispatcherImpl(); usm = new USM(SecurityProtocols.getInstance(), responder.getLocalEngineID(), 0); mpv3 = new MPv3(usm); SecurityModels.getInstance().addSecurityModel(usm); SecurityProtocols.getInstance().addDefaultProtocols(); // all other privacy and authentication protocols are provided by the above method SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES()); dispatcher.addMessageProcessingModel(new MPv1()); dispatcher.addMessageProcessingModel(new MPv2c()); dispatcher.addMessageProcessingModel(mpv3); }
private void initMessageDispatcher(){ this.dispatcher = new MessageDispatcherImpl(); usm = new USM(SecurityProtocols.getInstance(), responder.getLocalEngineID(), 0); mpv3 = new MPv3(usm); SecurityModels.getInstance().addSecurityModel(usm); SecurityProtocols.getInstance().addDefaultProtocols(); // all other privacy and authentication protocols are provided by the above method SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES()); dispatcher.addMessageProcessingModel(new MPv1()); dispatcher.addMessageProcessingModel(new MPv2c()); dispatcher.addMessageProcessingModel(mpv3); }
/** * Initializes the message dispatcher ({@link MessageDispatcherImpl}) with * the transport mappings. */ protected void initMessageDispatcher() { dispatcher = new MessageDispatcherImpl(); mpv3 = new MPv3(agent.getContextEngineID().getValue()); usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots()); SecurityModels.getInstance().addSecurityModel(usm); SecurityProtocols.getInstance().addDefaultProtocols(); dispatcher.addMessageProcessingModel(new MPv1()); dispatcher.addMessageProcessingModel(new MPv2c()); dispatcher.addMessageProcessingModel(mpv3); initSnmpSession(); }
/** * Initializes the message dispatcher ({@link MessageDispatcherImpl}) with * the transport mappings. */ protected void initMessageDispatcher() { dispatcher = new MessageDispatcherImpl(); mpv3 = new MPv3(agent.getContextEngineID().getValue()); usm = new USM(SecurityProtocols.getInstance(), agent.getContextEngineID(), updateEngineBoots()); SecurityModels.getInstance().addSecurityModel(usm); SecurityProtocols.getInstance().addDefaultProtocols(); dispatcher.addMessageProcessingModel(new MPv1()); dispatcher.addMessageProcessingModel(new MPv2c()); dispatcher.addMessageProcessingModel(mpv3); initSnmpSession(); }
@Override public synchronized void activate() throws Exception { super.activate(); this.targetAddress = GenericAddress.parse(this.address); this.transport = new DefaultUdpTransportMapping(); this.snmp = new Snmp(transport); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); // setting up target target = new CommunityTarget(); target.setCommunity(new OctetString(this.snmpCommunity)); target.setAddress(targetAddress); target.setRetries(this.retries); target.setTimeout(this.timeout); target.setVersion(this.snmpVersion); // creating PDU this.pdu = new PDU(); }