Update libsignal-service-java

Uses new device link endpoint

Fixes #1399
This commit is contained in:
AsamK 2023-12-14 18:07:13 +01:00
parent 2729772adb
commit fc6a4b78eb
6 changed files with 48 additions and 32 deletions

View file

@ -36,7 +36,6 @@ import org.whispersystems.signalservice.api.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil;
import org.whispersystems.signalservice.internal.push.ConfirmCodeMessage;
import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider;
import java.io.IOException;
@ -45,7 +44,7 @@ import java.nio.channels.OverlappingFileLockException;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import static org.asamk.signal.manager.config.ServiceConfig.getCapabilities;
import static org.asamk.signal.manager.util.KeyUtils.generatePreKeysForType;
public class ProvisioningManagerImpl implements ProvisioningManager {
@ -140,20 +139,21 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
encryptedDeviceName,
ret.getAciIdentity(),
ret.getPniIdentity(),
profileKey);
profileKey,
ret.getMasterKey());
account.getConfigurationStore().setReadReceipts(ret.isReadReceipts());
final var aciPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.ACI));
final var pniPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.PNI));
logger.debug("Finishing new device registration");
var deviceId = accountManager.finishNewDeviceRegistration(ret.getProvisioningCode(),
new ConfirmCodeMessage(false,
true,
account.getAccountData(ServiceIdType.ACI).getLocalRegistrationId(),
account.getAccountData(ServiceIdType.PNI).getLocalRegistrationId(),
encryptedDeviceName,
getCapabilities(false)));
account.getAccountAttributes(null),
aciPreKeys,
pniPreKeys);
account.finishLinking(deviceId);
account.finishLinking(deviceId, aciPreKeys, pniPreKeys);
ManagerImpl m = null;
try {

View file

@ -52,6 +52,8 @@ import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider
import java.io.IOException;
import java.util.function.Consumer;
import static org.asamk.signal.manager.util.KeyUtils.generatePreKeysForType;
public class RegistrationManagerImpl implements RegistrationManager {
private static final Logger logger = LoggerFactory.getLogger(RegistrationManagerImpl.class);
@ -137,8 +139,8 @@ public class RegistrationManagerImpl implements RegistrationManager {
account.setPniIdentityKeyPair(KeyUtils.generateIdentityKeyPair());
}
final var aciPreKeys = generatePreKeysForType(ServiceIdType.ACI);
final var pniPreKeys = generatePreKeysForType(ServiceIdType.PNI);
final var aciPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.ACI));
final var pniPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.PNI));
final var result = NumberVerificationUtils.verifyNumber(account.getSessionId(account.getNumber()),
verificationCode,
pin,
@ -252,21 +254,6 @@ public class RegistrationManagerImpl implements RegistrationManager {
true));
}
private PreKeyCollection generatePreKeysForType(ServiceIdType serviceIdType) {
final var accountData = account.getAccountData(serviceIdType);
final var keyPair = accountData.getIdentityKeyPair();
final var preKeyMetadata = accountData.getPreKeyMetadata();
final var nextSignedPreKeyId = preKeyMetadata.getNextSignedPreKeyId();
final var signedPreKey = KeyUtils.generateSignedPreKeyRecord(nextSignedPreKeyId, keyPair.getPrivateKey());
final var privateKey = keyPair.getPrivateKey();
final var kyberPreKeyIdOffset = preKeyMetadata.getNextKyberPreKeyId();
final var lastResortKyberPreKey = KeyUtils.generateKyberPreKeyRecord(kyberPreKeyIdOffset, privateKey);
return new PreKeyCollection(keyPair.getPublicKey(), signedPreKey, lastResortKyberPreKey);
}
@Override
public void close() {
if (account != null) {

View file

@ -275,7 +275,8 @@ public class SignalAccount implements Closeable {
final String encryptedDeviceName,
final IdentityKeyPair aciIdentity,
final IdentityKeyPair pniIdentity,
final ProfileKey profileKey
final ProfileKey profileKey,
final MasterKey masterKey
) {
this.deviceId = 0;
this.number = number;
@ -290,7 +291,7 @@ public class SignalAccount implements Closeable {
this.registered = false;
this.isMultiDevice = true;
getKeyValueStore().storeEntry(lastReceiveTimestamp, 0L);
this.pinMasterKey = null;
this.pinMasterKey = masterKey;
getKeyValueStore().storeEntry(storageManifestVersion, -1L);
this.setStorageManifest(null);
this.storageKey = null;
@ -304,9 +305,13 @@ public class SignalAccount implements Closeable {
save();
}
public void finishLinking(final int deviceId) {
public void finishLinking(
final int deviceId, final PreKeyCollection aciPreKeys, final PreKeyCollection pniPreKeys
) {
this.registered = true;
this.deviceId = deviceId;
setPreKeys(ServiceIdType.ACI, aciPreKeys);
setPreKeys(ServiceIdType.PNI, pniPreKeys);
save();
}

View file

@ -1,5 +1,6 @@
package org.asamk.signal.manager.util;
import org.asamk.signal.manager.storage.SignalAccount;
import org.signal.libsignal.protocol.IdentityKey;
import org.signal.libsignal.protocol.IdentityKeyPair;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -12,6 +13,7 @@ import org.signal.libsignal.protocol.state.PreKeyRecord;
import org.signal.libsignal.protocol.state.SignedPreKeyRecord;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
import org.whispersystems.signalservice.api.account.PreKeyCollection;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import java.security.SecureRandom;
@ -125,4 +127,18 @@ public class KeyUtils {
public static int getRandomInt(int bound) {
return secureRandom.nextInt(bound);
}
public static PreKeyCollection generatePreKeysForType(final SignalAccount.AccountData<?> accountData) {
final var keyPair = accountData.getIdentityKeyPair();
final var preKeyMetadata = accountData.getPreKeyMetadata();
final var nextSignedPreKeyId = preKeyMetadata.getNextSignedPreKeyId();
final var signedPreKey = generateSignedPreKeyRecord(nextSignedPreKeyId, keyPair.getPrivateKey());
final var privateKey = keyPair.getPrivateKey();
final var kyberPreKeyIdOffset = preKeyMetadata.getNextKyberPreKeyId();
final var lastResortKyberPreKey = generateKyberPreKeyRecord(kyberPreKeyIdOffset, privateKey);
return new PreKeyCollection(keyPair.getPublicKey(), signedPreKey, lastResortKyberPreKey);
}
}