Create master key before storage sync if it doesn't exist yet

This commit is contained in:
AsamK 2022-06-21 17:17:25 +02:00
parent c1dc44d4fd
commit a4db5d616a
4 changed files with 17 additions and 9 deletions

View file

@ -830,9 +830,7 @@ class ManagerImpl implements Manager {
} }
void retrieveRemoteStorage() throws IOException { void retrieveRemoteStorage() throws IOException {
if (account.getStorageKey() != null) { context.getStorageHelper().readDataFromStorage();
context.getStorageHelper().readDataFromStorage();
}
} }
@Override @Override

View file

@ -15,10 +15,6 @@ public class RetrieveStorageDataAction implements HandleAction {
@Override @Override
public void execute(Context context) throws Throwable { public void execute(Context context) throws Throwable {
if (context.getAccount().getStorageKey() != null) { context.getStorageHelper().readDataFromStorage();
context.getStorageHelper().readDataFromStorage();
} else if (!context.getAccount().isPrimaryDevice()) {
context.getSyncHelper().requestSyncKeys();
}
} }
} }

View file

@ -43,11 +43,18 @@ public class StorageHelper {
} }
public void readDataFromStorage() throws IOException { public void readDataFromStorage() throws IOException {
final var storageKey = account.getOrCreateStorageKey();
if (storageKey == null) {
logger.debug("Storage key unknown, requesting from primary device.");
context.getSyncHelper().requestSyncKeys();
return;
}
logger.debug("Reading data from remote storage"); logger.debug("Reading data from remote storage");
Optional<SignalStorageManifest> manifest; Optional<SignalStorageManifest> manifest;
try { try {
manifest = dependencies.getAccountManager() manifest = dependencies.getAccountManager()
.getStorageManifestIfDifferentVersion(account.getStorageKey(), account.getStorageManifestVersion()); .getStorageManifestIfDifferentVersion(storageKey, account.getStorageManifestVersion());
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
logger.warn("Manifest couldn't be decrypted, ignoring."); logger.warn("Manifest couldn't be decrypted, ignoring.");
return; return;

View file

@ -1288,6 +1288,13 @@ public class SignalAccount implements Closeable {
return storageKey; return storageKey;
} }
public StorageKey getOrCreateStorageKey() {
if (isPrimaryDevice()) {
return getOrCreatePinMasterKey().deriveStorageServiceKey();
}
return storageKey;
}
public void setStorageKey(final StorageKey storageKey) { public void setStorageKey(final StorageKey storageKey) {
if (storageKey.equals(this.storageKey)) { if (storageKey.equals(this.storageKey)) {
return; return;