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

View file

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

View file

@ -14,7 +14,7 @@ repositories {
}
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.google.protobuf", "protobuf-javalite", "3.11.4")
implementation("org.bouncycastle", "bcprov-jdk15on", "1.70")

View file

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

View file

@ -517,7 +517,7 @@ public record MessageEnvelope(
long expirationStartTimestamp,
Optional<RecipientAddress> destination,
Set<RecipientAddress> recipients,
Data message
Optional<Data> message
) {
static Sent from(
@ -534,7 +534,8 @@ public record MessageEnvelope(
.stream()
.map(d -> addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(d)))
.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;
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 {
TrustStore contactTrustStore = new IasTrustStore();
@ -50,7 +50,8 @@ public class ServiceConfig {
try {
try {
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;
} catch (UnsatisfiedLinkError e) {

View file

@ -529,7 +529,8 @@ class GroupV2Helper {
final var today = currentTimeDays();
if (groupApiCredentials == null || !groupApiCredentials.containsKey(today)) {
// 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
}
var authCredentialResponse = groupApiCredentials.get(today);

View file

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

View file

@ -616,10 +616,12 @@ public class SendHelper {
var address = account.getSelfAddress();
var transcript = new SentTranscriptMessage(Optional.of(address),
message.getTimestamp(),
message,
Optional.of(message),
message.getExpiresInSeconds(),
Map.of(address, true),
false);
false,
Optional.empty(),
Set.of());
var syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
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.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -18,7 +19,7 @@ public class MessageCacheUtils {
try (var f = new FileInputStream(file)) {
var in = new DataInputStream(f);
var version = in.readInt();
if (version > 4) {
if (version > 5) {
return null;
}
var type = in.readInt();
@ -32,6 +33,10 @@ public class MessageCacheUtils {
// read legacy relay field
in.readUTF();
}
String destinationUuid = null;
if (version >= 5) {
destinationUuid = in.readUTF();
}
var timestamp = in.readLong();
byte[] content = null;
var contentLen = in.readInt();
@ -69,18 +74,20 @@ public class MessageCacheUtils {
content,
serverReceivedTimestamp,
serverDeliveredTimestamp,
uuid);
uuid,
destinationUuid == null ? UuidUtil.UNKNOWN_UUID.toString() : destinationUuid);
}
}
public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
try (var f = new FileOutputStream(file)) {
try (var out = new DataOutputStream(f)) {
out.writeInt(4); // version
out.writeInt(5); // version
out.writeInt(envelope.getType());
out.writeUTF(envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : "");
out.writeUTF(envelope.getSourceUuid().isPresent() ? envelope.getSourceUuid().get() : "");
out.writeInt(envelope.getSourceDevice());
out.writeUTF(envelope.getDestinationUuid() == null ? "" : envelope.getDestinationUuid());
out.writeLong(envelope.getTimestamp());
if (envelope.hasContent()) {
out.writeInt(envelope.getContent().length);

View file

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

View file

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

View file

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

View file

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