Update libsignal-service-java

This commit is contained in:
AsamK 2022-05-14 15:08:19 +02:00
parent 5837a6982b
commit a80e18169a
14 changed files with 84 additions and 46 deletions

View file

@ -81,6 +81,7 @@
{ {
"name":"org.signal.libsignal.protocol.IdentityKey", "name":"org.signal.libsignal.protocol.IdentityKey",
"methods":[ "methods":[
{"name":"<init>","parameterTypes":["long"] },
{"name":"<init>","parameterTypes":["byte[]"] }, {"name":"<init>","parameterTypes":["byte[]"] },
{"name":"serialize","parameterTypes":[] } {"name":"serialize","parameterTypes":[] }
] ]
@ -102,7 +103,10 @@
}, },
{ {
"name":"org.signal.libsignal.protocol.SignalProtocolAddress", "name":"org.signal.libsignal.protocol.SignalProtocolAddress",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","int"] }] "methods":[
{"name":"<init>","parameterTypes":["long"] },
{"name":"<init>","parameterTypes":["java.lang.String","int"] }
]
}, },
{ {
"name":"org.signal.libsignal.protocol.UntrustedIdentityException", "name":"org.signal.libsignal.protocol.UntrustedIdentityException",
@ -159,7 +163,10 @@
{ {
"name":"org.signal.libsignal.protocol.state.SessionRecord", "name":"org.signal.libsignal.protocol.state.SessionRecord",
"fields":[{"name":"unsafeHandle"}], "fields":[{"name":"unsafeHandle"}],
"methods":[{"name":"<init>","parameterTypes":["byte[]"] }] "methods":[
{"name":"<init>","parameterTypes":["long"] },
{"name":"<init>","parameterTypes":["byte[]"] }
]
}, },
{ {
"name":"org.signal.libsignal.protocol.state.SessionStore" "name":"org.signal.libsignal.protocol.state.SessionStore"
@ -171,6 +178,10 @@
{ {
"name":"org.signal.libsignal.protocol.state.SignedPreKeyStore" "name":"org.signal.libsignal.protocol.state.SignedPreKeyStore"
}, },
{
"name":"org.signal.libsignal.zkgroup.InvalidInputException",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
},
{ {
"name":"org.sqlite.Collation" "name":"org.sqlite.Collation"
}, },

View file

@ -2560,6 +2560,7 @@
{"name":"delete_"}, {"name":"delete_"},
{"name":"expireTimer_"}, {"name":"expireTimer_"},
{"name":"flags_"}, {"name":"flags_"},
{"name":"giftBadge_"},
{"name":"groupCallUpdate_"}, {"name":"groupCallUpdate_"},
{"name":"groupV2_"}, {"name":"groupV2_"},
{"name":"group_"}, {"name":"group_"},
@ -2953,6 +2954,8 @@
{"name":"expirationStartTimestamp_"}, {"name":"expirationStartTimestamp_"},
{"name":"isRecipientUpdate_"}, {"name":"isRecipientUpdate_"},
{"name":"message_"}, {"name":"message_"},
{"name":"storyMessageRecipients_"},
{"name":"storyMessage_"},
{"name":"timestamp_"}, {"name":"timestamp_"},
{"name":"unidentifiedStatus_"} {"name":"unidentifiedStatus_"}
] ]
@ -3042,6 +3045,7 @@
"fields":[ "fields":[
{"name":"address_"}, {"name":"address_"},
{"name":"bitField0_"}, {"name":"bitField0_"},
{"name":"destinationUuid_"},
{"name":"groupId_"}, {"name":"groupId_"},
{"name":"needsReceipt_"}, {"name":"needsReceipt_"},
{"name":"senderDevice_"}, {"name":"senderDevice_"},

View file

@ -14,7 +14,7 @@ repositories {
} }
dependencies { dependencies {
implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_47") implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_48")
implementation("com.fasterxml.jackson.core", "jackson-databind", "2.13.2.2") implementation("com.fasterxml.jackson.core", "jackson-databind", "2.13.2.2")
implementation("com.google.protobuf", "protobuf-javalite", "3.11.4") implementation("com.google.protobuf", "protobuf-javalite", "3.11.4")
implementation("org.bouncycastle", "bcprov-jdk15on", "1.70") implementation("org.bouncycastle", "bcprov-jdk15on", "1.70")

View file

@ -540,7 +540,8 @@ class ManagerImpl implements Manager {
.resolveSignalServiceAddress(context.getRecipientHelper().resolveRecipient(quote.author())), .resolveSignalServiceAddress(context.getRecipientHelper().resolveRecipient(quote.author())),
quote.message(), quote.message(),
List.of(), List.of(),
resolveMentions(quote.mentions()))); resolveMentions(quote.mentions()),
SignalServiceDataMessage.Quote.Type.NORMAL));
} }
if (message.sticker().isPresent()) { if (message.sticker().isPresent()) {
final var sticker = message.sticker().get(); final var sticker = message.sticker().get();

View file

@ -517,7 +517,7 @@ public record MessageEnvelope(
long expirationStartTimestamp, long expirationStartTimestamp,
Optional<RecipientAddress> destination, Optional<RecipientAddress> destination,
Set<RecipientAddress> recipients, Set<RecipientAddress> recipients,
Data message Optional<Data> message
) { ) {
static Sent from( static Sent from(
@ -534,7 +534,8 @@ public record MessageEnvelope(
.stream() .stream()
.map(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(d))) .map(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(d)))
.collect(Collectors.toSet()), .collect(Collectors.toSet()),
Data.from(sentMessage.getMessage(), recipientResolver, addressResolver, fileProvider)); sentMessage.getDataMessage()
.map(message -> Data.from(message, recipientResolver, addressResolver, fileProvider)));
} }
} }

