Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit a6ecef1

Browse files
fail fast if encountering a shorteningThreshold other than MAXINT
because c9s support is not currently implemented
1 parent 412cd82 commit a6ecef1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/org/cryptomator/cloudaccess/CloudAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private static void verifyVaultFormat8GCMConfig(CloudProvider cloudProvider, Clo
7575
var verifier = JWT.require(algorithm)
7676
.withClaim("format", 8)
7777
.withClaim("cipherCombo", "SIV_GCM")
78+
.withClaim("shorteningThreshold", Integer.MAX_VALUE) // no shortening supported atm
7879
.build();
7980

8081
var read = cloudProvider.read(vaultConfigPath, ProgressListener.NO_PROGRESS_AWARE);

src/test/java/org/cryptomator/cloudaccess/vaultformat8/VaultFormat8IntegrationTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void testInstantiateFormat8GCMCloudAccessWithWrongVaultVersion() {
9797
.withJWTId(UUID.randomUUID().toString())
9898
.withClaim("format", 9)
9999
.withClaim("cipherCombo", "SIV_GCM")
100+
.withClaim("shorteningThreshold", Integer.MAX_VALUE)
100101
.sign(algorithm);
101102
var in = new ByteArrayInputStream(token.getBytes(StandardCharsets.US_ASCII));
102103
localProvider.write(CloudPath.of("/vaultconfig.jwt"), false, in, in.available(), Optional.empty(), ProgressListener.NO_PROGRESS_AWARE).toCompletableFuture().join();
@@ -115,6 +116,7 @@ public void testInstantiateFormat8GCMCloudAccessWithWrongCiphermode() {
115116
.withJWTId(UUID.randomUUID().toString())
116117
.withClaim("format", 8)
117118
.withClaim("cipherCombo", "FOO")
119+
.withClaim("shorteningThreshold", Integer.MAX_VALUE)
118120
.sign(algorithm);
119121
var in = new ByteArrayInputStream(token.getBytes(StandardCharsets.US_ASCII));
120122
localProvider.write(CloudPath.of("/vaultconfig.jwt"), false, in, in.available(), Optional.empty(), ProgressListener.NO_PROGRESS_AWARE).toCompletableFuture().join();
@@ -133,12 +135,32 @@ public void testInstantiateFormat8GCMCloudAccessWithWrongKey() {
133135
var token = JWT.create()
134136
.withJWTId(UUID.randomUUID().toString())
135137
.withClaim("format", 8)
136-
.withClaim("cipherCombo", "FOO")
138+
.withClaim("cipherCombo", "SIV_GCM")
139+
.withClaim("shorteningThreshold", Integer.MAX_VALUE)
137140
.sign(algorithm);
138141
var in = new ByteArrayInputStream(token.getBytes(StandardCharsets.US_ASCII));
139142
localProvider.write(CloudPath.of("/vaultconfig.jwt"), false, in, in.available(), Optional.empty(), ProgressListener.NO_PROGRESS_AWARE).toCompletableFuture().join();
140143

141144
Assertions.assertThrows(VaultKeyVerificationFailedException.class, () -> CloudAccess.vaultFormat8GCMCloudAccess(localProvider, CloudPath.of("/"), new byte[64]));
142145
}
143146

147+
@Test
148+
@DisplayName("init with shorteningThreshold")
149+
public void testInstantiateFormat8GCMCloudAccessWithShortening() {
150+
Assumptions.assumeFalse(localProvider.exists(CloudPath.of("/vaultconfig.jwt")).toCompletableFuture().join());
151+
152+
byte[] masterkey = new byte[64];
153+
Algorithm algorithm = Algorithm.HMAC256(masterkey);
154+
var token = JWT.create()
155+
.withJWTId(UUID.randomUUID().toString())
156+
.withClaim("format", 8)
157+
.withClaim("cipherCombo", "SIV_GCM")
158+
.withClaim("shorteningThreshold", 42)
159+
.sign(algorithm);
160+
var in = new ByteArrayInputStream(token.getBytes(StandardCharsets.US_ASCII));
161+
localProvider.write(CloudPath.of("/vaultconfig.jwt"), false, in, in.available(), Optional.empty(), ProgressListener.NO_PROGRESS_AWARE).toCompletableFuture().join();
162+
163+
Assertions.assertThrows(VaultVerificationFailedException.class, () -> CloudAccess.vaultFormat8GCMCloudAccess(localProvider, CloudPath.of("/"), new byte[64]));
164+
}
165+
144166
}

0 commit comments

Comments
 (0)