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,10 +830,8 @@ class ManagerImpl implements Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
void retrieveRemoteStorage() throws IOException {
|
void retrieveRemoteStorage() throws IOException {
|
||||||
if (account.getStorageKey() != null) {
|
|
||||||
context.getStorageHelper().readDataFromStorage();
|
context.getStorageHelper().readDataFromStorage();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addReceiveHandler(final ReceiveMessageHandler handler, final boolean isWeakListener) {
|
public void addReceiveHandler(final ReceiveMessageHandler handler, final boolean isWeakListener) {
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue