This commit is contained in:
nielsandriesse 2020-08-12 10:00:35 +10:00
parent c9c902218e
commit fcb2bbb768
7 changed files with 29 additions and 21 deletions

View File

@ -1169,7 +1169,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
builder.setPositiveButton(R.string.yes, (dialog, which) -> { builder.setPositiveButton(R.string.yes, (dialog, which) -> {
Recipient groupRecipient = getRecipient(); Recipient groupRecipient = getRecipient();
try { try {
String groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(groupRecipient.getAddress().toString())); String groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupRecipient.getAddress().toString())));
boolean isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey); boolean isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey);
if (isSSKBasedClosedGroup) { if (isSSKBasedClosedGroup) {
ClosedGroupsProtocol.leave(this, groupPublicKey); ClosedGroupsProtocol.leave(this, groupPublicKey);

View File

@ -303,7 +303,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
SessionMetaProtocol.handleProfileKeyUpdate(context, content); SessionMetaProtocol.handleProfileKeyUpdate(context, content);
} }
if (content.isNeedsReceipt()) { if (content.isNeedsReceipt() && SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(content.getSender()))) {
handleNeedsDeliveryReceipt(content, message); handleNeedsDeliveryReceipt(content, message);
} }
} }

View File

@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.whispersystems.signalservice.api.SignalServiceMessageSender; import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
@ -83,6 +84,8 @@ public class SendDeliveryReceiptJob extends BaseJob implements InjectableType {
Collections.singletonList(messageId), Collections.singletonList(messageId),
timestamp); timestamp);
if (!SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(address))) { return; }
messageSender.sendReceipt(remoteAddress, messageSender.sendReceipt(remoteAddress,
UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromSerialized(address), false)), UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromSerialized(address), false)),
receiptMessage); receiptMessage);

View File

