Ejemplo n.º 1
0
  private void handleErrorMessage(ErrorMessage errorMessage) throws OtrException {
    logger.finest(
        getSessionID().getAccountID()
            + " received an error message from "
            + getSessionID().getUserID()
            + " throught "
            + getSessionID().getUserID()
            + ".");

    OtrPolicy policy = getSessionPolicy();
    // Re-negotiate if we got an error and we are encrypted
    if (policy.getErrorStartAKE() && getSessionStatus() == SessionStatus.ENCRYPTED) {
      showWarning(errorMessage.error + " Initiating encryption.");

      logger.finest("Error message starts AKE.");
      doTransmitLastMessage = true;
      isLastMessageRetransmit = true;

      Vector<Integer> versions = new Vector<Integer>();
      if (policy.getAllowV1()) versions.add(1);

      if (policy.getAllowV2()) versions.add(2);

      logger.finest("Sending Query");
      injectMessage(new QueryMessage(versions));
    } else {
      showError(errorMessage.error);
    }
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * net.java.otr4j.session.ISession#handleReceivingMessage(java.lang.String)
   */
  public synchronized String transformReceiving(String msgText, List<TLV> tlvs)
      throws OtrException {
    OtrPolicy policy = getSessionPolicy();
    if (!policy.getAllowV1() && !policy.getAllowV2()) {
      logger.finest("Policy does not allow neither V1 not V2, ignoring message.");
      return msgText;
    }

    AbstractMessage m;
    try {
      m = SerializationUtils.toMessage(msgText);
    } catch (IOException e) {
      throw new OtrException(e);
    }

    if (m == null) return msgText; // Propably null or empty.

    switch (m.messageType) {
      case AbstractEncodedMessage.MESSAGE_DATA:
        return handleDataMessage((DataMessage) m, tlvs);
      case AbstractMessage.MESSAGE_ERROR:
        handleErrorMessage((ErrorMessage) m);
        return null;
      case AbstractMessage.MESSAGE_PLAINTEXT:
        return handlePlainTextMessage((PlainTextMessage) m);
      case AbstractMessage.MESSAGE_QUERY:
        handleQueryMessage((QueryMessage) m);
        return null;
      case AbstractEncodedMessage.MESSAGE_DH_COMMIT:
      case AbstractEncodedMessage.MESSAGE_DHKEY:
      case AbstractEncodedMessage.MESSAGE_REVEALSIG:
      case AbstractEncodedMessage.MESSAGE_SIGNATURE:
        AuthContext auth = this.getAuthContext();
        auth.handleReceivingMessage(m);

        if (auth.getIsSecure()) {
          this.setSessionStatus(SessionStatus.ENCRYPTED);
          logger.finest("Gone Secure.");
        }
        return null;
      default:
        throw new UnsupportedOperationException("Received an uknown message type.");
    }
  }
Ejemplo n.º 3
0
  private void handleQueryMessage(QueryMessage queryMessage) throws OtrException {
    logger.finest(
        getSessionID().getAccountID()
            + " received a query message from "
            + getSessionID().getUserID()
            + " throught "
            + getSessionID().getProtocolName()
            + ".");

    setSessionStatus(SessionStatus.PLAINTEXT);

    OtrPolicy policy = getSessionPolicy();
    if (queryMessage.versions.contains(2) && policy.getAllowV2()) {
      logger.finest("Query message with V2 support found.");
      getAuthContext().respondV2Auth();
    } else if (queryMessage.versions.contains(1) && policy.getAllowV1()) {
      throw new UnsupportedOperationException();
    }
  }
Ejemplo n.º 4
0
  private String handlePlainTextMessage(PlainTextMessage plainTextMessage) throws OtrException {
    logger.finest(
        getSessionID().getAccountID()
            + " received a plaintext message from "
            + getSessionID().getUserID()
            + " throught "
            + getSessionID().getProtocolName()
            + ".");

    OtrPolicy policy = getSessionPolicy();
    List<Integer> versions = plainTextMessage.versions;
    if (versions == null || versions.size() < 1) {
      logger.finest("Received plaintext message without the whitespace tag.");
      switch (this.getSessionStatus()) {
        case ENCRYPTED:
        case FINISHED:
          // Display the message to the user, but warn him that the
          // message was received unencrypted.
          showError("The message was received unencrypted.");
          return plainTextMessage.cleanText;
        case PLAINTEXT:
          // Simply display the message to the user. If
          // REQUIRE_ENCRYPTION
          // is set, warn him that the message was received
          // unencrypted.
          if (policy.getRequireEncryption()) {
            showError("The message was received unencrypted.");
          }
          return plainTextMessage.cleanText;
      }
    } else {
      logger.finest("Received plaintext message with the whitespace tag.");
      switch (this.getSessionStatus()) {
        case ENCRYPTED:
        case FINISHED:
          // Remove the whitespace tag and display the message to the
          // user, but warn him that the message was received
          // unencrypted.
          showError("The message was received unencrypted.");
        case PLAINTEXT:
          // Remove the whitespace tag and display the message to the
          // user. If REQUIRE_ENCRYPTION is set, warn him that the
          // message
          // was received unencrypted.
          if (policy.getRequireEncryption()) showError("The message was received unencrypted.");
      }

      if (policy.getWhitespaceStartAKE()) {
        logger.finest("WHITESPACE_START_AKE is set");

        if (plainTextMessage.versions.contains(2) && policy.getAllowV2()) {
          logger.finest("V2 tag found.");
          getAuthContext().respondV2Auth();
        } else if (plainTextMessage.versions.contains(1) && policy.getAllowV1()) {
          throw new UnsupportedOperationException();
        }
      }
    }

    return plainTextMessage.cleanText;
  }