diff --git a/pom.xml b/pom.xml index a5aeafc5..471ca4eb 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 - 2.0.0-beta5 + 2.0.0-beta6 3.12.0 2.31 30.1-jre diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java index ba0c4423..438b9577 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java @@ -49,13 +49,10 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT var configLoader = VaultConfig.decode(token); var keyId = configLoader.getKeyId(); - byte[] rawKey = new byte[0]; try (Masterkey key = properties.keyLoader(keyId.getScheme()).loadKey(keyId)) { - rawKey = key.getEncoded(); - var config = configLoader.verify(rawKey, Constants.VAULT_VERSION); + var config = configLoader.verify(key.getEncoded(), Constants.VAULT_VERSION); var adjustedProperties = adjustForCapabilities(pathToVault, properties); - var keyCopy = Masterkey.createFromRaw(key.getEncoded()); // TODO replace with key.clone() eventually - var cryptor = config.getCipherCombo().getCryptorProvider(csprng).withKey(keyCopy); + var cryptor = config.getCipherCombo().getCryptorProvider(csprng).withKey(key.clone()); try { checkVaultRootExistence(pathToVault, cryptor); return fileSystems.compute(normalizedPathToVault, (path, fs) -> { @@ -69,8 +66,6 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT cryptor.destroy(); throw e; } - } finally { - Arrays.fill(rawKey, (byte) 0x00); } } diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java index d5d8ea51..7bca22ee 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java @@ -67,7 +67,7 @@ public class Windows { public void setupClass(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFailedException { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme(Mockito.any())).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(tmpDir, properties, URI.create("test:key")); fileSystem = CryptoFileSystemProvider.newFileSystem(tmpDir, properties); @@ -143,7 +143,7 @@ public void beforeAll() throws IOException, MasterkeyLoadingFailedException { Files.createDirectories(vaultPath); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(vaultPath, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(vaultPath, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java index 8677bb00..97ef9c39 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java @@ -76,7 +76,6 @@ public class CryptoFileSystemProviderIntegrationTest { @TestInstance(TestInstance.Lifecycle.PER_CLASS) class WithLimitedPaths { - private byte[] rawKey = new byte[64]; private MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); private CryptoFileSystem fs; private Path shortFilePath; @@ -86,7 +85,7 @@ class WithLimitedPaths { @BeforeAll public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFailedException { Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(rawKey)); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = cryptoFileSystemProperties() // .withFlags() // .withMasterkeyFilename("masterkey.cryptomator") // @@ -195,8 +194,8 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { keyLoader2 = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader1.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader2.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader1.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(key1)); - Mockito.when(keyLoader2.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(key2)); + Mockito.when(keyLoader1.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(key1)); + Mockito.when(keyLoader2.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(key2)); pathToVault1 = tmpFs.getPath("/vaultDir1"); pathToVault2 = tmpFs.getPath("/vaultDir2"); Files.createDirectory(pathToVault1); @@ -537,7 +536,7 @@ public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFail Files.createDirectories(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fs = CryptoFileSystemProvider.newFileSystem(pathToVault, properties); @@ -630,7 +629,7 @@ public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFail Files.createDirectories(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fs = CryptoFileSystemProvider.newFileSystem(pathToVault, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java index 655395e8..ed488d7b 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java @@ -115,7 +115,7 @@ private static final Stream shouldFailWithRelativePat @SuppressWarnings("deprecation") public void setup() throws MasterkeyLoadingFailedException { Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + when(keyLoader.loadKey(Mockito.any())).thenReturn(new Masterkey(new byte[64])); CryptoFileSystemProviderComponent component = mock(CryptoFileSystemProviderComponent.class); when(component.fileSystems()).thenReturn(fileSystems); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java index d1dfc2a8..fe60e12d 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java @@ -76,7 +76,7 @@ public void testCreateWithPathToVaultFromNonDefaultProvider() throws IOException try { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(tempDir, properties, URI.create("test:key")); FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(tempDir, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java index 0f8d5669..43456ad2 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java @@ -60,7 +60,6 @@ public class CryptoFileSystemsTest { private MockedStatic vaultConficClass; private MockedStatic filesClass; - private MockedStatic masterkeyClass; private final CryptoFileSystems inTest = new CryptoFileSystems(cryptoFileSystemComponentBuilder, capabilityChecker, csprng); @@ -68,7 +67,6 @@ public class CryptoFileSystemsTest { public void setup() throws IOException, MasterkeyLoadingFailedException { vaultConficClass = Mockito.mockStatic(VaultConfig.class); filesClass = Mockito.mockStatic(Files.class); - masterkeyClass = Mockito.mockStatic(Masterkey.class); when(pathToVault.normalize()).thenReturn(normalizedPathToVault); when(normalizedPathToVault.resolve("vault.cryptomator")).thenReturn(configFilePath); @@ -80,8 +78,8 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { when(configLoader.getKeyId()).thenReturn(URI.create("test:key")); when(keyLoader.loadKey(Mockito.any())).thenReturn(masterkey); when(masterkey.getEncoded()).thenReturn(rawKey); + when(masterkey.clone()).thenReturn(clonedMasterkey); when(configLoader.verify(rawKey, Constants.VAULT_VERSION)).thenReturn(vaultConfig); - masterkeyClass.when(() -> Masterkey.createFromRaw(rawKey)).thenReturn(clonedMasterkey); when(cryptorProvider.withKey(clonedMasterkey)).thenReturn(cryptor); when(vaultConfig.getCipherCombo()).thenReturn(cipherCombo); when(cipherCombo.getCryptorProvider(csprng)).thenReturn(cryptorProvider); @@ -105,7 +103,6 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { public void tearDown() { vaultConficClass.close(); filesClass.close(); - masterkeyClass.close(); } @Test diff --git a/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java index b32e7260..021d3d86 100644 --- a/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java @@ -48,7 +48,7 @@ public static void setupClass(@TempDir Path tmpDir) throws IOException, Masterke Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); diff --git a/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java b/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java index ebfc1d9f..30c1a857 100644 --- a/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java +++ b/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java @@ -32,7 +32,7 @@ public class ReadmeCodeSamplesTest { public void testReadmeCodeSampleUsingFileSystemConstructionMethodA(@TempDir Path storageLocation) throws IOException, MasterkeyLoadingFailedException { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(storageLocation, properties, URI.create("test:key")); FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(storageLocation, properties); @@ -45,7 +45,7 @@ public void testReadmeCodeSampleUsingFileSystemConstructionMethodB(@TempDir Path URI uri = CryptoFileSystemUri.create(storageLocation); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(storageLocation, properties, URI.create("test:key")); FileSystem fileSystem = FileSystems.newFileSystem(uri, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java index 2431642f..d0c65013 100644 --- a/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java @@ -38,7 +38,7 @@ public static void setupClass(@TempDir Path tmpDir) throws IOException, Masterke Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); diff --git a/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java b/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java index dee2dddc..203f600f 100644 --- a/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java +++ b/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java @@ -37,7 +37,7 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); diff --git a/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java index de6ddb9a..9b5e59c6 100644 --- a/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java @@ -63,7 +63,7 @@ public static void setupClass() throws IOException, MasterkeyLoadingFailedExcept Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader.loadKey(Mockito.any())).thenReturn(Masterkey.createFromRaw(new byte[64])); + Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); diff --git a/src/test/java/org/cryptomator/cryptofs/migration/v6/Version6MigratorTest.java b/src/test/java/org/cryptomator/cryptofs/migration/v6/Version6MigratorTest.java index 00df36ef..b099554e 100644 --- a/src/test/java/org/cryptomator/cryptofs/migration/v6/Version6MigratorTest.java +++ b/src/test/java/org/cryptomator/cryptofs/migration/v6/Version6MigratorTest.java @@ -52,7 +52,7 @@ public void testMigrate() throws IOException, CryptoException { String newPassword = Normalizer.normalize("รค", Form.NFC); Assertions.assertNotEquals(oldPassword, newPassword); - Masterkey masterkey = Masterkey.createNew(csprng); + Masterkey masterkey = Masterkey.generate(csprng); MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess(new byte[0], csprng); masterkeyFileAccess.persist(masterkey, masterkeyFile, oldPassword, 5); byte[] beforeMigration = Files.readAllBytes(masterkeyFile); diff --git a/src/test/java/org/cryptomator/cryptofs/migration/v7/Version7MigratorTest.java b/src/test/java/org/cryptomator/cryptofs/migration/v7/Version7MigratorTest.java index ec776e0d..63b8ce50 100644 --- a/src/test/java/org/cryptomator/cryptofs/migration/v7/Version7MigratorTest.java +++ b/src/test/java/org/cryptomator/cryptofs/migration/v7/Version7MigratorTest.java @@ -41,7 +41,7 @@ public void setup() throws IOException { Files.createDirectory(dataDir); Files.createDirectory(metaDir); - Masterkey masterkey = Masterkey.createNew(csprng); + Masterkey masterkey = Masterkey.generate(csprng); MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess(new byte[0], csprng); masterkeyFileAccess.persist(masterkey, masterkeyFile, "test", 6); } diff --git a/src/test/java/org/cryptomator/cryptofs/migration/v8/Version8MigratorTest.java b/src/test/java/org/cryptomator/cryptofs/migration/v8/Version8MigratorTest.java index f754e672..716e5bfa 100644 --- a/src/test/java/org/cryptomator/cryptofs/migration/v8/Version8MigratorTest.java +++ b/src/test/java/org/cryptomator/cryptofs/migration/v8/Version8MigratorTest.java @@ -48,7 +48,7 @@ public void teardown() throws IOException { @Test public void testMigrate() throws CryptoException, IOException { - Masterkey masterkey = Masterkey.createNew(csprng); + Masterkey masterkey = Masterkey.generate(csprng); MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess(new byte[0], csprng); masterkeyFileAccess.persist(masterkey, masterkeyFile, "topsecret", 7); Assumptions.assumeFalse(Files.exists(vaultConfigFile));