Skip to content

Commit

Permalink
Bump to signal-cli 0.13.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dalgwen committed Jun 28, 2024
1 parent 3543b7e commit ab716c6
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 43 deletions.
6 changes: 3 additions & 3 deletions bundles/org.openhab.binding.signal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<dependency>
<artifactId>signal-service-java</artifactId>
<groupId>com.github.turasa</groupId>
<version>2.15.3_unofficial_101</version>
<version>2.15.3_unofficial_103</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.turasa</groupId>
<artifactId>core-util-jvm</artifactId>
<version>2.15.3_unofficial_101</version>
<version>2.15.3_unofficial_103</version>
</dependency>
<dependency>
<groupId>com.squareup.wire</groupId>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>org.signal</groupId>
<artifactId>libsignal-client</artifactId>
<version>0.44.0</version>
<version>0.47.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static Single fromAddress(RecipientAddress address) {
return new Number(address.number().get());
} else if (address.aci().isPresent()) {
return new Uuid(UUID.fromString(address.aci().get()));
} else if (address.pni().isPresent()) {
return new Pni(address.pni().get());
} else if (address.username().isPresent()) {
return new Username(address.username().get());
}
Expand All @@ -71,6 +73,19 @@ public RecipientAddress toPartialRecipientAddress() {
}
}

record Pni(String pni) implements Single {

@Override
public String getIdentifier() {
return pni;
}

@Override
public RecipientAddress toPartialRecipientAddress() {
return new RecipientAddress(null, pni, null, null);
}
}

record Number(String number) implements Single {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ private void reserveUsername(final List<Username> candidates) throws IOException
account.setUsername(username.getUsername());
account.setUsernameLink(linkComponents);
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
account.getRecipientStore().rotateSelfStorageId();
logger.debug("[confirmUsername] Successfully confirmed username.");
}

Expand Down Expand Up @@ -409,6 +410,7 @@ public void refreshCurrentUsername() throws IOException, BaseUsernameException {
e.getClass().getSimpleName());
account.setUsername(null);
account.setUsernameLink(null);
account.getRecipientStore().rotateSelfStorageId();
throw e;
}
} else {
Expand All @@ -431,6 +433,7 @@ private void tryReserveConfirmUsername(final Username username) throws IOExcepti
account.setUsernameLink(linkComponents);
logger.debug("[confirmUsername] Successfully reclaimed existing username and link.");
}
account.getRecipientStore().rotateSelfStorageId();
}

