mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Remove job-based decryption support and MCPv1.
This commit is contained in:
@@ -43,7 +43,7 @@ public class JobManager implements ConstraintObserver.Notifier {
|
||||
|
||||
private static final String TAG = Log.tag(JobManager.class);
|
||||
|
||||
public static final int CURRENT_VERSION = 9;
|
||||
public static final int CURRENT_VERSION = 10;
|
||||
|
||||
private final Application application;
|
||||
private final Configuration configuration;
|
||||
|
||||
@@ -1,60 +1,24 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.migrations;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||
import org.thoughtcrime.securesms.database.PushTable;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration;
|
||||
import org.thoughtcrime.securesms.jobs.FailingJob;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
|
||||
/**
|
||||
* We removed the messageId property from the job data and replaced it with a serialized envelope,
|
||||
* so we need to take jobs that referenced an ID and replace it with the envelope instead.
|
||||
*
|
||||
* @deprecated No longer have a PushDecryptJob to migrate, job now maps to {@link org.thoughtcrime.securesms.jobs.FailingJob}
|
||||
* in {@link org.thoughtcrime.securesms.jobs.JobManagerFactories}
|
||||
*/
|
||||
public class PushDecryptMessageJobEnvelopeMigration extends JobMigration {
|
||||
|
||||
private static final String TAG = Log.tag(PushDecryptMessageJobEnvelopeMigration.class);
|
||||
|
||||
private final PushTable pushDatabase;
|
||||
|
||||
public PushDecryptMessageJobEnvelopeMigration(@NonNull Context context) {
|
||||
public PushDecryptMessageJobEnvelopeMigration() {
|
||||
super(8);
|
||||
this.pushDatabase = SignalDatabase.push();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull JobData migrate(@NonNull JobData jobData) {
|
||||
if ("PushDecryptJob".equals(jobData.getFactoryKey())) {
|
||||
Log.i(TAG, "Found a PushDecryptJob to migrate.");
|
||||
return migratePushDecryptMessageJob(pushDatabase, jobData);
|
||||
} else {
|
||||
return jobData;
|
||||
}
|
||||
}
|
||||
|
||||
private static @NonNull JobData migratePushDecryptMessageJob(@NonNull PushTable pushDatabase, @NonNull JobData jobData) {
|
||||
JsonJobData data = JsonJobData.deserialize(jobData.getData());
|
||||
|
||||
if (data.hasLong("message_id")) {
|
||||
long messageId = data.getLong("message_id");
|
||||
try {
|
||||
SignalServiceEnvelope envelope = pushDatabase.get(messageId);
|
||||
return jobData.withData(data.buildUpon()
|
||||
.putBlobAsString("envelope", envelope.serialize())
|
||||
.serialize());
|
||||
} catch (NoSuchMessageException e) {
|
||||
Log.w(TAG, "Failed to find envelope in DB! Failing.");
|
||||
return jobData.withFactoryKey(FailingJob.KEY);
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "No message_id property?");
|
||||
return jobData;
|
||||
}
|
||||
return jobData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.migrations
|
||||
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData
|
||||
import org.thoughtcrime.securesms.jobs.FailingJob
|
||||
import org.thoughtcrime.securesms.jobs.PushProcessMessageErrorV2Job
|
||||
import org.thoughtcrime.securesms.messages.MessageState
|
||||
import org.thoughtcrime.securesms.util.Base64
|
||||
import org.whispersystems.signalservice.api.crypto.protos.CompleteMessage
|
||||
import org.whispersystems.signalservice.api.crypto.protos.EnvelopeMetadata
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope
|
||||
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto
|
||||
|
||||
/**
|
||||
* Migrate PushProcessMessageJob V1 to V2 versions.
|
||||
*/
|
||||
class PushProcessMessageJobMigration : JobMigration(10) {
|
||||
override fun migrate(jobData: JobData): JobData {
|
||||
return if ("PushProcessJob" == jobData.factoryKey) {
|
||||
migrateJob(jobData)
|
||||
} else {
|
||||
jobData
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(PushProcessMessageJobMigration::class.java)
|
||||
|
||||
@Suppress("MoveVariableDeclarationIntoWhen")
|
||||
private fun migrateJob(jobData: JobData): JobData {
|
||||
val data = JsonJobData.deserialize(jobData.data)
|
||||
return if (data.hasInt("message_state")) {
|
||||
val state = MessageState.values()[data.getInt("message_state")]
|
||||
return when (state) {
|
||||
MessageState.NOOP -> jobData.withFactoryKey(FailingJob.KEY)
|
||||
|
||||
MessageState.DECRYPTED_OK -> {
|
||||
try {
|
||||
migratePushProcessJobWithDecryptedData(jobData, data)
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "Unable to migrate successful process job", t)
|
||||
jobData.withFactoryKey(FailingJob.KEY)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.i(TAG, "Migrating push process error job for state: $state")
|
||||
jobData.withFactoryKey(PushProcessMessageErrorV2Job.KEY)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
jobData.withFactoryKey(FailingJob.KEY)
|
||||
}
|
||||
}
|
||||
|
||||
private fun migratePushProcessJobWithDecryptedData(jobData: JobData, inputData: JsonJobData): JobData {
|
||||
Log.i(TAG, "Migrating PushProcessJob to V2")
|
||||
|
||||
val protoBytes: ByteArray = Base64.decode(inputData.getString("message_content"))
|
||||
val proto = SignalServiceContentProto.parseFrom(protoBytes)
|
||||
|
||||
val sourceServiceId = ServiceId.parseOrThrow(proto.metadata.address.uuid)
|
||||
val destinationServiceId = ServiceId.parseOrThrow(proto.metadata.destinationUuid)
|
||||
|
||||
val envelope = Envelope.newBuilder()
|
||||
.setSourceServiceId(sourceServiceId.toString())
|
||||
.setSourceDevice(proto.metadata.senderDevice)
|
||||
.setDestinationServiceId(destinationServiceId.toString())
|
||||
.setTimestamp(proto.metadata.timestamp)
|
||||
.setServerGuid(proto.metadata.serverGuid)
|
||||
.setServerTimestamp(proto.metadata.serverReceivedTimestamp)
|
||||
|
||||
val metadata = EnvelopeMetadata(
|
||||
sourceServiceId = sourceServiceId.toByteArray().toByteString(),
|
||||
sourceE164 = if (proto.metadata.address.hasE164()) proto.metadata.address.e164 else null,
|
||||
sourceDeviceId = proto.metadata.senderDevice,
|
||||
sealedSender = proto.metadata.needsReceipt,
|
||||
groupId = if (proto.metadata.hasGroupId()) proto.metadata.groupId.toByteArray().toByteString() else null,
|
||||
destinationServiceId = destinationServiceId.toByteArray().toByteString()
|
||||
)
|
||||
|
||||
val completeMessage = CompleteMessage(
|
||||
envelope = envelope.build().toByteArray().toByteString(),
|
||||
content = proto.content.toByteArray().toByteString(),
|
||||
metadata = metadata,
|
||||
serverDeliveredTimestamp = proto.metadata.serverDeliveredTimestamp
|
||||
)
|
||||
|
||||
return jobData
|
||||
.withFactoryKey("PushProcessMessageJobV2")
|
||||
.withData(completeMessage.encode())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user