Пример #1
0
  /**
   * Handles all events related to messenger features: TextEvent, DrawEvent, ImageEvent,
   * ClearWhiteBoardEvent, MouseButtonEvent
   *
   * <p>If an event direction is DOWN an hash is generated otherwise received and calculated hashes
   * are compared. <br>
   * Different hashes mean that an event is ignored
   *
   * @param ev
   */
  private void handleInterestingEvent(GroupSendableEvent ev) {

    Message message = ev.getMessage();
    byte[] data;
    Hash h = new Hash();
    //		String type;

    if (ev.getDir() == Direction.DOWN) {
      data = message.toByteArray();
      md.update(data);
      md.update(secret);
      byte[] my = md.digest();
      h.setHash(my);
      message.pushObject(h);
      md.reset();
      // out.println("MD calculated");
      ev.setObjectsMessage(message);
      try {
        ev.go();
      } catch (AppiaEventException e) {
        e.printStackTrace();
      }

    } else {
      // incoming hash
      h = (Hash) message.popObject();
      data = message.toByteArray();

      // calculates hash
      md.update(data);
      md.update(secret);

      if (MessageDigest.isEqual(md.digest(), h.getHash())) {
        // out.println("Valid");
        try {
          ev.go();
        } catch (AppiaEventException e) {
          e.printStackTrace();
        }
      }
      //			else{
      //				out.println("Error! Compromised message received!");
      //				out.println("Message ignored!");
      //			}
      md.reset();
    }
  }
 public void pushMySelf(Message m) {
   m.pushObject(message);
   m.pushInt(number);
 }