Remove legacy fields from the Envelope.

fork-5.53.8
Greyson Parrelli 2022-08-18 13:32:29 -04:00 zatwierdzone przez Cody Henthorne
rodzic b4ae13fe8a
commit 9c266e7995
7 zmienionych plików z 27 dodań i 91 usunięć

Wyświetl plik

@ -58,9 +58,7 @@ public class PushDatabase extends Database {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(TYPE, envelope.getType()); values.put(TYPE, envelope.getType());
values.put(SOURCE_UUID, envelope.getSourceUuid().orElse(null)); values.put(SOURCE_UUID, envelope.getSourceUuid().orElse(null));
values.put(SOURCE_E164, envelope.getSourceE164().orElse(null));
values.put(DEVICE_ID, envelope.getSourceDevice()); values.put(DEVICE_ID, envelope.getSourceDevice());
values.put(LEGACY_MSG, envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "");
values.put(CONTENT, envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : ""); values.put(CONTENT, envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "");
values.put(TIMESTAMP, envelope.getTimestamp()); values.put(TIMESTAMP, envelope.getTimestamp());
values.put(SERVER_RECEIVED_TIMESTAMP, envelope.getServerReceivedTimestamp()); values.put(SERVER_RECEIVED_TIMESTAMP, envelope.getServerReceivedTimestamp());
@ -89,7 +87,6 @@ public class PushDatabase extends Database {
SignalServiceAddress.fromRaw(uuid, e164), SignalServiceAddress.fromRaw(uuid, e164),
cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)), cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)),
cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)), cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)),
Util.isEmpty(legacyMessage) ? null : Base64.decode(legacyMessage),
Util.isEmpty(content) ? null : Base64.decode(content), Util.isEmpty(content) ? null : Base64.decode(content),
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP)), cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP)),
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_DELIVERED_TIMESTAMP)), cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_DELIVERED_TIMESTAMP)),
@ -127,17 +124,13 @@ public class PushDatabase extends Database {
LEGACY_MSG + " = ? AND " + LEGACY_MSG + " = ? AND " +
CONTENT + " = ? AND " + CONTENT + " = ? AND " +
TIMESTAMP + " = ? AND " + TIMESTAMP + " = ? AND " +
"(" + "(" + SOURCE_UUID + " NOT NULL AND " + SOURCE_UUID + " = ?)";
"(" + SOURCE_E164 + " NOT NULL AND " + SOURCE_E164 + " = ?) OR " +
"(" + SOURCE_UUID + " NOT NULL AND " + SOURCE_UUID + " = ?)" +
")";
String[] args = new String[] { String.valueOf(envelope.getType()), String[] args = new String[] { String.valueOf(envelope.getType()),
String.valueOf(envelope.getSourceDevice()), String.valueOf(envelope.getSourceDevice()),
envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "",
envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "", envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "",
String.valueOf(envelope.getTimestamp()), String.valueOf(envelope.getTimestamp()),
String.valueOf(envelope.getSourceUuid().orElse(null)), String.valueOf(envelope.getSourceUuid().orElse(null)) };
String.valueOf(envelope.getSourceE164().orElse(null)) };
try (Cursor cursor = database.query(TABLE_NAME, null, query, args, null, null, null)) { try (Cursor cursor = database.query(TABLE_NAME, null, query, args, null, null, null)) {
@ -165,7 +158,6 @@ public class PushDatabase extends Database {
String sourceUuid = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_UUID)); String sourceUuid = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_UUID));
String sourceE164 = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_E164)); String sourceE164 = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_E164));
int deviceId = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)); int deviceId = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID));
String legacyMessage = cursor.getString(cursor.getColumnIndexOrThrow(LEGACY_MSG));
String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT)); String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)); long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP));
long serverReceivedTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP)); long serverReceivedTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP));
@ -176,7 +168,6 @@ public class PushDatabase extends Database {
SignalServiceAddress.fromRaw(sourceUuid, sourceE164), SignalServiceAddress.fromRaw(sourceUuid, sourceE164),
deviceId, deviceId,
timestamp, timestamp,
legacyMessage != null ? Base64.decode(legacyMessage) : null,
content != null ? Base64.decode(content) : null, content != null ? Base64.decode(content) : null,
serverReceivedTimestamp, serverReceivedTimestamp,
serverDeliveredTimestamp, serverDeliveredTimestamp,

Wyświetl plik

@ -81,11 +81,6 @@ public class IncomingMessageProcessor {
* one was created. Otherwise null. * one was created. Otherwise null.
*/ */
public @Nullable String processEnvelope(@NonNull SignalServiceEnvelope envelope) { public @Nullable String processEnvelope(@NonNull SignalServiceEnvelope envelope) {
if (FeatureFlags.phoneNumberPrivacy() && envelope.hasSourceE164()) {
Log.w(TAG, "PNP enabled -- mimicking PNP by dropping the E164 from the envelope.");
envelope = envelope.withoutE164();
}
if (envelope.hasSourceUuid()) { if (envelope.hasSourceUuid()) {
Recipient.externalPush(envelope.getSourceAddress()); Recipient.externalPush(envelope.getSourceAddress());
} }

Wyświetl plik

@ -220,7 +220,6 @@ public class SignalServiceMessageReceiver {
Optional.of(address), Optional.of(address),
entity.getSourceDevice(), entity.getSourceDevice(),
entity.getTimestamp(), entity.getTimestamp(),
entity.getMessage(),
entity.getContent(), entity.getContent(),
entity.getServerTimestamp(), entity.getServerTimestamp(),
messageResult.getServerDeliveredTimestamp(), messageResult.getServerDeliveredTimestamp(),
@ -230,7 +229,6 @@ public class SignalServiceMessageReceiver {
} else { } else {
envelope = new SignalServiceEnvelope(entity.getType(), envelope = new SignalServiceEnvelope(entity.getType(),
entity.getTimestamp(), entity.getTimestamp(),
entity.getMessage(),
entity.getContent(), entity.getContent(),
entity.getServerTimestamp(), entity.getServerTimestamp(),
messageResult.getServerDeliveredTimestamp(), messageResult.getServerDeliveredTimestamp(),

Wyświetl plik

@ -143,18 +143,7 @@ public class SignalServiceCipher {
SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException
{ {
try { try {
if (envelope.hasLegacyMessage()) { if (envelope.hasContent()) {
Plaintext plaintext = decrypt(envelope, envelope.getLegacyMessage());
SignalServiceProtos.DataMessage dataMessage = SignalServiceProtos.DataMessage.parseFrom(plaintext.getData());
SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder()
.setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress))
.setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata))
.setLegacyDataMessage(dataMessage)
.build();
return SignalServiceContent.createFromProto(contentProto);
} else if (envelope.hasContent()) {
Plaintext plaintext = decrypt(envelope, envelope.getContent()); Plaintext plaintext = decrypt(envelope, envelope.getContent());
SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData()); SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData());

Wyświetl plik

@ -10,8 +10,10 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.signalservice.api.push.ACI; import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.OptionalUtil; import org.whispersystems.signalservice.api.util.OptionalUtil;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.api.util.UuidUtil; import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope; import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope;
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceEnvelopeProto; import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceEnvelopeProto;
@ -60,7 +62,6 @@ public class SignalServiceEnvelope {
Optional<SignalServiceAddress> sender, Optional<SignalServiceAddress> sender,
int senderDevice, int senderDevice,
long timestamp, long timestamp,
byte[] legacyMessage,
byte[] content, byte[] content,
long serverReceivedTimestamp, long serverReceivedTimestamp,
long serverDeliveredTimestamp, long serverDeliveredTimestamp,
@ -78,18 +79,15 @@ public class SignalServiceEnvelope {
if (sender.isPresent()) { if (sender.isPresent()) {
builder.setSourceUuid(sender.get().getServiceId().toString()); builder.setSourceUuid(sender.get().getServiceId().toString());
if (sender.get().getNumber().isPresent()) {
builder.setSourceE164(sender.get().getNumber().get());
}
} }
if (uuid != null) { if (uuid != null) {
builder.setServerGuid(uuid); builder.setServerGuid(uuid);
} }
if (legacyMessage != null) builder.setLegacyMessage(ByteString.copyFrom(legacyMessage)); if (content != null) {
if (content != null) builder.setContent(ByteString.copyFrom(content)); builder.setContent(ByteString.copyFrom(content));
}
this.envelope = builder.build(); this.envelope = builder.build();
this.serverDeliveredTimestamp = serverDeliveredTimestamp; this.serverDeliveredTimestamp = serverDeliveredTimestamp;
@ -97,7 +95,6 @@ public class SignalServiceEnvelope {
public SignalServiceEnvelope(int type, public SignalServiceEnvelope(int type,
long timestamp, long timestamp,
byte[] legacyMessage,
byte[] content, byte[] content,
long serverReceivedTimestamp, long serverReceivedTimestamp,
long serverDeliveredTimestamp, long serverDeliveredTimestamp,
@ -116,19 +113,14 @@ public class SignalServiceEnvelope {
builder.setServerGuid(uuid); builder.setServerGuid(uuid);
} }
if (legacyMessage != null) builder.setLegacyMessage(ByteString.copyFrom(legacyMessage)); if (content != null) {
if (content != null) builder.setContent(ByteString.copyFrom(content)); builder.setContent(ByteString.copyFrom(content));
}
this.envelope = builder.build(); this.envelope = builder.build();
this.serverDeliveredTimestamp = serverDeliveredTimestamp; this.serverDeliveredTimestamp = serverDeliveredTimestamp;
} }
public SignalServiceEnvelope withoutE164() {
return deserialize(serializeToProto().clearSourceE164()
.build()
.toByteArray());
}
public String getServerGuid() { public String getServerGuid() {
return envelope.getServerGuid(); return envelope.getServerGuid();
} }
@ -144,13 +136,6 @@ public class SignalServiceEnvelope {
return envelope.hasSourceUuid(); return envelope.hasSourceUuid();
} }
/**
* @return The envelope's sender as an E164 number.
*/
public Optional<String> getSourceE164() {
return Optional.ofNullable(envelope.getSourceE164());
}
/** /**
* @return The envelope's sender as a UUID. * @return The envelope's sender as a UUID.
*/ */
@ -159,17 +144,13 @@ public class SignalServiceEnvelope {
} }
public String getSourceIdentifier() { public String getSourceIdentifier() {
return OptionalUtil.or(getSourceUuid(), getSourceE164()).orElse(null); return getSourceUuid().get().toString();
} }
public boolean hasSourceDevice() { public boolean hasSourceDevice() {
return envelope.hasSourceDevice(); return envelope.hasSourceDevice();
} }
public boolean hasSourceE164() {
return envelope.hasSourceE164();
}
/** /**
* @return The envelope's sender device ID. * @return The envelope's sender device ID.
*/ */
@ -181,7 +162,7 @@ public class SignalServiceEnvelope {
* @return The envelope's sender as a SignalServiceAddress. * @return The envelope's sender as a SignalServiceAddress.
*/ */
public SignalServiceAddress getSourceAddress() { public SignalServiceAddress getSourceAddress() {
return new SignalServiceAddress(ACI.parseOrNull(envelope.getSourceUuid()), envelope.getSourceE164()); return new SignalServiceAddress(ACI.parseOrNull(envelope.getSourceUuid()));
} }
/** /**
@ -212,20 +193,6 @@ public class SignalServiceEnvelope {
return serverDeliveredTimestamp; return serverDeliveredTimestamp;
} }
/**
* @return Whether the envelope contains a SignalServiceDataMessage
*/
public boolean hasLegacyMessage() {
return envelope.hasLegacyMessage();
}
/**
* @return The envelope's containing SignalService message.
*/
public byte[] getLegacyMessage() {
return envelope.getLegacyMessage().toByteArray();
}
/** /**
* @return Whether the envelope contains an encrypted SignalServiceContent * @return Whether the envelope contains an encrypted SignalServiceContent
*/ */
@ -294,14 +261,6 @@ public class SignalServiceEnvelope {
builder.setSourceUuid(getSourceUuid().get()); builder.setSourceUuid(getSourceUuid().get());
} }
if (getSourceE164().isPresent()) {
builder.setSourceE164(getSourceE164().get());
}
if (hasLegacyMessage()) {
builder.setLegacyMessage(ByteString.copyFrom(getLegacyMessage()));
}
if (hasContent()) { if (hasContent()) {
builder.setContent(ByteString.copyFrom(getContent())); builder.setContent(ByteString.copyFrom(getContent()));
} }
@ -311,7 +270,7 @@ public class SignalServiceEnvelope {
} }
if (hasDestinationUuid()) { if (hasDestinationUuid()) {
builder.setDestinationUuid(getDestinationUuid().toString()); builder.setDestinationUuid(getDestinationUuid());
} }
return builder; return builder;
@ -329,11 +288,14 @@ public class SignalServiceEnvelope {
e.printStackTrace(); e.printStackTrace();
} }
Preconditions.checkNotNull(proto);
ServiceId sourceServiceId = proto.hasSourceUuid() ? ServiceId.parseOrNull(proto.getSourceUuid()) : null;
return new SignalServiceEnvelope(proto.getType(), return new SignalServiceEnvelope(proto.getType(),
SignalServiceAddress.fromRaw(proto.getSourceUuid(), proto.getSourceE164()), sourceServiceId != null ? Optional.of(new SignalServiceAddress(sourceServiceId)) : Optional.empty(),
proto.getDeviceId(), proto.getDeviceId(),
proto.getTimestamp(), proto.getTimestamp(),
proto.hasLegacyMessage() ? proto.getLegacyMessage().toByteArray() : null,
proto.hasContent() ? proto.getContent().toByteArray() : null, proto.hasContent() ? proto.getContent().toByteArray() : null,
proto.getServerReceivedTimestamp(), proto.getServerReceivedTimestamp(),
proto.getServerDeliveredTimestamp(), proto.getServerDeliveredTimestamp(),

Wyświetl plik

@ -24,9 +24,9 @@ message SignalServiceContentProto {
message SignalServiceEnvelopeProto { message SignalServiceEnvelopeProto {
optional int32 type = 1; optional int32 type = 1;
optional string sourceUuid = 2; optional string sourceUuid = 2;
optional string sourceE164 = 3; reserved /*sourceE164*/ 3;
optional int32 deviceId = 4; optional int32 deviceId = 4;
optional bytes legacyMessage = 5; reserved /*legacyMessage*/ 5;
optional bytes content = 6; optional bytes content = 6;
optional int64 timestamp = 7; optional int64 timestamp = 7;
optional int64 serverReceivedTimestamp = 8; optional int64 serverReceivedTimestamp = 8;

Wyświetl plik

@ -23,18 +23,19 @@ message Envelope {
} }
optional Type type = 1; optional Type type = 1;
optional string sourceE164 = 2; reserved /*sourceE164*/ 2;
optional string sourceUuid = 11; optional string sourceUuid = 11;
optional uint32 sourceDevice = 7; optional uint32 sourceDevice = 7;
optional string destinationUuid = 13; optional string destinationUuid = 13;
optional string relay = 3; reserved /*relay*/ 3;
optional uint64 timestamp = 5; optional uint64 timestamp = 5;
optional bytes legacyMessage = 6; // Contains an encrypted DataMessage reserved /*legacyMessage*/ 6;
optional bytes content = 8; // Contains an encrypted Content optional bytes content = 8; // Contains an encrypted Content
optional string serverGuid = 9; optional string serverGuid = 9;
optional uint64 serverTimestamp = 10; optional uint64 serverTimestamp = 10;
optional bool urgent = 14 [default = true]; optional bool urgent = 14 [default = true];
// NEXT ID: 15 reserved /*updatedPni*/ 15; // Not used presently, may be used in the future
// NEXT ID: 16
} }
message Content { message Content {