Java Code Examples for org.whispersystems.libsignal.IdentityKey#equals()

The following examples show how to use org.whispersystems.libsignal.IdentityKey#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextSecureIdentityKeyStore.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private boolean isTrustedForSending(IdentityKey identityKey, Optional<IdentityRecord> identityRecord) {
  if (!identityRecord.isPresent()) {
    Log.w(TAG, "Nothing here, returning true...");
    return true;
  }

  if (!identityKey.equals(identityRecord.get().getIdentityKey())) {
    Log.w(TAG, "Identity keys don't match...");
    return false;
  }

  if (identityRecord.get().getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
    Log.w(TAG, "Needs unverified approval!");
    return false;
  }

  if (isNonBlockingApprovalRequired(identityRecord.get())) {
    Log.w(TAG, "Needs non-blocking approval!");
    return false;
  }

  return true;
}
 
Example 2
Source File: TextSecureIdentityKeyStore.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
    synchronized (LOCK) {
        IdentityRepo identityRepo = Repository.getIdentityRepo(accountContext);
        String ourNumber = accountContext.getUid();
        Address theirAddress = Address.from(accountContext, address.getName());

        if (ourNumber.equals(address.getName()) || Address.from(accountContext, ourNumber).equals(theirAddress)) {
            return identityKey.equals(IdentityKeyUtil.getIdentityKey(accountContext));
        }

        switch (direction) {
            case SENDING:
                return isTrustedForSending(identityKey, identityRepo.getIdentityRecord(theirAddress.serialize()));
            case RECEIVING:
                return true;
            default:
                throw new AssertionError("Unknown direction: " + direction);
        }
    }
}
 
Example 3
Source File: TextSecureIdentityKeyStore.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private boolean isTrustedForSending(IdentityKey identityKey, IdentityRecord identityRecord) {
    if (identityRecord == null) {
        Log.w(TAG, "Nothing here, returning true...");
        return true;
    }

    if (!identityKey.equals(identityRecord.getIdentityKey())) {
        Log.w(TAG, "Identity keys don't match...");
        return false;
    }

    if (identityRecord.getVerifyStatus() == IdentityRepo.VerifiedStatus.UNVERIFIED) {
        Log.w(TAG, "Needs unverified approval!");
        return false;
    }

    if (isNonBlockingApprovalRequired(identityRecord)) {
        Log.w(TAG, "Needs non-blocking approval!");
        return false;
    }

    return true;
}
 
Example 4
Source File: TextSecureIdentityKeyStore.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
  synchronized (LOCK) {
    if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
      IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
      RecipientId      ourRecipientId   = Recipient.self().getId();
      RecipientId      theirRecipientId = Recipient.external(context, address.getName()).getId();

      if (ourRecipientId.equals(theirRecipientId)) {
        return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));
      }

      switch (direction) {
        case SENDING:   return isTrustedForSending(identityKey, identityDatabase.getIdentity(theirRecipientId));
        case RECEIVING: return true;
        default:        throw new AssertionError("Unknown direction: " + direction);
      }
    } else {
      Log.w(TAG, "Tried to check if identity is trusted for " + address.getName() + ", but no matching recipient existed!");
      switch (direction) {
        case SENDING:   return false;
        case RECEIVING: return true;
        default:        throw new AssertionError("Unknown direction: " + direction);
      }
    }
  }
}
 
Example 5
Source File: InMemoryIdentityKeyStore.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
  IdentityKey existing = trustedKeys.get(address);

  if (!identityKey.equals(existing)) {
    trustedKeys.put(address, identityKey);
    return true;
  } else {
    return false;
  }
}
 
Example 6
Source File: InMemoryIdentityKeyStore.java    From libsignal-protocol-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
  IdentityKey trusted = trustedKeys.get(address);
  return (trusted == null || trusted.equals(identityKey));
}