Remove E164s most places and prefer ServiceId more places.\

This commit is contained in:
Greyson Parrelli
2022-02-23 17:28:11 -05:00
committed by Alex Hart
parent d6b6884c69
commit 935dd7de45
50 changed files with 296 additions and 304 deletions

View File

@@ -20,7 +20,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest;
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
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.exceptions.MissingConfigurationException;
@@ -204,7 +203,7 @@ public class SignalServiceMessageReceiver {
SignalServiceEnvelope envelope;
if (entity.hasSource() && entity.getSourceDevice() > 0) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(entity.getSourceUuid()), entity.getSourceE164());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(entity.getSourceUuid()), entity.getSourceE164());
envelope = new SignalServiceEnvelope(entity.getType(),
Optional.of(address),
entity.getSourceDevice(),

View File

@@ -802,7 +802,7 @@ public class SignalServiceMessageSender {
quoteBuilder.addBodyRanges(DataMessage.BodyRange.newBuilder()
.setStart(mention.getStart())
.setLength(mention.getLength())
.setMentionUuid(mention.getAci().toString()));
.setMentionUuid(mention.getServiceId().toString()));
}
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.MENTIONS_VALUE, builder.getRequiredProtocolVersion()));
@@ -856,7 +856,7 @@ public class SignalServiceMessageSender {
builder.addBodyRanges(DataMessage.BodyRange.newBuilder()
.setStart(mention.getStart())
.setLength(mention.getLength())
.setMentionUuid(mention.getAci().toString()));
.setMentionUuid(mention.getServiceId().toString()));
}
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.MENTIONS_VALUE, builder.getRequiredProtocolVersion()));
}
@@ -927,7 +927,7 @@ public class SignalServiceMessageSender {
SignalServiceDataMessage.StoryContext storyContext = message.getStoryContext().get();
builder.setStoryContext(DataMessage.StoryContext.newBuilder()
.setAuthorUuid(storyContext.getAuthorAci().toString())
.setAuthorUuid(storyContext.getAuthorServiceId().toString())
.setSentTimestamp(storyContext.getSentTimestamp()));
}
@@ -1069,26 +1069,16 @@ public class SignalServiceMessageSender {
for (SendMessageResult result : sendMessageResults) {
if (result.getSuccess() != null) {
SyncMessage.Sent.UnidentifiedDeliveryStatus.Builder builder = SyncMessage.Sent.UnidentifiedDeliveryStatus.newBuilder();
sentMessage.addUnidentifiedStatus(SyncMessage.Sent.UnidentifiedDeliveryStatus.newBuilder()
.setDestinationUuid(result.getAddress().getServiceId().toString())
.setUnidentified(result.getSuccess().isUnidentified())
.build());
builder.setDestinationUuid(result.getAddress().getServiceId().toString());
if (result.getAddress().getNumber().isPresent()) {
builder.setDestinationE164(result.getAddress().getNumber().get());
}
builder.setUnidentified(result.getSuccess().isUnidentified());
sentMessage.addUnidentifiedStatus(builder.build());
}
}
if (recipient.isPresent()) {
sentMessage.setDestinationUuid(recipient.get().getServiceId().toString());
if (recipient.get().getNumber().isPresent()) {
sentMessage.setDestinationE164(recipient.get().getNumber().get());
}
}
if (dataMessage.getExpireTimer() > 0) {
@@ -1110,15 +1100,9 @@ public class SignalServiceMessageSender {
SyncMessage.Builder builder = createSyncMessageBuilder();
for (ReadMessage readMessage : readMessages) {
SyncMessage.Read.Builder readBuilder = SyncMessage.Read.newBuilder().setTimestamp(readMessage.getTimestamp());
readBuilder.setSenderUuid(readMessage.getSender().getServiceId().toString());
if (readMessage.getSender().getNumber().isPresent()) {
readBuilder.setSenderE164(readMessage.getSender().getNumber().get());
}
builder.addRead(readBuilder.build());
builder.addRead(SyncMessage.Read.newBuilder()
.setTimestamp(readMessage.getTimestamp())
.setSenderUuid(readMessage.getSender().getServiceId().toString()));
}
return container.setSyncMessage(builder).build();
@@ -1129,15 +1113,9 @@ public class SignalServiceMessageSender {
SyncMessage.Builder builder = createSyncMessageBuilder();
for (ViewedMessage readMessage : readMessages) {
SyncMessage.Viewed.Builder viewedBuilder = SyncMessage.Viewed.newBuilder().setTimestamp(readMessage.getTimestamp());
viewedBuilder.setSenderUuid(readMessage.getSender().getServiceId().toString());
if (readMessage.getSender().getNumber().isPresent()) {
viewedBuilder.setSenderE164(readMessage.getSender().getNumber().get());
}
builder.addViewed(viewedBuilder.build());
builder.addViewed(SyncMessage.Viewed.newBuilder()
.setTimestamp(readMessage.getTimestamp())
.setSenderUuid(readMessage.getSender().getServiceId().toString()));
}
return container.setSyncMessage(builder).build();
@@ -1146,15 +1124,10 @@ public class SignalServiceMessageSender {
private Content createMultiDeviceViewOnceOpenContent(ViewOnceOpenMessage readMessage) {
Content.Builder container = Content.newBuilder();
SyncMessage.Builder builder = createSyncMessageBuilder();
SyncMessage.ViewOnceOpen.Builder viewOnceBuilder = SyncMessage.ViewOnceOpen.newBuilder().setTimestamp(readMessage.getTimestamp());
viewOnceBuilder.setSenderUuid(readMessage.getSender().getServiceId().toString());
if (readMessage.getSender().getNumber().isPresent()) {
viewOnceBuilder.setSenderE164(readMessage.getSender().getNumber().get());
}
builder.setViewOnceOpen(viewOnceBuilder.build());
builder.setViewOnceOpen(SyncMessage.ViewOnceOpen.newBuilder()
.setTimestamp(readMessage.getTimestamp())
.setSenderUuid(readMessage.getSender().getServiceId().toString()));
return container.setSyncMessage(builder).build();
}
@@ -1265,9 +1238,6 @@ public class SignalServiceMessageSender {
}
if (message.getPerson().isPresent()) {
if (message.getPerson().get().getNumber().isPresent()) {
responseMessage.setThreadE164(message.getPerson().get().getNumber().get());
}
responseMessage.setThreadUuid(message.getPerson().get().getServiceId().toString());
}
@@ -1355,9 +1325,6 @@ public class SignalServiceMessageSender {
verifiedMessageBuilder.setIdentityKey(ByteString.copyFrom(verifiedMessage.getIdentityKey().serialize()));
verifiedMessageBuilder.setDestinationUuid(verifiedMessage.getDestination().getServiceId().toString());
if (verifiedMessage.getDestination().getNumber().isPresent()) {
verifiedMessageBuilder.setDestinationE164(verifiedMessage.getDestination().getNumber().get());
}
switch(verifiedMessage.getVerified()) {
case DEFAULT: verifiedMessageBuilder.setState(Verified.State.DEFAULT); break;
@@ -1850,13 +1817,13 @@ public class SignalServiceMessageSender {
} catch (GroupMismatchedDevicesException e) {
Log.w(TAG, "[sendGroupMessage][" + timestamp + "] Handling mismatched devices. (" + e.getMessage() + ")");
for (GroupMismatchedDevices mismatched : e.getMismatchedDevices()) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(mismatched.getUuid()), Optional.absent());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(mismatched.getUuid()), Optional.absent());
handleMismatchedDevices(socket, address, mismatched.getDevices());
}
} catch (GroupStaleDevicesException e) {
Log.w(TAG, "[sendGroupMessage][" + timestamp + "] Handling stale devices. (" + e.getMessage() + ")");
for (GroupStaleDevices stale : e.getStaleDevices()) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(stale.getUuid()), Optional.absent());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(stale.getUuid()), Optional.absent());
handleStaleDevices(address, stale.getDevices());
}
}
@@ -1905,7 +1872,7 @@ public class SignalServiceMessageSender {
}
private List<SendMessageResult> transformGroupResponseToMessageResults(Map<SignalServiceAddress, List<Integer>> recipients, SendGroupMessageResponse response, Content content) {
Set<ACI> unregistered = response.getUnsentTargets();
Set<ServiceId> unregistered = response.getUnsentTargets();
List<SendMessageResult> failures = unregistered.stream()
.map(SignalServiceAddress::new)

View File

@@ -46,26 +46,22 @@ import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.payments.Money;
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.storage.StorageKey;
import org.whispersystems.signalservice.api.util.AttachmentPointerUtil;
import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException;
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException;
import org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer;
import org.whispersystems.signalservice.internal.serialize.SignalServiceMetadataProtobufSerializer;
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto;
import org.whispersystems.util.FlagUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext.Type.DELIVER;
public final class SignalServiceContent {
@@ -594,8 +590,8 @@ public final class SignalServiceContent {
Map<SignalServiceAddress, Boolean> unidentifiedStatuses = new HashMap<>();
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(ACI.parseOrThrow(sentContent.getDestinationUuid()), sentContent.getDestinationE164()))
Optional<SignalServiceAddress> address = SignalServiceAddress.isValidAddress(sentContent.getDestinationUuid())
? Optional.of(new SignalServiceAddress(ServiceId.parseOrThrow(sentContent.getDestinationUuid())))
: Optional.<SignalServiceAddress>absent();
if (!address.isPresent() && !dataMessage.getGroupContext().isPresent()) {
@@ -603,8 +599,8 @@ public final class SignalServiceContent {
}
for (SignalServiceProtos.SyncMessage.Sent.UnidentifiedDeliveryStatus status : sentContent.getUnidentifiedStatusList()) {
if (SignalServiceAddress.isValidAddress(status.getDestinationUuid(), status.getDestinationE164())) {
SignalServiceAddress recipient = new SignalServiceAddress(ACI.parseOrThrow(status.getDestinationUuid()), status.getDestinationE164());
if (SignalServiceAddress.isValidAddress(status.getDestinationUuid(), null)) {
SignalServiceAddress recipient = new SignalServiceAddress(ServiceId.parseOrThrow(status.getDestinationUuid()));
unidentifiedStatuses.put(recipient, status.getUnidentified());
} else {
Log.w(TAG, "Encountered an invalid UnidentifiedDeliveryStatus in a SentTranscript! Ignoring.");
@@ -627,8 +623,8 @@ public final class SignalServiceContent {
List<ReadMessage> readMessages = new LinkedList<>();
for (SignalServiceProtos.SyncMessage.Read read : content.getReadList()) {
if (SignalServiceAddress.isValidAddress(read.getSenderUuid(), read.getSenderE164())) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(read.getSenderUuid()), read.getSenderE164());
if (SignalServiceAddress.isValidAddress(read.getSenderUuid())) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(read.getSenderUuid()));
readMessages.add(new ReadMessage(address, read.getTimestamp()));
} else {
Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
@@ -642,8 +638,8 @@ public final class SignalServiceContent {
List<ViewedMessage> viewedMessages = new LinkedList<>();
for (SignalServiceProtos.SyncMessage.Viewed viewed : content.getViewedList()) {
if (SignalServiceAddress.isValidAddress(viewed.getSenderUuid(), viewed.getSenderE164())) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(viewed.getSenderUuid()), viewed.getSenderE164());
if (SignalServiceAddress.isValidAddress(viewed.getSenderUuid())) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(viewed.getSenderUuid()));
viewedMessages.add(new ViewedMessage(address, viewed.getTimestamp()));
} else {
Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
@@ -654,8 +650,8 @@ public final class SignalServiceContent {
}
if (content.hasViewOnceOpen()) {
if (SignalServiceAddress.isValidAddress(content.getViewOnceOpen().getSenderUuid(), content.getViewOnceOpen().getSenderE164())) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(content.getViewOnceOpen().getSenderUuid()), content.getViewOnceOpen().getSenderE164());
if (SignalServiceAddress.isValidAddress(content.getViewOnceOpen().getSenderUuid())) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(content.getViewOnceOpen().getSenderUuid()));
ViewOnceOpenMessage timerRead = new ViewOnceOpenMessage(address, content.getViewOnceOpen().getTimestamp());
return SignalServiceSyncMessage.forViewOnceOpen(timerRead);
} else {
@@ -664,11 +660,11 @@ public final class SignalServiceContent {
}
if (content.hasVerified()) {
if (SignalServiceAddress.isValidAddress(content.getVerified().getDestinationUuid(), content.getVerified().getDestinationE164())) {
if (SignalServiceAddress.isValidAddress(content.getVerified().getDestinationUuid())) {
try {
SignalServiceProtos.Verified verified = content.getVerified();
SignalServiceAddress destination = new SignalServiceAddress(ACI.parseOrThrow(verified.getDestinationUuid()), verified.getDestinationE164());
IdentityKey identityKey = new IdentityKey(verified.getIdentityKey().toByteArray(), 0);
SignalServiceAddress destination = new SignalServiceAddress(ServiceId.parseOrThrow(verified.getDestinationUuid()));
IdentityKey identityKey = new IdentityKey(verified.getIdentityKey().toByteArray(), 0);
VerifiedMessage.VerifiedState verifiedState;
@@ -779,7 +775,7 @@ public final class SignalServiceContent {
if (content.getMessageRequestResponse().hasGroupId()) {
responseMessage = MessageRequestResponseMessage.forGroup(content.getMessageRequestResponse().getGroupId().toByteArray(), type);
} else {
Optional<SignalServiceAddress> address = SignalServiceAddress.fromRaw(content.getMessageRequestResponse().getThreadUuid(), content.getMessageRequestResponse().getThreadE164());
Optional<SignalServiceAddress> address = SignalServiceAddress.fromRaw(content.getMessageRequestResponse().getThreadUuid(), null);
if (address.isPresent()) {
responseMessage = MessageRequestResponseMessage.forIndividual(address.get(), type);
@@ -899,7 +895,7 @@ public final class SignalServiceContent {
return new SignalServiceTypingMessage(action, content.getTimestamp(),
content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) :
Optional.<byte[]>absent());
Optional.absent());
}
private static SignalServiceDataMessage.Quote createQuote(SignalServiceProtos.DataMessage content, boolean isGroupV2)
@@ -915,8 +911,8 @@ public final class SignalServiceContent {
attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
}
if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid(), content.getQuote().getAuthorE164())) {
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());
if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid())) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(content.getQuote().getAuthorUuid()));
return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
address,
@@ -963,7 +959,7 @@ public final class SignalServiceContent {
for (SignalServiceProtos.DataMessage.BodyRange bodyRange : bodyRanges) {
if (bodyRange.hasMentionUuid()) {
try {
mentions.add(new SignalServiceDataMessage.Mention(ACI.parseOrThrow(bodyRange.getMentionUuid()), bodyRange.getStart(), bodyRange.getLength()));
mentions.add(new SignalServiceDataMessage.Mention(ServiceId.parseOrThrow(bodyRange.getMentionUuid()), bodyRange.getStart(), bodyRange.getLength()));
} catch (IllegalArgumentException e) {
throw new InvalidMessageStructureException("Invalid body range!");
}
@@ -1005,17 +1001,17 @@ public final class SignalServiceContent {
return null;
}
SignalServiceProtos.DataMessage.Reaction reaction = content.getReaction();
ACI uuid = ACI.parseOrNull(reaction.getTargetAuthorUuid());
SignalServiceProtos.DataMessage.Reaction reaction = content.getReaction();
ServiceId serviceId = ServiceId.parseOrNull(reaction.getTargetAuthorUuid());
if (uuid == null) {
if (serviceId == null) {
Log.w(TAG, "Cannot parse author UUID on reaction");
return null;
}
return new SignalServiceDataMessage.Reaction(reaction.getEmoji(),
reaction.getRemove(),
new SignalServiceAddress(uuid),
new SignalServiceAddress(serviceId),
reaction.getTargetSentTimestamp());
}
@@ -1057,13 +1053,13 @@ public final class SignalServiceContent {
return null;
}
ACI aci = ACI.parseOrNull(content.getStoryContext().getAuthorUuid());
ServiceId serviceId = ServiceId.parseOrNull(content.getStoryContext().getAuthorUuid());
if (aci == null) {
if (serviceId == null) {
throw new InvalidMessageStructureException("Invalid author ACI!");
}
return new SignalServiceDataMessage.StoryContext(aci, content.getStoryContext().getSentTimestamp());
return new SignalServiceDataMessage.StoryContext(serviceId, content.getStoryContext().getSentTimestamp());
}
private static SignalServiceDataMessage.PaymentNotification createPaymentNotification(SignalServiceProtos.DataMessage.Payment content)

View File

@@ -10,7 +10,6 @@ import org.signal.zkgroup.groups.GroupSecretParams;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
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;
@@ -611,18 +610,18 @@ public class SignalServiceDataMessage {
}
public static class Mention {
private final ServiceId aci;
private final ServiceId serviceId;
private final int start;
private final int length;
public Mention(ServiceId aci, int start, int length) {
this.aci = aci;
this.start = start;
this.length = length;
public Mention(ServiceId serviceId, int start, int length) {
this.serviceId = serviceId;
this.start = start;
this.length = length;
}
public ServiceId getAci() {
return aci;
public ServiceId getServiceId() {
return serviceId;
}
public int getStart() {
@@ -678,16 +677,16 @@ public class SignalServiceDataMessage {
}
public static class StoryContext {
private final ACI authorAci;
private final long sentTimestamp;
private final ServiceId authorServiceId;
private final long sentTimestamp;
public StoryContext(ACI authorAci, long sentTimestamp) {
this.authorAci = authorAci;
this.sentTimestamp = sentTimestamp;
public StoryContext(ServiceId authorServiceId, long sentTimestamp) {
this.authorServiceId = authorServiceId;
this.sentTimestamp = sentTimestamp;
}
public ACI getAuthorAci() {
return authorAci;
public ServiceId getAuthorServiceId() {
return authorServiceId;
}
public long getSentTimestamp() {

View File

@@ -14,7 +14,7 @@ import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
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.internal.push.SignalServiceProtos;
import org.whispersystems.signalservice.internal.util.Util;
@@ -45,7 +45,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
throw new IOException("Missing contact address!");
}
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(details.getUuid()), details.getNumber());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.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,12 +66,11 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
if (details.hasVerified()) {
try {
if (!SignalServiceAddress.isValidAddress(details.getVerified().getDestinationUuid(), details.getVerified().getDestinationE164())) {
if (!SignalServiceAddress.isValidAddress(details.getVerified().getDestinationUuid(), null)) {
throw new InvalidMessageException("Missing Verified address!");
}
IdentityKey identityKey = new IdentityKey(details.getVerified().getIdentityKey().toByteArray(), 0);
SignalServiceAddress destination = new SignalServiceAddress(ACI.parseOrThrow(details.getVerified().getDestinationUuid()),
details.getVerified().getDestinationE164());
SignalServiceAddress destination = new SignalServiceAddress(ServiceId.parseOrThrow(details.getVerified().getDestinationUuid()));
VerifiedMessage.VerifiedState state;

View File

@@ -72,10 +72,6 @@ public class DeviceContactsOutputStream extends ChunkedOutputStream {
.setDestinationUuid(contact.getVerified().get().getDestination().getServiceId().toString())
.setState(state);
if (contact.getVerified().get().getDestination().getNumber().isPresent()) {
verifiedBuilder.setDestinationE164(contact.getVerified().get().getDestination().getNumber().get());
}
contactDetails.setVerified(verifiedBuilder.build());
}

View File

@@ -12,6 +12,7 @@ import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.profiles.ProfileKeyCredentialResponse;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.internal.util.JsonUtil;
import java.math.BigDecimal;
@@ -55,9 +56,9 @@ public class SignalServiceProfile {
private Capabilities capabilities;
@JsonProperty
@JsonSerialize(using = JsonUtil.AciSerializer.class)
@JsonDeserialize(using = JsonUtil.AciDeserializer.class)
private ACI uuid;
@JsonSerialize(using = JsonUtil.ServiceIdSerializer.class)
@JsonDeserialize(using = JsonUtil.ServiceIdDeserializer.class)
private ServiceId uuid;
@JsonProperty
private byte[] credential;
@@ -110,7 +111,7 @@ public class SignalServiceProfile {
return badges;
}
public ACI getAci() {
public ServiceId getServiceId() {
return uuid;
}

View File

@@ -12,8 +12,6 @@ import java.util.UUID;
*/
public final class ACI extends ServiceId {
public static final ACI UNKNOWN = ACI.from(UuidUtil.UNKNOWN_UUID);
public static ACI from(UUID uuid) {
return new ACI(uuid);
}

View File

@@ -66,13 +66,17 @@ public class SignalServiceAddress {
return this.serviceId.equals(other.serviceId);
}
public static boolean isValidAddress(String rawUuid) {
return isValidAddress(rawUuid, null);
}
public static boolean isValidAddress(String rawUuid, String e164) {
return UuidUtil.parseOrNull(rawUuid) != null;
}
public static Optional<SignalServiceAddress> fromRaw(String rawUuid, String e164) {
if (isValidAddress(rawUuid, e164)) {
return Optional.of(new SignalServiceAddress(ACI.parseOrThrow(rawUuid), e164));
return Optional.of(new SignalServiceAddress(ServiceId.parseOrThrow(rawUuid), e164));
} else {
return Optional.absent();
}

View File

@@ -6,7 +6,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.payments.PaymentsConstants;
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.ProtoUtil;
@@ -315,7 +315,7 @@ public final class SignalAccountRecord implements SignalRecord {
static PinnedConversation fromRemote(AccountRecord.PinnedConversation remote) {
if (remote.hasContact()) {
return forContact(new SignalServiceAddress(ACI.parseOrThrow(remote.getContact().getUuid()), remote.getContact().getE164()));
return forContact(new SignalServiceAddress(ServiceId.parseOrThrow(remote.getContact().getUuid()), remote.getContact().getE164()));
} else if (!remote.getLegacyGroupId().isEmpty()) {
return forGroupV1(remote.getLegacyGroupId().toByteArray());
} else if (!remote.getGroupMasterKey().isEmpty()) {

View File

@@ -6,6 +6,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
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.ProtoUtil;
@@ -37,7 +38,7 @@ public final class SignalContactRecord implements SignalRecord {
this.proto = proto;
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
this.address = new SignalServiceAddress(ACI.parseOrUnknown(proto.getServiceUuid()), proto.getServiceE164());
this.address = new SignalServiceAddress(ServiceId.parseOrUnknown(proto.getServiceUuid()), proto.getServiceE164());
this.givenName = OptionalUtil.absentIfEmpty(proto.getGivenName());
this.familyName = OptionalUtil.absentIfEmpty(proto.getFamilyName());
this.profileKey = OptionalUtil.absentIfEmpty(proto.getProfileKey());

View File

@@ -2,8 +2,10 @@ package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.HashSet;
@@ -12,21 +14,25 @@ import java.util.UUID;
public class SendGroupMessageResponse {
private static final String TAG = SendGroupMessageResponse.class.getSimpleName();
@JsonProperty
private String[] uuids404;
public SendGroupMessageResponse() {}
public Set<ACI> getUnsentTargets() {
Set<ACI> acis = new HashSet<>(uuids404.length);
public Set<ServiceId> getUnsentTargets() {
Set<ServiceId> serviceIds = new HashSet<>(uuids404.length);
for (String raw : uuids404) {
ACI parsed = ACI.parseOrNull(raw);
ServiceId parsed = ServiceId.parseOrNull(raw);
if (parsed != null) {
acis.add(parsed);
serviceIds.add(parsed);
} else {
Log.w(TAG, "Failed to parse ServiceId!");
}
}
return acis;
return serviceIds;
}
}

View File

@@ -22,6 +22,7 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.util.Base64;
@@ -131,4 +132,20 @@ public class JsonUtil {
return ACI.parseOrNull(p.getValueAsString());
}
}
public static class ServiceIdSerializer extends JsonSerializer<ServiceId> {
@Override
public void serialize(ServiceId value, JsonGenerator gen, SerializerProvider serializers)
throws IOException
{
gen.writeString(value.toString());
}
}
public static class ServiceIdDeserializer extends JsonDeserializer<ServiceId> {
@Override
public ServiceId deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return ServiceId.parseOrNull(p.getValueAsString());
}
}
}

View File

@@ -144,7 +144,7 @@ message DataMessage {
}
optional uint64 id = 1;
optional string authorE164 = 2;
reserved /*authorE164*/ 2;
optional string authorUuid = 5;
optional string text = 3;
repeated QuotedAttachment attachments = 4;
@@ -237,7 +237,7 @@ message DataMessage {
message Reaction {
optional string emoji = 1;
optional bool remove = 2;
reserved /* targetAuthorE164 */ 3; // removed
reserved /*targetAuthorE164*/ 3;
optional string targetAuthorUuid = 4;
optional uint64 targetSentTimestamp = 5;
}
@@ -363,7 +363,7 @@ message Verified {
UNVERIFIED = 2;
}
optional string destinationE164 = 1;
reserved /*destinationE164*/ 1;
optional string destinationUuid = 5;
optional bytes identityKey = 2;
optional State state = 3;
@@ -373,12 +373,12 @@ message Verified {
message SyncMessage {
message Sent {
message UnidentifiedDeliveryStatus {
optional string destinationE164 = 1;
reserved /*destinationE164*/ 1;
optional string destinationUuid = 3;
optional bool unidentified = 2;
}
optional string destinationE164 = 1;
reserved /*destinationE164*/ 1;
optional string destinationUuid = 7;
optional uint64 timestamp = 2;
optional DataMessage message = 3;
@@ -417,22 +417,22 @@ message SyncMessage {
}
message Read {
optional string senderE164 = 1;
reserved /*senderE164*/ 1;
optional string senderUuid = 3;
optional uint64 timestamp = 2;
}
message Viewed {
optional string senderE164 = 1;
reserved /*senderE164*/ 1;
optional string senderUuid = 3;
optional uint64 timestamp = 2;
optional uint64 timestamp = 2;
}
message Configuration {
optional bool readReceipts = 1;
optional bool unidentifiedDeliveryIndicators = 2;
optional bool typingIndicators = 3;
reserved /* linkPreviews */ 4; // removed
reserved /* linkPreviews */ 4;
optional uint32 provisioningVersion = 5;
optional bool linkPreviews = 6;
}
@@ -449,7 +449,7 @@ message SyncMessage {
}
message ViewOnceOpen {
optional string senderE164 = 1;
reserved /*senderE164*/ 1;
optional string senderUuid = 3;
optional uint64 timestamp = 2;
}
@@ -483,7 +483,7 @@ message SyncMessage {
BLOCK_AND_DELETE = 4;
}
optional string threadE164 = 1;
reserved /*threadE164*/ 1;
optional string threadUuid = 2;
optional bytes groupId = 3;
optional Type type = 4;

View File

@@ -7,7 +7,7 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.libsignal.util.guava.Optional;
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.internal.util.Util;
@@ -17,7 +17,6 @@ import java.io.IOException;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class DeviceContactsInputStreamTest {
@@ -25,8 +24,8 @@ public class DeviceContactsInputStreamTest {
public void read() throws IOException, InvalidInputException {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
DeviceContactsOutputStream output = new DeviceContactsOutputStream(byteArrayOut);
SignalServiceAddress addressFirst = new SignalServiceAddress(ACI.from(UUID.randomUUID()), "+1404555555");
SignalServiceAddress addressSecond = new SignalServiceAddress(ACI.from(UUID.randomUUID()), "+1444555555");
SignalServiceAddress addressFirst = new SignalServiceAddress(ServiceId.from(UUID.randomUUID()), "+1404555555");
SignalServiceAddress addressSecond = new SignalServiceAddress(ServiceId.from(UUID.randomUUID()), "+1444555555");
DeviceContact first = new DeviceContact(
addressFirst,

View File

@@ -2,24 +2,24 @@ package org.whispersystems.signalservice.api.storage;
import org.junit.Test;
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.UuidUtil;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class SignalContactRecordTest {
private static final ACI ACI_A = ACI.parseOrThrow("ebef429e-695e-4f51-bcc4-526a60ac68c7");
private static final String E164_A = "+16108675309";
private static final ServiceId SID_A = ServiceId.parseOrThrow("ebef429e-695e-4f51-bcc4-526a60ac68c7");
private static final String E164_A = "+16108675309";
@Test
public void contacts_with_same_identity_key_contents_are_equal() {
byte[] profileKey = new byte[32];
byte[] profileKeyCopy = profileKey.clone();
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setIdentityKey(profileKey).build();
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setIdentityKey(profileKeyCopy).build();
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setIdentityKey(profileKey).build();
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setIdentityKey(profileKeyCopy).build();
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
@@ -31,8 +31,8 @@ public class SignalContactRecordTest {
byte[] profileKeyCopy = profileKey.clone();
profileKeyCopy[0] = 1;
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setIdentityKey(profileKey).build();
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setIdentityKey(profileKeyCopy).build();
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setIdentityKey(profileKey).build();
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setIdentityKey(profileKeyCopy).build();
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
@@ -48,11 +48,11 @@ public class SignalContactRecordTest {
}
private static SignalContactRecord.Builder contactBuilder(int key,
ACI aci,
ServiceId serviceId,
String e164,
String givenName)
{
return new SignalContactRecord.Builder(byteArray(key), new SignalServiceAddress(aci, e164), null)
return new SignalContactRecord.Builder(byteArray(key), new SignalServiceAddress(serviceId, e164), null)
.setGivenName(givenName);
}
}