Fix NPE for vault key

This commit is contained in:
crschnick
2025-01-04 03:10:43 +00:00
parent bbf91d112b
commit fc2b111b53
4 changed files with 10 additions and 2 deletions

View File

@@ -32,6 +32,12 @@ import javax.crypto.SecretKey;
public abstract class DataStorage {
protected static SecretKey secretKey;
public static SecretKey getSecretKey() {
return get() != null ? get().getVaultKey() : secretKey;
}
public static final UUID ALL_CONNECTIONS_CATEGORY_UUID = UUID.fromString("bfb0b51a-e7a3-4ce4-8878-8d4cb5828d6c");
public static final UUID ALL_SCRIPTS_CATEGORY_UUID = UUID.fromString("19024cf9-d192-41a9-88a6-a22694cf716a");
public static final UUID PREDEFINED_SCRIPTS_CATEGORY_UUID = UUID.fromString("5faf1d71-0efc-4293-8b70-299406396973");

View File

@@ -483,11 +483,13 @@ public class StandardStorage extends DataStorage {
var s = Files.readString(file);
var id = new String(Base64.getDecoder().decode(s), StandardCharsets.UTF_8);
vaultKey = EncryptionKey.getVaultSecretKey(id);
secretKey = vaultKey;
} else {
FileUtils.forceMkdir(dir.toFile());
var id = UUID.randomUUID().toString();
Files.writeString(file, Base64.getEncoder().encodeToString(id.getBytes(StandardCharsets.UTF_8)));
vaultKey = EncryptionKey.getVaultSecretKey(id);
secretKey = vaultKey;
}
}

View File

@@ -101,7 +101,7 @@ public class EncryptionToken {
return isVault;
}
var key = DataStorage.get().getVaultKey();
var key = DataStorage.getSecretKey();
var s = decode(key);
return (isVault = s.equals("xpipe"));
}

View File

@@ -28,7 +28,7 @@ public class VaultKeySecretValue extends AesSecretValue {
@Override
protected SecretKey getSecretKey() throws InvalidKeySpecException {
return DataStorage.get().getVaultKey();
return DataStorage.getSecretKey();
}
@Override