Update libsignal-service-java

This commit is contained in:
AsamK 2022-08-11 19:09:41 +02:00
parent 64f6a1f072
commit 6843643aad
8 changed files with 52 additions and 10 deletions

View file

@ -2995,6 +2995,7 @@
{"name":"messageRequestResponse_"}, {"name":"messageRequestResponse_"},
{"name":"outgoingPayment_"}, {"name":"outgoingPayment_"},
{"name":"padding_"}, {"name":"padding_"},
{"name":"pniChangeNumber_"},
{"name":"pniIdentity_"}, {"name":"pniIdentity_"},
{"name":"read_"}, {"name":"read_"},
{"name":"request_"}, {"name":"request_"},

View file

@ -14,7 +14,7 @@ repositories {
} }
dependencies { dependencies {
implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_54") implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_55")
implementation("com.fasterxml.jackson.core", "jackson-databind", "2.13.3") implementation("com.fasterxml.jackson.core", "jackson-databind", "2.13.3")
implementation("com.google.protobuf", "protobuf-javalite", "3.11.4") implementation("com.google.protobuf", "protobuf-javalite", "3.11.4")
implementation("org.bouncycastle", "bcprov-jdk15on", "1.70") implementation("org.bouncycastle", "bcprov-jdk15on", "1.70")

View file

@ -33,6 +33,7 @@ import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException; import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil; import org.whispersystems.signalservice.api.util.DeviceNameUtil;
import org.whispersystems.signalservice.internal.push.ConfirmCodeMessage;
import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider; import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider;
import java.io.IOException; import java.io.IOException;
@ -54,6 +55,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
private final SignalServiceAccountManager accountManager; private final SignalServiceAccountManager accountManager;
private final IdentityKeyPair tempIdentityKey; private final IdentityKeyPair tempIdentityKey;
private final int registrationId; private final int registrationId;
private final int pniRegistrationId;
private final String password; private final String password;
ProvisioningManagerImpl( ProvisioningManagerImpl(
@ -71,6 +73,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
tempIdentityKey = KeyUtils.generateIdentityKeyPair(); tempIdentityKey = KeyUtils.generateIdentityKeyPair();
registrationId = KeyHelper.generateRegistrationId(false); registrationId = KeyHelper.generateRegistrationId(false);
pniRegistrationId = KeyHelper.generateRegistrationId(false);
password = KeyUtils.createPassword(); password = KeyUtils.createPassword();
GroupsV2Operations groupsV2Operations; GroupsV2Operations groupsV2Operations;
try { try {
@ -123,10 +126,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
logger.debug("Finishing new device registration"); logger.debug("Finishing new device registration");
var deviceId = accountManager.finishNewDeviceRegistration(ret.getProvisioningCode(), var deviceId = accountManager.finishNewDeviceRegistration(ret.getProvisioningCode(),
false, new ConfirmCodeMessage(false, true, registrationId, pniRegistrationId, encryptedDeviceName, null));
true,
registrationId,
encryptedDeviceName);
// Create new account with the synced identity // Create new account with the synced identity
var profileKey = ret.getProfileKey() == null ? KeyUtils.createProfileKey() : ret.getProfileKey(); var profileKey = ret.getProfileKey() == null ? KeyUtils.createProfileKey() : ret.getProfileKey();
@ -145,6 +145,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
ret.getAciIdentity(), ret.getAciIdentity(),
ret.getPniIdentity(), ret.getPniIdentity(),
registrationId, registrationId,
pniRegistrationId,
profileKey, profileKey,
TrustNewIdentity.ON_FIRST_USE); TrustNewIdentity.ON_FIRST_USE);

View file

@ -187,7 +187,8 @@ class RegistrationManagerImpl implements RegistrationManager {
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
capabilities, capabilities,
account.isDiscoverableByPhoneNumber(), account.isDiscoverableByPhoneNumber(),
account.getEncryptedDeviceName()); account.getEncryptedDeviceName(),
account.getLocalPniRegistrationId());
account.setRegistered(true); account.setRegistered(true);
logger.info("Reactivated existing account, verify is not necessary."); logger.info("Reactivated existing account, verify is not necessary.");
if (newManagerListener != null) { if (newManagerListener != null) {
@ -216,7 +217,8 @@ class RegistrationManagerImpl implements RegistrationManager {
account.getSelfUnidentifiedAccessKey(), account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
ServiceConfig.capabilities, ServiceConfig.capabilities,
account.isDiscoverableByPhoneNumber()); account.isDiscoverableByPhoneNumber(),
account.getLocalPniRegistrationId());
} else { } else {
return accountManager.verifyAccountWithRegistrationLockPin(verificationCode, return accountManager.verifyAccountWithRegistrationLockPin(verificationCode,
account.getLocalRegistrationId(), account.getLocalRegistrationId(),
@ -225,7 +227,8 @@ class RegistrationManagerImpl implements RegistrationManager {
account.getSelfUnidentifiedAccessKey(), account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
ServiceConfig.capabilities, ServiceConfig.capabilities,
account.isDiscoverableByPhoneNumber()); account.isDiscoverableByPhoneNumber(),
account.getLocalPniRegistrationId());
} }
} }

