mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Fix some issues around SignalServiceAddress creation.
This commit is contained in:
committed by
Alex Hart
parent
a57adcb2b0
commit
08008629b3
@@ -82,7 +82,7 @@ public class MultiDeviceBlockedUpdateJob extends BaseJob {
|
||||
while ((recipient = reader.getNext()) != null) {
|
||||
if (recipient.isPushGroup()) {
|
||||
blockedGroups.add(recipient.requireGroupId().getDecodedId());
|
||||
} else if (recipient.isMaybeRegistered()) {
|
||||
} else if (recipient.isMaybeRegistered() && (recipient.hasUuid() || recipient.hasE164())) {
|
||||
blockedIndividuals.add(RecipientUtil.toSignalServiceAddress(context, recipient));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,7 @@ public final class MessageGroupContext {
|
||||
return Stream.of(groupContext.getMembersList())
|
||||
.map(GroupContext.Member::getE164)
|
||||
.withoutNulls()
|
||||
.map(e164 -> new SignalServiceAddress(null, e164))
|
||||
.map(RecipientId::from)
|
||||
.map(RecipientId::fromExternalPush)
|
||||
.filterNot(selfId::equals)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class RecipientUtil {
|
||||
|
||||
return Stream.of(recipients)
|
||||
.map(Recipient::resolve)
|
||||
.map(r -> new SignalServiceAddress(r.getUuid().orNull(), r.getE164().orNull()))
|
||||
.map(r -> new SignalServiceAddress(r.requireUuid(), r.getE164().orNull()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ public class SignalServiceMessageReceiver {
|
||||
SignalServiceEnvelope envelope;
|
||||
|
||||
if (entity.hasSource() && entity.getSourceDevice() > 0) {
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(entity.getSourceUuid()), entity.getSourceE164());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(entity.getSourceUuid()), entity.getSourceE164());
|
||||
envelope = new SignalServiceEnvelope(entity.getType(),
|
||||
Optional.of(address),
|
||||
entity.getSourceDevice(),
|
||||
|
||||
@@ -505,12 +505,11 @@ public final class SignalServiceContent {
|
||||
SignalServiceProtos.DataMessage content)
|
||||
throws UnsupportedDataMessageException, InvalidMessageStructureException
|
||||
{
|
||||
SignalServiceGroup groupInfoV1 = createGroupV1Info(content);
|
||||
SignalServiceGroupV2 groupInfoV2 = createGroupV2Info(content);
|
||||
Optional<SignalServiceGroupContext> groupContext;
|
||||
|
||||
try {
|
||||
groupContext = SignalServiceGroupContext.createOptional(groupInfoV1, groupInfoV2);
|
||||
groupContext = SignalServiceGroupContext.createOptional(null, groupInfoV2);
|
||||
} catch (InvalidMessageException e) {
|
||||
throw new InvalidMessageStructureException(e);
|
||||
}
|
||||
@@ -559,7 +558,8 @@ public final class SignalServiceContent {
|
||||
}
|
||||
|
||||
return new SignalServiceDataMessage(metadata.getTimestamp(),
|
||||
groupInfoV1, groupInfoV2,
|
||||
null,
|
||||
groupInfoV2,
|
||||
attachments,
|
||||
content.hasBody() ? content.getBody() : null,
|
||||
endSession,
|
||||
@@ -588,7 +588,7 @@ public final class SignalServiceContent {
|
||||
SignalServiceProtos.SyncMessage.Sent sentContent = content.getSent();
|
||||
SignalServiceDataMessage dataMessage = createSignalServiceMessage(metadata, sentContent.getMessage());
|
||||
Optional<SignalServiceAddress> address = SignalServiceAddress.isValidAddress(sentContent.getDestinationUuid(), sentContent.getDestinationE164())
|
||||
? Optional.of(new SignalServiceAddress(UuidUtil.parseOrNull(sentContent.getDestinationUuid()), sentContent.getDestinationE164()))
|
||||
? Optional.of(new SignalServiceAddress(UuidUtil.parseOrThrow(sentContent.getDestinationUuid()), sentContent.getDestinationE164()))
|
||||
: Optional.<SignalServiceAddress>absent();
|
||||
|
||||
if (!address.isPresent() && !dataMessage.getGroupContext().isPresent()) {
|
||||
@@ -597,7 +597,7 @@ public final class SignalServiceContent {
|
||||
|
||||
for (SignalServiceProtos.SyncMessage.Sent.UnidentifiedDeliveryStatus status : sentContent.getUnidentifiedStatusList()) {
|
||||
if (SignalServiceAddress.isValidAddress(status.getDestinationUuid(), status.getDestinationE164())) {
|
||||
SignalServiceAddress recipient = new SignalServiceAddress(UuidUtil.parseOrNull(status.getDestinationUuid()), status.getDestinationE164());
|
||||
SignalServiceAddress recipient = new SignalServiceAddress(UuidUtil.parseOrThrow(status.getDestinationUuid()), status.getDestinationE164());
|
||||
unidentifiedStatuses.put(recipient, status.getUnidentified());
|
||||
} else {
|
||||
Log.w(TAG, "Encountered an invalid UnidentifiedDeliveryStatus in a SentTranscript! Ignoring.");
|
||||
@@ -621,7 +621,7 @@ public final class SignalServiceContent {
|
||||
|
||||
for (SignalServiceProtos.SyncMessage.Read read : content.getReadList()) {
|
||||
if (SignalServiceAddress.isValidAddress(read.getSenderUuid(), read.getSenderE164())) {
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(read.getSenderUuid()), read.getSenderE164());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(read.getSenderUuid()), read.getSenderE164());
|
||||
readMessages.add(new ReadMessage(address, read.getTimestamp()));
|
||||
} else {
|
||||
Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
|
||||
@@ -636,7 +636,7 @@ public final class SignalServiceContent {
|
||||
|
||||
for (SignalServiceProtos.SyncMessage.Viewed viewed : content.getViewedList()) {
|
||||
if (SignalServiceAddress.isValidAddress(viewed.getSenderUuid(), viewed.getSenderE164())) {
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(viewed.getSenderUuid()), viewed.getSenderE164());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(viewed.getSenderUuid()), viewed.getSenderE164());
|
||||
viewedMessages.add(new ViewedMessage(address, viewed.getTimestamp()));
|
||||
} else {
|
||||
Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
|
||||
@@ -648,7 +648,7 @@ public final class SignalServiceContent {
|
||||
|
||||
if (content.hasViewOnceOpen()) {
|
||||
if (SignalServiceAddress.isValidAddress(content.getViewOnceOpen().getSenderUuid(), content.getViewOnceOpen().getSenderE164())) {
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(content.getViewOnceOpen().getSenderUuid()), content.getViewOnceOpen().getSenderE164());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(content.getViewOnceOpen().getSenderUuid()), content.getViewOnceOpen().getSenderE164());
|
||||
ViewOnceOpenMessage timerRead = new ViewOnceOpenMessage(address, content.getViewOnceOpen().getTimestamp());
|
||||
return SignalServiceSyncMessage.forViewOnceOpen(timerRead);
|
||||
} else {
|
||||
@@ -660,7 +660,7 @@ public final class SignalServiceContent {
|
||||
if (SignalServiceAddress.isValidAddress(content.getVerified().getDestinationUuid(), content.getVerified().getDestinationE164())) {
|
||||
try {
|
||||
SignalServiceProtos.Verified verified = content.getVerified();
|
||||
SignalServiceAddress destination = new SignalServiceAddress(UuidUtil.parseOrNull(verified.getDestinationUuid()), verified.getDestinationE164());
|
||||
SignalServiceAddress destination = new SignalServiceAddress(UuidUtil.parseOrThrow(verified.getDestinationUuid()), verified.getDestinationE164());
|
||||
IdentityKey identityKey = new IdentityKey(verified.getIdentityKey().toByteArray(), 0);
|
||||
|
||||
VerifiedMessage.VerifiedState verifiedState;
|
||||
@@ -898,7 +898,7 @@ public final class SignalServiceContent {
|
||||
}
|
||||
|
||||
if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid(), content.getQuote().getAuthorE164())) {
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());
|
||||
|
||||
return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
|
||||
address,
|
||||
@@ -1162,71 +1162,6 @@ public final class SignalServiceContent {
|
||||
|
||||
}
|
||||
|
||||
private static SignalServiceGroup createGroupV1Info(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
|
||||
if (!content.hasGroup()) return null;
|
||||
|
||||
SignalServiceGroup.Type type;
|
||||
|
||||
switch (content.getGroup().getType()) {
|
||||
case DELIVER: type = SignalServiceGroup.Type.DELIVER; break;
|
||||
case UPDATE: type = SignalServiceGroup.Type.UPDATE; break;
|
||||
case QUIT: type = SignalServiceGroup.Type.QUIT; break;
|
||||
case REQUEST_INFO: type = SignalServiceGroup.Type.REQUEST_INFO; break;
|
||||
default: type = SignalServiceGroup.Type.UNKNOWN; break;
|
||||
}
|
||||
|
||||
if (content.getGroup().getType() != DELIVER) {
|
||||
String name = null;
|
||||
List<SignalServiceAddress> members = null;
|
||||
SignalServiceAttachmentPointer avatar = null;
|
||||
|
||||
if (content.getGroup().hasName()) {
|
||||
name = content.getGroup().getName();
|
||||
}
|
||||
|
||||
if (content.getGroup().getMembersCount() > 0) {
|
||||
members = new ArrayList<>(content.getGroup().getMembersCount());
|
||||
|
||||
for (SignalServiceProtos.GroupContext.Member member : content.getGroup().getMembersList()) {
|
||||
if (SignalServiceAddress.isValidAddress(null, member.getE164())) {
|
||||
members.add(new SignalServiceAddress(null, member.getE164()));
|
||||
} else {
|
||||
throw new InvalidMessageStructureException("GroupContext.Member had no address!");
|
||||
}
|
||||
}
|
||||
} else if (content.getGroup().getMembersE164Count() > 0) {
|
||||
members = new ArrayList<>(content.getGroup().getMembersE164Count());
|
||||
|
||||
for (String member : content.getGroup().getMembersE164List()) {
|
||||
members.add(new SignalServiceAddress(null, member));
|
||||
}
|
||||
}
|
||||
|
||||
if (content.getGroup().hasAvatar()) {
|
||||
SignalServiceProtos.AttachmentPointer pointer = content.getGroup().getAvatar();
|
||||
|
||||
avatar = new SignalServiceAttachmentPointer(pointer.getCdnNumber(),
|
||||
SignalServiceAttachmentRemoteId.from(pointer),
|
||||
pointer.getContentType(),
|
||||
pointer.getKey().toByteArray(),
|
||||
Optional.of(pointer.getSize()),
|
||||
Optional.<byte[]>absent(), 0, 0,
|
||||
Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null),
|
||||
Optional.<String>absent(),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
Optional.<String>absent(),
|
||||
Optional.<String>absent(),
|
||||
pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);
|
||||
}
|
||||
|
||||
return new SignalServiceGroup(type, content.getGroup().getId().toByteArray(), name, members, avatar);
|
||||
}
|
||||
|
||||
return new SignalServiceGroup(content.getGroup().getId().toByteArray());
|
||||
}
|
||||
|
||||
private static SignalServiceGroupV2 createGroupV2Info(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
|
||||
if (!content.hasGroupV2()) return null;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
|
||||
throw new IOException("Missing contact address!");
|
||||
}
|
||||
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(details.getUuid()), details.getNumber());
|
||||
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrThrow(details.getUuid()), details.getNumber());
|
||||
Optional<String> name = Optional.fromNullable(details.getName());
|
||||
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
|
||||
Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
|
||||
@@ -66,7 +66,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
|
||||
throw new InvalidMessageException("Missing Verified address!");
|
||||
}
|
||||
IdentityKey identityKey = new IdentityKey(details.getVerified().getIdentityKey().toByteArray(), 0);
|
||||
SignalServiceAddress destination = new SignalServiceAddress(UuidUtil.parseOrNull(details.getVerified().getDestinationUuid()),
|
||||
SignalServiceAddress destination = new SignalServiceAddress(UuidUtil.parseOrThrow(details.getVerified().getDestinationUuid()),
|
||||
details.getVerified().getDestinationE164());
|
||||
|
||||
VerifiedMessage.VerifiedState state;
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2018 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.signalservice.api.messages.multidevice;
|
||||
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceGroupsInputStream extends ChunkedInputStream{
|
||||
|
||||
public DeviceGroupsInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public DeviceGroup read() throws IOException {
|
||||
long detailsLength = readRawVarint32();
|
||||
byte[] detailsSerialized = new byte[(int)detailsLength];
|
||||
Util.readFully(in, detailsSerialized);
|
||||
|
||||
GroupDetails details = GroupDetails.parseFrom(detailsSerialized);
|
||||
|
||||
if (!details.hasId()) {
|
||||
throw new IOException("ID missing on group record!");
|
||||
}
|
||||
|
||||
byte[] id = details.getId().toByteArray();
|
||||
Optional<String> name = Optional.fromNullable(details.getName());
|
||||
List<GroupDetails.Member> members = details.getMembersList();
|
||||
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
|
||||
boolean active = details.getActive();
|
||||
Optional<Integer> expirationTimer = Optional.absent();
|
||||
Optional<String> color = Optional.fromNullable(details.getColor());
|
||||
boolean blocked = details.getBlocked();
|
||||
Optional<Integer> inboxPosition = Optional.absent();
|
||||
boolean archived = false;
|
||||
|
||||
if (details.hasAvatar()) {
|
||||
long avatarLength = details.getAvatar().getLength();
|
||||
InputStream avatarStream = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
|
||||
String avatarContentType = details.getAvatar().getContentType();
|
||||
|
||||
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, false, null, null));
|
||||
}
|
||||
|
||||
if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
|
||||
expirationTimer = Optional.of(details.getExpireTimer());
|
||||
}
|
||||
|
||||
List<SignalServiceAddress> addressMembers = new ArrayList<>(members.size());
|
||||
for (GroupDetails.Member member : members) {
|
||||
if (SignalServiceAddress.isValidAddress(null, member.getE164())) {
|
||||
addressMembers.add(new SignalServiceAddress(null, member.getE164()));
|
||||
} else {
|
||||
throw new IOException("Missing group member address!");
|
||||
}
|
||||
}
|
||||
|
||||
if (details.hasInboxPosition()) {
|
||||
inboxPosition = Optional.of(details.getInboxPosition());
|
||||
}
|
||||
|
||||
if (details.hasArchived()) {
|
||||
archived = details.getArchived();
|
||||
}
|
||||
|
||||
return new DeviceGroup(id, name, addressMembers, avatar, active, expirationTimer, color, blocked, inboxPosition, archived);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class SignalServiceAddress {
|
||||
|
||||
public static Optional<SignalServiceAddress> fromRaw(String rawUuid, String e164) {
|
||||
if (isValidAddress(rawUuid, e164)) {
|
||||
return Optional.of(new SignalServiceAddress(UuidUtil.parseOrNull(rawUuid), e164));
|
||||
return Optional.of(new SignalServiceAddress(UuidUtil.parseOrThrow(rawUuid), e164));
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public final class SignalAccountRecord implements SignalRecord {
|
||||
|
||||
static PinnedConversation fromRemote(AccountRecord.PinnedConversation remote) {
|
||||
if (remote.hasContact()) {
|
||||
return forContact(new SignalServiceAddress(UuidUtil.parseOrNull(remote.getContact().getUuid()), remote.getContact().getE164()));
|
||||
return forContact(new SignalServiceAddress(UuidUtil.parseOrThrow(remote.getContact().getUuid()), remote.getContact().getE164()));
|
||||
} else if (!remote.getLegacyGroupId().isEmpty()) {
|
||||
return forGroupV1(remote.getLegacyGroupId().toByteArray());
|
||||
} else if (!remote.getGroupMasterKey().isEmpty()) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SignalServiceEnvelopeEntity {
|
||||
}
|
||||
|
||||
public boolean hasSource() {
|
||||
return source != null || sourceUuid != null;
|
||||
return sourceUuid != null;
|
||||
}
|
||||
|
||||
public int getSourceDevice() {
|
||||
|
||||
Reference in New Issue
Block a user