mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Update libsignal-service-java
This commit is contained in:
parent
52bb92dce4
commit
41726d339f
9 changed files with 69 additions and 33 deletions
|
@ -28,7 +28,8 @@ public class ServiceConfig {
|
|||
|
||||
public static AccountAttributes.Capabilities getCapabilities(boolean isPrimaryDevice) {
|
||||
final var deleteSync = !isPrimaryDevice;
|
||||
return new AccountAttributes.Capabilities(true, deleteSync);
|
||||
final var versionedExpirationTimer = !isPrimaryDevice;
|
||||
return new AccountAttributes.Capabilities(true, deleteSync, versionedExpirationTimer);
|
||||
}
|
||||
|
||||
public static ServiceEnvironmentConfig getServiceEnvironmentConfig(
|
||||
|
|
|
@ -220,20 +220,30 @@ public class AccountHelper {
|
|||
final var messageSender = dependencies.getMessageSender();
|
||||
for (final var deviceId : deviceIds) {
|
||||
// Signed Prekey
|
||||
final var signedPreKeyRecord = KeyUtils.generateSignedPreKeyRecord(KeyUtils.getRandomInt(PREKEY_MAXIMUM_ID),
|
||||
pniIdentity.getPrivateKey());
|
||||
final var signedPreKeyEntity = new SignedPreKeyEntity(signedPreKeyRecord.getId(),
|
||||
signedPreKeyRecord.getKeyPair().getPublicKey(),
|
||||
signedPreKeyRecord.getSignature());
|
||||
devicePniSignedPreKeys.put(deviceId, signedPreKeyEntity);
|
||||
final SignedPreKeyRecord signedPreKeyRecord;
|
||||
try {
|
||||
signedPreKeyRecord = KeyUtils.generateSignedPreKeyRecord(KeyUtils.getRandomInt(PREKEY_MAXIMUM_ID),
|
||||
pniIdentity.getPrivateKey());
|
||||
final var signedPreKeyEntity = new SignedPreKeyEntity(signedPreKeyRecord.getId(),
|
||||
signedPreKeyRecord.getKeyPair().getPublicKey(),
|
||||
signedPreKeyRecord.getSignature());
|
||||
devicePniSignedPreKeys.put(deviceId, signedPreKeyEntity);
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new AssertionError("unexpected invalid key", e);
|
||||
}
|
||||
|
||||
// Last-resort kyber prekey
|
||||
final var lastResortKyberPreKeyRecord = KeyUtils.generateKyberPreKeyRecord(KeyUtils.getRandomInt(
|
||||
PREKEY_MAXIMUM_ID), pniIdentity.getPrivateKey());
|
||||
final var kyberPreKeyEntity = new KyberPreKeyEntity(lastResortKyberPreKeyRecord.getId(),
|
||||
lastResortKyberPreKeyRecord.getKeyPair().getPublicKey(),
|
||||
lastResortKyberPreKeyRecord.getSignature());
|
||||
devicePniLastResortKyberPreKeys.put(deviceId, kyberPreKeyEntity);
|
||||
final KyberPreKeyRecord lastResortKyberPreKeyRecord;
|
||||
try {
|
||||
lastResortKyberPreKeyRecord = KeyUtils.generateKyberPreKeyRecord(KeyUtils.getRandomInt(PREKEY_MAXIMUM_ID),
|
||||
pniIdentity.getPrivateKey());
|
||||
final var kyberPreKeyEntity = new KyberPreKeyEntity(lastResortKyberPreKeyRecord.getId(),
|
||||
lastResortKyberPreKeyRecord.getKeyPair().getPublicKey(),
|
||||
lastResortKyberPreKeyRecord.getSignature());
|
||||
devicePniLastResortKyberPreKeys.put(deviceId, kyberPreKeyEntity);
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new AssertionError("unexpected invalid key", e);
|
||||
}
|
||||
|
||||
// Registration Id
|
||||
var pniRegistrationId = -1;
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.asamk.signal.manager.storage.groups.GroupInfoV1;
|
|||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
||||
import org.asamk.signal.manager.storage.stickers.StickerPack;
|
||||
import org.asamk.signal.manager.util.AttachmentUtils;
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.asamk.signal.manager.util.MimeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -18,12 +17,12 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactAvatar;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsInputStream;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup;
|
||||
|
@ -170,7 +169,14 @@ public class SyncHelper {
|
|||
final var contact = contactPair.second();
|
||||
final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);
|
||||
|
||||
out.write(getDeviceContact(address, recipientId, contact));
|
||||
final var deviceContact = getDeviceContact(address, recipientId, contact);
|
||||
out.write(deviceContact);
|
||||
deviceContact.getAvatar().ifPresent(a -> {
|
||||
try {
|
||||
a.getInputStream().close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (account.getProfileKey() != null) {
|
||||
|
@ -178,7 +184,14 @@ public class SyncHelper {
|
|||
final var address = account.getSelfRecipientAddress();
|
||||
final var recipientId = account.getSelfRecipientId();
|
||||
final var contact = account.getContactStore().getContact(recipientId);
|
||||
out.write(getDeviceContact(address, recipientId, contact));
|
||||
final var deviceContact = getDeviceContact(address, recipientId, contact);
|
||||
out.write(deviceContact);
|
||||
deviceContact.getAvatar().ifPresent(a -> {
|
||||
try {
|
||||
a.getInputStream().close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +247,7 @@ public class SyncHelper {
|
|||
Optional.ofNullable(profileKey),
|
||||
Optional.ofNullable(contact == null ? null : contact.messageExpirationTime()),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
contact != null && contact.isArchived());
|
||||
}
|
||||
|
||||
|
@ -391,7 +405,7 @@ public class SyncHelper {
|
|||
account.getContactStore().storeContact(recipientId, builder.build());
|
||||
|
||||
if (c.getAvatar().isPresent()) {
|
||||
downloadContactAvatar(c.getAvatar().get(), address);
|
||||
storeContactAvatar(c.getAvatar().get(), address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,21 +439,22 @@ public class SyncHelper {
|
|||
return context.getSendHelper().sendSyncMessage(message);
|
||||
}
|
||||
|
||||
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(RecipientAddress address) throws IOException {
|
||||
private Optional<DeviceContactAvatar> createContactAvatarAttachment(RecipientAddress address) throws IOException {
|
||||
final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
|
||||
if (streamDetails == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final var uploadSpec = context.getDependencies().getMessageSender().getResumableUploadSpec().toProto();
|
||||
return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec));
|
||||
return Optional.of(new DeviceContactAvatar(streamDetails.getStream(),
|
||||
streamDetails.getLength(),
|
||||
streamDetails.getContentType()));
|
||||
}
|
||||
|
||||
private void downloadContactAvatar(SignalServiceAttachment avatar, RecipientAddress address) {
|
||||
private void storeContactAvatar(DeviceContactAvatar avatar, RecipientAddress address) {
|
||||
try {
|
||||
context.getAvatarStore()
|
||||
.storeContactAvatar(address,
|
||||
outputStream -> context.getAttachmentHelper().retrieveAttachment(avatar, outputStream));
|
||||
outputStream -> IOUtils.copyStream(avatar.getInputStream(), outputStream));
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to download avatar for contact {}, ignoring: {}", address, e.getMessage());
|
||||
}
|
||||
|
|
|
@ -93,9 +93,13 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
|
|||
try (final var statement = connection.prepareStatement(sql)) {
|
||||
statement.setInt(1, accountIdType);
|
||||
statement.setInt(2, signedPreKeyId);
|
||||
final var keyPair = record.getKeyPair();
|
||||
statement.setBytes(3, keyPair.getPublicKey().serialize());
|
||||
statement.setBytes(4, keyPair.getPrivateKey().serialize());
|
||||
try {
|
||||
final var keyPair = record.getKeyPair();
|
||||
statement.setBytes(3, keyPair.getPublicKey().serialize());
|
||||
statement.setBytes(4, keyPair.getPrivateKey().serialize());
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new AssertionError("unexpected invalid key", e);
|
||||
}
|
||||
statement.setBytes(5, record.getSignature());
|
||||
statement.setLong(6, record.getTimestamp());
|
||||
statement.executeUpdate();
|
||||
|
@ -193,9 +197,13 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
|
|||
for (final var record : signedPreKeys) {
|
||||
statement.setInt(1, accountIdType);
|
||||
statement.setInt(2, record.getId());
|
||||
final var keyPair = record.getKeyPair();
|
||||
statement.setBytes(3, keyPair.getPublicKey().serialize());
|
||||
statement.setBytes(4, keyPair.getPrivateKey().serialize());
|
||||
try {
|
||||
final var keyPair = record.getKeyPair();
|
||||
statement.setBytes(3, keyPair.getPublicKey().serialize());
|
||||
statement.setBytes(4, keyPair.getPrivateKey().serialize());
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new AssertionError("unexpected invalid key", e);
|
||||
}
|
||||
statement.setBytes(5, record.getSignature());
|
||||
statement.setLong(6, record.getTimestamp());
|
||||
statement.executeUpdate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue