Exemplo n.º 1
0
 private void fillMap(SQLiteAxolotlStore store) {
   List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toString());
   putDevicesForJid(account.getJid().toBareJid().toString(), deviceIds, store);
   for (Contact contact : account.getRoster().getContacts()) {
     Jid bareJid = contact.getJid().toBareJid();
     if (bareJid == null) {
       continue; // FIXME: handle this?
     }
     String address = bareJid.toString();
     deviceIds = store.getSubDeviceSessions(address);
     putDevicesForJid(address, deviceIds, store);
   }
 }
Exemplo n.º 2
0
 public void regenerateKeys() {
   axolotlStore.regenerate();
   sessions.clear();
   fetchStatusMap.clear();
   publishBundlesIfNeeded();
   publishOwnDeviceIdIfNeeded();
 }
Exemplo n.º 3
0
 private XmppAxolotlSession recreateUncachedSession(AxolotlAddress address) {
   IdentityKey identityKey =
       axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
   return (identityKey != null)
       ? new XmppAxolotlSession(
           account, axolotlStore, address, identityKey.getFingerprint().replaceAll("\\s", ""))
       : null;
 }
Exemplo n.º 4
0
 public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
   if (jid.toBareJid().equals(account.getJid().toBareJid())) {
     if (deviceIds.contains(getOwnDeviceId())) {
       deviceIds.remove(getOwnDeviceId());
     }
     for (Integer deviceId : deviceIds) {
       AxolotlAddress ownDeviceAddress = new AxolotlAddress(jid.toBareJid().toString(), deviceId);
       if (sessions.get(ownDeviceAddress) == null) {
         buildSessionFromPEP(ownDeviceAddress);
       }
     }
   }
   Set<Integer> expiredDevices =
       new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toString()));
   expiredDevices.removeAll(deviceIds);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.TRUSTED,
       XmppAxolotlSession.Trust.INACTIVE_TRUSTED);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.UNDECIDED,
       XmppAxolotlSession.Trust.INACTIVE_UNDECIDED);
   setTrustOnSessions(
       jid,
       expiredDevices,
       XmppAxolotlSession.Trust.UNTRUSTED,
       XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED);
   Set<Integer> newDevices = new HashSet<>(deviceIds);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_TRUSTED,
       XmppAxolotlSession.Trust.TRUSTED);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_UNDECIDED,
       XmppAxolotlSession.Trust.UNDECIDED);
   setTrustOnSessions(
       jid,
       newDevices,
       XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED,
       XmppAxolotlSession.Trust.UNTRUSTED);
   this.deviceIds.put(jid, deviceIds);
   mXmppConnectionService.keyStatusUpdated();
   publishOwnDeviceIdIfNeeded();
 }
Exemplo n.º 5
0
 private void putDevicesForJid(
     String bareJid, List<Integer> deviceIds, SQLiteAxolotlStore store) {
   for (Integer deviceId : deviceIds) {
     AxolotlAddress axolotlAddress = new AxolotlAddress(bareJid, deviceId);
     Log.d(
         Config.LOGTAG,
         AxolotlService.getLogprefix(account)
             + "Building session for remote address: "
             + axolotlAddress.toString());
     String fingerprint =
         store
             .loadSession(axolotlAddress)
             .getSessionState()
             .getRemoteIdentityKey()
             .getFingerprint()
             .replaceAll("\\s", "");
     this.put(
         axolotlAddress, new XmppAxolotlSession(account, store, axolotlAddress, fingerprint));
   }
 }
Exemplo n.º 6
0
  public Set<AxolotlAddress> findDevicesWithoutSession(final Conversation conversation) {
    Log.d(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account)
            + "Finding devices without session for "
            + conversation.getContact().getJid().toBareJid());
    Jid contactJid = conversation.getContact().getJid().toBareJid();
    Set<AxolotlAddress> addresses = new HashSet<>();
    if (deviceIds.get(contactJid) != null) {
      for (Integer foreignId : this.deviceIds.get(contactJid)) {
        AxolotlAddress address = new AxolotlAddress(contactJid.toString(), foreignId);
        if (sessions.get(address) == null) {
          IdentityKey identityKey =
              axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
          if (identityKey != null) {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Already have session for "
                    + address.toString()
                    + ", adding to cache...");
            XmppAxolotlSession session =
                new XmppAxolotlSession(
                    account,
                    axolotlStore,
                    address,
                    identityKey.getFingerprint().replaceAll("\\s", ""));
            sessions.put(address, session);
          } else {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Found device "
                    + account.getJid().toBareJid()
                    + ":"
                    + foreignId);
            addresses.add(new AxolotlAddress(contactJid.toString(), foreignId));
          }
        }
      }
    } else {
      Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Have no target devices in PEP!");
    }
    if (deviceIds.get(account.getJid().toBareJid()) != null) {
      for (Integer ownId : this.deviceIds.get(account.getJid().toBareJid())) {
        AxolotlAddress address = new AxolotlAddress(account.getJid().toBareJid().toString(), ownId);
        if (sessions.get(address) == null) {
          IdentityKey identityKey =
              axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
          if (identityKey != null) {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Already have session for "
                    + address.toString()
                    + ", adding to cache...");
            XmppAxolotlSession session =
                new XmppAxolotlSession(
                    account,
                    axolotlStore,
                    address,
                    identityKey.getFingerprint().replaceAll("\\s", ""));
            sessions.put(address, session);
          } else {
            Log.d(
                Config.LOGTAG,
                AxolotlService.getLogprefix(account)
                    + "Found device "
                    + account.getJid().toBareJid()
                    + ":"
                    + ownId);
            addresses.add(new AxolotlAddress(account.getJid().toBareJid().toString(), ownId));
          }
        }
      }
    }

    return addresses;
  }
Exemplo n.º 7
0
 public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
   axolotlStore.setFingerprintTrust(fingerprint, trust);
 }
Exemplo n.º 8
0
 public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
   return axolotlStore.getFingerprintTrust(fingerprint);
 }
Exemplo n.º 9
0
 public void purgeKey(IdentityKey identityKey) {
   axolotlStore.setFingerprintTrust(
       identityKey.getFingerprint().replaceAll("\\s", ""), XmppAxolotlSession.Trust.COMPROMISED);
 }
Exemplo n.º 10
0
 public int getOwnDeviceId() {
   return axolotlStore.getLocalRegistrationId();
 }
Exemplo n.º 11
0
 public long getNumTrustedKeys(Contact contact) {
   return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
 }
Exemplo n.º 12
0
 public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
   return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust);
 }
Exemplo n.º 13
0
 public IdentityKey getOwnPublicKey() {
   return axolotlStore.getIdentityKeyPair().getPublicKey();
 }