mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-19 02:33:39 +00:00
Vault fixes
This commit is contained in:
parent
0dfa43efe6
commit
3cd01a91c5
5 changed files with 31 additions and 23 deletions
|
@ -307,8 +307,8 @@ public abstract class DataStorage {
|
|||
|
||||
DataStoreEntry c = entry;
|
||||
do {
|
||||
// We can't check for sharing of invalid entries
|
||||
if (!c.getValidity().isUsable()) {
|
||||
// We can't check for sharing of failed entries
|
||||
if (c.getValidity() == DataStoreEntry.Validity.LOAD_FAILED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,11 @@ public abstract class DataStorage {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!c.getProvider().isShareable(c)) {
|
||||
try {
|
||||
if (!c.getProvider().isShareable(c)) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
} while ((c = DataStorage.get().getDefaultDisplayParent(c).orElse(null)) != null);
|
||||
|
@ -398,6 +402,8 @@ public abstract class DataStorage {
|
|||
DataStorage.get().saveAsync();
|
||||
}
|
||||
|
||||
public abstract boolean isOtherUserEntry(UUID uuid);
|
||||
|
||||
public void moveEntryToCategory(DataStoreEntry entry, DataStoreCategory newCategory) {
|
||||
if (getStoreCategoryIfPresent(entry.getUuid())
|
||||
.map(category -> category.equals(newCategory))
|
||||
|
|
|
@ -90,16 +90,14 @@ public class DataStorageSecret {
|
|||
|
||||
// User key must have changed
|
||||
if (!isUser && !isVault) {
|
||||
// There must be a key mismatch
|
||||
// We have loaded a secret with a user key that does no longer exist
|
||||
// This means that the user was deleted in this session
|
||||
// Replace it with a vault key
|
||||
if (userHandler.getActiveUser() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We don't want to use the new user key
|
||||
if (!allowUserSecretKey) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Password was changed
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.xpipe.app.ext.LocalStore;
|
|||
import io.xpipe.app.util.EncryptionKey;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class ImpersistentStorage extends DataStorage {
|
||||
|
@ -63,4 +64,9 @@ public class ImpersistentStorage extends DataStorage {
|
|||
public boolean supportsSharing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOtherUserEntry(UUID uuid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,11 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
|
@ -43,6 +41,7 @@ public class StandardStorage extends DataStorage {
|
|||
private boolean disposed;
|
||||
private boolean saveQueued;
|
||||
private final ReentrantLock busyIo = new ReentrantLock();
|
||||
private final Set<UUID> inaccessibleEntries = new HashSet<>();
|
||||
|
||||
|
||||
StandardStorage() {
|
||||
|
@ -294,6 +293,7 @@ public class StandardStorage extends DataStorage {
|
|||
.map(dataStoreEntry -> dataStoreEntry.getDirectory())
|
||||
.toList());
|
||||
toRemove.forEach(storeEntries::remove);
|
||||
inaccessibleEntries.addAll(toRemove.stream().map(dataStoreEntry -> dataStoreEntry.getUuid()).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
private boolean shouldRemoveOtherUserEntry(DataStoreEntry entry) {
|
||||
|
@ -435,6 +435,11 @@ public class StandardStorage extends DataStorage {
|
|||
return dataStorageSyncHandler.supportsSync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOtherUserEntry(UUID uuid) {
|
||||
return inaccessibleEntries.contains(uuid);
|
||||
}
|
||||
|
||||
private void deleteLeftovers() {
|
||||
var storesDir = getStoresDir();
|
||||
var categoriesDir = getCategoriesDir();
|
||||
|
|
|
@ -40,7 +40,7 @@ public class EncryptionToken {
|
|||
}
|
||||
|
||||
public static EncryptionToken ofInvalid() {
|
||||
return EncryptionToken.builder().token("").isUser(false).isVault(false).build();
|
||||
return EncryptionToken.builder().token("").isVault(false).build();
|
||||
}
|
||||
|
||||
public static EncryptionToken ofUser() {
|
||||
|
@ -64,9 +64,6 @@ public class EncryptionToken {
|
|||
|
||||
private final String token;
|
||||
|
||||
@JsonIgnore
|
||||
private Boolean isUser;
|
||||
|
||||
@JsonIgnore
|
||||
private Boolean isVault;
|
||||
|
||||
|
@ -85,16 +82,12 @@ public class EncryptionToken {
|
|||
}
|
||||
|
||||
public boolean isUser() {
|
||||
if (isUser != null) {
|
||||
return isUser;
|
||||
}
|
||||
|
||||
var userHandler = DataStorageUserHandler.getInstance();
|
||||
if (userHandler.getActiveUser() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (isUser = userHandler.getActiveUser().equals(decode(userHandler.getEncryptionKey())));
|
||||
return userHandler.getActiveUser().equals(decode(userHandler.getEncryptionKey()));
|
||||
}
|
||||
|
||||
public boolean isVault() {
|
||||
|
|
Loading…
Add table
Reference in a new issue