|
| 1 | +package ch.cyberduck.core.cryptomator; |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (c) 2002-2025 iterate GmbH. All rights reserved. |
| 5 | + * https://cyberduck.io/ |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + */ |
| 17 | + |
| 18 | +import ch.cyberduck.core.PasswordCallback; |
| 19 | +import ch.cyberduck.core.Path; |
| 20 | +import ch.cyberduck.core.PathAttributes; |
| 21 | +import ch.cyberduck.core.Session; |
| 22 | +import ch.cyberduck.core.cryptomator.impl.CryptoDirectoryV7Provider; |
| 23 | +import ch.cyberduck.core.cryptomator.impl.CryptoFilenameV7Provider; |
| 24 | +import ch.cyberduck.core.cryptomator.random.FastSecureRandomProvider; |
| 25 | +import ch.cyberduck.core.exception.BackgroundException; |
| 26 | +import ch.cyberduck.core.features.Vault; |
| 27 | +import ch.cyberduck.core.vault.VaultCredentials; |
| 28 | + |
| 29 | +import org.apache.logging.log4j.LogManager; |
| 30 | +import org.apache.logging.log4j.Logger; |
| 31 | +import org.cryptomator.cryptolib.api.Cryptor; |
| 32 | +import org.cryptomator.cryptolib.api.CryptorProvider; |
| 33 | +import org.cryptomator.cryptolib.api.UVFMasterkey; |
| 34 | + |
| 35 | +import java.util.EnumSet; |
| 36 | + |
| 37 | +public class UVFVault implements Vault { |
| 38 | + |
| 39 | + private static final Logger log = LogManager.getLogger(UVFVault.class); |
| 40 | + |
| 41 | + /** |
| 42 | + * Root of vault directory |
| 43 | + */ |
| 44 | + private final Path home; |
| 45 | + private final Path vault; |
| 46 | + |
| 47 | + private final String decrypted; |
| 48 | + private Cryptor cryptor; |
| 49 | + private CryptorCache fileNameCryptor; |
| 50 | + private CryptoFilename filenameProvider; |
| 51 | + private CryptoDirectory directoryProvider; |
| 52 | + |
| 53 | + public UVFVault(final Path home, final String decryptedPayload) { |
| 54 | + this.home = home; |
| 55 | + this.decrypted = decryptedPayload; |
| 56 | + // New vault home with vault flag set for internal use |
| 57 | + final EnumSet<Path.Type> type = EnumSet.copyOf(home.getType()); |
| 58 | + type.add(Path.Type.vault); |
| 59 | + if(home.isRoot()) { |
| 60 | + this.vault = new Path(home.getAbsolute(), type, new PathAttributes(home.attributes())); |
| 61 | + } |
| 62 | + else { |
| 63 | + this.vault = new Path(home.getParent(), home.getName(), type, new PathAttributes(home.attributes())); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Path create(final Session<?> session, final String region, final VaultCredentials credentials) throws BackgroundException { |
| 69 | + return null; |
| 70 | + } |
| 71 | + |
| 72 | + // load -> unlock -> open |
| 73 | + @Override |
| 74 | + public UVFVault load(final Session<?> session, final PasswordCallback prompt) throws BackgroundException { |
| 75 | + UVFMasterkey masterKey = UVFMasterkey.fromDecryptedPayload(this.decrypted); |
| 76 | + |
| 77 | + final CryptorProvider provider = CryptorProvider.forScheme(CryptorProvider.Scheme.UVF_DRAFT); |
| 78 | + log.debug("Initialized crypto provider {}", provider); |
| 79 | + this.cryptor = provider.provide(masterKey, FastSecureRandomProvider.get().provide()); |
| 80 | + this.fileNameCryptor = new CryptorCache(cryptor.fileNameCryptor()); |
| 81 | + this.filenameProvider = new CryptoFilenameV7Provider(/* TODO threshold was previously defined in vault.config - default now? */); |
| 82 | + this.directoryProvider = new CryptoDirectoryV7Provider(vault, filenameProvider, fileNameCryptor); |
| 83 | + //TODO where? this.nonceSize = vaultConfig.getNonceSize(); |
| 84 | + return this; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void close() { |
| 89 | + |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public boolean contains(final Path file) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public Path encrypt(final Session<?> session, final Path file) throws BackgroundException { |
| 99 | + return null; |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public Path encrypt(final Session<?> session, final Path file, final boolean metadata) throws BackgroundException { |
| 104 | + return null; |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public Path decrypt(final Session<?> session, final Path file) throws BackgroundException { |
| 109 | + return null; |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public long toCiphertextSize(final long cleartextFileOffset, final long cleartextFileSize) { |
| 114 | + return 0; |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public long toCleartextSize(final long cleartextFileOffset, final long ciphertextFileSize) throws BackgroundException { |
| 119 | + return 0; |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public <T> T getFeature(final Session<?> session, final Class<T> type, final T delegate) { |
| 124 | + return null; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public State getState() { |
| 129 | + return null; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public Path getHome() { |
| 134 | + return null; |
| 135 | + } |
| 136 | +} |
0 commit comments