kopia lustrzana https://github.com/ryukoposting/Signal-Android
Remove legacy fields from the Envelope.
rodzic
b4ae13fe8a
commit
9c266e7995
|
@ -58,9 +58,7 @@ public class PushDatabase extends Database {
|
|||
ContentValues values = new ContentValues();
|
||||
values.put(TYPE, envelope.getType());
|
||||
values.put(SOURCE_UUID, envelope.getSourceUuid().orElse(null));
|
||||
values.put(SOURCE_E164, envelope.getSourceE164().orElse(null));
|
||||
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(TIMESTAMP, envelope.getTimestamp());
|
||||
values.put(SERVER_RECEIVED_TIMESTAMP, envelope.getServerReceivedTimestamp());
|
||||
|
@ -89,7 +87,6 @@ public class PushDatabase extends Database {
|
|||
SignalServiceAddress.fromRaw(uuid, e164),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)),
|
||||
Util.isEmpty(legacyMessage) ? null : Base64.decode(legacyMessage),
|
||||
Util.isEmpty(content) ? null : Base64.decode(content),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP)),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_DELIVERED_TIMESTAMP)),
|
||||
|
@ -127,17 +124,13 @@ public class PushDatabase extends Database {
|
|||
LEGACY_MSG + " = ? AND " +
|
||||
CONTENT + " = ? AND " +
|
||||
TIMESTAMP + " = ? AND " +
|
||||
"(" +
|
||||
"(" + SOURCE_E164 + " NOT NULL AND " + SOURCE_E164 + " = ?) OR " +
|
||||
"(" + SOURCE_UUID + " NOT NULL AND " + SOURCE_UUID + " = ?)" +
|
||||
")";
|
||||
"(" + SOURCE_UUID + " NOT NULL AND " + SOURCE_UUID + " = ?)";
|
||||
|
||||
String[] args = new String[] { String.valueOf(envelope.getType()),
|
||||
String.valueOf(envelope.getSourceDevice()),
|
||||
envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "",
|
||||
envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "",
|
||||
String.valueOf(envelope.getTimestamp()),
|
||||
String.valueOf(envelope.getSourceUuid().orElse(null)),
|
||||
String.valueOf(envelope.getSourceE164().orElse(null)) };
|
||||
String.valueOf(envelope.getSourceUuid().orElse(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 sourceE164 = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_E164));
|
||||
int deviceId = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID));
|
||||
String legacyMessage = cursor.getString(cursor.getColumnIndexOrThrow(LEGACY_MSG));
|
||||
String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
|
||||
long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP));
|
||||
long serverReceivedTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP));
|
||||
|
@ -176,7 +168,6 @@ public class PushDatabase extends Database {
|
|||
SignalServiceAddress.fromRaw(sourceUuid, sourceE164),
|
||||
deviceId,
|
||||
timestamp,
|
||||
legacyMessage != null ? Base64.decode(legacyMessage) : null,
|
||||
content != null ? Base64.decode(content) : null,
|
||||
serverReceivedTimestamp,
|
||||
serverDeliveredTimestamp,
|
||||
|
|
|
@ -81,11 +81,6 @@ public class IncomingMessageProcessor {
|
|||
* one was created. Otherwise null.
|
||||
*/
|
||||
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()) {
|
||||
Recipient.externalPush(envelope.getSourceAddress());
|
||||
}
|
||||
|
|
|
@ -220,7 +220,6 @@ public class SignalServiceMessageReceiver {
|
|||
Optional.of(address),
|
||||
entity.getSourceDevice(),
|
||||
entity.getTimestamp(),
|
||||
entity.getMessage(),
|
||||
entity.getContent(),
|
||||
entity.getServerTimestamp(),
|
||||
messageResult.getServerDeliveredTimestamp(),
|
||||
|
@ -230,7 +229,6 @@ public class SignalServiceMessageReceiver {
|
|||
} else {
|
||||
envelope = new SignalServiceEnvelope(entity.getType(),
|
||||
entity.getTimestamp(),
|
||||
entity.getMessage(),
|
||||
entity.getContent(),
|
||||
entity.getServerTimestamp(),
|
||||
messageResult.getServerDeliveredTimestamp(),
|
||||
|
|
|
@ -143,18 +143,7 @@ public class SignalServiceCipher {
|
|||
SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException
|
||||
{
|
||||
try {
|
||||
if (envelope.hasLegacyMessage()) {
|
||||
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()) {
|
||||
if (envelope.hasContent()) {
|
||||
Plaintext plaintext = decrypt(envelope, envelope.getContent());
|
||||
SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData());
|
||||
|
||||
|
|
|
@ -10,8 +10,10 @@ import com.google.protobuf.ByteString;
|
|||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
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.util.OptionalUtil;
|
||||
import org.whispersystems.signalservice.api.util.Preconditions;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope;
|
||||
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceEnvelopeProto;
|
||||
|
@ -60,7 +62,6 @@ public class SignalServiceEnvelope {
|
|||
Optional<SignalServiceAddress> sender,
|
||||
int senderDevice,
|
||||
long timestamp,
|
||||
byte[] legacyMessage,
|
||||
byte[] content,
|
||||
long serverReceivedTimestamp,
|
||||
long serverDeliveredTimestamp,
|
||||
|
@ -78,18 +79,15 @@ public class SignalServiceEnvelope {
|
|||
|
||||
if (sender.isPresent()) {
|
||||
builder.setSourceUuid(sender.get().getServiceId().toString());
|
||||
|
||||
if (sender.get().getNumber().isPresent()) {
|
||||
builder.setSourceE164(sender.get().getNumber().get());
|
||||
}
|
||||
}
|
||||
|
||||
if (uuid != null) {
|
||||
builder.setServerGuid(uuid);
|
||||
}
|
||||
|
||||
if (legacyMessage != null) builder.setLegacyMessage(ByteString.copyFrom(legacyMessage));
|
||||
if (content != null) builder.setContent(ByteString.copyFrom(content));
|
||||
if (content != null) {
|
||||
builder.setContent(ByteString.copyFrom(content));
|
||||
}
|
||||
|
||||
this.envelope = builder.build();
|
||||
this.serverDeliveredTimestamp = serverDeliveredTimestamp;
|
||||
|
@ -97,7 +95,6 @@ public class SignalServiceEnvelope {
|
|||
|
||||
public SignalServiceEnvelope(int type,
|
||||
long timestamp,
|
||||
byte[] legacyMessage,
|
||||
byte[] content,
|
||||
long serverReceivedTimestamp,
|
||||
long serverDeliveredTimestamp,
|
||||
|
@ -116,19 +113,14 @@ public class SignalServiceEnvelope {
|
|||
builder.setServerGuid(uuid);
|
||||
}
|
||||
|
||||
if (legacyMessage != null) builder.setLegacyMessage(ByteString.copyFrom(legacyMessage));
|
||||
if (content != null) builder.setContent(ByteString.copyFrom(content));
|
||||
if (content != null) {
|
||||
builder.setContent(ByteString.copyFrom(content));
|
||||
}
|
||||
|
||||
this.envelope = builder.build();
|
||||
this.serverDeliveredTimestamp = serverDeliveredTimestamp;
|
||||
}
|
||||
|
||||
public SignalServiceEnvelope withoutE164() {
|
||||
return deserialize(serializeToProto().clearSourceE164()
|
||||
.build()
|
||||
.toByteArray());
|
||||
}
|
||||
|
||||
public String getServerGuid() {
|
||||
return envelope.getServerGuid();
|
||||
}
|
||||
|
@ -144,13 +136,6 @@ public class SignalServiceEnvelope {
|
|||
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.
|
||||
*/
|
||||
|
@ -159,17 +144,13 @@ public class SignalServiceEnvelope {
|
|||
}
|
||||
|
||||
public String getSourceIdentifier() {
|
||||
return OptionalUtil.or(getSourceUuid(), getSourceE164()).orElse(null);
|
||||
return getSourceUuid().get().toString();
|
||||
}
|
||||
|
||||
public boolean hasSourceDevice() {
|
||||
return envelope.hasSourceDevice();
|
||||
}
|
||||
|
||||
public boolean hasSourceE164() {
|
||||
return envelope.hasSourceE164();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The envelope's sender device ID.
|
||||
*/
|
||||
|
@ -181,7 +162,7 @@ public class SignalServiceEnvelope {
|
|||
* @return The envelope's sender as a SignalServiceAddress.
|
||||
*/
|
||||
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 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
|
||||
*/
|
||||
|
@ -294,14 +261,6 @@ public class SignalServiceEnvelope {
|
|||
builder.setSourceUuid(getSourceUuid().get());
|
||||
}
|
||||
|
||||
if (getSourceE164().isPresent()) {
|
||||
builder.setSourceE164(getSourceE164().get());
|
||||
}
|
||||
|
||||
if (hasLegacyMessage()) {
|
||||
builder.setLegacyMessage(ByteString.copyFrom(getLegacyMessage()));
|
||||
}
|
||||
|
||||
if (hasContent()) {
|
||||
builder.setContent(ByteString.copyFrom(getContent()));
|
||||
}
|
||||
|
@ -311,7 +270,7 @@ public class SignalServiceEnvelope {
|
|||
}
|
||||
|
||||
if (hasDestinationUuid()) {
|
||||
builder.setDestinationUuid(getDestinationUuid().toString());
|
||||
builder.setDestinationUuid(getDestinationUuid());
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
@ -329,11 +288,14 @@ public class SignalServiceEnvelope {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Preconditions.checkNotNull(proto);
|
||||
|
||||
ServiceId sourceServiceId = proto.hasSourceUuid() ? ServiceId.parseOrNull(proto.getSourceUuid()) : null;
|
||||
|
||||
return new SignalServiceEnvelope(proto.getType(),
|
||||
SignalServiceAddress.fromRaw(proto.getSourceUuid(), proto.getSourceE164()),
|
||||
sourceServiceId != null ? Optional.of(new SignalServiceAddress(sourceServiceId)) : Optional.empty(),
|
||||
proto.getDeviceId(),
|
||||
proto.getTimestamp(),
|
||||
proto.hasLegacyMessage() ? proto.getLegacyMessage().toByteArray() : null,
|
||||
proto.hasContent() ? proto.getContent().toByteArray() : null,
|
||||
proto.getServerReceivedTimestamp(),
|
||||
proto.getServerDeliveredTimestamp(),
|
||||
|
|
|
@ -24,9 +24,9 @@ message SignalServiceContentProto {
|
|||
message SignalServiceEnvelopeProto {
|
||||
optional int32 type = 1;
|
||||
optional string sourceUuid = 2;
|
||||
optional string sourceE164 = 3;
|
||||
reserved /*sourceE164*/ 3;
|
||||
optional int32 deviceId = 4;
|
||||
optional bytes legacyMessage = 5;
|
||||
reserved /*legacyMessage*/ 5;
|
||||
optional bytes content = 6;
|
||||
optional int64 timestamp = 7;
|
||||
optional int64 serverReceivedTimestamp = 8;
|
||||
|
|
|
@ -23,18 +23,19 @@ message Envelope {
|
|||
}
|
||||
|
||||
optional Type type = 1;
|
||||
optional string sourceE164 = 2;
|
||||
reserved /*sourceE164*/ 2;
|
||||
optional string sourceUuid = 11;
|
||||
optional uint32 sourceDevice = 7;
|
||||
optional string destinationUuid = 13;
|
||||
optional string relay = 3;
|
||||
reserved /*relay*/ 3;
|
||||
optional uint64 timestamp = 5;
|
||||
optional bytes legacyMessage = 6; // Contains an encrypted DataMessage
|
||||
reserved /*legacyMessage*/ 6;
|
||||
optional bytes content = 8; // Contains an encrypted Content
|
||||
optional string serverGuid = 9;
|
||||
optional uint64 serverTimestamp = 10;
|
||||
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 {
|
||||
|
|
Ładowanie…
Reference in New Issue