76
76
/**
77
77
* Cryptomator vault implementation
78
78
*/
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?
79
83
public class CryptoVault implements Vault {
80
84
private static final Logger log = LogManager .getLogger (CryptoVault .class );
81
85
@@ -114,13 +118,16 @@ public class CryptoVault implements Vault {
114
118
private final byte [] pepper ;
115
119
116
120
public CryptoVault (final Path home ) {
121
+ // readVaultConfigdo we need to try multiple file names for dection "masterkey.cryptomator" and "vault.uvf"?
117
122
this (home , DefaultVaultRegistry .DEFAULT_MASTERKEY_FILE_NAME , DEFAULT_VAULTCONFIG_FILE_NAME , VAULT_PEPPER );
118
123
}
119
124
120
125
public CryptoVault (final Path home , final String masterkey , final String config , final byte [] pepper ) {
121
126
this .home = home ;
122
127
this .masterkey = new Path (home , masterkey , EnumSet .of (Path .Type .file , Path .Type .vault ));
123
128
this .config = new Path (home , config , EnumSet .of (Path .Type .file , Path .Type .vault ));
129
+
130
+ // UVF: no pepper for uvf
124
131
this .pepper = pepper ;
125
132
// New vault home with vault flag set for internal use
126
133
final EnumSet <Path .Type > type = EnumSet .copyOf (home .getType ());
@@ -133,10 +140,13 @@ public CryptoVault(final Path home, final String masterkey, final String config,
133
140
}
134
141
}
135
142
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?
136
145
public synchronized Path create (final Session <?> session , final VaultCredentials credentials , final int version ) throws BackgroundException {
137
146
return this .create (session , null , credentials , version );
138
147
}
139
148
149
+ // UVF: Switch on version -> CryptoVaultImple: one for v6/v7 and one for uvf
140
150
public synchronized Path create (final Session <?> session , final String region , final VaultCredentials credentials , final int version ) throws BackgroundException {
141
151
final Host bookmark = session .getHost ();
142
152
if (credentials .isSaved ()) {
@@ -219,6 +229,7 @@ public synchronized CryptoVault load(final Session<?> session, final PasswordCal
219
229
return this .unlock (session , prompt , bookmark , passphrase );
220
230
}
221
231
232
+ // UVF: VaultConfig v6/v7 only
222
233
private VaultConfig readVaultConfig (final Session <?> session ) throws BackgroundException {
223
234
try {
224
235
final String token = new ContentReader (session ).read (config );
@@ -235,7 +246,7 @@ private VaultConfig readVaultConfig(final Session<?> session) throws BackgroundE
235
246
}
236
247
}
237
248
238
-
249
+ // UVF: v6/v7 specific
239
250
public static VaultConfig parseVaultConfigFromJWT (final String token ) {
240
251
final DecodedJWT decoded = JWT .decode (token );
241
252
return new VaultConfig (
@@ -245,6 +256,8 @@ public static VaultConfig parseVaultConfigFromJWT(final String token) {
245
256
decoded .getAlgorithm (), decoded );
246
257
}
247
258
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!
248
261
private MasterkeyFile readMasterkeyFile (final Session <?> session , final Path masterkey ) throws BackgroundException {
249
262
log .debug ("Read master key {}" , masterkey );
250
263
try (Reader reader = new ContentReader (session ).getReader (masterkey )) {
@@ -256,13 +269,15 @@ private MasterkeyFile readMasterkeyFile(final Session<?> session, final Path mas
256
269
}
257
270
258
271
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
259
273
final VaultConfig vaultConfig = this .readVaultConfig (session );
260
274
this .unlock (vaultConfig , passphrase , bookmark , prompt ,
261
275
MessageFormat .format (LocaleFactory .localizedString ("Provide your passphrase to unlock the Cryptomator Vault {0}" , "Cryptomator" ), home .getName ())
262
276
);
263
277
return this ;
264
278
}
265
279
280
+ // UVF: extract to v6/v7 and uvf imple
266
281
public void unlock (final VaultConfig vaultConfig , final String passphrase , final Host bookmark , final PasswordCallback prompt ,
267
282
final String message ) throws BackgroundException {
268
283
final Credentials credentials ;
@@ -316,6 +331,7 @@ public synchronized void close() {
316
331
fileNameCryptor = null ;
317
332
}
318
333
334
+ // UVF: at this point, we have done the version detection, we can directly go to a delegate, no switch
319
335
protected CryptoFilename createFilenameProvider (final VaultConfig vaultConfig ) {
320
336
switch (vaultConfig .version ) {
321
337
case VAULT_VERSION_DEPRECATED :
@@ -334,10 +350,15 @@ protected CryptoDirectory createDirectoryProvider(final VaultConfig vaultConfig)
334
350
}
335
351
}
336
352
353
+ // UVF: extract to v6/v7/uvf imple, VaultConfig only for v6/v7
354
+ // pro memoria:
355
+ // create -> open
356
+ // unlock -> open
337
357
protected void open (final VaultConfig vaultConfig , final CharSequence passphrase ) throws BackgroundException {
338
358
this .open (vaultConfig , passphrase , this .createFilenameProvider (vaultConfig ), this .createDirectoryProvider (vaultConfig ));
339
359
}
340
360
361
+ // UVF: extract to v6/v7/uvf, at this point we know which version
341
362
protected void open (final VaultConfig vaultConfig , final CharSequence passphrase ,
342
363
final CryptoFilename filenameProvider , final CryptoDirectory directoryProvider ) throws BackgroundException {
343
364
try {
@@ -352,10 +373,12 @@ protected void open(final VaultConfig vaultConfig, final CharSequence passphrase
352
373
}
353
374
}
354
375
376
+ // UVF: unused?!
355
377
protected void open (final VaultConfig vaultConfig , final Masterkey masterKey ) throws BackgroundException {
356
378
this .open (vaultConfig , masterKey , this .createFilenameProvider (vaultConfig ), this .createDirectoryProvider (vaultConfig ));
357
379
}
358
380
381
+ // UVF: extract to v6/v7 imple, can we use the new MasterKey interface from https://github.com/cryptomator/cryptolib/pull/51/files?
359
382
protected void open (final VaultConfig vaultConfig , final Masterkey masterKey ,
360
383
final CryptoFilename filenameProvider , final CryptoDirectory directoryProvider ) throws BackgroundException {
361
384
this .vaultVersion = vaultConfig .version ;
@@ -403,6 +426,7 @@ public Path encrypt(final Session<?> session, final Path file, boolean metadata)
403
426
return this .encrypt (session , file , file .attributes ().getDirectoryId (), metadata );
404
427
}
405
428
429
+ // UVF: extract to delegate?
406
430
public Path encrypt (final Session <?> session , final Path file , final String directoryId , boolean metadata ) throws BackgroundException {
407
431
final Path encrypted ;
408
432
if (file .isFile () || metadata ) {
0 commit comments