Skip to content

Commit

Permalink
[signal] signal-cli 0.12.7
Browse files Browse the repository at this point in the history
Changing the feature name (I hope avoiding issue with the kar autodeletion feature from openhab)
  • Loading branch information
dalgwen committed Dec 18, 2023
1 parent c4426f1 commit 14bdb97
Show file tree
Hide file tree
Showing 31 changed files with 192 additions and 156 deletions.
8 changes: 4 additions & 4 deletions bundles/org.openhab.binding.signal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<artifactId>signal-service-java</artifactId>
<groupId>com.github.turasa</groupId>
<version>2.15.3_unofficial_86</version>
<version>2.15.3_unofficial_90</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>org.signal</groupId>
<artifactId>libsignal-client</artifactId>
<version>0.32.1</version>
<version>0.36.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -52,7 +52,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
<version>5.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -64,7 +64,7 @@
<dependency>
<artifactId>bcpkix-jdk18on</artifactId>
<groupId>org.bouncycastle</groupId>
<version>1.76</version>
<version>1.77</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public RegistrationManager initRegistrationManager(
pniIdentityKey,
profileKey,
settings);
account.initDatabase();

return new RegistrationManagerImpl(account,
pathConfig,
Expand All @@ -183,6 +184,7 @@ public RegistrationManager initRegistrationManager(
account.close();
throw new IOException("Number in account file doesn't match expected number: " + account.getNumber());
}
account.initDatabase();

return new RegistrationManagerImpl(account,
pathConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.push.ServiceId;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -140,7 +141,9 @@ static Data from(
dataMessage.isProfileKeyUpdate(),
dataMessage.getProfileKey().isPresent(),
dataMessage.getReaction().map(r -> Reaction.from(r, recipientResolver, addressResolver)),
dataMessage.getQuote().map(q -> Quote.from(q, recipientResolver, addressResolver, fileProvider)),
dataMessage.getQuote()
.filter(q -> q.getAuthor() != null && q.getAuthor().isValid())
.map(q -> Quote.from(q, recipientResolver, addressResolver, fileProvider)),
dataMessage.getPayment().map(p -> p.getPaymentNotification().isPresent() ? Payment.from(p) : null),
dataMessage.getAttachments()
.map(a -> a.stream().map(as -> Attachment.from(as, fileProvider)).toList())
Expand Down Expand Up @@ -480,13 +483,13 @@ public record Address(
static Address from(org.whispersystems.signalservice.api.messages.shared.SharedContact.PostalAddress address) {
return new Address(Address.Type.from(address.getType()),
address.getLabel(),
address.getLabel(),
address.getLabel(),
address.getLabel(),
address.getLabel(),
address.getLabel(),
address.getLabel(),
address.getLabel());
address.getStreet(),
address.getPobox(),
address.getNeighborhood(),
address.getCity(),
address.getRegion(),
address.getPostcode(),
address.getCountry());
}

public enum Type {
Expand Down Expand Up @@ -902,8 +905,9 @@ public static MessageEnvelope from(
final AttachmentFileProvider fileProvider,
Exception exception
) {
final var source = !envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()
? recipientResolver.resolveRecipient(envelope.getSourceAddress())
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
final var source = !envelope.isUnidentifiedSender() && serviceId != null
? recipientResolver.resolveRecipient(serviceId)
: envelope.isUnidentifiedSender() && content != null
? recipientResolver.resolveRecipient(content.getSender())
: exception instanceof ProtocolException e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class ServiceConfig {

public static AccountAttributes.Capabilities getCapabilities(boolean isPrimaryDevice) {
final var giftBadges = !isPrimaryDevice;
return new AccountAttributes.Capabilities(false, true, true, true, true, giftBadges, false, false);
final var pni = !isPrimaryDevice;
final var paymentActivation = !isPrimaryDevice;
return new AccountAttributes.Capabilities(false, true, true, true, true, giftBadges, pni, paymentActivation);
}

public static ServiceEnvironmentConfig getServiceEnvironmentConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ public void addDevice(DeviceLinkUrl deviceLinkInfo) throws IOException, InvalidD
account.getAciIdentityKeyPair(),
account.getPniIdentityKeyPair(),
account.getProfileKey(),
account.getOrCreatePinMasterKey(),
verificationCode);
} catch (InvalidKeyException e) {
throw new InvalidDeviceLinkException("Invalid device link", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,28 @@ public boolean trustIdentityAllKeys(RecipientId recipientId) {
}

public String computeSafetyNumber(ServiceId serviceId, IdentityKey theirIdentityKey) {
final var fingerprint = computeSafetyNumberFingerprint(serviceId, theirIdentityKey, false);
final var fingerprint = computeSafetyNumberFingerprint(serviceId, theirIdentityKey);
return fingerprint == null ? null : fingerprint.getDisplayableFingerprint().getDisplayText();
}

public ScannableFingerprint computeSafetyNumberForScanning(ServiceId serviceId, IdentityKey theirIdentityKey) {
var fingerprint = computeSafetyNumberFingerprint(serviceId, theirIdentityKey, false);
if (fingerprint == null) {
fingerprint = computeSafetyNumberFingerprint(serviceId, theirIdentityKey, true);
}
var fingerprint = computeSafetyNumberFingerprint(serviceId, theirIdentityKey);
return fingerprint == null ? null : fingerprint.getScannableFingerprint();
}

private Fingerprint computeSafetyNumberFingerprint(
final ServiceId serviceId, final IdentityKey theirIdentityKey, boolean useServiceId
final ServiceId serviceId, final IdentityKey theirIdentityKey
) {
final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);

if (useServiceId) {
if (serviceId.isUnknown()) {
return null;
}
if (!serviceId.isUnknown()) {
return Utils.computeSafetyNumberForUuid(account.getAci(),
account.getAciIdentityKeyPair().getPublicKey(),
serviceId,
theirIdentityKey);
}

final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);

if (address.number().isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,10 @@ public Pair<List<HandleAction>, Exception> handleEnvelope(
final var actions = new ArrayList<HandleAction>();
SignalServiceContent content = null;
Exception exception = null;
try {
if (envelope.hasSourceServiceId()) {
envelope.getSourceServiceId().map(ServiceId::parseOrNull)
// Store uuid if we don't have it already
// uuid in envelope is sent by server
account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
}
} catch (Exception e) {
exception = e;
}
.ifPresent(serviceId -> account.getRecipientResolver().resolveRecipient(serviceId));
if (!envelope.isReceipt()) {
try {
final var cipherResult = dependencies.getCipher()
Expand Down Expand Up @@ -488,7 +483,7 @@ private List<HandleAction> handleSyncMessage(
sender,
destination == null
? null
: new DeviceAddress(context.getRecipientHelper().resolveRecipient(destination),
: new DeviceAddress(account.getRecipientResolver().resolveRecipient(destination),
destination.getServiceId(),
0),
ignoreAttachments));
Expand Down Expand Up @@ -530,7 +525,7 @@ private List<HandleAction> handleSyncMessage(
final var blockedListMessage = syncMessage.getBlockedList().get();
for (var address : blockedListMessage.getAddresses()) {
context.getContactHelper()
.setContactBlocked(context.getRecipientHelper().resolveRecipient(address), true);
.setContactBlocked(account.getRecipientResolver().resolveRecipient(address), true);
}
for (var groupId : blockedListMessage.getGroupIds()
.stream()
Expand Down Expand Up @@ -654,7 +649,7 @@ private boolean isMessageBlocked(SignalServiceEnvelope envelope, SignalServiceCo
if (source == null) {
return false;
}
final var recipientId = context.getRecipientHelper().resolveRecipient(source);
final var recipientId = account.getRecipientResolver().resolveRecipient(source);
if (context.getContactHelper().isContactBlocked(recipientId)) {
return true;
}
Expand Down Expand Up @@ -694,7 +689,7 @@ private boolean isNotAllowedToSendToGroup(SignalServiceEnvelope envelope, Signal

final var message = content.getDataMessage().orElse(null);

final var recipientId = context.getRecipientHelper().resolveRecipient(source);
final var recipientId = account.getRecipientResolver().resolveRecipient(source);
if (!group.isMember(recipientId) && !(
group.isPendingMember(recipientId) && message != null && message.isGroupV2Update()
)) {
Expand Down Expand Up @@ -745,10 +740,11 @@ private List<HandleAction> handleSignalServiceDataMessage(
}

if (groupInfo.getMembers().isPresent()) {
final var recipientResolver = account.getRecipientResolver();
groupV1.addMembers(groupInfo.getMembers()
.get()
.stream()
.map(context.getRecipientHelper()::resolveRecipient)
.map(recipientResolver::resolveRecipient)
.collect(Collectors.toSet()));
}

Expand Down Expand Up @@ -921,8 +917,9 @@ private void handleIncomingProfileKey(final byte[] profileKeyBytes, final Recipi
}

private SignalServiceAddress getSenderAddress(SignalServiceEnvelope envelope, SignalServiceContent content) {
if (!envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()) {
return envelope.getSourceAddress();
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
if (!envelope.isUnidentifiedSender() && serviceId != null) {
return new SignalServiceAddress(serviceId);
} else if (content != null) {
return content.getSender();
} else {
Expand All @@ -931,12 +928,13 @@ private SignalServiceAddress getSenderAddress(SignalServiceEnvelope envelope, Si
}

private DeviceAddress getSender(SignalServiceEnvelope envelope, SignalServiceContent content) {
if (!envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()) {
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(envelope.getSourceAddress()),
envelope.getSourceAddress().getServiceId(),
final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
if (!envelope.isUnidentifiedSender() && serviceId != null) {
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(serviceId),
serviceId,
envelope.getSourceDevice());
} else {
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(content.getSender()),
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(content.getSender()),
content.getSender().getServiceId(),
content.getSenderDevice());
}
Expand All @@ -951,7 +949,7 @@ private DeviceAddress getDestination(SignalServiceEnvelope envelope) {
return new DeviceAddress(account.getSelfRecipientId(), account.getAci(), account.getDeviceId());
}
final var address = addressOptional.get();
return new DeviceAddress(context.getRecipientHelper().resolveRecipient(address),
return new DeviceAddress(account.getRecipientResolver().resolveRecipient(address),
address.getServiceId(),
account.getDeviceId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.SignalWebSocket;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
import org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException;
Expand Down Expand Up @@ -147,8 +148,10 @@ private void receiveMessagesInternal(
for (final var it : batch) {
SignalServiceEnvelope envelope1 = new SignalServiceEnvelope(it.getEnvelope(),
it.getServerDeliveredTimestamp());
final var recipientId = envelope1.hasSourceServiceId() ? account.getRecipientResolver()
.resolveRecipient(envelope1.getSourceAddress()) : null;
final var recipientId = envelope1.getSourceServiceId()
.map(ServiceId::parseOrNull)
.map(s -> account.getRecipientResolver().resolveRecipient(s))
.orElse(null);
logger.trace("Storing new message from {}", recipientId);
// store message on disk, before acknowledging receipt to the server
cachedMessage[0] = account.getMessageCache().cacheMessage(envelope1, recipientId);
Expand Down Expand Up @@ -230,7 +233,7 @@ private void receiveMessagesInternal(
if (exception instanceof UntrustedIdentityException) {
logger.debug("Keeping message with untrusted identity in message cache");
final var address = ((UntrustedIdentityException) exception).getSender();
if (!envelope.hasSourceServiceId() && address.uuid().isPresent()) {
if (envelope.getSourceServiceId().isEmpty() && address.uuid().isPresent()) {
final var recipientId = account.getRecipientResolver()
.resolveRecipient(ACI.from(address.uuid().get()));
try {
Expand Down Expand Up @@ -282,7 +285,7 @@ private List<HandleAction> retryFailedReceivedMessage(
cachedMessage.delete();
return null;
}
if (!envelope.hasSourceServiceId()) {
if (envelope.getSourceServiceId().isEmpty()) {
final var identifier = ((UntrustedIdentityException) exception).getSender();
final var recipientId = account.getRecipientResolver()
.resolveRecipient(new RecipientAddress(identifier));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.asamk.signal.manager.internal.SignalDependencies;
import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.signal.core.util.Base64;
import org.signal.libsignal.usernames.BaseUsernameException;
import org.signal.libsignal.usernames.Username;
import org.slf4j.Logger;
Expand Down Expand Up @@ -68,10 +67,6 @@ public SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId)
.toSignalServiceAddress();
}

public RecipientId resolveRecipient(final SignalServiceAddress address) {
return account.getRecipientResolver().resolveRecipient(address);
}

public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException {
final var recipientIds = new HashSet<RecipientId>(recipients.size());
for (var number : recipients) {
Expand Down Expand Up @@ -234,8 +229,7 @@ private Map<String, RegisteredUser> getRegisteredUsersV2(
}

private ACI getRegisteredUserByUsername(String username) throws IOException, BaseUsernameException {
return dependencies.getAccountManager()
.getAciByUsernameHash(Base64.encodeUrlSafeWithoutPadding(new Username(username).getHash()));
return dependencies.getAccountManager().getAciByUsername(new Username(username));
}

public record RegisteredUser(Optional<ACI> aci, Optional<PNI> pni) {
Expand Down
Loading

0 comments on commit 14bdb97

Please sign in to comment.