mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Create master key before storage sync if it doesn't exist yet
This commit is contained in:
parent
c1dc44d4fd
commit
a4db5d616a
4 changed files with 17 additions and 9 deletions
|
@ -830,9 +830,7 @@ class ManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
void retrieveRemoteStorage() throws IOException {
|
||||
if (account.getStorageKey() != null) {
|
||||
context.getStorageHelper().readDataFromStorage();
|
||||
}
|
||||
context.getStorageHelper().readDataFromStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,10 +15,6 @@ public class RetrieveStorageDataAction implements HandleAction {
|
|||
|
||||
@Override
|
||||
public void execute(Context context) throws Throwable {
|
||||
if (context.getAccount().getStorageKey() != null) {
|
||||
context.getStorageHelper().readDataFromStorage();
|
||||
} else if (!context.getAccount().isPrimaryDevice()) {
|
||||
context.getSyncHelper().requestSyncKeys();
|
||||
}
|
||||
context.getStorageHelper().readDataFromStorage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,18 @@ public class StorageHelper {
|
|||
}
|
||||
|
||||
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");
|
||||
Optional<SignalStorageManifest> manifest;
|
||||
try {
|
||||
manifest = dependencies.getAccountManager()
|
||||
.getStorageManifestIfDifferentVersion(account.getStorageKey(), account.getStorageManifestVersion());
|
||||
.getStorageManifestIfDifferentVersion(storageKey, account.getStorageManifestVersion());
|
||||
} catch (InvalidKeyException e) {
|
||||
logger.warn("Manifest couldn't be decrypted, ignoring.");
|
||||
return;
|
||||
|
|
|
@ -1288,6 +1288,13 @@ public class SignalAccount implements Closeable {
|
|||
return storageKey;
|
||||
}
|
||||
|
||||
public StorageKey getOrCreateStorageKey() {
|
||||
if (isPrimaryDevice()) {
|
||||
return getOrCreatePinMasterKey().deriveStorageServiceKey();
|
||||
}
|
||||
return storageKey;
|
||||
}
|
||||
|
||||
public void setStorageKey(final StorageKey storageKey) {
|
||||
if (storageKey.equals(this.storageKey)) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue