Update libsignal-service-java

This commit is contained in:
AsamK 2021-05-13 17:15:14 +02:00
parent c1d3a647a2
commit 06e9f8ba64
10 changed files with 89 additions and 51 deletions

View file

@ -14,7 +14,7 @@ repositories {
}
dependencies {
api("com.github.turasa:signal-service-java:2.15.3_unofficial_21")
api("com.github.turasa:signal-service-java:2.15.3_unofficial_22")
implementation("com.google.protobuf:protobuf-javalite:3.10.0")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation("org.slf4j:slf4j-api:1.7.30")

View file

@ -83,6 +83,7 @@ import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.SignalSessionLock;
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
@ -161,6 +162,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -193,6 +195,15 @@ public class Manager implements Closeable {
private final PinHelper pinHelper;
private final AvatarStore avatarStore;
private final AttachmentStore attachmentStore;
private final SignalSessionLock sessionLock = new SignalSessionLock() {
private final ReentrantLock LEGACY_LOCK = new ReentrantLock();
@Override
public Lock acquire() {
LEGACY_LOCK.lock();
return LEGACY_LOCK::unlock;
}
};
Manager(
SignalAccount account,
@ -389,6 +400,7 @@ public class Manager implements Closeable {
newProfile.getInternalServiceName(),
newProfile.getAbout() == null ? "" : newProfile.getAbout(),
newProfile.getAboutEmoji() == null ? "" : newProfile.getAboutEmoji(),
Optional.absent(),
streamDetails);
}
@ -534,6 +546,7 @@ public class Manager implements Closeable {
account.getPassword(),
account.getDeviceId(),
account.getSignalProtocolStore(),
sessionLock,
userAgent,
account.isMultiDevice(),
Optional.fromNullable(messagePipe),
@ -1511,18 +1524,12 @@ public class Manager implements Closeable {
}
}
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, SelfSendException, UnsupportedDataMessageException, org.whispersystems.libsignal.UntrustedIdentityException {
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, SelfSendException, UnsupportedDataMessageException, ProtocolUntrustedIdentityException {
var cipher = new SignalServiceCipher(account.getSelfAddress(),
account.getSignalProtocolStore(),
sessionLock,
certificateValidator);
try {
return cipher.decrypt(envelope);
} catch (ProtocolUntrustedIdentityException e) {
if (e.getCause() instanceof org.whispersystems.libsignal.UntrustedIdentityException) {
throw (org.whispersystems.libsignal.UntrustedIdentityException) e.getCause();
}
throw new AssertionError(e);
}
return cipher.decrypt(envelope);
}
private void handleEndSession(RecipientId recipientId) {
@ -1766,9 +1773,9 @@ public class Manager implements Closeable {
if (!envelope.isReceipt()) {
try {
content = decryptMessage(envelope);
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
} catch (ProtocolUntrustedIdentityException e) {
if (!envelope.hasSource()) {
final var identifier = ((org.whispersystems.libsignal.UntrustedIdentityException) e).getName();
final var identifier = e.getSender();
final var recipientId = resolveRecipient(identifier);
try {
account.getMessageCache().replaceSender(cachedMessage, recipientId);
@ -1889,8 +1896,8 @@ public class Manager implements Closeable {
handler.handleMessage(envelope, content, exception);
}
if (cachedMessage[0] != null) {
if (exception instanceof org.whispersystems.libsignal.UntrustedIdentityException) {
final var identifier = ((org.whispersystems.libsignal.UntrustedIdentityException) exception).getName();
if (exception instanceof ProtocolUntrustedIdentityException) {
final var identifier = ((ProtocolUntrustedIdentityException) exception).getSender();
final var recipientId = resolveRecipient(identifier);
queuedActions.add(new RetrieveProfileAction(recipientId));
if (!envelope.hasSource()) {

View file

@ -51,7 +51,7 @@ public class ServiceConfig {
public static boolean isSignalClientAvailable() {
try {
org.signal.client.internal.Native.DisplayableFingerprint_Format(new byte[30], new byte[30]);
org.signal.client.internal.Native.DeviceTransfer_GeneratePrivateKey();
return true;
} catch (UnsatisfiedLinkError ignored) {
return false;

View file

@ -4,6 +4,7 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.groups.state.SenderKeyRecord;
import org.whispersystems.libsignal.state.IdentityKeyStore;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.PreKeyStore;
@ -14,6 +15,7 @@ import org.whispersystems.signalservice.api.SignalServiceProtocolStore;
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
import java.util.List;
import java.util.UUID;
public class SignalProtocolStore implements SignalServiceProtocolStore {
@ -138,4 +140,15 @@ public class SignalProtocolStore implements SignalServiceProtocolStore {
public void removeSignedPreKey(int signedPreKeyId) {
signedPreKeyStore.removeSignedPreKey(signedPreKeyId);
}
@Override
public void storeSenderKey(
final SignalProtocolAddress sender, final UUID distributionId, final SenderKeyRecord record
) {
}
@Override
public SenderKeyRecord loadSenderKey(final SignalProtocolAddress sender, final UUID distributionId) {
return null;
}
}

View file

@ -49,6 +49,7 @@ public class AttachmentUtils {
name,
false,
false,
false,
preview,
0,
0,

View file

@ -18,9 +18,9 @@ public class ProfileUtils {
) {
var profileCipher = new ProfileCipher(profileKey);
try {
var name = decryptName(encryptedProfile.getName(), profileCipher);
var about = decryptName(encryptedProfile.getAbout(), profileCipher);
var aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
var name = decrypt(encryptedProfile.getName(), profileCipher);
var about = decrypt(encryptedProfile.getAbout(), profileCipher);
var aboutEmoji = decrypt(encryptedProfile.getAboutEmoji(), profileCipher);
final var nameParts = splitName(name);
return new Profile(new Date().getTime(),
@ -66,13 +66,13 @@ public class ProfileUtils {
return capabilities;
}
private static String decryptName(
private static String decrypt(
final String encryptedName, final ProfileCipher profileCipher
) throws InvalidCiphertextException {
try {
return encryptedName == null
? null
: new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedName)));
: new String(profileCipher.decrypt(Base64.getDecoder().decode(encryptedName)));
} catch (IllegalArgumentException e) {
return null;
}