Store last resort kyber pre key from PniChangeNumber message

This commit is contained in:
AsamK 2023-07-01 14:06:35 +02:00
parent e57e5b090e
commit ffeae1a95a
3 changed files with 24 additions and 11 deletions

View file

@ -14,6 +14,7 @@ import org.asamk.signal.manager.util.NumberVerificationUtils;
import org.asamk.signal.manager.util.Utils; import org.asamk.signal.manager.util.Utils;
import org.signal.libsignal.protocol.IdentityKeyPair; import org.signal.libsignal.protocol.IdentityKeyPair;
import org.signal.libsignal.protocol.InvalidKeyException; import org.signal.libsignal.protocol.InvalidKeyException;
import org.signal.libsignal.protocol.state.KyberPreKeyRecord;
import org.signal.libsignal.protocol.state.SignedPreKeyRecord; import org.signal.libsignal.protocol.state.SignedPreKeyRecord;
import org.signal.libsignal.usernames.BaseUsernameException; import org.signal.libsignal.usernames.BaseUsernameException;
import org.signal.libsignal.usernames.Username; import org.signal.libsignal.usernames.Username;
@ -120,20 +121,21 @@ public class AccountHelper {
// TODO check and update remote storage // TODO check and update remote storage
context.getUnidentifiedAccessHelper().rotateSenderCertificates(); context.getUnidentifiedAccessHelper().rotateSenderCertificates();
dependencies.resetAfterAddressChange(); dependencies.resetAfterAddressChange();
context.getGroupV2Helper().clearAuthCredentialCache();
context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci()); context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
} }
public void setPni( public void setPni(
final PNI updatedPni, final PNI updatedPni,
final IdentityKeyPair pniIdentityKeyPair, final IdentityKeyPair pniIdentityKeyPair,
final String number,
final int localPniRegistrationId,
final SignedPreKeyRecord pniSignedPreKey, final SignedPreKeyRecord pniSignedPreKey,
final int localPniRegistrationId final KyberPreKeyRecord lastResortKyberPreKey
) throws IOException { ) throws IOException {
account.setPni(updatedPni, pniIdentityKeyPair, pniSignedPreKey, localPniRegistrationId); updateSelfIdentifiers(number != null ? number : account.getNumber(), account.getAci(), updatedPni);
account.setNewPniIdentity(pniIdentityKeyPair, pniSignedPreKey, lastResortKyberPreKey, localPniRegistrationId);
context.getPreKeyHelper().refreshPreKeysIfNecessary(ServiceIdType.PNI); context.getPreKeyHelper().refreshPreKeysIfNecessary(ServiceIdType.PNI);
if (account.getPni() == null || !account.getPni().equals(updatedPni)) {
context.getGroupV2Helper().clearAuthCredentialCache();
}
} }
public void startChangeNumber( public void startChangeNumber(

View file

@ -44,6 +44,7 @@ import org.signal.libsignal.protocol.IdentityKeyPair;
import org.signal.libsignal.protocol.InvalidMessageException; import org.signal.libsignal.protocol.InvalidMessageException;
import org.signal.libsignal.protocol.groups.GroupSessionBuilder; import org.signal.libsignal.protocol.groups.GroupSessionBuilder;
import org.signal.libsignal.protocol.message.DecryptionErrorMessage; import org.signal.libsignal.protocol.message.DecryptionErrorMessage;
import org.signal.libsignal.protocol.state.KyberPreKeyRecord;
import org.signal.libsignal.protocol.state.SignedPreKeyRecord; import org.signal.libsignal.protocol.state.SignedPreKeyRecord;
import org.signal.libsignal.zkgroup.InvalidInputException; import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.profiles.ProfileKey; import org.signal.libsignal.zkgroup.profiles.ProfileKey;
@ -646,8 +647,13 @@ public final class IncomingMessageHandler {
context.getAccountHelper() context.getAccountHelper()
.setPni(updatedPni, .setPni(updatedPni,
new IdentityKeyPair(pniChangeNumber.getIdentityKeyPair().toByteArray()), new IdentityKeyPair(pniChangeNumber.getIdentityKeyPair().toByteArray()),
pniChangeNumber.hasNewE164() ? pniChangeNumber.getNewE164() : null,
pniChangeNumber.getRegistrationId(),
new SignedPreKeyRecord(pniChangeNumber.getSignedPreKey().toByteArray()), new SignedPreKeyRecord(pniChangeNumber.getSignedPreKey().toByteArray()),
pniChangeNumber.getRegistrationId()); pniChangeNumber.hasLastResortKyberPreKey()
? new KyberPreKeyRecord(pniChangeNumber.getLastResortKyberPreKey()
.toByteArray())
: null);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Failed to handle change number message", e); logger.warn("Failed to handle change number message", e);
} }

View file

@ -1379,17 +1379,22 @@ public class SignalAccount implements Closeable {
save(); save();
} }
public void setPni( public void setNewPniIdentity(
final PNI updatedPni,
final IdentityKeyPair pniIdentityKeyPair, final IdentityKeyPair pniIdentityKeyPair,
final SignedPreKeyRecord pniSignedPreKey, final SignedPreKeyRecord pniSignedPreKey,
final KyberPreKeyRecord lastResortKyberPreKey,
final int localPniRegistrationId final int localPniRegistrationId
) { ) {
setPni(updatedPni);
setPniIdentityKeyPair(pniIdentityKeyPair); setPniIdentityKeyPair(pniIdentityKeyPair);
addSignedPreKey(ServiceIdType.PNI, pniSignedPreKey);
setLocalPniRegistrationId(localPniRegistrationId); setLocalPniRegistrationId(localPniRegistrationId);
final var preKeyMetadata = getAccountData(ServiceIdType.PNI).getPreKeyMetadata();
preKeyMetadata.nextSignedPreKeyId = pniSignedPreKey.getId();
addSignedPreKey(ServiceIdType.PNI, pniSignedPreKey);
if (lastResortKyberPreKey != null) {
preKeyMetadata.kyberPreKeyIdOffset = lastResortKyberPreKey.getId();
addLastResortKyberPreKey(ServiceIdType.PNI, lastResortKyberPreKey);
}
} }
public SignalServiceAddress getSelfAddress() { public SignalServiceAddress getSelfAddress() {