Package org.snmp4j.smi

Examples of org.snmp4j.smi.OctetString


    if (!isProtocolVersionSupported(messageProcessingModel)) {
      logger.error("MPv2c used with unsupported SNMP version");
      return SnmpConstants.SNMP_MP_UNSUPPORTED_SECURITY_MODEL;
    }

    OctetString community = new OctetString(securityName);
    Integer32 version = new Integer32(messageProcessingModel);
    // compute total length
    int length = pdu.getBERLength();
    length += community.getBERLength();
    length += version.getBERLength();

    ByteBuffer buf = ByteBuffer.allocate(length +
                                         BER.getBERLengthOfLength(length) + 1);
    // set the buffer of the outgoing message
    outgoingMessage.setBuffer(buf);

    // encode the message
    BER.encodeHeader(outgoingMessage, BER.SEQUENCE, length);
    version.encodeBER(outgoingMessage);

    community.encodeBER(outgoingMessage);
    pdu.encodeBER(outgoingMessage);

    return SnmpConstants.SNMP_MP_OK;
  }
View Full Code Here


                                           OctetString securityName) {
    return (UsmUserEntry)table.get(new UsmUserKey(engineID, securityName));
  }

  public synchronized UsmUserEntry getUser(OctetString securityName) {
    return (UsmUserEntry)table.get(new UsmUserKey(new OctetString(), securityName));
  }
View Full Code Here

      this.securityName = securityName;
    }

    private void setEngineID(OctetString engineID) {
      if (engineID == null) {
        this.engineID = new OctetString();
      }
      else {
        this.engineID = engineID;
      }
    }
