Skip to content

Commit 6f92a4c

Browse files
committed
Merge branch 'release/2.3.0'
2 parents 51bdba5 + 41eda8c commit 6f92a4c

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.cryptomator</groupId>
44
<artifactId>cryptofs</artifactId>
5-
<version>2.2.0</version>
5+
<version>2.3.0</version>
66
<name>Cryptomator Crypto Filesystem</name>
77
<description>This library provides the Java filesystem provider used by Cryptomator.</description>
88
<url>https://github.com/cryptomator/cryptofs</url>
@@ -18,7 +18,7 @@
1818
<maven.compiler.release>17</maven.compiler.release>
1919

2020
<!-- dependencies -->
21-
<cryptolib.version>2.0.2</cryptolib.version>
21+
<cryptolib.version>2.0.3</cryptolib.version>
2222
<jwt.version>3.18.1</jwt.version>
2323
<dagger.version>2.37</dagger.version>
2424
<guava.version>30.1.1-jre</guava.version>
@@ -295,7 +295,7 @@
295295
<repository>
296296
<id>ossrh</id>
297297
<name>Maven Central</name>
298-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
298+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
299299
</repository>
300300
</distributionManagement>
301301
<build>
@@ -307,7 +307,7 @@
307307
<extensions>true</extensions>
308308
<configuration>
309309
<serverId>ossrh</serverId>
310-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
310+
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
311311
<autoReleaseAfterClose>true</autoReleaseAfterClose>
312312
</configuration>
313313
</plugin>

src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cryptomator.cryptofs;
22

