Skip to content

Commit 4730d93

Browse files
committed
First ideas for uvf imple.
1 parent 2cd498e commit 4730d93

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
/**
7777
* Cryptomator vault implementation
7878
*/
79+
// UVF: Keep this as façade for detecting vault version and delegating to implementation
80+
// - upon create, the vault version is determined from preferences -> set the delegate impl
81+
// - upon unlock, the vault version needs to be determined by reading masterkey.cryptomator or (!) vault.uvf file -> set the delegate impl
82+
// - open is called either from create or unlock, hence at this point we can delegate calls to the v6/v7/uvf imple?
7983
public class CryptoVault implements Vault {
8084
private static final Logger log = LogManager.getLogger(CryptoVault.class);
8185

@@ -114,13 +118,16 @@ public class CryptoVault implements Vault {
114118
private final byte[] pepper;
115119

116120
public CryptoVault(final Path home) {
121+
// readVaultConfigdo we need to try multiple file names for dection "masterkey.cryptomator" and "vault.uvf"?
117122
this(home, DefaultVaultRegistry.DEFAULT_MASTERKEY_FILE_NAME, DEFAULT_VAULTCONFIG_FILE_NAME, VAULT_PEPPER);
118123
}
119124

120125
public CryptoVault(final Path home, final String masterkey, final String config, final byte[] pepper) {
121126
this.home = home;
122127
this.masterkey = new Path(home, masterkey, EnumSet.of(Path.Type.file, Path.Type.vault));
123128
this.config = new Path(home, config, EnumSet.of(Path.Type.file, Path.Type.vault));
129+
130+
// UVF: no pepper for uvf
124131
this.pepper = pepper;
125132
// New vault home with vault flag set for internal use
126133
final EnumSet<Path.Type> type = EnumSet.copyOf(home.getType());
@@ -133,10 +140,13 @@ public CryptoVault(final Path home, final String masterkey, final String config,
133140
}
134141
}
135142

143+
// UVF: VaultCredentials must come with specification of recipient, see the recipient header in https://github.com/encryption-alliance/unified-vault-format/tree/develop/vault%20metadata#example-per-recipient-unprotected-header
144+
// UVF: version string instead of int?
136145
public synchronized Path create(final Session<?> session, final VaultCredentials credentials, final int version) throws BackgroundException {
137146
return this.create(session, null, credentials, version);
138147
}
139148

149+
// UVF: Switch on version -> CryptoVaultImple: one for v6/v7 and one for uvf
140150
public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final int version) throws BackgroundException {
141151
final Host bookmark = session.getHost();
142152
if(credentials.isSaved()) {
@@ -219,6 +229,7 @@ public synchronized CryptoVault load(final Session<?> session, final PasswordCal
219229
return this.unlock(session, prompt, bookmark, passphrase);
220230
}
221231

232+
// UVF: VaultConfig v6/v7 only
222233
private VaultConfig readVaultConfig(final Session<?> session) throws BackgroundException {
223234
try {
224235
final String token = new ContentReader(session).read(config);
@@ -235,7 +246,7 @@ private VaultConfig readVaultConfig(final Session<?> session) throws BackgroundE
235246
}
236247
}
237248

238-
249+
// UVF: v6/v7 specific
239250
public static VaultConfig parseVaultConfigFromJWT(final String token) {
240251
final DecodedJWT decoded = JWT.decode(token);
241252
return new VaultConfig(
@@ -245,6 +256,8 @@ public static VaultConfig parseVaultConfigFromJWT(final String token) {
245256
decoded.getAlgorithm(), decoded);
246257
}
247258

259+
// UVF: v6/v7 and vault.uvf are different - can we use the new MasterKey interface from https://github.com/cryptomator/cryptolib/pull/51/files?
260+
// called from readVaultConfig() only which is v6/v7 only... good for us!
248261
private MasterkeyFile readMasterkeyFile(final Session<?> session, final Path masterkey) throws BackgroundException {
249262
log.debug("Read master key {}", masterkey);
250263
try (Reader reader = new ContentReader(session).getReader(masterkey)) {
@@ -256,13 +269,15 @@ private MasterkeyFile readMasterkeyFile(final Session<?> session, final Path mas
256269
}
257270

258271
public CryptoVault unlock(final Session<?> session, final PasswordCallback prompt, final Host bookmark, final String passphrase) throws BackgroundException {
272+
// UVF: we need to detect the version here, vault.uvf is different from VaultConfig
259273
final VaultConfig vaultConfig = this.readVaultConfig(session);
260274
this.unlock(vaultConfig, passphrase, bookmark, prompt,
261275
MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName())
262276
);
263277
return this;
264278
}
265279

280+
// UVF: extract to v6/v7 and uvf imple
266281
public void unlock(final VaultConfig vaultConfig, final String passphrase, final Host bookmark, final PasswordCallback prompt,
267282
final String message) throws BackgroundException {
268283
final Credentials credentials;
@@ -316,6 +331,7 @@ public synchronized void close() {
316331
fileNameCryptor = null;
317332
}
318333

334+
// UVF: at this point, we have done the version detection, we can directly go to a delegate, no switch
319335
protected CryptoFilename createFilenameProvider(final VaultConfig vaultConfig) {
320336
switch(vaultConfig.version) {
321337
case VAULT_VERSION_DEPRECATED:
@@ -334,10 +350,15 @@ protected CryptoDirectory createDirectoryProvider(final VaultConfig vaultConfig)
334350
}
335351
}
336352

353+
// UVF: extract to v6/v7/uvf imple, VaultConfig only for v6/v7
354+
// pro memoria:
355+
// create -> open
356+
// unlock -> open
337357
protected void open(final VaultConfig vaultConfig, final CharSequence passphrase) throws BackgroundException {
338358
this.open(vaultConfig, passphrase, this.createFilenameProvider(vaultConfig), this.createDirectoryProvider(vaultConfig));
339359
}
340360

361+
// UVF: extract to v6/v7/uvf, at this point we know which version
341362
protected void open(final VaultConfig vaultConfig, final CharSequence passphrase,
342363
final CryptoFilename filenameProvider, final CryptoDirectory directoryProvider) throws BackgroundException {
343364
try {
@@ -352,10 +373,12 @@ protected void open(final VaultConfig vaultConfig, final CharSequence passphrase
352373
}
353374
}
354375

376+
// UVF: unused?!
355377
protected void open(final VaultConfig vaultConfig, final Masterkey masterKey) throws BackgroundException {
356378
this.open(vaultConfig, masterKey, this.createFilenameProvider(vaultConfig), this.createDirectoryProvider(vaultConfig));
357379
}
358380

381+
// UVF: extract to v6/v7 imple, can we use the new MasterKey interface from https://github.com/cryptomator/cryptolib/pull/51/files?
359382
protected void open(final VaultConfig vaultConfig, final Masterkey masterKey,
360383
final CryptoFilename filenameProvider, final CryptoDirectory directoryProvider) throws BackgroundException {
361384
this.vaultVersion = vaultConfig.version;
@@ -403,6 +426,7 @@ public Path encrypt(final Session<?> session, final Path file, boolean metadata)
403426
return this.encrypt(session, file, file.attributes().getDirectoryId(), metadata);
404427
}
405428

429+
// UVF: extract to delegate?
406430
public Path encrypt(final Session<?> session, final Path file, final String directoryId, boolean metadata) throws BackgroundException {
407431
final Path encrypted;
408432
if(file.isFile() || metadata) {

0 commit comments

Comments
 (0)