@ -335,7 +335,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
val isClosedGroup = recipient.address.isClosedGroup val isClosedGroup = recipient.address.isClosedGroup
// Send a leave group message if this is an active closed group // Send a leave group message if this is an active closed group
if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) { if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) {
val groupPublicKey = GroupUtil.getDecodedId(recipient.address.toString()).toHexString() val groupPublicKey = GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(recipient.address.toString())).toHexString()
val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey) val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
if (isSSKBasedClosedGroup) { if (isSSKBasedClosedGroup) {
ClosedGroupsProtocol.leave(this, groupPublicKey) ClosedGroupsProtocol.leave(this, groupPublicKey)

View File

@ -36,7 +36,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
private val lastMessageHashValueTable2 = "last_message_hash_value_table" private val lastMessageHashValueTable2 = "last_message_hash_value_table"
private val lastMessageHashValue = "last_message_hash_value" private val lastMessageHashValue = "last_message_hash_value"
@JvmStatic val createLastMessageHashValueTable2Command @JvmStatic val createLastMessageHashValueTable2Command
= "CREATE TABLE $lastMessageHashValueTable2 ($snode STRING, $publicKey STRING, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));" = "CREATE TABLE $lastMessageHashValueTable2 ($snode TEXT, $publicKey TEXT, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));"
// Received message hash values // Received message hash values
private val receivedMessageHashValuesTable2 = "received_message_hash_values_table" private val receivedMessageHashValuesTable2 = "received_message_hash_values_table"
private val receivedMessageHashValues = "received_message_hash_values" private val receivedMessageHashValues = "received_message_hash_values"
@ -110,7 +110,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
} }
string string
} }
val row = wrap(mapOf(Companion.dummyKey to "dummy_key", snodePool to snodePoolAsString)) val row = wrap(mapOf( Companion.dummyKey to "dummy_key", snodePool to snodePoolAsString ))
database.insertOrUpdate(snodePoolTable, row, "${Companion.dummyKey} = ?", wrap("dummy_key")) database.insertOrUpdate(snodePoolTable, row, "${Companion.dummyKey} = ?", wrap("dummy_key"))
} }
@ -155,13 +155,13 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
if (path0.count() != 3 || path1.count() != 3) { return } if (path0.count() != 3 || path1.count() != 3) { return }
Log.d("Loki", "Persisting onion request paths to database.") Log.d("Loki", "Persisting onion request paths to database.")
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
fun set(indexPath: String ,snode: Snode) { fun set(indexPath: String, snode: Snode) {
var snodeAsString = "${snode.address}-${snode.port}" var snodeAsString = "${snode.address}-${snode.port}"
val keySet = snode.publicKeySet val keySet = snode.publicKeySet
if (keySet != null) { if (keySet != null) {
snodeAsString += "-${keySet.ed25519Key}-${keySet.x25519Key}" snodeAsString += "-${keySet.ed25519Key}-${keySet.x25519Key}"
} }
val row = wrap(mapOf(Companion.indexPath to indexPath, Companion.snode to snodeAsString)) val row = wrap(mapOf( Companion.indexPath to indexPath, Companion.snode to snodeAsString ))
database.insertOrUpdate(onionRequestPathTable, row, "${Companion.indexPath} = ?", wrap(indexPath)) database.insertOrUpdate(onionRequestPathTable, row, "${Companion.indexPath} = ?", wrap(indexPath))
} }
set("0-0", path0[0]); set("0-1", path0[1]) set("0-0", path0[0]); set("0-1", path0[1])
@ -194,23 +194,23 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
} }
string string
} }
val row = wrap(mapOf(Companion.swarmPublicKey to publicKey, swarm to swarmAsString)) val row = wrap(mapOf( Companion.swarmPublicKey to publicKey, swarm to swarmAsString ))
database.insertOrUpdate(swarmTable, row, "${Companion.swarmPublicKey} = ?", wrap(publicKey)) database.insertOrUpdate(swarmTable, row, "${Companion.swarmPublicKey} = ?", wrap(publicKey))
} }
override fun getLastMessageHashValue(snode: Snode, publicKey: String): String? { override fun getLastMessageHashValue(snode: Snode, publicKey: String): String? {
val database = databaseHelper.readableDatabase val database = databaseHelper.readableDatabase
val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?" val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?"
return database.get(lastMessageHashValueTable2, query, arrayOf( snode.address, publicKey )) { cursor -> return database.get(lastMessageHashValueTable2, query, arrayOf( snode.toString(), publicKey )) { cursor ->
cursor.getString(cursor.getColumnIndexOrThrow(lastMessageHashValue)) cursor.getString(cursor.getColumnIndexOrThrow(lastMessageHashValue))
} }
} }
override fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String) { override fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val row = wrap(mapOf(Companion.snode to snode.address, Companion.publicKey to publicKey, lastMessageHashValue to newValue)) val row = wrap(mapOf( Companion.snode to snode.toString(), Companion.publicKey to publicKey, lastMessageHashValue to newValue ))
val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?" val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?"
database.insertOrUpdate(lastMessageHashValueTable2, row, query, arrayOf( snode.address, publicKey )) database.insertOrUpdate(lastMessageHashValueTable2, row, query, arrayOf( snode.toString(), publicKey ))
} }
override fun getReceivedMessageHashValues(publicKey: String): Set<String>? { override fun getReceivedMessageHashValues(publicKey: String): Set<String>? {
@ -218,13 +218,13 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val query = "$Companion.publicKey = ?" val query = "$Companion.publicKey = ?"
return database.get(receivedMessageHashValuesTable2, query, arrayOf( publicKey )) { cursor -> return database.get(receivedMessageHashValuesTable2, query, arrayOf( publicKey )) { cursor ->
val receivedMessageHashValuesAsString = cursor.getString(cursor.getColumnIndexOrThrow(receivedMessageHashValues)) val receivedMessageHashValuesAsString = cursor.getString(cursor.getColumnIndexOrThrow(receivedMessageHashValues))
receivedMessageHashValuesAsString.split(", ").toSet() receivedMessageHashValuesAsString.split("-").toSet()
} }
} }
override fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>) { override fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val receivedMessageHashValuesAsString = newValue.joinToString(", ") val receivedMessageHashValuesAsString = newValue.joinToString("-")
val row = wrap(mapOf( Companion.publicKey to publicKey, receivedMessageHashValues to receivedMessageHashValuesAsString )) val row = wrap(mapOf( Companion.publicKey to publicKey, receivedMessageHashValues to receivedMessageHashValuesAsString ))
val query = "$Companion.publicKey = ?" val query = "$Companion.publicKey = ?"
database.insertOrUpdate(receivedMessageHashValuesTable2, row, query, arrayOf( publicKey )) database.insertOrUpdate(receivedMessageHashValuesTable2, row, query, arrayOf( publicKey ))
@ -240,7 +240,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setAuthToken(server: String, newValue: String?) { override fun setAuthToken(server: String, newValue: String?) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
if (newValue != null) { if (newValue != null) {
val row = wrap(mapOf(Companion.server to server, token to newValue)) val row = wrap(mapOf( Companion.server to server, token to newValue ))
database.insertOrUpdate(openGroupAuthTokenTable, row, "${Companion.server} = ?", wrap(server)) database.insertOrUpdate(openGroupAuthTokenTable, row, "${Companion.server} = ?", wrap(server))
} else { } else {
database.delete(openGroupAuthTokenTable, "${Companion.server} = ?", wrap(server)) database.delete(openGroupAuthTokenTable, "${Companion.server} = ?", wrap(server))
@ -258,7 +258,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setLastMessageServerID(group: Long, server: String, newValue: Long) { override fun setLastMessageServerID(group: Long, server: String, newValue: Long) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val index = "$server.$group" val index = "$server.$group"
val row = wrap(mapOf(lastMessageServerIDTableIndex to index, lastMessageServerID to newValue.toString())) val row = wrap(mapOf( lastMessageServerIDTableIndex to index, lastMessageServerID to newValue.toString() ))
database.insertOrUpdate(lastMessageServerIDTable, row, "$lastMessageServerIDTableIndex = ?", wrap(index)) database.insertOrUpdate(lastMessageServerIDTable, row, "$lastMessageServerIDTableIndex = ?", wrap(index))
} }
@ -279,7 +279,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setLastDeletionServerID(group: Long, server: String, newValue: Long) { override fun setLastDeletionServerID(group: Long, server: String, newValue: Long) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val index = "$server.$group" val index = "$server.$group"
val row = wrap(mapOf(lastDeletionServerIDTableIndex to index, lastDeletionServerID to newValue.toString())) val row = wrap(mapOf( lastDeletionServerIDTableIndex to index, lastDeletionServerID to newValue.toString() ))
database.insertOrUpdate(lastDeletionServerIDTable, row, "$lastDeletionServerIDTableIndex = ?", wrap(index)) database.insertOrUpdate(lastDeletionServerIDTable, row, "$lastDeletionServerIDTableIndex = ?", wrap(index))
} }
@ -300,7 +300,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setUserCount(group: Long, server: String, newValue: Int) { override fun setUserCount(group: Long, server: String, newValue: Int) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val index = "$server.$group" val index = "$server.$group"
val row = wrap(mapOf(publicChatID to index, Companion.userCount to newValue.toString())) val row = wrap(mapOf( publicChatID to index, Companion.userCount to newValue.toString() ))
database.insertOrUpdate(userCountTable, row, "$publicChatID = ?", wrap(index)) database.insertOrUpdate(userCountTable, row, "$publicChatID = ?", wrap(index))
} }
@ -313,7 +313,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setSessionRequestSentTimestamp(publicKey: String, newValue: Long) { override fun setSessionRequestSentTimestamp(publicKey: String, newValue: Long) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val row = wrap(mapOf(LokiAPIDatabase.publicKey to publicKey, LokiAPIDatabase.timestamp to newValue.toString())) val row = wrap(mapOf( LokiAPIDatabase.publicKey to publicKey, LokiAPIDatabase.timestamp to newValue.toString() ))
database.insertOrUpdate(sessionRequestSentTimestampTable, row, "${LokiAPIDatabase.publicKey} = ?", wrap(publicKey)) database.insertOrUpdate(sessionRequestSentTimestampTable, row, "${LokiAPIDatabase.publicKey} = ?", wrap(publicKey))
} }
@ -339,7 +339,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setOpenGroupPublicKey(server: String, newValue: String) { override fun setOpenGroupPublicKey(server: String, newValue: String) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val row = wrap(mapOf(LokiAPIDatabase.server to server, LokiAPIDatabase.publicKey to newValue)) val row = wrap(mapOf( LokiAPIDatabase.server to server, LokiAPIDatabase.publicKey to newValue ))
database.insertOrUpdate(openGroupPublicKeyTable, row, "${LokiAPIDatabase.server} = ?", wrap(server)) database.insertOrUpdate(openGroupPublicKeyTable, row, "${LokiAPIDatabase.server} = ?", wrap(server))
} }