View Full Code Here

      if (bc != null) {
        engineBoots = bc.intValue();
        snmp.getUSM().setEngineBoots(engineBoots);
      }
      int engineTime = 0;
      OctetString localEngineID =
          createOctetString((String)
                            ArgumentParser.getValue(settings, oLocalEngineID, 0),
                            null);
      if (localEngineID == null) {
        if (snmp.getLocalEngineID() == null) {
          snmp.setLocalEngine(MPv3.createLocalEngineID(), engineBoots,
                              engineTime);
        }
      }
      else {
        snmp.setLocalEngine(localEngineID.getValue(), engineBoots, engineTime);
      }
      String sn = (String)
          ArgumentParser.getValue(settings, oSecurityName, 0);
      if (sn != null) {
        String authPP =
            (String) ArgumentParser.getValue(settings, oAuthPassphrase, 0);
        String privPP =
            (String) ArgumentParser.getValue(settings, oPrivPassphrase, 0);
        OID authProtocol = null;
        String authP =
            (String) ArgumentParser.getValue(settings, oAuthProtocol, 0);
        String privP =
            (String) ArgumentParser.getValue(settings, oPrivProtocol, 0);
        OID privProtocol = null;
        if ("MD5".equals(authP)) {
          authProtocol = AuthMD5.ID;
        }
        else if ("SHA".equals(authP)) {
          authProtocol = AuthSHA.ID;
        }
        if ("DES".equals(privP)) {
          privProtocol = PrivDES.ID;
        }
        else if ("3DES".equals(privP)) {
          privProtocol = Priv3DES.ID;
        }
        else if ("AES".equals(privP) || "AES128".equals(privP)) {
          privProtocol = PrivAES128.ID;
        }
        else if ("AES192".equals(privP)) {
          privProtocol = PrivAES192.ID;
        }
        else if ("AES256".equals(privP)) {
          privProtocol = PrivAES256.ID;
        }
        OctetString un = createOctetString(sn, null);
        snmp.getUSM().addUser(un, new UsmUser(un,
                                              authProtocol,
                                              createOctetString(authPP, null),
                                              privProtocol,
                                              createOctetString(privPP, null)));
View Full Code Here

  }

  public Target getTarget(Map settings) {
    String version =
        (String) ArgumentParser.getValue(settings, oVersion, 0);
    OctetString community =
        createOctetString((String)
                          ArgumentParser.getValue(settings, oCommunity, 0),
                          "public");
    Target t;
    if ("1".equals(version)) {
View Full Code Here

   *    an OctetString or <code>null</code> if <code>s</code> is
   *    <code>null</code>.
   * @since 1.10.2
   */
  public static OctetString createOctetString(String s, String defaultString) {
    OctetString octetString = null;
    if (s == null) {
      s = defaultString;
    }
    if ((s != null) && s.startsWith("0x")) {
      octetString = OctetString.fromHexString(s.substring(2), ':');
    }
    else if (s != null) {
      octetString = new OctetString(s);
    }
    return octetString;
  }
View Full Code Here

    int digestLength = hash.getDigestLength();

    if (logger.isDebugEnabled()) {
      logger.debug(protoName + "oldKey: " +
                   new OctetString(oldKey).toHexString());
      logger.debug(protoName + "newKey: " +
                   new OctetString(newKey).toHexString());
      logger.debug(protoName + "random: " +
                   new OctetString(random).toHexString());
    }
    int iterations = (oldKey.length - 1) / hash.getDigestLength();

    OctetString tmp = new OctetString(oldKey);
    OctetString delta = new OctetString();
    for (int k = 0; k < iterations; k++) {
        tmp.append(random);
        hash.update(tmp.getValue());
        tmp.setValue(hash.digest());
        delta.append(new byte[digestLength]);
        for (int kk=0; kk < digestLength; kk++) {
          delta.set(k * digestLength + kk,
                    (byte)(tmp.get(kk) ^ newKey[k * digestLength + kk]));
        }
    }

    tmp.append(random);
    hash.update(tmp.getValue());
    tmp = new OctetString(hash.digest(), 0, oldKey.length - delta.length());
    for (int j = 0; j < tmp.length(); j++) {
      tmp.set(j, (byte) (tmp.get(j) ^ newKey[iterations * digestLength + j]));
    }
    byte[] keyChange = new byte[random.length + delta.length() + tmp.length()];
    System.arraycopy(random, 0, keyChange, 0, random.length);
    System.arraycopy(delta.getValue(), 0, keyChange,
                     random.length, delta.length());
    System.arraycopy(tmp.getValue(), 0, keyChange,
                     random.length + delta.length(), tmp.length());

    if (logger.isDebugEnabled()) {
      logger.debug(protoName + "keyChange:" +
                   new OctetString(keyChange).toHexString());
    }
    return keyChange;
  }
View Full Code Here

      count += 64;
    }
    digest = md.digest();
    if (logger.isDebugEnabled()) {
      logger.debug(protoName + "First digest: " +
                   new OctetString(digest).toHexString());
    }

    /*****************************************************/
    /* Now localize the key with the engine_id and pass  */
    /* through MD to produce final key                   */
    /*****************************************************/
    md.reset();
    md.update(digest);
    md.update(engineID);
    md.update(digest);
    digest = md.digest();
    if (logger.isDebugEnabled()) {
      logger.debug(protoName + "localized key: " +
                   new OctetString(digest).toHexString());
    }

    return digest;
  }
View Full Code Here

        buf = new StringBuffer();
        t = t.substring(1);
      }
      if ((buf != null) && (t.endsWith("'"))) {
        buf.append(t.substring(0, t.length()-1));
        OID o = new OctetString(buf.toString()).toSubIndex(true);
        int[] h = value;
        value = new int[st.countTokens()+h.length+o.size()];
        System.arraycopy(h, 0, value, 0, size);
        System.arraycopy(o.getValue(), 0, value, size, o.size());
        size += o.size();
View Full Code Here

    snmp = new Snmp(dispatcher, transport);
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
    USM usm = new USM(SecurityProtocols.getInstance(),
                      new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(usm);
    snmp.listen();
  }
View Full Code Here

TOP

Related Classes of org.snmp4j.smi.OctetString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.