Update libsignal-service-java

This commit is contained in:
AsamK 2023-07-14 19:25:32 +02:00
parent 2487fff44a
commit 02d4cb4a14
8 changed files with 116 additions and 41 deletions

View file

@ -5,14 +5,15 @@ import org.asamk.signal.manager.api.Pair;
import org.signal.libsignal.protocol.InvalidKeyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.KbsPinData;
import org.whispersystems.signalservice.api.KeyBackupService;
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
import org.whispersystems.signalservice.api.SvrNoDataException;
import org.whispersystems.signalservice.api.SvrPinData;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.api.kbs.PinHashUtil;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse;
import org.whispersystems.signalservice.internal.push.AuthCredentials;
import org.whispersystems.signalservice.internal.push.LockedException;
import java.io.IOException;
@ -70,26 +71,27 @@ public class PinHelper {
}
}
public KbsPinData getRegistrationLockData(
public SvrPinData getRegistrationLockData(
String pin, LockedException e
) throws IOException, IncorrectPinException {
var basicStorageCredentials = e.getBasicStorageCredentials();
var basicStorageCredentials = e.getSvr1Credentials();
if (basicStorageCredentials == null) {
return null;
}
try {
return getRegistrationLockData(pin, basicStorageCredentials);
} catch (KeyBackupSystemNoDataException ex) {
} catch (SvrNoDataException ex) {
throw new IOException(e);
} catch (KeyBackupServicePinException ex) {
throw new IncorrectPinException(ex.getTriesRemaining());
}
}
private KbsPinData getRegistrationLockData(
String pin, String basicStorageCredentials
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
private SvrPinData getRegistrationLockData(
String pin, AuthCredentials authCredentials
) throws IOException, SvrNoDataException, KeyBackupServicePinException {
final var basicStorageCredentials = authCredentials.asBasic();
var tokenResponsePair = getTokenResponse(basicStorageCredentials);
final var tokenResponse = tokenResponsePair.first();
final var keyBackupService = tokenResponsePair.second();
@ -113,12 +115,12 @@ public class PinHelper {
throw new IOException("KBS Account locked, maximum pin attempts reached.");
}
private KbsPinData restoreMasterKey(
private SvrPinData restoreMasterKey(
String pin,
String basicStorageCredentials,
TokenResponse tokenResponse,
final KeyBackupService keyBackupService
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
) throws IOException, SvrNoDataException, KeyBackupServicePinException {
if (pin == null) return null;
if (basicStorageCredentials == null) {

View file

@ -163,6 +163,7 @@ public class RecipientHelper {
useCompat,
Optional.empty(),
serviceEnvironmentConfig.getCdsiMrenclave(),
null,
token -> {
// Not storing for partial refresh
});

View file

@ -51,8 +51,6 @@ import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider
import java.io.IOException;
import java.util.function.Consumer;
import static org.asamk.signal.manager.config.ServiceConfig.PREKEY_MAXIMUM_ID;
public class RegistrationManagerImpl implements RegistrationManager {
private final static Logger logger = LoggerFactory.getLogger(RegistrationManagerImpl.class);
@ -267,28 +265,14 @@ public class RegistrationManagerImpl implements RegistrationManager {
final var keyPair = accountData.getIdentityKeyPair();
final var preKeyMetadata = accountData.getPreKeyMetadata();
final var preKeyIdOffset = preKeyMetadata.getPreKeyIdOffset();
final var oneTimeEcPreKeys = KeyUtils.generatePreKeyRecords(preKeyIdOffset);
final var nextSignedPreKeyId = preKeyMetadata.getNextSignedPreKeyId();
final var signedPreKey = KeyUtils.generateSignedPreKeyRecord(nextSignedPreKeyId, keyPair);
final var privateKey = keyPair.getPrivateKey();
final var kyberPreKeyIdOffset = preKeyMetadata.getKyberPreKeyIdOffset();
final var oneTimeKyberPreKeys = KeyUtils.generateKyberPreKeyRecords(kyberPreKeyIdOffset, privateKey);
final var lastResortKyberPreKeyId = (kyberPreKeyIdOffset + oneTimeKyberPreKeys.size()) % PREKEY_MAXIMUM_ID;
final var lastResortKyberPreKey = KeyUtils.generateKyberPreKeyRecord(lastResortKyberPreKeyId, privateKey);
final var lastResortKyberPreKey = KeyUtils.generateKyberPreKeyRecord(kyberPreKeyIdOffset, privateKey);
return new PreKeyCollection(keyPair,
nextSignedPreKeyId,
preKeyIdOffset,
lastResortKyberPreKeyId,
kyberPreKeyIdOffset,
serviceIdType,
keyPair.getPublicKey(),
signedPreKey,
oneTimeEcPreKeys,
lastResortKyberPreKey,
oneTimeKyberPreKeys);
return new PreKeyCollection(keyPair.getPublicKey(), signedPreKey, lastResortKyberPreKey);
}
@Override

View file

@ -303,18 +303,14 @@ public class SignalAccount implements Closeable {
private void setPreKeys(ServiceIdType serviceIdType, PreKeyCollection preKeyCollection) {
final var accountData = getAccountData(serviceIdType);
final var preKeyMetadata = accountData.getPreKeyMetadata();
preKeyMetadata.nextSignedPreKeyId = preKeyCollection.getNextSignedPreKeyId();
preKeyMetadata.preKeyIdOffset = preKeyCollection.getEcOneTimePreKeyIdOffset();
preKeyMetadata.kyberPreKeyIdOffset = preKeyCollection.getOneTimeKyberPreKeyIdOffset();
preKeyMetadata.activeLastResortKyberPreKeyId = preKeyCollection.getLastResortKyberPreKeyId();
preKeyMetadata.nextSignedPreKeyId = preKeyCollection.getSignedPreKey().getId();
preKeyMetadata.kyberPreKeyIdOffset = preKeyCollection.getLastResortKyberPreKey().getId();
accountData.getPreKeyStore().removeAllPreKeys();
accountData.getSignedPreKeyStore().removeAllSignedPreKeys();
accountData.getKyberPreKeyStore().removeAllKyberPreKeys();
addPreKeys(serviceIdType, preKeyCollection.getOneTimeEcPreKeys());
addSignedPreKey(serviceIdType, preKeyCollection.getSignedPreKey());
addKyberPreKeys(serviceIdType, preKeyCollection.getOneTimeKyberPreKeys());
addLastResortKyberPreKey(serviceIdType, preKeyCollection.getLastResortKyberPreKey());
save();
@ -1335,13 +1331,14 @@ public class SignalAccount implements Closeable {
public AccountAttributes getAccountAttributes(String registrationLock) {
return new AccountAttributes(null,
getLocalRegistrationId(),
false,
false,
true,
null,
registrationLock != null ? registrationLock : getRegistrationLock(),
getSelfUnidentifiedAccessKey(),
isUnrestrictedUnidentifiedAccess(),
getAccountCapabilities(),
isDiscoverableByPhoneNumber(),
getAccountCapabilities(),
encryptedDeviceName,
getLocalPniRegistrationId(),
null); // TODO recoveryPassword?

View file

@ -7,7 +7,6 @@ import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.helper.PinHelper;
import org.whispersystems.signalservice.api.KbsPinData;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException;
@ -116,8 +115,7 @@ public class NumberVerificationUtils {
throw new PinLockedException(e.getTimeRemaining());
}
KbsPinData registrationLockData;
registrationLockData = pinHelper.getRegistrationLockData(pin, e);
final var registrationLockData = pinHelper.getRegistrationLockData(pin, e);
if (registrationLockData == null) {
throw e;
}