View File

@ -39,7 +39,7 @@ class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) :
return database.get(closedGroupRatchetTable, query, arrayOf( groupPublicKey, senderPublicKey )) { cursor -> return database.get(closedGroupRatchetTable, query, arrayOf( groupPublicKey, senderPublicKey )) { cursor ->
val chainKey = cursor.getString(Companion.chainKey) val chainKey = cursor.getString(Companion.chainKey)
val keyIndex = cursor.getInt(Companion.keyIndex) val keyIndex = cursor.getInt(Companion.keyIndex)
val messageKeys = cursor.getString(Companion.messageKeys).split(" - ") val messageKeys = cursor.getString(Companion.messageKeys).split("-")
ClosedGroupRatchet(chainKey, keyIndex, messageKeys) ClosedGroupRatchet(chainKey, keyIndex, messageKeys)
} }
} }
@ -51,7 +51,7 @@ class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) :
values.put(Companion.senderPublicKey, senderPublicKey) values.put(Companion.senderPublicKey, senderPublicKey)
values.put(Companion.chainKey, ratchet.chainKey) values.put(Companion.chainKey, ratchet.chainKey)
values.put(Companion.keyIndex, ratchet.keyIndex) values.put(Companion.keyIndex, ratchet.keyIndex)
values.put(Companion.messageKeys, ratchet.messageKeys.joinToString(" - ")) values.put(Companion.messageKeys, ratchet.messageKeys.joinToString("-"))
val query = "${Companion.closedGroupPublicKey} = ? AND ${Companion.senderPublicKey} = ?" val query = "${Companion.closedGroupPublicKey} = ? AND ${Companion.senderPublicKey} = ?"
database.insertOrUpdate(closedGroupRatchetTable, values, query, arrayOf( groupPublicKey, senderPublicKey )) database.insertOrUpdate(closedGroupRatchetTable, values, query, arrayOf( groupPublicKey, senderPublicKey ))
} }

View File

@ -78,6 +78,11 @@ object SessionMetaProtocol {
return !recipient.address.isRSSFeed return !recipient.address.isRSSFeed
} }
@JvmStatic
fun shouldSendDeliveryReceipt(address: Address): Boolean {
return !address.isGroup
}
/** /**
* Should be invoked for the recipient's master device. * Should be invoked for the recipient's master device.
*/ */