View file

@ -31,7 +31,7 @@ public class ServiceConfig {
public static final AccountAttributes.Capabilities capabilities; public static final AccountAttributes.Capabilities capabilities;
static { static {
capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, true, false); capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, true, false, false);
try { try {
TrustStore contactTrustStore = new IasTrustStore(); TrustStore contactTrustStore = new IasTrustStore();
@ -50,7 +50,8 @@ public class ServiceConfig {
try { try {
try { try {
org.signal.libsignal.internal.Native.UuidCiphertext_CheckValidContents(new byte[0]); org.signal.libsignal.internal.Native.UuidCiphertext_CheckValidContents(new byte[0]);
} catch (IllegalArgumentException ignored) { } catch (Exception e) {
logger.trace("Expected exception when checking libsignal-client: {}", e.getMessage());
} }
return true; return true;
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {

View file

@ -529,7 +529,8 @@ class GroupV2Helper {
final var today = currentTimeDays(); final var today = currentTimeDays();
if (groupApiCredentials == null || !groupApiCredentials.containsKey(today)) { if (groupApiCredentials == null || !groupApiCredentials.containsKey(today)) {
// Returns credentials for the next 7 days // Returns credentials for the next 7 days
groupApiCredentials = dependencies.getGroupsV2Api().getCredentials(today); final var isAci = true; // TODO enable group handling with PNI
groupApiCredentials = dependencies.getGroupsV2Api().getCredentials(today, isAci);
// TODO cache credentials on disk until they expire // TODO cache credentials on disk until they expire
} }
var authCredentialResponse = groupApiCredentials.get(today); var authCredentialResponse = groupApiCredentials.get(today);

View file

@ -122,7 +122,8 @@ public final class IncomingMessageHandler {
actions.add(new RetrieveProfileAction(recipientId)); actions.add(new RetrieveProfileAction(recipientId));
exception = new UntrustedIdentityException(account.getRecipientStore() exception = new UntrustedIdentityException(account.getRecipientStore()
.resolveRecipientAddress(recipientId), e.getSenderDevice()); .resolveRecipientAddress(recipientId), e.getSenderDevice());
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | ProtocolInvalidMessageException e) { } catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException |
ProtocolInvalidMessageException e) {
logger.debug("Failed to decrypt incoming message", e); logger.debug("Failed to decrypt incoming message", e);
final var sender = account.getRecipientStore().resolveRecipient(e.getSender()); final var sender = account.getRecipientStore().resolveRecipient(e.getSender());
if (context.getContactHelper().isContactBlocked(sender)) { if (context.getContactHelper().isContactBlocked(sender)) {
@ -319,12 +320,14 @@ public final class IncomingMessageHandler {
if (syncMessage.getSent().isPresent()) { if (syncMessage.getSent().isPresent()) {
var message = syncMessage.getSent().get(); var message = syncMessage.getSent().get();
final var destination = message.getDestination().orElse(null); final var destination = message.getDestination().orElse(null);
actions.addAll(handleSignalServiceDataMessage(message.getMessage(), if (message.getDataMessage().isPresent()) {
actions.addAll(handleSignalServiceDataMessage(message.getDataMessage().get(),
true, true,
sender, sender,
destination == null ? null : context.getRecipientHelper().resolveRecipient(destination), destination == null ? null : context.getRecipientHelper().resolveRecipient(destination),
ignoreAttachments)); ignoreAttachments));
} }
}
if (syncMessage.getRequest().isPresent() && account.isMasterDevice()) { if (syncMessage.getRequest().isPresent() && account.isMasterDevice()) {
var rm = syncMessage.getRequest().get(); var rm = syncMessage.getRequest().get();
if (rm.isContactsRequest()) { if (rm.isContactsRequest()) {

View file

@ -616,10 +616,12 @@ public class SendHelper {
var address = account.getSelfAddress(); var address = account.getSelfAddress();
var transcript = new SentTranscriptMessage(Optional.of(address), var transcript = new SentTranscriptMessage(Optional.of(address),
message.getTimestamp(), message.getTimestamp(),
message, Optional.of(message),
message.getExpiresInSeconds(), message.getExpiresInSeconds(),
Map.of(address, true), Map.of(address, true),
false); false,
Optional.empty(),
Set.of());
var syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript); var syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
return sendSyncMessage(syncMessage); return sendSyncMessage(syncMessage);

View file

@ -3,6 +3,7 @@ package org.asamk.signal.manager.util;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.ServiceId; import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -18,7 +19,7 @@ public class MessageCacheUtils {
try (var f = new FileInputStream(file)) { try (var f = new FileInputStream(file)) {
var in = new DataInputStream(f); var in = new DataInputStream(f);
var version = in.readInt(); var version = in.readInt();
if (version > 4) { if (version > 5) {
return null; return null;
} }
var type = in.readInt(); var type = in.readInt();
@ -32,6 +33,10 @@ public class MessageCacheUtils {
// read legacy relay field // read legacy relay field
in.readUTF(); in.readUTF();
} }
String destinationUuid = null;
if (version >= 5) {
destinationUuid = in.readUTF();
}
var timestamp = in.readLong(); var timestamp = in.readLong();
byte[] content = null; byte[] content = null;
var contentLen = in.readInt(); var contentLen = in.readInt();
@ -69,18 +74,20 @@ public class MessageCacheUtils {
content, content,
serverReceivedTimestamp, serverReceivedTimestamp,
serverDeliveredTimestamp, serverDeliveredTimestamp,
uuid); uuid,
destinationUuid == null ? UuidUtil.UNKNOWN_UUID.toString() : destinationUuid);
} }
} }
public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException { public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
try (var f = new FileOutputStream(file)) { try (var f = new FileOutputStream(file)) {
try (var out = new DataOutputStream(f)) { try (var out = new DataOutputStream(f)) {
out.writeInt(4); // version out.writeInt(5); // version
out.writeInt(envelope.getType()); out.writeInt(envelope.getType());
out.writeUTF(envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : ""); out.writeUTF(envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : "");
out.writeUTF(envelope.getSourceUuid().isPresent() ? envelope.getSourceUuid().get() : ""); out.writeUTF(envelope.getSourceUuid().isPresent() ? envelope.getSourceUuid().get() : "");
out.writeInt(envelope.getSourceDevice()); out.writeInt(envelope.getSourceDevice());
out.writeUTF(envelope.getDestinationUuid() == null ? "" : envelope.getDestinationUuid());
out.writeLong(envelope.getTimestamp()); out.writeLong(envelope.getTimestamp());
if (envelope.hasContent()) { if (envelope.hasContent()) {
out.writeInt(envelope.getContent().length); out.writeInt(envelope.getContent().length);

View file

@ -298,9 +298,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
.println("Expiration started at: {}", .println("Expiration started at: {}",
DateUtils.formatTimestamp(sentTranscriptMessage.expirationStartTimestamp())); DateUtils.formatTimestamp(sentTranscriptMessage.expirationStartTimestamp()));
} }
var message = sentTranscriptMessage.message(); if (sentTranscriptMessage.message().isPresent()) {
var message = sentTranscriptMessage.message().get();
printDataMessage(writer.indentedWriter(), message); printDataMessage(writer.indentedWriter(), message);
} }
}
if (syncMessage.blocked().isPresent()) { if (syncMessage.blocked().isPresent()) {
writer.println("Received sync message with block list"); writer.println("Received sync message with block list");
writer.println("Blocked:"); writer.println("Blocked:");

View file

@ -786,7 +786,7 @@ public class DbusManagerImpl implements Manager {
? Optional.empty() ? Optional.empty()
: Optional.of(new RecipientAddress(null, syncReceived.getDestination())), : Optional.of(new RecipientAddress(null, syncReceived.getDestination())),
Set.of(), Set.of(),
new MessageEnvelope.Data(syncReceived.getTimestamp(), Optional.of(new MessageEnvelope.Data(syncReceived.getTimestamp(),
syncReceived.getGroupId().length > 0 syncReceived.getGroupId().length > 0
? Optional.of(new MessageEnvelope.Data.GroupContext(GroupId.unknownVersion( ? Optional.of(new MessageEnvelope.Data.GroupContext(GroupId.unknownVersion(
syncReceived.getGroupId()), false, 0)) syncReceived.getGroupId()), false, 0))
@ -806,7 +806,7 @@ public class DbusManagerImpl implements Manager {
Optional.empty(), Optional.empty(),
List.of(), List.of(),
List.of(), List.of(),
List.of()))), List.of())))),
Optional.empty(), Optional.empty(),
List.of(), List.of(),
List.of(), List.of(),

View file

@ -79,27 +79,29 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
if (syncMessage.sent().isPresent()) { if (syncMessage.sent().isPresent()) {
var transcript = syncMessage.sent().get(); var transcript = syncMessage.sent().get();
if (transcript.destination().isPresent() || transcript.message().groupContext().isPresent()) { if (transcript.message().isPresent()) {
var message = transcript.message(); final var dataMessage = transcript.message().get();
var groupId = message.groupContext() if (transcript.destination().isPresent() || dataMessage.groupContext().isPresent()) {
var groupId = dataMessage.groupContext()
.map(MessageEnvelope.Data.GroupContext::groupId) .map(MessageEnvelope.Data.GroupContext::groupId)
.map(GroupId::serialize) .map(GroupId::serialize)
.orElseGet(() -> new byte[0]); .orElseGet(() -> new byte[0]);
conn.sendMessage(new Signal.SyncMessageReceived(objectPath, conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
transcript.message().timestamp(), dataMessage.timestamp(),
senderString, senderString,
transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""), transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
groupId, groupId,
message.body().orElse(""), dataMessage.body().orElse(""),
getAttachments(message))); getAttachments(dataMessage)));
conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath, conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
transcript.message().timestamp(), dataMessage.timestamp(),
senderString, senderString,
transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""), transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
groupId, groupId,
message.body().orElse(""), dataMessage.body().orElse(""),
getMessageExtras(message))); getMessageExtras(dataMessage)));
}
} }
} }
} }

View file

@ -19,10 +19,13 @@ record JsonSyncDataMessage(
return new JsonSyncDataMessage(address.getLegacyIdentifier(), return new JsonSyncDataMessage(address.getLegacyIdentifier(),
address.number().orElse(null), address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null), address.uuid().map(UUID::toString).orElse(null),
JsonDataMessage.from(transcriptMessage.message())); transcriptMessage.message().map(JsonDataMessage::from).orElse(null));
} else { } else {
return new JsonSyncDataMessage(null, null, null, JsonDataMessage.from(transcriptMessage.message())); return new JsonSyncDataMessage(null,
null,
null,
transcriptMessage.message().map(JsonDataMessage::from).orElse(null));
} }
} }
} }