Update signal-service-java

This commit is contained in:
AsamK 2021-02-12 22:31:33 +01:00
parent 630803c3d1
commit 40fc712581
9 changed files with 46 additions and 44 deletions

View file

@ -76,7 +76,6 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.InvalidVersionException;
import org.whispersystems.libsignal.ecc.ECPublicKey;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
@ -219,7 +218,6 @@ public class Manager implements Closeable {
new DynamicCredentialsProvider(account.getUuid(),
account.getUsername(),
account.getPassword(),
account.getSignalingKey(),
account.getDeviceId()),
userAgent,
groupsV2Operations,
@ -242,7 +240,6 @@ public class Manager implements Closeable {
account.getUsername(),
account.getPassword(),
account.getDeviceId(),
account.getSignalingKey(),
userAgent,
null,
timer,
@ -352,7 +349,7 @@ public class Manager implements Closeable {
}
public void updateAccountAttributes() throws IOException {
accountManager.setAccountAttributes(account.getSignalingKey(),
accountManager.setAccountAttributes(null,
account.getSignalProtocolStore().getLocalRegistrationId(),
true,
// set legacy pin only if no KBS master key is set
@ -1747,9 +1744,6 @@ public class Manager implements Closeable {
} catch (TimeoutException e) {
if (returnOnTimeout) return;
continue;
} catch (InvalidVersionException e) {
logger.warn("Error while receiving messages, ignoring: {}", e.getMessage());
continue;
}
if (envelope.hasSource()) {

View file

@ -69,7 +69,7 @@ public class ProvisioningManager {
groupsV2Operations = null;
}
accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
new DynamicCredentialsProvider(null, null, password, null, SignalServiceAddress.DEFAULT_DEVICE_ID),
new DynamicCredentialsProvider(null, null, password, SignalServiceAddress.DEFAULT_DEVICE_ID),
userAgent,
groupsV2Operations,
ServiceConfig.AUTOMATIC_NETWORK_RETRY,
@ -95,10 +95,8 @@ public class ProvisioningManager {
}
public String finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
String signalingKey = KeyUtils.createSignalingKey();
SignalServiceAccountManager.NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(
identityKey,
signalingKey,
false,
true,
registrationId,
@ -130,7 +128,6 @@ public class ProvisioningManager {
ret.getDeviceId(),
ret.getIdentity(),
registrationId,
signalingKey,
profileKey)) {
account.save();

View file

@ -77,11 +77,7 @@ public class RegistrationManager implements Closeable {
this.accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
new DynamicCredentialsProvider(
// Using empty UUID, because registering doesn't work otherwise
null,
account.getUsername(),
account.getPassword(),
account.getSignalingKey(),
SignalServiceAddress.DEFAULT_DEVICE_ID),
null, account.getUsername(), account.getPassword(), SignalServiceAddress.DEFAULT_DEVICE_ID),
userAgent,
groupsV2Operations,
ServiceConfig.AUTOMATIC_NETWORK_RETRY,
@ -142,9 +138,6 @@ public class RegistrationManager implements Closeable {
String verificationCode, String pin
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
verificationCode = verificationCode.replace("-", "");
if (account.getSignalingKey() == null) {
account.setSignalingKey(KeyUtils.createSignalingKey());
}
VerifyAccountResponse response;
try {
response = verifyAccountWithCode(verificationCode, pin, null);
@ -176,6 +169,7 @@ public class RegistrationManager implements Closeable {
account.setRegistered(true);
account.setUuid(UuidUtil.parseOrNull(response.getUuid()));
account.setRegistrationLockPin(pin);
account.getSignalProtocolStore().archiveAllSessions();
account.getSignalProtocolStore()
.saveIdentity(account.getSelfAddress(),
account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
@ -195,7 +189,7 @@ public class RegistrationManager implements Closeable {
final String verificationCode, final String legacyPin, final String registrationLock
) throws IOException {
return accountManager.verifyAccountWithCode(verificationCode,
account.getSignalingKey(),
null,
account.getSignalProtocolStore().getLocalRegistrationId(),
true,
legacyPin,

View file

@ -9,6 +9,7 @@ import org.whispersystems.signalservice.api.push.TrustStore;
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
import org.whispersystems.signalservice.internal.configuration.SignalContactDiscoveryUrl;
import org.whispersystems.signalservice.internal.configuration.SignalKeyBackupServiceUrl;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.configuration.SignalServiceUrl;
import org.whispersystems.signalservice.internal.configuration.SignalStorageUrl;
@ -40,6 +41,7 @@ class LiveConfig {
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
private final static Optional<Dns> dns = Optional.absent();
private final static Optional<SignalProxy> proxy = Optional.absent();
private final static byte[] zkGroupServerPublicParams = Base64.getDecoder()
.decode("AMhf5ywVwITZMsff/eCyudZx9JDmkkkbV6PInzG4p8x3VqVJSFiMvnvlEKWuRob/1eaIetR31IYeAbm0NdOuHH8Qi+Rexi1wLlpzIo1gstHWBfZzy1+qHRV5A4TqPp15YzBPm0WSggW6PbSn+F4lf57VCnHF7p8SvzAA2ZZJPYJURt8X7bbg+H3i+PEjH9DXItNEqs2sNcug37xZQDLm7X0=");
@ -58,6 +60,7 @@ class LiveConfig {
new SignalStorageUrl[]{new SignalStorageUrl(STORAGE_URL, TRUST_STORE)},
interceptors,
dns,
proxy,
zkGroupServerPublicParams);
}

View file

@ -9,6 +9,7 @@ import org.whispersystems.signalservice.api.push.TrustStore;
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
import org.whispersystems.signalservice.internal.configuration.SignalContactDiscoveryUrl;
import org.whispersystems.signalservice.internal.configuration.SignalKeyBackupServiceUrl;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.configuration.SignalServiceUrl;
import org.whispersystems.signalservice.internal.configuration.SignalStorageUrl;
@ -40,6 +41,7 @@ class SandboxConfig {
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
private final static Optional<Dns> dns = Optional.absent();
private final static Optional<SignalProxy> proxy = Optional.absent();
private final static byte[] zkGroupServerPublicParams = Base64.getDecoder()
.decode("ABSY21VckQcbSXVNCGRYJcfWHiAMZmpTtTELcDmxgdFbtp/bWsSxZdMKzfCp8rvIs8ocCU3B37fT3r4Mi5qAemeGeR2X+/YmOGR5ofui7tD5mDQfstAI9i+4WpMtIe8KC3wU5w3Inq3uNWVmoGtpKndsNfwJrCg0Hd9zmObhypUnSkfYn2ooMOOnBpfdanRtrvetZUayDMSC5iSRcXKpdls=");
@ -58,6 +60,7 @@ class SandboxConfig {
new SignalStorageUrl[]{new SignalStorageUrl(STORAGE_URL, TRUST_STORE)},
interceptors,
dns,
proxy,
zkGroupServerPublicParams);
}

View file

@ -73,7 +73,6 @@ public class SignalAccount implements Closeable {
private String registrationLockPin;
private MasterKey pinMasterKey;
private StorageKey storageKey;
private String signalingKey;
private ProfileKey profileKey;
private int preKeyIdOffset;
private int nextSignedPreKeyId;
@ -153,7 +152,6 @@ public class SignalAccount implements Closeable {
int deviceId,
IdentityKeyPair identityKey,
int registrationId,
String signalingKey,
ProfileKey profileKey
) throws IOException {
IOUtils.createPrivateDirectories(dataPath);
@ -170,7 +168,6 @@ public class SignalAccount implements Closeable {
account.password = password;
account.profileKey = profileKey;
account.deviceId = deviceId;
account.signalingKey = signalingKey;
account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
account.groupStore = new JsonGroupStore(getGroupCachePath(dataPath, username));
account.contactStore = new JsonContactsStore();
@ -268,13 +265,6 @@ public class SignalAccount implements Closeable {
if (rootNode.hasNonNull("storageKey")) {
storageKey = new StorageKey(Base64.getDecoder().decode(rootNode.get("storageKey").asText()));
}
if (rootNode.hasNonNull("signalingKey")) {
signalingKey = rootNode.get("signalingKey").asText();
if (signalingKey.equals("null")) {
// Workaround for load bug in older versions
signalingKey = null;
}
}
if (rootNode.hasNonNull("preKeyIdOffset")) {
preKeyIdOffset = rootNode.get("preKeyIdOffset").asInt(0);
} else {
@ -406,7 +396,6 @@ public class SignalAccount implements Closeable {
pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
.put("storageKey",
storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
.put("signalingKey", signalingKey)
.put("preKeyIdOffset", preKeyIdOffset)
.put("nextSignedPreKeyId", nextSignedPreKeyId)
.put("profileKey", Base64.getEncoder().encodeToString(profileKey.serialize()))
@ -552,14 +541,6 @@ public class SignalAccount implements Closeable {
this.storageKey = storageKey;
}
public String getSignalingKey() {
return signalingKey;
}
public void setSignalingKey(final String signalingKey) {
this.signalingKey = signalingKey;
}
public ProfileKey getProfileKey() {
return profileKey;
}

View file

@ -13,7 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SessionStore;
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;
@ -24,7 +24,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
class JsonSessionStore implements SessionStore {
class JsonSessionStore implements SignalServiceSessionStore {
private final static Logger logger = LoggerFactory.getLogger(JsonSessionStore.class);
@ -127,6 +127,27 @@ class JsonSessionStore implements SessionStore {
sessions.removeIf(info -> info.address.matches(serviceAddress));
}
@Override
public void archiveSession(final SignalProtocolAddress address) {
final SessionRecord sessionRecord = loadSession(address);
if (sessionRecord == null) {
return;
}
sessionRecord.archiveCurrentState();
storeSession(address, sessionRecord);
}
public void archiveAllSessions() {
for (SessionInfo info : sessions) {
try {
final SessionRecord sessionRecord = new SessionRecord(info.sessionRecord);
sessionRecord.archiveCurrentState();
info.sessionRecord = sessionRecord.serialize();
} catch (IOException ignored) {
}
}
}
public static class JsonSessionStoreDeserializer extends JsonDeserializer<JsonSessionStore> {
@Override

View file

@ -11,13 +11,13 @@ import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.signalservice.api.SignalServiceProtocolStore;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.List;
public class JsonSignalProtocolStore implements SignalProtocolStore {
public class JsonSignalProtocolStore implements SignalServiceProtocolStore {
@JsonProperty("preKeys")
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)
@ -171,6 +171,15 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
sessionStore.deleteAllSessions(serviceAddress);
}
@Override
public void archiveSession(final SignalProtocolAddress address) {
sessionStore.archiveSession(address);
}
public void archiveAllSessions() {
sessionStore.archiveAllSessions();
}
@Override
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
return signedPreKeyStore.loadSignedPreKey(signedPreKeyId);