View file

@ -149,6 +149,7 @@ public class SignalAccountFiles {
var aciIdentityKey = KeyUtils.generateIdentityKeyPair(); var aciIdentityKey = KeyUtils.generateIdentityKeyPair();
var pniIdentityKey = KeyUtils.generateIdentityKeyPair(); var pniIdentityKey = KeyUtils.generateIdentityKeyPair();
var registrationId = KeyHelper.generateRegistrationId(false); var registrationId = KeyHelper.generateRegistrationId(false);
var pniRegistrationId = KeyHelper.generateRegistrationId(false);
var profileKey = KeyUtils.createProfileKey(); var profileKey = KeyUtils.createProfileKey();
var account = SignalAccount.create(pathConfig.dataPath(), var account = SignalAccount.create(pathConfig.dataPath(),
@ -158,6 +159,7 @@ public class SignalAccountFiles {
aciIdentityKey, aciIdentityKey,
pniIdentityKey, pniIdentityKey,
registrationId, registrationId,
pniRegistrationId,
profileKey, profileKey,
trustNewIdentity); trustNewIdentity);

View file

@ -13,12 +13,17 @@ import org.asamk.signal.manager.util.NumberVerificationUtils;
import org.signal.libsignal.protocol.InvalidKeyException; import org.signal.libsignal.protocol.InvalidKeyException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest;
import org.whispersystems.signalservice.api.push.ACI; import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.PNI; import org.whispersystems.signalservice.api.push.PNI;
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException; import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil; import org.whispersystems.signalservice.api.util.DeviceNameUtil;
import org.whispersystems.signalservice.internal.push.OutgoingPushMessage;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -103,11 +108,21 @@ public class AccountHelper {
public void finishChangeNumber( public void finishChangeNumber(
String newNumber, String verificationCode, String pin String newNumber, String verificationCode, String pin
) throws IncorrectPinException, PinLockedException, IOException { ) throws IncorrectPinException, PinLockedException, IOException {
// TODO create new PNI identity key
final List<OutgoingPushMessage> deviceMessages = null;
final Map<String, SignedPreKeyEntity> devicePniSignedPreKeys = null;
final Map<String, Integer> pniRegistrationIds = null;
final var result = NumberVerificationUtils.verifyNumber(verificationCode, final var result = NumberVerificationUtils.verifyNumber(verificationCode,
pin, pin,
context.getPinHelper(), context.getPinHelper(),
(verificationCode1, registrationLock) -> dependencies.getAccountManager() (verificationCode1, registrationLock) -> dependencies.getAccountManager()
.changeNumber(verificationCode1, newNumber, registrationLock)); .changeNumber(new ChangePhoneNumberRequest(newNumber,
verificationCode1,
registrationLock,
account.getPniIdentityKeyPair().getPublicKey(),
deviceMessages,
devicePniSignedPreKeys,
pniRegistrationIds)));
// TODO handle response // TODO handle response
updateSelfIdentifiers(newNumber, account.getAci(), PNI.parseOrThrow(result.first().getPni())); updateSelfIdentifiers(newNumber, account.getAci(), PNI.parseOrThrow(result.first().getPni()));
} }
@ -129,7 +144,8 @@ public class AccountHelper {
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
ServiceConfig.capabilities, ServiceConfig.capabilities,
account.isDiscoverableByPhoneNumber(), account.isDiscoverableByPhoneNumber(),
account.getEncryptedDeviceName()); account.getEncryptedDeviceName(),
account.getLocalPniRegistrationId());
} }
public void addDevice(DeviceLinkInfo deviceLinkInfo) throws IOException, InvalidDeviceLinkException { public void addDevice(DeviceLinkInfo deviceLinkInfo) throws IOException, InvalidDeviceLinkException {

View file

@ -492,6 +492,7 @@ public final class IncomingMessageHandler {
pniIdentity.getPrivateKey().toByteArray())); pniIdentity.getPrivateKey().toByteArray()));
actions.add(RefreshPreKeysAction.create()); actions.add(RefreshPreKeysAction.create());
} }
// TODO handle PniChangeNumber
return actions; return actions;
} }

