예제 #1
0
  @Nullable
  private XmppAxolotlMessage buildHeader(Contact contact) {
    final XmppAxolotlMessage axolotlMessage =
        new XmppAxolotlMessage(contact.getJid().toBareJid(), getOwnDeviceId());

    Set<XmppAxolotlSession> contactSessions = findSessionsforContact(contact);
    Set<XmppAxolotlSession> ownSessions = findOwnSessions();
    if (contactSessions.isEmpty()) {
      return null;
    }
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account) + "Building axolotl foreign keyElements...");
    for (XmppAxolotlSession session : contactSessions) {
      Log.v(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account) + session.getRemoteAddress().toString());
      axolotlMessage.addDevice(session);
    }
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account) + "Building axolotl own keyElements...");
    for (XmppAxolotlSession session : ownSessions) {
      Log.v(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account) + session.getRemoteAddress().toString());
      axolotlMessage.addDevice(session);
    }

    return axolotlMessage;
  }
예제 #2
0
 private XmppAxolotlSession getReceivingSession(XmppAxolotlMessage message) {
   AxolotlAddress senderAddress =
       new AxolotlAddress(message.getFrom().toString(), message.getSenderDeviceId());
   XmppAxolotlSession session = sessions.get(senderAddress);
   if (session == null) {
     Log.d(
         Config.LOGTAG,
         AxolotlService.getLogprefix(account)
             + "Account: "
             + account.getJid()
             + " No axolotl session found while parsing received message "
             + message);
     session = recreateUncachedSession(senderAddress);
     if (session == null) {
       session = new XmppAxolotlSession(account, axolotlStore, senderAddress);
     }
   }
   return session;
 }
예제 #3
0
  public XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(
      XmppAxolotlMessage message) {
    XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage = null;

    XmppAxolotlSession session = getReceivingSession(message);
    keyTransportMessage = message.getParameters(session, getOwnDeviceId());

    if (session.isFresh() && keyTransportMessage != null) {
      sessions.put(session);
    }

    return keyTransportMessage;
  }
예제 #4
0
  @Nullable
  public XmppAxolotlMessage encrypt(Message message) {
    XmppAxolotlMessage axolotlMessage = buildHeader(message.getContact());

    if (axolotlMessage != null) {
      final String content;
      if (message.hasFileOnRemoteHost()) {
        content = message.getFileParams().url.toString();
      } else {
        content = message.getBody();
      }
      try {
        axolotlMessage.encrypt(content);
      } catch (CryptoFailedException e) {
        Log.w(
            Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage());
        return null;
      }
    }

    return axolotlMessage;
  }
예제 #5
0
  public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(
      XmppAxolotlMessage message) {
    XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;

    XmppAxolotlSession session = getReceivingSession(message);
    try {
      plaintextMessage = message.decrypt(session, getOwnDeviceId());
      Integer preKeyId = session.getPreKeyId();
      if (preKeyId != null) {
        publishBundlesIfNeeded();
        session.resetPreKeyId();
      }
    } catch (CryptoFailedException e) {
      Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message: " + e.getMessage());
    }

    if (session.isFresh() && plaintextMessage != null) {
      sessions.put(session);
    }

    return plaintextMessage;
  }