Skip to content

Commit

Permalink
Merge pull request iterate-ch#12843 from iterate-ch/bugfix/MD-15988-d…
Browse files Browse the repository at this point in the history
…elete

Bugfix/md 15988 delete
  • Loading branch information
dkocher authored Feb 2, 2022
2 parents b928e97 + 04b4bf8 commit 8405814
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public Vault find(final Session session, final Path file, final boolean lookup)
if(file.attributes().getVault() != null) {
return listener.load(session, file.attributes().getVault(),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.config.filename"), new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
}
final Path directory = file.getParent();
if(directory.attributes().getVault() != null) {
return listener.load(session, directory.attributes().getVault(),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.config.filename"), new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
}
}
return Vault.DISABLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class DisabledVaultLookupListener implements VaultLookupListener {
private static final Logger log = LogManager.getLogger(DisabledVaultLookupListener.class);

@Override
public Vault load(final Session session, final Path directory, final String masterkey, final byte[] pepper) {
public Vault load(final Session session, final Path directory, final String masterkey, final String config, final byte[] pepper) {
log.warn(String.format("Ignore vault %s", directory));
return Vault.DISABLED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public LoadingVaultLookupListener(final VaultRegistry registry, final PasswordSt
}

@Override
public Vault load(final Session session, final Path directory, final String masterkey, final byte[] pepper) throws VaultUnlockCancelException {
public Vault load(final Session session, final Path directory, final String masterkey, final String config, final byte[] pepper) throws VaultUnlockCancelException {
synchronized(registry) {
if(registry.contains(directory)) {
return registry.find(session, directory);
}
final Vault vault = VaultFactory.get(directory, masterkey, pepper);
final Vault vault = VaultFactory.get(directory, masterkey, config, pepper);
if(log.isInfoEnabled()) {
log.info(String.format("Loading vault %s for session %s", vault, session));
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/ch/cyberduck/core/vault/VaultFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ protected VaultFactory() {
super("factory.vault.class");
}

public static Vault get(final Path directory, final String masterkey, final byte[] pepper) {
return new VaultFactory().create(directory, masterkey, pepper);
public static Vault get(final Path directory, final String masterkey, final String config, final byte[] pepper) {
return new VaultFactory().create(directory, masterkey, config, pepper);
}

private Vault create(final Path directory, final String masterkey, final byte[] pepper) {
private Vault create(final Path directory, final String masterkey, final String config, final byte[] pepper) {
try {
final Constructor<Vault> constructor = ConstructorUtils.getMatchingAccessibleConstructor(clazz,
directory.getClass(), masterkey.getClass(), pepper.getClass());
directory.getClass(), masterkey.getClass(), config.getClass(), pepper.getClass());
if(null == constructor) {
log.warn(String.format("No matching constructor for parameter %s", directory.getClass()));
// Call default constructor for disabled implementations
return clazz.newInstance();
}
return constructor.newInstance(directory, masterkey, pepper);
return constructor.newInstance(directory, masterkey, config, pepper);
}
catch(InstantiationException | InvocationTargetException | IllegalAccessException e) {
log.error(String.format("Failure loading callback class %s. %s", clazz, e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void visit(final AttributedList<Path> list, final int index, final Path f
try {
final Vault vault = listener.load(session, directory,
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.config.filename"), new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
if(vault.equals(Vault.DISABLED)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
import ch.cyberduck.core.features.Vault;

public interface VaultLookupListener {
Vault load(final Session session, Path directory, String masterkey, byte[] pepper) throws VaultUnlockCancelException;
Vault load(final Session session, Path directory, String masterkey, final String config, byte[] pepper) throws VaultUnlockCancelException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public boolean find(final Path file, final ListProgressListener listener) throws
log.info(String.format("Found vault %s", directory));
}
return lookup.load(session, directory,
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8))
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.config.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8))
.getFeature(session, Find.class, proxy)
.find(file, listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public LoadVaultWorker(final VaultLookupListener listener, final Path directory)
public Vault run(final Session<?> session) throws BackgroundException {
return listener.load(session, directory,
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.config.filename"),
new HostPreferences(session.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ public synchronized Path create(final Session<?> session, final VaultCredentials
if(log.isDebugEnabled()) {
log.debug(String.format("Write master key to %s", masterkey));
}
// Create vaultconfig.cryptomator
final Algorithm algorithm = Algorithm.HMAC256(mk.getEncoded());
final String conf = JWT.create()
.withJWTId(new UUIDRandomStringService().random())
.withKeyId(String.format("masterkeyfile:%s", masterkey.getName()))
.withClaim("format", VAULT_VERSION)
.withClaim("cipherCombo", CryptorProvider.Scheme.SIV_CTRMAC.toString())
.withClaim("shorteningThreshold", CryptoFilenameV7Provider.NAME_SHORTENING_THRESHOLD)
.sign(algorithm);
// Obtain non encrypted directory writer
final Directory directory = session._getFeature(Directory.class);
final TransferStatus status = new TransferStatus();
Expand All @@ -164,7 +155,18 @@ public synchronized Path create(final Session<?> session, final VaultCredentials
}
final Path vault = directory.mkdir(home, status);
new ContentWriter(session).write(masterkey, mkArray.toByteArray());
new ContentWriter(session).write(config, conf.getBytes(StandardCharsets.US_ASCII));
if(VAULT_VERSION == version) {
// Create vaultconfig.cryptomator
final Algorithm algorithm = Algorithm.HMAC256(mk.getEncoded());
final String conf = JWT.create()
.withJWTId(new UUIDRandomStringService().random())
.withKeyId(String.format("masterkeyfile:%s", masterkey.getName()))
.withClaim("format", version)
.withClaim("cipherCombo", CryptorProvider.Scheme.SIV_CTRMAC.toString())
.withClaim("shorteningThreshold", CryptoFilenameV7Provider.NAME_SHORTENING_THRESHOLD)
.sign(algorithm);
new ContentWriter(session).write(config, conf.getBytes(StandardCharsets.US_ASCII));
}
this.open(masterkeyFile, passphrase);
final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home);
final Path firstLevel = secondLevel.getParent();
Expand Down Expand Up @@ -520,6 +522,10 @@ public Path getMasterkey() {
return masterkey;
}

public Path getConfig() {
return config;
}

public FileHeaderCryptor getFileHeaderCryptor() {
return cryptor.fileHeaderCryptor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public void delete(final Map<Path, TransferStatus> files, final PasswordCallback
metadata.add(dataRoot);
}
metadata.add(vault.getMasterkey());
if(find.find(vault.getConfig())) {
metadata.add(vault.getConfig());
}
}
metadata.add(f);
proxy.delete(metadata, prompt, callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ public void callback(final Path folder, final String region, final VaultCredenti
background(new WorkerBackgroundAction<>(BrowserController.this, pool,
new CreateVaultWorker(region, passphrase, PasswordStoreFactory.get(), VaultFactory.get(folder,
new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.config.filename"),
new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8))) {
@Override
public void cleanup(final Path vault) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import ch.cyberduck.core.sftp.AbstractSFTPTest;
import ch.cyberduck.core.sftp.SFTPAttributesFinderFeature;
import ch.cyberduck.core.sftp.SFTPDeleteFeature;
import ch.cyberduck.core.sftp.SFTPFindFeature;
import ch.cyberduck.core.sftp.SFTPHomeDirectoryService;
import ch.cyberduck.core.sftp.SFTPListService;
import ch.cyberduck.core.sftp.SFTPWriteFeature;
Expand All @@ -51,8 +52,7 @@
import java.util.Arrays;
import java.util.EnumSet;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

@Category(IntegrationTest.class)
@RunWith(value = Parameterized.class)
Expand All @@ -73,6 +73,10 @@ public void testFindCryptomator() throws Exception {
assertNotNull(attributes);
assertEquals(0L, attributes.getSize());
cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertFalse(new SFTPFindFeature(session).find(vault));
assertFalse(new SFTPFindFeature(session).find(cryptomator.getHome()));
assertFalse(new SFTPFindFeature(session).find(cryptomator.getMasterkey()));
assertFalse(new SFTPFindFeature(session).find(cryptomator.getConfig()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public InnerCreateVaultWorker(BrowserController controller, Path folder, String
String region, String passphrase)
: base(region, new VaultCredentials(passphrase), PasswordStoreFactory.get(), VaultFactory.get(folder,
new HostPreferences(controller.Session.getHost()).getProperty("cryptomator.vault.masterkey.filename"),
new HostPreferences(controller.Session.getHost()).getProperty("cryptomator.vault.config.filename"),
Encoding.UTF8.GetBytes(new HostPreferences(controller.Session.getHost()).getProperty("cryptomator.vault.pepper"))))
{
_controller = controller;
Expand Down

0 comments on commit 8405814

Please sign in to comment.