View file

@ -45,6 +45,7 @@ import org.signal.libsignal.protocol.SignalProtocolAddress;
import org.signal.libsignal.protocol.state.PreKeyRecord; import org.signal.libsignal.protocol.state.PreKeyRecord;
import org.signal.libsignal.protocol.state.SessionRecord; import org.signal.libsignal.protocol.state.SessionRecord;
import org.signal.libsignal.protocol.state.SignedPreKeyRecord; import org.signal.libsignal.protocol.state.SignedPreKeyRecord;
import org.signal.libsignal.protocol.util.KeyHelper;
import org.signal.libsignal.protocol.util.Medium; import org.signal.libsignal.protocol.util.Medium;
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;
@ -125,6 +126,7 @@ public class SignalAccount implements Closeable {
private IdentityKeyPair aciIdentityKeyPair; private IdentityKeyPair aciIdentityKeyPair;
private IdentityKeyPair pniIdentityKeyPair; private IdentityKeyPair pniIdentityKeyPair;
private int localRegistrationId; private int localRegistrationId;
private int localPniRegistrationId;
private TrustNewIdentity trustNewIdentity; private TrustNewIdentity trustNewIdentity;
private long lastReceiveTimestamp = 0; private long lastReceiveTimestamp = 0;
@ -186,6 +188,7 @@ public class SignalAccount implements Closeable {
IdentityKeyPair aciIdentityKey, IdentityKeyPair aciIdentityKey,
IdentityKeyPair pniIdentityKey, IdentityKeyPair pniIdentityKey,
int registrationId, int registrationId,
int pniRegistrationId,
ProfileKey profileKey, ProfileKey profileKey,
final TrustNewIdentity trustNewIdentity final TrustNewIdentity trustNewIdentity
) throws IOException { ) throws IOException {
@ -207,6 +210,7 @@ public class SignalAccount implements Closeable {
signalAccount.aciIdentityKeyPair = aciIdentityKey; signalAccount.aciIdentityKeyPair = aciIdentityKey;
signalAccount.pniIdentityKeyPair = pniIdentityKey; signalAccount.pniIdentityKeyPair = pniIdentityKey;
signalAccount.localRegistrationId = registrationId; signalAccount.localRegistrationId = registrationId;
signalAccount.localPniRegistrationId = pniRegistrationId;
signalAccount.trustNewIdentity = trustNewIdentity; signalAccount.trustNewIdentity = trustNewIdentity;
signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath), signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
signalAccount.getRecipientResolver(), signalAccount.getRecipientResolver(),
@ -236,6 +240,7 @@ public class SignalAccount implements Closeable {
IdentityKeyPair aciIdentityKey, IdentityKeyPair aciIdentityKey,
IdentityKeyPair pniIdentityKey, IdentityKeyPair pniIdentityKey,
int registrationId, int registrationId,
int pniRegistrationId,
ProfileKey profileKey, ProfileKey profileKey,
final TrustNewIdentity trustNewIdentity final TrustNewIdentity trustNewIdentity
) throws IOException { ) throws IOException {
@ -254,6 +259,7 @@ public class SignalAccount implements Closeable {
aciIdentityKey, aciIdentityKey,
pniIdentityKey, pniIdentityKey,
registrationId, registrationId,
pniRegistrationId,
profileKey, profileKey,
trustNewIdentity); trustNewIdentity);
} }
@ -305,6 +311,7 @@ public class SignalAccount implements Closeable {
IdentityKeyPair aciIdentityKey, IdentityKeyPair aciIdentityKey,
IdentityKeyPair pniIdentityKey, IdentityKeyPair pniIdentityKey,
int registrationId, int registrationId,
int pniRegistrationId,
ProfileKey profileKey, ProfileKey profileKey,
final TrustNewIdentity trustNewIdentity final TrustNewIdentity trustNewIdentity
) throws IOException { ) throws IOException {
@ -318,6 +325,7 @@ public class SignalAccount implements Closeable {
signalAccount.accountPath = accountPath; signalAccount.accountPath = accountPath;
signalAccount.serviceEnvironment = serviceEnvironment; signalAccount.serviceEnvironment = serviceEnvironment;
signalAccount.localRegistrationId = registrationId; signalAccount.localRegistrationId = registrationId;
signalAccount.localPniRegistrationId = pniRegistrationId;
signalAccount.trustNewIdentity = trustNewIdentity; signalAccount.trustNewIdentity = trustNewIdentity;
signalAccount.setProvisioningData(number, signalAccount.setProvisioningData(number,
aci, aci,
@ -549,6 +557,11 @@ public class SignalAccount implements Closeable {
if (rootNode.hasNonNull("registrationId")) { if (rootNode.hasNonNull("registrationId")) {
registrationId = rootNode.get("registrationId").asInt(); registrationId = rootNode.get("registrationId").asInt();
} }
if (rootNode.hasNonNull("pniRegistrationId")) {
localPniRegistrationId = rootNode.get("pniRegistrationId").asInt();
} else {
localPniRegistrationId = KeyHelper.generateRegistrationId(false);
}
IdentityKeyPair aciIdentityKeyPair = null; IdentityKeyPair aciIdentityKeyPair = null;
if (rootNode.hasNonNull("identityPrivateKey") && rootNode.hasNonNull("identityKey")) { if (rootNode.hasNonNull("identityPrivateKey") && rootNode.hasNonNull("identityKey")) {
final var publicKeyBytes = Base64.getDecoder().decode(rootNode.get("identityKey").asText()); final var publicKeyBytes = Base64.getDecoder().decode(rootNode.get("identityKey").asText());
@ -855,6 +868,7 @@ public class SignalAccount implements Closeable {
.put("lastReceiveTimestamp", lastReceiveTimestamp) .put("lastReceiveTimestamp", lastReceiveTimestamp)
.put("password", password) .put("password", password)
.put("registrationId", localRegistrationId) .put("registrationId", localRegistrationId)
.put("pniRegistrationId", localPniRegistrationId)
.put("identityPrivateKey", .put("identityPrivateKey",
Base64.getEncoder().encodeToString(aciIdentityKeyPair.getPrivateKey().serialize())) Base64.getEncoder().encodeToString(aciIdentityKeyPair.getPrivateKey().serialize()))
.put("identityKey", .put("identityKey",
@ -1245,6 +1259,10 @@ public class SignalAccount implements Closeable {
return localRegistrationId; return localRegistrationId;
} }
public int getLocalPniRegistrationId() {
return localPniRegistrationId;
}
public String getPassword() { public String getPassword() {
return password; return password;
} }