Skip to content

Commit 949f1d9

Browse files
ylangiscdkocher
authored andcommitted
Hide directoryId.
1 parent 75b7986 commit 949f1d9

File tree

12 files changed

+81
-67
lines changed

12 files changed

+81
-67
lines changed

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/AbstractVault.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,11 @@ public long toCiphertextSize(final long cleartextFileOffset, final long cleartex
122122

123123
@Override
124124
public Path encrypt(Session<?> session, Path file) throws BackgroundException {
125-
return this.encrypt(session, file, file.attributes().getDirectoryId(), false);
125+
return this.encrypt(session, file, false);
126126
}
127127

128128
@Override
129129
public Path encrypt(Session<?> session, Path file, boolean metadata) throws BackgroundException {
130-
return this.encrypt(session, file, file.attributes().getDirectoryId(), metadata);
131-
}
132-
133-
public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean metadata) throws BackgroundException {
134130
final Path encrypted;
135131
if(file.isFile() || metadata) {
136132
if(file.getType().contains(Path.Type.vault)) {
@@ -145,12 +141,12 @@ public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean m
145141
final String filename;
146142
if(file.getType().contains(Path.Type.encrypted)) {
147143
final Path decrypted = file.attributes().getDecrypted();
148-
parent = this.getDirectoryProvider().toEncrypted(session, decrypted.getParent().attributes().getDirectoryId(), decrypted.getParent());
149-
filename = this.getDirectoryProvider().toEncrypted(session, parent.attributes().getDirectoryId(), decrypted.getName(), decrypted.getType());
144+
parent = this.getDirectoryProvider().toEncrypted(session, decrypted.getParent());
145+
filename = this.getDirectoryProvider().toEncrypted(session, decrypted.getParent(), decrypted.getName(), decrypted.getType());
150146
}
151147
else {
152-
parent = this.getDirectoryProvider().toEncrypted(session, file.getParent().attributes().getDirectoryId(), file.getParent());
153-
filename = this.getDirectoryProvider().toEncrypted(session, parent.attributes().getDirectoryId(), file.getName(), file.getType());
148+
parent = this.getDirectoryProvider().toEncrypted(session, file.getParent());
149+
filename = this.getDirectoryProvider().toEncrypted(session, file.getParent(), file.getName(), file.getType());
154150
}
155151
final PathAttributes attributes = new PathAttributes(file.attributes());
156152
attributes.setDirectoryId(null);
@@ -176,9 +172,9 @@ public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean m
176172
return file;
177173
}
178174
if(file.getType().contains(Path.Type.vault)) {
179-
return this.getDirectoryProvider().toEncrypted(session, this.getHome().attributes().getDirectoryId(), this.getHome());
175+
return this.getDirectoryProvider().toEncrypted(session, this.getHome());
180176
}
181-
encrypted = this.getDirectoryProvider().toEncrypted(session, directoryId, file);
177+
encrypted = this.getDirectoryProvider().toEncrypted(session, file);
182178
}
183179
// Add reference to decrypted file
184180
if(!file.getType().contains(Path.Type.encrypted)) {
@@ -208,7 +204,7 @@ public Path decrypt(final Session<?> session, final Path file) throws Background
208204
try {
209205
final String cleartextFilename = this.getFileNameCryptor().decryptFilename(
210206
this.getVersion() == VAULT_VERSION_DEPRECATED ? BaseEncoding.base32() : BaseEncoding.base64Url(),
211-
ciphertext, file.getParent().attributes().getDirectoryId());
207+
ciphertext, this.getDirectoryProvider().getOrCreateDirectoryId(session, file.getParent()));
212208
final PathAttributes attributes = new PathAttributes(file.attributes());
213209
if(this.isDirectory(inflated)) {
214210
if(Permission.EMPTY != attributes.getPermission()) {

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/CryptoDirectory.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,29 @@ public interface CryptoDirectory {
2727
* Get encrypted filename for given clear text filename with id of parent encrypted directory.
2828
*
2929
* @param session Connection
30-
* @param directoryId Parent folder directory id
30+
* @param parent Parent folder
3131
* @param filename Clear text filename
3232
* @param type File type
3333
* @return Encrypted filename
3434
*/
35-
String toEncrypted(Session<?> session, byte[] directoryId, String filename, EnumSet<Path.Type> type) throws BackgroundException;
35+
String toEncrypted(Session<?> session, Path parent, String filename, EnumSet<Path.Type> type) throws BackgroundException;
3636

3737
/**
3838
* Get encrypted reference for clear text directory path.
3939
*
40-
* @param session Connection
41-
* @param directoryId Directory ID or null to read directory id from metadata file
42-
* @param directory Clear text
40+
* @param session Connection
41+
* @param directory Clear text
4342
*/
44-
Path toEncrypted(Session<?> session, byte[] directoryId, Path directory) throws BackgroundException;
43+
Path toEncrypted(Session<?> session, Path directory) throws BackgroundException;
4544

4645
/**
4746
* Remove from cache
4847
*/
4948
void delete(Path directory);
5049

5150
void destroy();
51+
52+
byte[] getOrCreateDirectoryId(Session<?> session, Path directory) throws BackgroundException;
53+
54+
byte[] createDirectoryId(final Path directory);
5255
}

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/CryptoVault.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public synchronized Path create(final Session<?> session, final String region, f
198198
this.open(new VaultConfig(version, CryptoFilenameV6Provider.DEFAULT_NAME_SHORTENING_THRESHOLD,
199199
CryptorProvider.Scheme.SIV_CTRMAC, null, null).withMasterkeyFile(masterkeyFile), passphrase);
200200
}
201-
final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home);
201+
final Path secondLevel = directoryProvider.toEncrypted(session, home);
202202
final Path firstLevel = secondLevel.getParent();
203203
final Path dataDir = firstLevel.getParent();
204204
log.debug("Create vault root directory at {}", secondLevel);

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/UVFVault.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Path decrypt(final Session<?> session, final Path file) throws Background
131131
// \
132132
final String cleartextFilename = effectivefileNameCryptor.decryptFilename(
133133
this.getVersion() == VAULT_VERSION_DEPRECATED ? BaseEncoding.base32() : BaseEncoding.base64Url(),
134-
ciphertext, file.getParent().attributes().getDirectoryId());
134+
ciphertext, directoryProvider.getOrCreateDirectoryId(session, file.getParent()));
135135
final PathAttributes attributes = new PathAttributes(file.attributes());
136136
if(this.isDirectory(inflated)) {
137137
if(Permission.EMPTY != attributes.getPermission()) {
@@ -176,7 +176,8 @@ public Path decrypt(final Session<?> session, final Path file) throws Background
176176
}
177177
}
178178

179-
public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean metadata) throws BackgroundException {
179+
@Override
180+
public Path encrypt(Session<?> session, Path file, boolean metadata) throws BackgroundException {
180181
final Path encrypted;
181182
if(file.isFile() || metadata) {
182183
if(file.getType().contains(Path.Type.vault)) {
@@ -191,18 +192,17 @@ public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean m
191192
final String filename;
192193
if(file.getType().contains(Path.Type.encrypted)) {
193194
final Path decrypted = file.attributes().getDecrypted();
194-
parent = this.getDirectoryProvider().toEncrypted(session, decrypted.getParent().attributes().getDirectoryId(), decrypted.getParent());
195-
filename = this.getDirectoryProvider().toEncrypted(session, parent.attributes().getDirectoryId(), decrypted.getName(), decrypted.getType());
195+
parent = this.getDirectoryProvider().toEncrypted(session, decrypted.getParent());
196+
filename = this.getDirectoryProvider().toEncrypted(session, parent, decrypted.getName(), decrypted.getType());
196197
}
197198
else {
198-
parent = this.getDirectoryProvider().toEncrypted(session, file.getParent().attributes().getDirectoryId(), file.getParent());
199+
parent = this.getDirectoryProvider().toEncrypted(session, file.getParent());
199200
// / diff to AbstractVault.encrypt
200-
String filenameO = this.getDirectoryProvider().toEncrypted(session, parent.attributes().getDirectoryId(), file.getName(), file.getType());
201+
String filenameO = this.getDirectoryProvider().toEncrypted(session, parent, file.getName(), file.getType());
201202
filename = ((CryptoDirectoryUVFProvider) this.getDirectoryProvider()).toEncrypted(session, file.getParent(), file.getName());
202203
// \ diff to AbstractVault.decrypt
203204
}
204205
final PathAttributes attributes = new PathAttributes(file.attributes());
205-
attributes.setDirectoryId(null);
206206
if(!file.isFile() && !metadata) {
207207
// The directory is different from the metadata file used to resolve the actual folder
208208
attributes.setVersionId(null);
@@ -225,9 +225,9 @@ public Path encrypt(Session<?> session, Path file, byte[] directoryId, boolean m
225225
return file;
226226
}
227227
if(file.getType().contains(Path.Type.vault)) {
228-
return this.getDirectoryProvider().toEncrypted(session, this.getHome().attributes().getDirectoryId(), this.getHome());
228+
return this.getDirectoryProvider().toEncrypted(session, this.getHome());
229229
}
230-
encrypted = this.getDirectoryProvider().toEncrypted(session, directoryId, file);
230+
encrypted = this.getDirectoryProvider().toEncrypted(session, file);
231231
}
232232
// Add reference to decrypted file
233233
if(!file.getType().contains(Path.Type.encrypted)) {

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoBulkFeature.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import org.cryptomator.cryptolib.api.FileHeader;
3636

37-
import java.nio.charset.StandardCharsets;
3837
import java.util.ArrayList;
3938
import java.util.Comparator;
4039
import java.util.HashMap;
@@ -84,9 +83,7 @@ public int compare(final Map.Entry<TransferItem, TransferStatus> o1, final Map.E
8483
if(!status.isExists()) {
8584
switch(type) {
8685
case upload:
87-
// Preset directory ID for new folders to avert lookup with not found failure in directory ID provider
88-
final byte[] directoryId = random.random().getBytes(StandardCharsets.US_ASCII);
89-
encrypted.put(new TransferItem(cryptomator.encrypt(session, file, directoryId, false), local), status);
86+
encrypted.put(new TransferItem(cryptomator.encrypt(session, file, false), local), status);
9087
break;
9188
default:
9289
encrypted.put(new TransferItem(cryptomator.encrypt(session, file), local), status);

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryV6Feature.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.apache.logging.log4j.Logger;
3333
import org.cryptomator.cryptolib.api.FileHeader;
3434

35-
import java.nio.charset.StandardCharsets;
36-
3735
public class CryptoDirectoryV6Feature<Reply> implements Directory<Reply> {
3836
private static final Logger log = LogManager.getLogger(CryptoDirectoryV6Feature.class);
3937

@@ -53,8 +51,8 @@ public CryptoDirectoryV6Feature(final Session<?> session, final Directory<Reply>
5351

5452
@Override
5553
public Path mkdir(final Path folder, final TransferStatus status) throws BackgroundException {
56-
final Path encrypt = vault.encrypt(session, folder, random.random().getBytes(StandardCharsets.US_ASCII), false);
57-
final byte[] directoryId = encrypt.attributes().getDirectoryId();
54+
final byte[] directoryId = vault.getDirectoryProvider().createDirectoryId(folder);
55+
final Path encrypt = vault.encrypt(session, folder, false);
5856
// Create metadata file for directory
5957
final Path directoryMetadataFile = vault.encrypt(session, folder, true);
6058
log.debug("Write metadata {} for folder {}", directoryMetadataFile, folder);

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryV7Feature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.logging.log4j.Logger;
3333
import org.cryptomator.cryptolib.api.FileHeader;
3434

35-
import java.nio.charset.StandardCharsets;
3635
import java.util.EnumSet;
3736

3837
public class CryptoDirectoryV7Feature<Reply> implements Directory<Reply> {
@@ -54,8 +53,8 @@ public CryptoDirectoryV7Feature(final Session<?> session, final Directory<Reply>
5453

5554
@Override
5655
public Path mkdir(final Path folder, final TransferStatus status) throws BackgroundException {
57-
final Path encrypt = vault.encrypt(session, folder, random.random().getBytes(StandardCharsets.US_ASCII), false);
58-
final byte[] directoryId = encrypt.attributes().getDirectoryId();
56+
final byte[] directoryId = vault.getDirectoryProvider().createDirectoryId(folder);
57+
final Path encrypt = vault.encrypt(session, folder, false);
5958
// Create metadata file for directory
6059
final Path directoryMetadataFolder = session._getFeature(Directory.class).mkdir(vault.encrypt(session, folder, true),
6160
new TransferStatus().setRegion(status.getRegion()));

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.cryptomator.cryptolib.api.FileHeader;
3434

3535
import java.nio.ByteBuffer;
36-
import java.nio.ByteOrder;
3736
import java.nio.charset.StandardCharsets;
3837
import java.util.EnumSet;
3938

@@ -83,7 +82,7 @@ public String toEncrypted(final Session<?> session, final Path parent, final Str
8382
}
8483

8584
@Override
86-
public Path toEncrypted(final Session<?> session, final byte[] directoryId, final Path directory) throws BackgroundException {
85+
public Path toEncrypted(final Session<?> session, final Path directory) throws BackgroundException {
8786
if(!directory.isDirectory()) {
8887
throw new NotfoundException(directory.getAbsolute());
8988
}
@@ -93,7 +92,7 @@ public Path toEncrypted(final Session<?> session, final byte[] directoryId, fina
9392
attributes.setVersionId(null);
9493
attributes.setFileId(null);
9594
// Remember random directory id for use in vault
96-
final byte[] id = this.toDirectoryId(session, directory, directoryId);
95+
final byte[] id = this.getOrCreateDirectoryId(session, directory);
9796
log.debug("Use directory ID '{}' for folder {}", id, directory);
9897
attributes.setDirectoryId(id);
9998
attributes.setDecrypted(directory);
@@ -120,9 +119,9 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
120119
if(new SimplePathPredicate(home).test(directory)) {
121120
return vault.getRootDirId();
122121
}
123-
final Path parent = this.toEncrypted(session, directory.getParent().attributes().getDirectoryId(), directory.getParent());
122+
final Path parent = this.toEncrypted(session, directory.getParent());
124123
final String cleartextName = directory.getName();
125-
final String ciphertextName = this.toEncrypted(session, parent.attributes().getDirectoryId(), cleartextName, EnumSet.of(Path.Type.directory));
124+
final String ciphertextName = this.toEncrypted(session, parent, cleartextName, EnumSet.of(Path.Type.directory));
126125
final Path metadataParent = new Path(parent, ciphertextName, EnumSet.of(Path.Type.directory));
127126
// Read directory id from file
128127
try {
@@ -155,6 +154,9 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
155154
}
156155

157156
protected int loadRevision(final Session<?> session, final Path directory) throws BackgroundException {
157+
//TODO
158+
159+
/*
158160
final Path parent = this.toEncrypted(session, directory.getParent().attributes().getDirectoryId(), directory.getParent());
159161
final String cleartextName = directory.getName();
160162
final String ciphertextName = this.toEncrypted(session, parent.attributes().getDirectoryId(), cleartextName, EnumSet.of(Path.Type.directory));
@@ -172,6 +174,7 @@ protected int loadRevision(final Session<?> session, final Path directory) throw
172174
ByteBuffer buffer = ByteBuffer.wrap(ciphertext);
173175
ByteBuffer headerBuf = buffer.duplicate();
174176
headerBuf.position(4).limit(headerSize);
175-
return headerBuf.order(ByteOrder.BIG_ENDIAN).getInt();
177+
return headerBuf.order(ByteOrder.BIG_ENDIAN).getInt();*/
178+
return 0;
176179
}
177180
}

0 commit comments

Comments
 (0)