mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 06:08:33 +00:00
Put safeguards around Recipient creation in the IdentityStore.
This commit is contained in:
parent
a16242b9f8
commit
5e2a4fb058
@ -92,30 +92,44 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
|
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||||
RecipientId ourRecipientId = Recipient.self().getId();
|
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
||||||
RecipientId theirRecipientId = Recipient.external(context, address.getName()).getId();
|
RecipientId ourRecipientId = Recipient.self().getId();
|
||||||
|
RecipientId theirRecipientId = Recipient.external(context, address.getName()).getId();
|
||||||
|
|
||||||
if (ourRecipientId.equals(theirRecipientId)) {
|
if (ourRecipientId.equals(theirRecipientId)) {
|
||||||
return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));
|
return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case SENDING: return isTrustedForSending(identityKey, identityDatabase.getIdentity(theirRecipientId));
|
case SENDING: return isTrustedForSending(identityKey, identityDatabase.getIdentity(theirRecipientId));
|
||||||
case RECEIVING: return true;
|
case RECEIVING: return true;
|
||||||
default: throw new AssertionError("Unknown direction: " + direction);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
||||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||||
Optional<IdentityRecord> record = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipientId);
|
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||||
|
Optional<IdentityRecord> record = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipientId);
|
||||||
|
|
||||||
if (record.isPresent()) {
|
if (record.isPresent()) {
|
||||||
return record.get().getIdentityKey();
|
return record.get().getIdentityKey();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Log.w(TAG, "Tried to get identity for " + address.getName() + ", but no matching recipient existed!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
import com.google.android.gms.common.util.ArrayUtils;
|
import com.google.android.gms.common.util.ArrayUtils;
|
||||||
@ -39,7 +38,6 @@ import org.whispersystems.signalservice.api.storage.SignalContactRecord;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -15,7 +15,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(manifest = Config.NONE, application = Application.class)
|
@Config(manifest = Config.NONE, application = Application.class)
|
||||||
public class SqliteUtilTest {
|
public class SqlUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildTrueUpdateQuery_simple() {
|
public void buildTrueUpdateQuery_simple() {
|
Loading…
x
Reference in New Issue
Block a user