Skip to content

Commit 97bbd74

Browse files
ylangiscdkocher
authored andcommitted
Fix dirId length for UVF.
1 parent 92d01e7 commit 97bbd74

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/impl/CryptoDirectoryUVFProvider.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
import ch.cyberduck.core.Path;
1919
import ch.cyberduck.core.PathAttributes;
20-
import ch.cyberduck.core.RandomStringService;
2120
import ch.cyberduck.core.Session;
2221
import ch.cyberduck.core.SimplePathPredicate;
23-
import ch.cyberduck.core.UUIDRandomStringService;
2422
import ch.cyberduck.core.cryptomator.AbstractVault;
2523
import ch.cyberduck.core.cryptomator.ContentReader;
2624
import ch.cyberduck.core.cryptomator.CryptoFilename;
2725
import ch.cyberduck.core.cryptomator.CryptorCache;
26+
import ch.cyberduck.core.cryptomator.random.FastSecureRandomProvider;
2827
import ch.cyberduck.core.exception.BackgroundException;
2928
import ch.cyberduck.core.exception.NotfoundException;
3029

@@ -34,7 +33,7 @@
3433

3534
import java.nio.ByteBuffer;
3635
import java.nio.ByteOrder;
37-
import java.nio.charset.StandardCharsets;
36+
import java.security.SecureRandom;
3837
import java.util.EnumSet;
3938

4039
import com.google.common.io.BaseEncoding;
@@ -45,8 +44,8 @@ public class CryptoDirectoryUVFProvider extends CryptoDirectoryV7Provider {
4544
private final Path home;
4645
private final AbstractVault vault;
4746

48-
private final RandomStringService random
49-
= new UUIDRandomStringService();
47+
private final SecureRandom random
48+
= FastSecureRandomProvider.get().provide();
5049
private final Path dataRoot;
5150
private final CryptorCache filenameCryptor;
5251
private final CryptoFilename filenameProvider;
@@ -150,7 +149,7 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
150149
}
151150
catch(NotfoundException e) {
152151
log.warn("Missing directory ID for folder {}", directory);
153-
return random.random().getBytes(StandardCharsets.US_ASCII);
152+
return this.getOrCreateDirectoryId(session, directory);
154153
}
155154
}
156155

@@ -174,4 +173,14 @@ protected int loadRevision(final Session<?> session, final Path directory) throw
174173
headerBuf.position(4).limit(headerSize);
175174
return headerBuf.order(ByteOrder.BIG_ENDIAN).getInt();
176175
}
176+
177+
@Override
178+
public byte[] createDirectoryId(final Path directory) {
179+
final byte[] dirId = new byte[32];
180+
random.nextBytes(dirId);
181+
//TODO lock?
182+
cache.put(new SimplePathPredicate(directory), dirId);
183+
return dirId;
184+
185+
}
177186
}

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/impl/CryptoDirectoryV6Provider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class CryptoDirectoryV6Provider implements CryptoDirectory {
5656

5757
private final ReadWriteLock lock = new ReentrantReadWriteLock();
5858

59-
private final LRUCache<CacheReference<Path>, byte[]> cache = LRUCache.build(
59+
protected final LRUCache<CacheReference<Path>, byte[]> cache = LRUCache.build(
6060
PreferencesFactory.get().getInteger("cryptomator.cache.size"));
6161

6262
public static final byte[] ROOT_DIR_ID = new byte[0];

0 commit comments

Comments
 (0)