private void tryToSetUsernameLink(Username username) {
Expand All @@ -446,6 +449,8 @@ private void tryToSetUsernameLink(Username username) {
}

public void deleteUsername() throws IOException {
dependencies.getAccountManager().deleteUsernameLink();
account.setUsernameLink(null);
dependencies.getAccountManager().deleteUsername();
account.setUsername(null);
logger.debug("[deleteUsername] Successfully deleted the username.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupHistoryEntry;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupChangeLog;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
Expand Down Expand Up @@ -79,6 +79,12 @@ public GroupInfo getGroup(GroupId groupId) {
return getGroup(groupId, false);
}

public List<GroupInfo> getGroups() {
final var groups = account.getGroupStore().getGroups();
groups.forEach(group -> fillOrUpdateGroup(group, false));
return groups;
}

public boolean isGroupBlocked(final GroupId groupId) {
var group = getGroup(groupId);
return group != null && group.isBlocked();
Expand Down Expand Up @@ -379,34 +385,46 @@ public SendGroupMessageResults sendGroupInfoMessage(

private GroupInfo getGroup(GroupId groupId, boolean forceUpdate) {
final var group = account.getGroupStore().getGroup(groupId);
if (group instanceof GroupInfoV2 groupInfoV2) {
if (forceUpdate || (!groupInfoV2.isPermissionDenied() && groupInfoV2.getGroup() == null)) {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
DecryptedGroup decryptedGroup;
try {
decryptedGroup = context.getGroupV2Helper().getDecryptedGroup(groupSecretParams);
} catch (NotAGroupMemberException e) {
groupInfoV2.setPermissionDenied(true);
decryptedGroup = null;
}
if (decryptedGroup != null) {
try {
storeProfileKeysFromHistory(groupSecretParams, groupInfoV2, decryptedGroup);
} catch (NotAGroupMemberException ignored) {
}
storeProfileKeysFromMembers(decryptedGroup);
final var avatar = decryptedGroup.avatar;
if (!avatar.isEmpty()) {
downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
}
}
groupInfoV2.setGroup(decryptedGroup);
account.getGroupStore().updateGroup(group);
}
}
fillOrUpdateGroup(group, forceUpdate);
return group;
}

private void fillOrUpdateGroup(final GroupInfo group, final boolean forceUpdate) {
if (!(group instanceof GroupInfoV2 groupInfoV2)) {
return;
}

if (!forceUpdate && (groupInfoV2.isPermissionDenied() || groupInfoV2.getGroup() != null)) {
return;
}

final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
DecryptedGroup decryptedGroup;
try {
decryptedGroup = context.getGroupV2Helper().getDecryptedGroup(groupSecretParams);
} catch (NotAGroupMemberException e) {
groupInfoV2.setPermissionDenied(true);
account.getGroupStore().updateGroup(group);
return;
}

if (decryptedGroup == null) {
return;
}

try {
storeProfileKeysFromHistory(groupSecretParams, groupInfoV2, decryptedGroup);
} catch (NotAGroupMemberException ignored) {
}
storeProfileKeysFromMembers(decryptedGroup);
final var avatar = decryptedGroup.avatar;
if (!avatar.isEmpty()) {
downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
}
groupInfoV2.setGroup(decryptedGroup);
account.getGroupStore().updateGroup(group);
}

private void downloadGroupAvatar(GroupIdV2 groupId, GroupSecretParams groupSecretParams, String cdnKey) {
try {
context.getAvatarStore()
Expand Down Expand Up @@ -479,11 +497,10 @@ private void storeProfileKeysFromHistory(
final var newProfileKeys = new HashMap<RecipientId, ProfileKey>();
while (true) {
final var page = context.getGroupV2Helper().getDecryptedGroupHistoryPage(groupSecretParams, fromRevision);
page.getResults()
page.getChangeLogs()
.stream()
.map(DecryptedGroupHistoryEntry::getChange)
.filter(Optional::isPresent)
.map(Optional::get)
.map(DecryptedGroupChangeLog::getChange)
.filter(Objects::nonNull)
.map(context.getGroupV2Helper()::getAuthoritativeProfileKeyFromChange)
.filter(Objects::nonNull)
.forEach(p -> {
Expand All @@ -492,13 +509,16 @@ private void storeProfileKeysFromHistory(
final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
newProfileKeys.put(recipientId, profileKey);
});
if (!page.getPagingData().hasMorePages()) {
if (!page.getPagingData().getHasMorePages()) {
break;
}
fromRevision = page.getPagingData().getNextPageRevision();
}

newProfileKeys.forEach(account.getProfileStore()::storeProfileKey);
newProfileKeys.entrySet()
.stream()
.filter(entry -> account.getProfileStore().getProfileKey(entry.getKey()) == null)
.forEach(entry -> account.getProfileStore().storeProfileKey(entry.getKey(), entry.getValue()));
}

private GroupInfo getGroupForUpdating(GroupId groupId) throws GroupNotFoundException, NotAGroupMemberException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single>
public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) {
return account.getRecipientResolver().resolveRecipient(ACI.from(uuidRecipient.uuid()));
} else if (recipient instanceof RecipientIdentifier.Pni pniRecipient) {
return account.getRecipientResolver().resolveRecipient(PNI.parseOrThrow(pniRecipient.pni()));
} else if (recipient instanceof RecipientIdentifier.Number numberRecipient) {
final var number = numberRecipient.number();
return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public SendMessageResult resendMessage(
}

final var groupId = messageSendLogEntry.groupId().get();
final var group = account.getGroupStore().getGroup(groupId);
final var group = context.getGroupHelper().getGroup(groupId);

if (group == null) {
logger.debug("Could not find a matching group for the groupId {}! Skipping message send.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.ServiceId.PNI;
import org.whispersystems.signalservice.api.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.exceptions.CdsiResourceExhaustedException;
import org.whispersystems.signalservice.api.push.exceptions.UsernameMalformedException;
import org.whispersystems.signalservice.api.push.exceptions.UsernameTakenException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
Expand Down Expand Up @@ -395,6 +398,10 @@ public void setUsername(final String username) throws IOException, InvalidUserna
} else {
context.getAccountHelper().reserveUsernameFromNickname(username);
}
} catch (UsernameMalformedException e) {
throw new InvalidUsernameException("Username is malformed", e);
} catch (UsernameTakenException e) {
throw new InvalidUsernameException("Username is already registered", e);
} catch (BaseUsernameException e) {
throw new InvalidUsernameException(e.getMessage() + " (" + e.getClass().getSimpleName() + ")", e);
}
Expand Down Expand Up @@ -504,7 +511,7 @@ void refreshPreKeys() throws IOException {

@Override
public List<Group> getGroups() {
return account.getGroupStore().getGroups().stream().map(this::toGroup).toList();
return context.getGroupHelper().getGroups().stream().map(this::toGroup).toList();
}

private Group toGroup(final GroupInfo groupInfo) {
Expand Down Expand Up @@ -836,6 +843,9 @@ public SendMessageResults sendRemoteDeleteMessage(
if (recipient instanceof RecipientIdentifier.Uuid u) {
account.getMessageSendLogStore()
.deleteEntryForRecipientNonGroup(targetSentTimestamp, ACI.from(u.uuid()));
} else if (recipient instanceof RecipientIdentifier.Pni pni) {
account.getMessageSendLogStore()
.deleteEntryForRecipientNonGroup(targetSentTimestamp, PNI.parseOrThrow(pni.pni()));
} else if (recipient instanceof RecipientIdentifier.Single r) {
try {
final var recipientId = context.getRecipientHelper().resolveRecipient(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
import org.whispersystems.signalservice.api.websocket.WebSocketFactory;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;
import org.whispersystems.signalservice.internal.websocket.WebSocketConnection;

import java.util.List;
Expand Down Expand Up @@ -108,7 +109,7 @@ public PushServiceSocket getPushServiceSocket() {

public Network getLibSignalNetwork() {
return getOrCreate(() -> libSignalNetwork,
() -> libSignalNetwork = new Network(serviceEnvironmentConfig.netEnvironment()));
() -> libSignalNetwork = new Network(serviceEnvironmentConfig.netEnvironment(), userAgent));
}

public SignalServiceAccountManager getAccountManager() {
Expand Down Expand Up @@ -159,7 +160,7 @@ public SignalWebSocket getSignalWebSocket() {
final var webSocketFactory = new WebSocketFactory() {
@Override
public WebSocketConnection createWebSocket() {
return new WebSocketConnection("normal",
return new OkHttpWebSocketConnection("normal",
serviceEnvironmentConfig.signalServiceConfiguration(),
Optional.of(credentialsProvider),
userAgent,
Expand All @@ -169,7 +170,7 @@ public WebSocketConnection createWebSocket() {

@Override
public WebSocketConnection createUnidentifiedWebSocket() {
return new WebSocketConnection("unidentified",
return new OkHttpWebSocketConnection("unidentified",
serviceEnvironmentConfig.signalServiceConfiguration(),
Optional.empty(),
userAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.whispersystems.signalservice.api.util.SleepTimer;
import org.whispersystems.signalservice.api.websocket.HealthMonitor;
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
import org.whispersystems.signalservice.internal.websocket.WebSocketConnection;
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;
Expand All @@ -25,7 +25,7 @@ final class SignalWebSocketHealthMonitor implements HealthMonitor {

private static final Logger logger = LoggerFactory.getLogger(SignalWebSocketHealthMonitor.class);

private static final long KEEP_ALIVE_SEND_CADENCE = TimeUnit.SECONDS.toMillis(WebSocketConnection.KEEPALIVE_FREQUENCY_SECONDS);
private static final long KEEP_ALIVE_SEND_CADENCE = TimeUnit.SECONDS.toMillis(OkHttpWebSocketConnection.KEEPALIVE_FREQUENCY_SECONDS);
private static final long MAX_TIME_SINCE_SUCCESSFUL_KEEP_ALIVE = KEEP_ALIVE_SEND_CADENCE * 3;

private SignalWebSocket signalWebSocket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ public UsernameLinkComponents getUsernameLink() {

public void setUsernameLink(final UsernameLinkComponents usernameLink) {
this.usernameLink = usernameLink;
save();
}

public ServiceEnvironment getServiceEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
@org.osgi.annotation.bundle.Header(name = org.osgi.framework.Constants.BUNDLE_NATIVECODE, value = "lib/windows/x86-64/signal_jni.dll;processor=amd64;osname=win32;osname=Windows8;osname=Windows 8;osname=Win8;osname=Windows10;osname=Windows 10;osname=Win10,lib/linux/x86-64-musl/libsignal_jni.so;processor=x86-64;processor=amd64;osname=Linux;selection-filter=\"(org.osgi.framework.os.libc=musl)\",lib/linux/x86-64/libsignal_jni.so;processor=x86-64;processor=amd64;osname=Linux,lib/linux/armv7/libsignal_jni.so;processor=ARM;processor=arm;osname=Linux,lib/linux/arm64/libsignal_jni.so;processor=AArch64;processor=ARM64;osname=Linux,lib/apple/amd64/libsignal_jni.dylib;processor=x86-64;osname=MacOS;osname=MacOSX;osname=Mac OS;osname=Mac OS X,lib/apple/aarch64/libsignal_jni.dylib;processor=AArch64;processor=ARM64;osname=MacOS;osname=MacOSX;osname=Mac OS;osname=Mac OS X,*")
@org.osgi.annotation.bundle.Header(name = org.osgi.framework.Constants.BUNDLE_NATIVECODE, value = "lib/windows/x86-64/signal_jni.dll;processor=amd64;osname=win32;osname=Windows8;osname=Windows 8;osname=Win8;osname=Windows10;osname=Windows 10;osname=Win10,lib/linux/x86-64-musl/libsignal_jni.so;processor=x86-64;processor=amd64;osname=Linux;selection-filter=\"(org.osgi.framework.os.libc=musl)\",lib/linux/x86-64/libsignal_jni.so;processor=x86-64;processor=amd64;osname=Linux,lib/linux/x86/libsignal_jni.so;processor=x86;osname=Linux,lib/linux/armv7/libsignal_jni.so;processor=ARM;processor=arm;osname=Linux,lib/linux/arm64/libsignal_jni.so;processor=AArch64;processor=ARM64;osname=Linux,lib/apple/amd64/libsignal_jni.dylib;processor=x86-64;osname=MacOS;osname=MacOSX;osname=Mac OS;osname=Mac OS X,lib/apple/aarch64/libsignal_jni.dylib;processor=AArch64;processor=ARM64;osname=MacOS;osname=MacOSX;osname=Mac OS;osname=Mac OS X,*")
package org.openhab.binding.signal.internal;

/**
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit ab716c6

Please sign in to comment.