3+
import org.cryptomator.cryptofs.common.BackupHelper;
34
import org.cryptomator.cryptofs.common.Constants;
45
import org.cryptomator.cryptofs.common.FileSystemCapabilityChecker;
56
import org.cryptomator.cryptolib.api.Cryptor;
@@ -51,6 +52,7 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT
5152
var keyId = configLoader.getKeyId();
5253
try (Masterkey key = properties.keyLoader().loadKey(keyId)) {
5354
var config = configLoader.verify(key.getEncoded(), Constants.VAULT_VERSION);
55+
backupVaultConfigFile(normalizedPathToVault, properties);
5456
var adjustedProperties = adjustForCapabilities(pathToVault, properties);
5557
var cryptor = CryptorProvider.forScheme(config.getCipherCombo()).provide(key.copy(), csprng);
5658
try {
@@ -71,6 +73,7 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT
7173

7274
/**
7375
* Checks if the vault has a content root folder. If not, an exception is raised.
76+
*
7477
* @param pathToVault Path to the vault root
7578
* @param cryptor Cryptor object initialized with the correct masterkey
7679
* @throws ContentRootMissingException If the existence of encrypted vault content root cannot be ensured
@@ -119,6 +122,18 @@ private String readVaultConfigFile(Path pathToVault, CryptoFileSystemProperties
119122
}
120123
}
121124

125+
/**
126+
* Attempts to create a backup of the vault config or compares to an existing one.
127+
*
128+
* @param pathToVault path to the vault's root
129+
* @param properties properties used when attempting to construct a fs for this vault
130+
* @throws IOException If the config cannot be read
131+
*/
132+
private void backupVaultConfigFile(Path pathToVault, CryptoFileSystemProperties properties) throws IOException {
133+
Path vaultConfigFile = pathToVault.resolve(properties.vaultConfigFilename());
134+
BackupHelper.attemptBackup(vaultConfigFile);
135+
}
136+
122137
private CryptoFileSystemProperties adjustForCapabilities(Path pathToVault, CryptoFileSystemProperties originalProperties) throws FileSystemCapabilityChecker.MissingCapabilityException {
123138
if (!originalProperties.readonly()) {
124139
try {

src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cryptomator.cryptofs;
22

3+
import org.cryptomator.cryptofs.common.BackupHelper;
34
import org.cryptomator.cryptofs.common.Constants;
45
import org.cryptomator.cryptofs.common.FileSystemCapabilityChecker;
56
import org.cryptomator.cryptolib.api.Cryptor;
@@ -36,6 +37,7 @@ public class CryptoFileSystemsTest {
3637
private final Path pathToVault = mock(Path.class, "vaultPath");
3738
private final Path normalizedPathToVault = mock(Path.class, "normalizedVaultPath");
3839
private final Path configFilePath = mock(Path.class, "normalizedVaultPath/vault.cryptomator");
40+
private final Path configFileBackupPath = mock(Path.class, "normalizedVaultPath/vault.cryptomator.12345678.bkup");
3941
private final Path dataDirPath = mock(Path.class, "normalizedVaultPath/d");
4042
private final Path preContenRootPath = mock(Path.class, "normalizedVaultPath/d/AB");
4143
private final Path contenRootPath = mock(Path.class, "normalizedVaultPath/d/AB/CDEFGHIJKLMNOP");
@@ -61,6 +63,7 @@ public class CryptoFileSystemsTest {
6163
private MockedStatic<VaultConfig> vaultConficClass;
6264
private MockedStatic<Files> filesClass;
6365
private MockedStatic<CryptorProvider> cryptorProviderClass;
66+
private MockedStatic<BackupHelper> backupHelperClass;
6467

6568
private final CryptoFileSystems inTest = new CryptoFileSystems(cryptoFileSystemComponentBuilder, capabilityChecker, csprng);
6669

@@ -69,6 +72,7 @@ public void setup() throws IOException, MasterkeyLoadingFailedException {
6972
vaultConficClass = Mockito.mockStatic(VaultConfig.class);
7073
filesClass = Mockito.mockStatic(Files.class);
7174
cryptorProviderClass = Mockito.mockStatic(CryptorProvider.class);
75+
backupHelperClass = Mockito.mockStatic(BackupHelper.class);
7276

7377
when(pathToVault.normalize()).thenReturn(normalizedPathToVault);
7478
when(normalizedPathToVault.resolve("vault.cryptomator")).thenReturn(configFilePath);
@@ -77,6 +81,7 @@ public void setup() throws IOException, MasterkeyLoadingFailedException {
7781
filesClass.when(() -> Files.readString(configFilePath, StandardCharsets.US_ASCII)).thenReturn("jwt-vault-config");
7882
vaultConficClass.when(() -> VaultConfig.decode("jwt-vault-config")).thenReturn(configLoader);
7983
cryptorProviderClass.when(() -> CryptorProvider.forScheme(cipherCombo)).thenReturn(cryptorProvider);
84+
backupHelperClass.when(() -> BackupHelper.attemptBackup(configFilePath)).thenReturn(configFileBackupPath);
8085
when(VaultConfig.decode("jwt-vault-config")).thenReturn(configLoader);
8186
when(configLoader.getKeyId()).thenReturn(URI.create("test:key"));
8287
when(keyLoader.loadKey(Mockito.any())).thenReturn(masterkey);
@@ -105,6 +110,7 @@ public void tearDown() {
105110
vaultConficClass.close();
106111
filesClass.close();
107112
cryptorProviderClass.close();
113+
backupHelperClass.close();
108114
}
109115

110116
@Test
@@ -153,6 +159,25 @@ public void testCreateThrowsIOExceptionIfContentRootExistenceCheckFails() {
153159
Assertions.assertThrows(IOException.class, () -> inTest.create(provider, pathToVault, properties));
154160
}
155161

162+
@Test
163+
public void testCreateAttemptsBackupOnSuccessfulVerification() throws IOException {
164+
inTest.create(provider, pathToVault, properties);
165+
backupHelperClass.verify(() -> BackupHelper.attemptBackup(configFilePath));
166+
}
167+
168+
@Test
169+
public void testCreateWithFailedConfigVerificationMakesNoBackup() throws IOException {
170+
when(configLoader.verify(rawKey, Constants.VAULT_VERSION)).thenThrow(VaultKeyInvalidException.class);
171+
Assertions.assertThrows(VaultKeyInvalidException.class, () -> inTest.create(provider, pathToVault, properties));
172+
backupHelperClass.verify(() -> BackupHelper.attemptBackup(configFilePath), Mockito.never());
173+
}
174+
175+
@Test
176+
public void testCreateThrowsIOExceptionIfBackupAttemptThrowsOne() throws IOException {
177+
backupHelperClass.when(() -> BackupHelper.attemptBackup(configFilePath)).thenThrow(new IOException());
178+
Assertions.assertThrows(IOException.class,() -> inTest.create(provider, pathToVault, properties));
179+
}
180+
156181
@Test
157182
public void testGetReturnsFileSystemForPathIfItExists() throws IOException, MasterkeyLoadingFailedException {
158183
CryptoFileSystemImpl fileSystem = inTest.create(provider, pathToVault, properties);

0 commit comments

Comments
 (0)