mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:18:25 +00:00
update signal service cipher for closed group update v2
This commit is contained in:
parent
806e48dc89
commit
3c8447a257
@ -76,6 +76,7 @@ import org.session.libsignal.service.internal.push.PushTransportDetails;
|
|||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos;
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.AttachmentPointer;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.AttachmentPointer;
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.ClosedGroupUpdate;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.ClosedGroupUpdate;
|
||||||
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.ClosedGroupUpdateV2;
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.Content;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.Content;
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.DataMessage;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.DataMessage;
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.Envelope.Type;
|
import org.session.libsignal.service.internal.push.SignalServiceProtos.Envelope.Type;
|
||||||
@ -142,7 +143,7 @@ public class SignalServiceCipher {
|
|||||||
public OutgoingPushMessage encrypt(SignalProtocolAddress destination,
|
public OutgoingPushMessage encrypt(SignalProtocolAddress destination,
|
||||||
Optional<UnidentifiedAccess> unidentifiedAccess,
|
Optional<UnidentifiedAccess> unidentifiedAccess,
|
||||||
byte[] unpaddedMessage)
|
byte[] unpaddedMessage)
|
||||||
throws UntrustedIdentityException, InvalidKeyException, IOException
|
throws UntrustedIdentityException, InvalidKeyException, IOException
|
||||||
{
|
{
|
||||||
if (unidentifiedAccess.isPresent() && sskDatabase.isSSKBasedClosedGroup(destination.getName())) {
|
if (unidentifiedAccess.isPresent() && sskDatabase.isSSKBasedClosedGroup(destination.getName())) {
|
||||||
String userPublicKey = localAddress.getNumber();
|
String userPublicKey = localAddress.getNumber();
|
||||||
@ -191,111 +192,111 @@ public class SignalServiceCipher {
|
|||||||
* @return a decrypted SignalServiceContent
|
* @return a decrypted SignalServiceContent
|
||||||
*/
|
*/
|
||||||
public SignalServiceContent decrypt(SignalServiceEnvelope envelope)
|
public SignalServiceContent decrypt(SignalServiceEnvelope envelope)
|
||||||
throws InvalidMetadataMessageException, InvalidMetadataVersionException,
|
throws InvalidMetadataMessageException, InvalidMetadataVersionException,
|
||||||
ProtocolInvalidKeyIdException, ProtocolLegacyMessageException,
|
ProtocolInvalidKeyIdException, ProtocolLegacyMessageException,
|
||||||
ProtocolUntrustedIdentityException, ProtocolNoSessionException,
|
ProtocolUntrustedIdentityException, ProtocolNoSessionException,
|
||||||
ProtocolInvalidVersionException, ProtocolInvalidMessageException,
|
ProtocolInvalidVersionException, ProtocolInvalidMessageException,
|
||||||
ProtocolInvalidKeyException, ProtocolDuplicateMessageException,
|
ProtocolInvalidKeyException, ProtocolDuplicateMessageException,
|
||||||
SelfSendException, IOException, SessionProtocol.Exception
|
SelfSendException, IOException, SessionProtocol.Exception
|
||||||
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Plaintext plaintext = decrypt(envelope, envelope.getContent());
|
Plaintext plaintext = decrypt(envelope, envelope.getContent());
|
||||||
Content message = Content.parseFrom(plaintext.getData());
|
Content message = Content.parseFrom(plaintext.getData());
|
||||||
|
|
||||||
PreKeyBundleMessage preKeyBundleMessage = null;
|
PreKeyBundleMessage preKeyBundleMessage = null;
|
||||||
if (message.hasPreKeyBundleMessage()) {
|
if (message.hasPreKeyBundleMessage()) {
|
||||||
SignalServiceProtos.PreKeyBundleMessage protoPreKeyBundleMessage = message.getPreKeyBundleMessage();
|
SignalServiceProtos.PreKeyBundleMessage protoPreKeyBundleMessage = message.getPreKeyBundleMessage();
|
||||||
preKeyBundleMessage = new PreKeyBundleMessage(protoPreKeyBundleMessage.getIdentityKey().toByteArray(),
|
preKeyBundleMessage = new PreKeyBundleMessage(protoPreKeyBundleMessage.getIdentityKey().toByteArray(),
|
||||||
protoPreKeyBundleMessage.getDeviceId(),
|
protoPreKeyBundleMessage.getDeviceId(),
|
||||||
protoPreKeyBundleMessage.getPreKeyId(),
|
protoPreKeyBundleMessage.getPreKeyId(),
|
||||||
protoPreKeyBundleMessage.getSignedKeyId(),
|
protoPreKeyBundleMessage.getSignedKeyId(),
|
||||||
protoPreKeyBundleMessage.getPreKey().toByteArray(),
|
protoPreKeyBundleMessage.getPreKey().toByteArray(),
|
||||||
protoPreKeyBundleMessage.getSignedKey().toByteArray(),
|
protoPreKeyBundleMessage.getSignedKey().toByteArray(),
|
||||||
protoPreKeyBundleMessage.getSignature().toByteArray()
|
protoPreKeyBundleMessage.getSignature().toByteArray()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.hasDeviceLinkMessage()) {
|
||||||
|
SignalServiceProtos.DeviceLinkMessage protoDeviceLinkMessage = message.getDeviceLinkMessage();
|
||||||
|
String masterPublicKey = protoDeviceLinkMessage.getPrimaryPublicKey();
|
||||||
|
String slavePublicKey = protoDeviceLinkMessage.getSecondaryPublicKey();
|
||||||
|
byte[] requestSignature = protoDeviceLinkMessage.hasRequestSignature() ? protoDeviceLinkMessage.getRequestSignature().toByteArray() : null;
|
||||||
|
byte[] authorizationSignature = protoDeviceLinkMessage.hasAuthorizationSignature() ? protoDeviceLinkMessage.getAuthorizationSignature().toByteArray() : null;
|
||||||
|
DeviceLink deviceLink = new DeviceLink(masterPublicKey, slavePublicKey, requestSignature, authorizationSignature);
|
||||||
|
SignalServiceCipher.Metadata metadata = plaintext.getMetadata();
|
||||||
|
SignalServiceContent content = new SignalServiceContent(deviceLink, metadata.getSender(), metadata.getSenderDevice(), metadata.getTimestamp());
|
||||||
|
|
||||||
|
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
||||||
|
|
||||||
|
if (message.hasSyncMessage() && message.getSyncMessage().hasContacts()) {
|
||||||
|
SignalServiceSyncMessage syncMessage = createSynchronizeMessage(metadata, message.getSyncMessage());
|
||||||
|
content.setSyncMessage(syncMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.hasDeviceLinkMessage()) {
|
if (message.hasDataMessage()) {
|
||||||
SignalServiceProtos.DeviceLinkMessage protoDeviceLinkMessage = message.getDeviceLinkMessage();
|
setProfile(message.getDataMessage(), content);
|
||||||
String masterPublicKey = protoDeviceLinkMessage.getPrimaryPublicKey();
|
SignalServiceDataMessage signalServiceDataMessage = createSignalServiceMessage(metadata, message.getDataMessage());
|
||||||
String slavePublicKey = protoDeviceLinkMessage.getSecondaryPublicKey();
|
content.setDataMessage(signalServiceDataMessage);
|
||||||
byte[] requestSignature = protoDeviceLinkMessage.hasRequestSignature() ? protoDeviceLinkMessage.getRequestSignature().toByteArray() : null;
|
}
|
||||||
byte[] authorizationSignature = protoDeviceLinkMessage.hasAuthorizationSignature() ? protoDeviceLinkMessage.getAuthorizationSignature().toByteArray() : null;
|
|
||||||
DeviceLink deviceLink = new DeviceLink(masterPublicKey, slavePublicKey, requestSignature, authorizationSignature);
|
|
||||||
Metadata metadata = plaintext.getMetadata();
|
|
||||||
SignalServiceContent content = new SignalServiceContent(deviceLink, metadata.getSender(), metadata.getSenderDevice(), metadata.getTimestamp());
|
|
||||||
|
|
||||||
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
return content;
|
||||||
|
} else if (message.hasDataMessage()) {
|
||||||
|
DataMessage dataMessage = message.getDataMessage();
|
||||||
|
|
||||||
if (message.hasSyncMessage() && message.getSyncMessage().hasContacts()) {
|
SignalServiceDataMessage signalServiceDataMessage = createSignalServiceMessage(plaintext.getMetadata(), dataMessage);
|
||||||
SignalServiceSyncMessage syncMessage = createSynchronizeMessage(metadata, message.getSyncMessage());
|
SignalServiceContent content = new SignalServiceContent(signalServiceDataMessage,
|
||||||
content.setSyncMessage(syncMessage);
|
plaintext.getMetadata().getSender(),
|
||||||
}
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp(),
|
||||||
|
plaintext.getMetadata().isNeedsReceipt(),
|
||||||
|
signalServiceDataMessage.isDeviceUnlinkingRequest());
|
||||||
|
|
||||||
if (message.hasDataMessage()) {
|
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
||||||
setProfile(message.getDataMessage(), content);
|
|
||||||
SignalServiceDataMessage signalServiceDataMessage = createSignalServiceMessage(metadata, message.getDataMessage());
|
|
||||||
content.setDataMessage(signalServiceDataMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
setProfile(dataMessage, content);
|
||||||
} else if (message.hasDataMessage()) {
|
|
||||||
DataMessage dataMessage = message.getDataMessage();
|
|
||||||
|
|
||||||
SignalServiceDataMessage signalServiceDataMessage = createSignalServiceMessage(plaintext.getMetadata(), dataMessage);
|
return content;
|
||||||
SignalServiceContent content = new SignalServiceContent(signalServiceDataMessage,
|
} else if (message.hasSyncMessage()) {
|
||||||
plaintext.getMetadata().getSender(),
|
SignalServiceContent content = new SignalServiceContent(createSynchronizeMessage(
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
plaintext.getMetadata(),
|
||||||
plaintext.getMetadata().getTimestamp(),
|
message.getSyncMessage()),
|
||||||
plaintext.getMetadata().isNeedsReceipt(),
|
plaintext.getMetadata().getSender(),
|
||||||
signalServiceDataMessage.isDeviceUnlinkingRequest());
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp());
|
||||||
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
|
||||||
|
|
||||||
|
if (message.getSyncMessage().hasSent() && message.getSyncMessage().getSent().hasMessage()) {
|
||||||
|
DataMessage dataMessage = message.getSyncMessage().getSent().getMessage();
|
||||||
setProfile(dataMessage, content);
|
setProfile(dataMessage, content);
|
||||||
|
|
||||||
return content;
|
|
||||||
} else if (message.hasSyncMessage()) {
|
|
||||||
SignalServiceContent content = new SignalServiceContent(createSynchronizeMessage(
|
|
||||||
plaintext.getMetadata(),
|
|
||||||
message.getSyncMessage()),
|
|
||||||
plaintext.getMetadata().getSender(),
|
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
|
||||||
plaintext.getMetadata().getTimestamp());
|
|
||||||
|
|
||||||
if (message.getSyncMessage().hasSent() && message.getSyncMessage().getSent().hasMessage()) {
|
|
||||||
DataMessage dataMessage = message.getSyncMessage().getSent().getMessage();
|
|
||||||
setProfile(dataMessage, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
} else if (message.hasCallMessage()) {
|
|
||||||
return new SignalServiceContent(createCallMessage(message.getCallMessage()),
|
|
||||||
plaintext.getMetadata().getSender(),
|
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
|
||||||
plaintext.getMetadata().getTimestamp());
|
|
||||||
} else if (message.hasReceiptMessage()) {
|
|
||||||
return new SignalServiceContent(createReceiptMessage(plaintext.getMetadata(), message.getReceiptMessage()),
|
|
||||||
plaintext.getMetadata().getSender(),
|
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
|
||||||
plaintext.getMetadata().getTimestamp());
|
|
||||||
} else if (message.hasTypingMessage()) {
|
|
||||||
return new SignalServiceContent(createTypingMessage(plaintext.getMetadata(), message.getTypingMessage()),
|
|
||||||
plaintext.getMetadata().getSender(),
|
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
|
||||||
plaintext.getMetadata().getTimestamp());
|
|
||||||
} else if (message.hasNullMessage()) {
|
|
||||||
SignalServiceContent content = new SignalServiceContent(new SignalServiceNullMessage(),
|
|
||||||
plaintext.getMetadata().getSender(),
|
|
||||||
plaintext.getMetadata().getSenderDevice(),
|
|
||||||
plaintext.getMetadata().getTimestamp());
|
|
||||||
|
|
||||||
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
} else if (message.hasCallMessage()) {
|
||||||
|
return new SignalServiceContent(createCallMessage(message.getCallMessage()),
|
||||||
|
plaintext.getMetadata().getSender(),
|
||||||
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp());
|
||||||
|
} else if (message.hasReceiptMessage()) {
|
||||||
|
return new SignalServiceContent(createReceiptMessage(plaintext.getMetadata(), message.getReceiptMessage()),
|
||||||
|
plaintext.getMetadata().getSender(),
|
||||||
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp());
|
||||||
|
} else if (message.hasTypingMessage()) {
|
||||||
|
return new SignalServiceContent(createTypingMessage(plaintext.getMetadata(), message.getTypingMessage()),
|
||||||
|
plaintext.getMetadata().getSender(),
|
||||||
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp());
|
||||||
|
} else if (message.hasNullMessage()) {
|
||||||
|
SignalServiceContent content = new SignalServiceContent(new SignalServiceNullMessage(),
|
||||||
|
plaintext.getMetadata().getSender(),
|
||||||
|
plaintext.getMetadata().getSenderDevice(),
|
||||||
|
plaintext.getMetadata().getTimestamp());
|
||||||
|
|
||||||
|
content.setPreKeyBundleMessage(preKeyBundleMessage);
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
throw new InvalidMetadataMessageException(e);
|
throw new InvalidMetadataMessageException(e);
|
||||||
@ -310,12 +311,12 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Plaintext decrypt(SignalServiceEnvelope envelope, byte[] ciphertext)
|
protected Plaintext decrypt(SignalServiceEnvelope envelope, byte[] ciphertext)
|
||||||
throws InvalidMetadataMessageException, InvalidMetadataVersionException,
|
throws InvalidMetadataMessageException, InvalidMetadataVersionException,
|
||||||
ProtocolDuplicateMessageException, ProtocolUntrustedIdentityException,
|
ProtocolDuplicateMessageException, ProtocolUntrustedIdentityException,
|
||||||
ProtocolLegacyMessageException, ProtocolInvalidKeyException,
|
ProtocolLegacyMessageException, ProtocolInvalidKeyException,
|
||||||
ProtocolInvalidVersionException, ProtocolInvalidMessageException,
|
ProtocolInvalidVersionException, ProtocolInvalidMessageException,
|
||||||
ProtocolInvalidKeyIdException, ProtocolNoSessionException,
|
ProtocolInvalidKeyIdException, ProtocolNoSessionException,
|
||||||
SelfSendException, IOException, SessionProtocol.Exception
|
SelfSendException, IOException, SessionProtocol.Exception
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), envelope.getSourceDevice());
|
SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), envelope.getSourceDevice());
|
||||||
@ -387,7 +388,7 @@ public class SignalServiceCipher {
|
|||||||
List<Preview> previews = createPreviews(content);
|
List<Preview> previews = createPreviews(content);
|
||||||
Sticker sticker = createSticker(content);
|
Sticker sticker = createSticker(content);
|
||||||
ClosedGroupUpdate closedGroupUpdate = content.getClosedGroupUpdate();
|
ClosedGroupUpdate closedGroupUpdate = content.getClosedGroupUpdate();
|
||||||
SignalServiceProtos.ClosedGroupUpdateV2 closedGroupUpdateV2 = content.getClosedGroupUpdateV2();
|
ClosedGroupUpdateV2 closedGroupUpdateV2 = content.getClosedGroupUpdateV2();
|
||||||
boolean isDeviceUnlinkingRequest = ((content.getFlags() & DataMessage.Flags.DEVICE_UNLINKING_REQUEST_VALUE) != 0);
|
boolean isDeviceUnlinkingRequest = ((content.getFlags() & DataMessage.Flags.DEVICE_UNLINKING_REQUEST_VALUE) != 0);
|
||||||
|
|
||||||
for (AttachmentPointer pointer : content.getAttachmentsList()) {
|
for (AttachmentPointer pointer : content.getAttachmentsList()) {
|
||||||
@ -396,32 +397,32 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
|
if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
|
||||||
throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
|
throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
|
||||||
metadata.getSender(),
|
metadata.getSender(),
|
||||||
metadata.getSenderDevice());
|
metadata.getSenderDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SignalServiceDataMessage(metadata.getTimestamp(),
|
return new SignalServiceDataMessage(metadata.getTimestamp(),
|
||||||
groupInfo,
|
groupInfo,
|
||||||
attachments,
|
attachments,
|
||||||
content.getBody(),
|
content.getBody(),
|
||||||
endSession,
|
endSession,
|
||||||
content.getExpireTimer(),
|
content.getExpireTimer(),
|
||||||
expirationUpdate,
|
expirationUpdate,
|
||||||
content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
|
content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
|
||||||
profileKeyUpdate,
|
profileKeyUpdate,
|
||||||
quote,
|
quote,
|
||||||
sharedContacts,
|
sharedContacts,
|
||||||
previews,
|
previews,
|
||||||
sticker,
|
sticker,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
closedGroupUpdate,
|
closedGroupUpdate,
|
||||||
closedGroupUpdateV2,
|
closedGroupUpdateV2,
|
||||||
isDeviceUnlinkingRequest);
|
isDeviceUnlinkingRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceSyncMessage createSynchronizeMessage(Metadata metadata, SyncMessage content)
|
private SignalServiceSyncMessage createSynchronizeMessage(Metadata metadata, SyncMessage content)
|
||||||
throws ProtocolInvalidMessageException, ProtocolInvalidKeyException
|
throws ProtocolInvalidMessageException, ProtocolInvalidKeyException
|
||||||
{
|
{
|
||||||
if (content.hasSent()) {
|
if (content.hasSent()) {
|
||||||
SyncMessage.Sent sentContent = content.getSent();
|
SyncMessage.Sent sentContent = content.getSent();
|
||||||
@ -432,10 +433,10 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return SignalServiceSyncMessage.forSentTranscript(new SentTranscriptMessage(sentContent.getDestination(),
|
return SignalServiceSyncMessage.forSentTranscript(new SentTranscriptMessage(sentContent.getDestination(),
|
||||||
sentContent.getTimestamp(),
|
sentContent.getTimestamp(),
|
||||||
createSignalServiceMessage(metadata, sentContent.getMessage()),
|
createSignalServiceMessage(metadata, sentContent.getMessage()),
|
||||||
sentContent.getExpirationStartTimestamp(),
|
sentContent.getExpirationStartTimestamp(),
|
||||||
unidentifiedStatuses));
|
unidentifiedStatuses));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.hasRequest()) {
|
if (content.hasRequest()) {
|
||||||
@ -458,10 +459,10 @@ public class SignalServiceCipher {
|
|||||||
if (data != null && !data.isEmpty()) {
|
if (data != null && !data.isEmpty()) {
|
||||||
byte[] bytes = data.toByteArray();
|
byte[] bytes = data.toByteArray();
|
||||||
SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
||||||
.withStream(new ByteArrayInputStream(data.toByteArray()))
|
.withStream(new ByteArrayInputStream(data.toByteArray()))
|
||||||
.withContentType("application/octet-stream")
|
.withContentType("application/octet-stream")
|
||||||
.withLength(bytes.length)
|
.withLength(bytes.length)
|
||||||
.build();
|
.build();
|
||||||
return SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, contacts.getComplete()));
|
return SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, contacts.getComplete()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,10 +473,10 @@ public class SignalServiceCipher {
|
|||||||
if (data != null && !data.isEmpty()) {
|
if (data != null && !data.isEmpty()) {
|
||||||
byte[] bytes = data.toByteArray();
|
byte[] bytes = data.toByteArray();
|
||||||
SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
||||||
.withStream(new ByteArrayInputStream(data.toByteArray()))
|
.withStream(new ByteArrayInputStream(data.toByteArray()))
|
||||||
.withContentType("application/octet-stream")
|
.withContentType("application/octet-stream")
|
||||||
.withLength(bytes.length)
|
.withLength(bytes.length)
|
||||||
.build();
|
.build();
|
||||||
return SignalServiceSyncMessage.forGroups(attachmentStream);
|
return SignalServiceSyncMessage.forGroups(attachmentStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,7 +497,7 @@ public class SignalServiceCipher {
|
|||||||
verifiedState = VerifiedState.UNVERIFIED;
|
verifiedState = VerifiedState.UNVERIFIED;
|
||||||
} else {
|
} else {
|
||||||
throw new ProtocolInvalidMessageException(new InvalidMessageException("Unknown state: " + verified.getState().getNumber()),
|
throw new ProtocolInvalidMessageException(new InvalidMessageException("Unknown state: " + verified.getState().getNumber()),
|
||||||
metadata.getSender(), metadata.getSenderDevice());
|
metadata.getSender(), metadata.getSenderDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
return SignalServiceSyncMessage.forVerified(new VerifiedMessage(destination, identityKey, verifiedState, System.currentTimeMillis()));
|
return SignalServiceSyncMessage.forVerified(new VerifiedMessage(destination, identityKey, verifiedState, System.currentTimeMillis()));
|
||||||
@ -527,17 +528,17 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
List<SyncMessage.OpenGroupDetails> openGroupDetails = content.getOpenGroupsList();
|
List<SyncMessage.OpenGroupDetails> openGroupDetails = content.getOpenGroupsList();
|
||||||
if (openGroupDetails.size() > 0) {
|
if (openGroupDetails.size() > 0) {
|
||||||
List<PublicChat> openGroups = new LinkedList<>();
|
List<PublicChat> openGroups = new LinkedList<>();
|
||||||
for (SyncMessage.OpenGroupDetails details : content.getOpenGroupsList()) {
|
for (SyncMessage.OpenGroupDetails details : content.getOpenGroupsList()) {
|
||||||
openGroups.add(new PublicChat(details.getChannelID(), details.getUrl(), "", true));
|
openGroups.add(new PublicChat(details.getChannelID(), details.getUrl(), "", true));
|
||||||
}
|
}
|
||||||
return SignalServiceSyncMessage.forOpenGroups(openGroups);
|
return SignalServiceSyncMessage.forOpenGroups(openGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.hasBlocked()) {
|
if (content.hasBlocked()) {
|
||||||
SyncMessage.Blocked blocked = content.getBlocked();
|
SyncMessage.Blocked blocked = content.getBlocked();
|
||||||
List<String> publicKeys = blocked.getNumbersList();
|
List<String> publicKeys = blocked.getNumbersList();
|
||||||
return SignalServiceSyncMessage.forBlocked(new BlockedListMessage(publicKeys, new ArrayList<byte[]>()));
|
return SignalServiceSyncMessage.forBlocked(new BlockedListMessage(publicKeys, new ArrayList<byte[]>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return SignalServiceSyncMessage.empty();
|
return SignalServiceSyncMessage.empty();
|
||||||
@ -588,13 +589,13 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
|
if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
|
||||||
throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
|
throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
|
||||||
metadata.getSender(),
|
metadata.getSender(),
|
||||||
metadata.getSenderDevice());
|
metadata.getSenderDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SignalServiceTypingMessage(action, content.getTimestamp(),
|
return new SignalServiceTypingMessage(action, content.getTimestamp(),
|
||||||
content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) :
|
content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) :
|
||||||
Optional.<byte[]>absent());
|
Optional.<byte[]>absent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceDataMessage.Quote createQuote(DataMessage content) {
|
private SignalServiceDataMessage.Quote createQuote(DataMessage content) {
|
||||||
@ -604,14 +605,14 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
for (DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
|
for (DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
|
||||||
attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
|
attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
|
||||||
attachment.getFileName(),
|
attachment.getFileName(),
|
||||||
attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
|
attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
|
return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
|
||||||
new SignalServiceAddress(content.getQuote().getAuthor()),
|
new SignalServiceAddress(content.getQuote().getAuthor()),
|
||||||
content.getQuote().getText(),
|
content.getQuote().getText(),
|
||||||
attachments);
|
attachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Preview> createPreviews(DataMessage content) {
|
private List<Preview> createPreviews(DataMessage content) {
|
||||||
@ -627,8 +628,8 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
results.add(new Preview(preview.getUrl(),
|
results.add(new Preview(preview.getUrl(),
|
||||||
preview.getTitle(),
|
preview.getTitle(),
|
||||||
Optional.fromNullable(attachment)));
|
Optional.fromNullable(attachment)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
@ -636,10 +637,10 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
private Sticker createSticker(DataMessage content) {
|
private Sticker createSticker(DataMessage content) {
|
||||||
if (!content.hasSticker() ||
|
if (!content.hasSticker() ||
|
||||||
!content.getSticker().hasPackId() ||
|
!content.getSticker().hasPackId() ||
|
||||||
!content.getSticker().hasPackKey() ||
|
!content.getSticker().hasPackKey() ||
|
||||||
!content.getSticker().hasStickerId() ||
|
!content.getSticker().hasStickerId() ||
|
||||||
!content.getSticker().hasData())
|
!content.getSticker().hasData())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -647,9 +648,9 @@ public class SignalServiceCipher {
|
|||||||
DataMessage.Sticker sticker = content.getSticker();
|
DataMessage.Sticker sticker = content.getSticker();
|
||||||
|
|
||||||
return new Sticker(sticker.getPackId().toByteArray(),
|
return new Sticker(sticker.getPackId().toByteArray(),
|
||||||
sticker.getPackKey().toByteArray(),
|
sticker.getPackKey().toByteArray(),
|
||||||
sticker.getStickerId(),
|
sticker.getStickerId(),
|
||||||
createAttachmentPointer(sticker.getData()));
|
createAttachmentPointer(sticker.getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SharedContact> createSharedContacts(DataMessage content) {
|
private List<SharedContact> createSharedContacts(DataMessage content) {
|
||||||
@ -659,14 +660,14 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
for (DataMessage.Contact contact : content.getContactList()) {
|
for (DataMessage.Contact contact : content.getContactList()) {
|
||||||
SharedContact.Builder builder = SharedContact.newBuilder()
|
SharedContact.Builder builder = SharedContact.newBuilder()
|
||||||
.setName(SharedContact.Name.newBuilder()
|
.setName(SharedContact.Name.newBuilder()
|
||||||
.setDisplay(contact.getName().getDisplayName())
|
.setDisplay(contact.getName().getDisplayName())
|
||||||
.setFamily(contact.getName().getFamilyName())
|
.setFamily(contact.getName().getFamilyName())
|
||||||
.setGiven(contact.getName().getGivenName())
|
.setGiven(contact.getName().getGivenName())
|
||||||
.setMiddle(contact.getName().getMiddleName())
|
.setMiddle(contact.getName().getMiddleName())
|
||||||
.setPrefix(contact.getName().getPrefix())
|
.setPrefix(contact.getName().getPrefix())
|
||||||
.setSuffix(contact.getName().getSuffix())
|
.setSuffix(contact.getName().getSuffix())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
if (contact.getAddressCount() > 0) {
|
if (contact.getAddressCount() > 0) {
|
||||||
for (DataMessage.Contact.PostalAddress address : contact.getAddressList()) {
|
for (DataMessage.Contact.PostalAddress address : contact.getAddressList()) {
|
||||||
@ -679,16 +680,16 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.withAddress(SharedContact.PostalAddress.newBuilder()
|
builder.withAddress(SharedContact.PostalAddress.newBuilder()
|
||||||
.setCity(address.getCity())
|
.setCity(address.getCity())
|
||||||
.setCountry(address.getCountry())
|
.setCountry(address.getCountry())
|
||||||
.setLabel(address.getLabel())
|
.setLabel(address.getLabel())
|
||||||
.setNeighborhood(address.getNeighborhood())
|
.setNeighborhood(address.getNeighborhood())
|
||||||
.setPobox(address.getPobox())
|
.setPobox(address.getPobox())
|
||||||
.setPostcode(address.getPostcode())
|
.setPostcode(address.getPostcode())
|
||||||
.setRegion(address.getRegion())
|
.setRegion(address.getRegion())
|
||||||
.setStreet(address.getStreet())
|
.setStreet(address.getStreet())
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,10 +705,10 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.withPhone(SharedContact.Phone.newBuilder()
|
builder.withPhone(SharedContact.Phone.newBuilder()
|
||||||
.setLabel(phone.getLabel())
|
.setLabel(phone.getLabel())
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.setValue(phone.getValue())
|
.setValue(phone.getValue())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,18 +724,18 @@ public class SignalServiceCipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.withEmail(SharedContact.Email.newBuilder()
|
builder.withEmail(SharedContact.Email.newBuilder()
|
||||||
.setLabel(email.getLabel())
|
.setLabel(email.getLabel())
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.setValue(email.getValue())
|
.setValue(email.getValue())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.hasAvatar()) {
|
if (contact.hasAvatar()) {
|
||||||
builder.setAvatar(SharedContact.Avatar.newBuilder()
|
builder.setAvatar(SharedContact.Avatar.newBuilder()
|
||||||
.withAttachment(createAttachmentPointer(contact.getAvatar().getAvatar()))
|
.withAttachment(createAttachmentPointer(contact.getAvatar().getAvatar()))
|
||||||
.withProfileFlag(contact.getAvatar().getIsProfile())
|
.withProfileFlag(contact.getAvatar().getIsProfile())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact.hasOrganization()) {
|
if (contact.hasOrganization()) {
|
||||||
@ -749,16 +750,16 @@ public class SignalServiceCipher {
|
|||||||
|
|
||||||
private SignalServiceAttachmentPointer createAttachmentPointer(AttachmentPointer pointer) {
|
private SignalServiceAttachmentPointer createAttachmentPointer(AttachmentPointer pointer) {
|
||||||
return new SignalServiceAttachmentPointer(pointer.getId(),
|
return new SignalServiceAttachmentPointer(pointer.getId(),
|
||||||
pointer.getContentType(),
|
pointer.getContentType(),
|
||||||
pointer.getKey().toByteArray(),
|
pointer.getKey().toByteArray(),
|
||||||
pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
|
pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
|
||||||
pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
|
pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
|
||||||
pointer.getWidth(), pointer.getHeight(),
|
pointer.getWidth(), pointer.getHeight(),
|
||||||
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
|
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
|
||||||
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
|
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
|
||||||
(pointer.getFlags() & AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
|
(pointer.getFlags() & AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
|
||||||
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
|
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
|
||||||
pointer.getUrl());
|
pointer.getUrl());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,15 +794,15 @@ public class SignalServiceCipher {
|
|||||||
AttachmentPointer pointer = content.getGroup().getAvatar();
|
AttachmentPointer pointer = content.getGroup().getAvatar();
|
||||||
|
|
||||||
avatar = new SignalServiceAttachmentPointer(pointer.getId(),
|
avatar = new SignalServiceAttachmentPointer(pointer.getId(),
|
||||||
pointer.getContentType(),
|
pointer.getContentType(),
|
||||||
pointer.getKey().toByteArray(),
|
pointer.getKey().toByteArray(),
|
||||||
Optional.of(pointer.getSize()),
|
Optional.of(pointer.getSize()),
|
||||||
Optional.<byte[]>absent(), 0, 0,
|
Optional.<byte[]>absent(), 0, 0,
|
||||||
Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null),
|
Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null),
|
||||||
Optional.<String>absent(),
|
Optional.<String>absent(),
|
||||||
false,
|
false,
|
||||||
Optional.<String>absent(),
|
Optional.<String>absent(),
|
||||||
pointer.getUrl());
|
pointer.getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.getGroup().getAdminsCount() > 0) {
|
if (content.getGroup().getAdminsCount() > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user