Skip to content

Commit

Permalink
Merge branch 'release/2.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Mar 15, 2023
2 parents ec170e7 + fe1dbd5 commit 470bcb5
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 256 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>cryptofs</artifactId>
<version>2.6.1</version>
<version>2.6.2</version>
<name>Cryptomator Crypto Filesystem</name>
<description>This library provides the Java filesystem provider used by Cryptomator.</description>
<url>https://github.com/cryptomator/cryptofs</url>
Expand All @@ -18,8 +18,8 @@
<maven.compiler.release>17</maven.compiler.release>

<!-- dependencies -->
<cryptolib.version>2.1.0</cryptolib.version>
<jwt.version>4.2.1</jwt.version>
<cryptolib.version>2.1.2</cryptolib.version>
<jwt.version>4.3.0</jwt.version>
<dagger.version>2.44.2</dagger.version>
<guava.version>31.1-jre</guava.version>
<slf4j.version>2.0.3</slf4j.version>
Expand All @@ -30,7 +30,7 @@
<hamcrest.version>2.2</hamcrest.version>

<!-- build plugin dependencies -->
<dependency-check.version>7.3.2</dependency-check.version>
<dependency-check.version>8.1.2</dependency-check.version>
<jacoco.version>0.8.8</jacoco.version>
<nexus-staging.version>1.6.13</nexus-staging.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ public interface CryptoFileSystemComponent {

CryptoFileSystemImpl cryptoFileSystem();

@Subcomponent.Builder
interface Builder {

@BindsInstance
Builder cryptor(Cryptor cryptor);

@BindsInstance
Builder vaultConfig(VaultConfig vaultConfig);

@BindsInstance
Builder provider(CryptoFileSystemProvider provider);

@BindsInstance
Builder pathToVault(@PathToVault Path pathToVault);

@BindsInstance
Builder properties(CryptoFileSystemProperties cryptoFileSystemProperties);

CryptoFileSystemComponent build();
@Subcomponent.Factory
interface Factory {
CryptoFileSystemComponent create(@BindsInstance Cryptor cryptor, //
@BindsInstance VaultConfig vaultConfig, //
@BindsInstance CryptoFileSystemProvider provider, //
@BindsInstance @PathToVault Path pathToVault, //
@BindsInstance CryptoFileSystemProperties cryptoFileSystemProperties);
}

}
20 changes: 4 additions & 16 deletions src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class CryptoFileSystems {
private static final Logger LOG = LoggerFactory.getLogger(CryptoFileSystems.class);

private final ConcurrentMap<Path, CryptoFileSystemImpl> fileSystems = new ConcurrentHashMap<>();
private final CryptoFileSystemComponent.Builder cryptoFileSystemComponentBuilder; // sharing reusable builder via synchronized
private final CryptoFileSystemComponent.Factory cryptoFileSystemComponentFactory;
private final FileSystemCapabilityChecker capabilityChecker;
private final SecureRandom csprng;

@Inject
public CryptoFileSystems(CryptoFileSystemComponent.Builder cryptoFileSystemComponentBuilder, FileSystemCapabilityChecker capabilityChecker, SecureRandom csprng) {
this.cryptoFileSystemComponentBuilder = cryptoFileSystemComponentBuilder;
public CryptoFileSystems(CryptoFileSystemComponent.Factory cryptoFileSystemComponentFactory, FileSystemCapabilityChecker capabilityChecker, SecureRandom csprng) {
this.cryptoFileSystemComponentFactory = cryptoFileSystemComponentFactory;
this.capabilityChecker = capabilityChecker;
this.csprng = csprng;
}
Expand All @@ -59,7 +59,7 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT
checkVaultRootExistence(pathToVault, cryptor);
return fileSystems.compute(normalizedPathToVault, (path, fs) -> {
if (fs == null) {
return create(provider, normalizedPathToVault, adjustedProperties, cryptor, config);
return cryptoFileSystemComponentFactory.create(cryptor, config, provider, normalizedPathToVault, adjustedProperties).cryptoFileSystem();
} else {
throw new FileSystemAlreadyExistsException();
}
Expand All @@ -86,18 +86,6 @@ private void checkVaultRootExistence(Path pathToVault, Cryptor cryptor) throws C
}
}

// synchronized access to non-threadsafe cryptoFileSystemComponentBuilder required
private synchronized CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathToVault, CryptoFileSystemProperties properties, Cryptor cryptor, VaultConfig config) {
return cryptoFileSystemComponentBuilder //
.cryptor(cryptor) //
.vaultConfig(config) //
.pathToVault(pathToVault) //
.properties(properties) //
.provider(provider) //
.build() //
.cryptoFileSystem();
}

/**
* Attempts to read a vault config file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ default <T extends BasicFileAttributes> T attributes(Class<T> type) {
}
}

@Subcomponent.Builder
interface Builder {
@Subcomponent.Factory
interface Factory {

@BindsInstance
Builder ciphertextPath(Path ciphertextPath);
AttributeComponent create(@BindsInstance Path ciphertextPath, //
@BindsInstance CiphertextFileType ciphertextFileType, //
@BindsInstance @Named("ciphertext") BasicFileAttributes ciphertextAttributes);

@BindsInstance
Builder ciphertextFileType(CiphertextFileType ciphertextFileType);

@BindsInstance
Builder ciphertextAttributes(@Named("ciphertext") BasicFileAttributes ciphertextAttributes);

AttributeComponent build();
}
}
18 changes: 7 additions & 11 deletions src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.cryptomator.cryptofs.common.CiphertextFileType;

import javax.inject.Inject;
import javax.inject.Provider;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
Expand All @@ -26,13 +25,13 @@
@CryptoFileSystemScoped
public class AttributeProvider {

private final Provider<AttributeComponent.Builder> attributeComponentBuilderProvider;
private final AttributeComponent.Factory attributeComponentFactory;
private final CryptoPathMapper pathMapper;
private final Symlinks symlinks;

@Inject
AttributeProvider(Provider<AttributeComponent.Builder> attributeComponentBuilderProvider, CryptoPathMapper pathMapper, Symlinks symlinks) {
this.attributeComponentBuilderProvider = attributeComponentBuilderProvider;
AttributeProvider(AttributeComponent.Factory attributeComponentFactory, CryptoPathMapper pathMapper, Symlinks symlinks) {
this.attributeComponentFactory = attributeComponentFactory;
this.pathMapper = pathMapper;
this.symlinks = symlinks;
}
Expand All @@ -45,13 +44,10 @@ public <A extends BasicFileAttributes> A readAttributes(CryptoPath cleartextPath
}
Path ciphertextPath = getCiphertextPath(cleartextPath, ciphertextFileType);
A ciphertextAttrs = Files.readAttributes(ciphertextPath, type);
AttributeComponent.Builder builder = attributeComponentBuilderProvider.get();
return builder //
.ciphertextFileType(ciphertextFileType) //
.ciphertextPath(ciphertextPath) //
.ciphertextAttributes(ciphertextAttrs) //
.build() //
.attributes(type);
return attributeComponentFactory.create(ciphertextPath, //
ciphertextFileType, //
ciphertextAttrs) //
.attributes(type); //
}

private Path getCiphertextPath(CryptoPath path, CiphertextFileType type) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ public interface AttributeViewComponent {

Optional<FileAttributeView> attributeView();

@Subcomponent.Builder
interface Builder {
@Subcomponent.Factory
interface Factory {

@BindsInstance
Builder cleartextPath(CryptoPath cleartextPath);
AttributeViewComponent create(@BindsInstance CryptoPath cleartextPath, @BindsInstance Class<? extends FileAttributeView> type, @BindsInstance LinkOption[] linkOptions);

@BindsInstance
Builder viewType(Class<? extends FileAttributeView> type);

@BindsInstance
Builder linkOptions(LinkOption[] linkOptions);

AttributeViewComponent build();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Provider;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.attribute.FileAttributeView;
Expand All @@ -25,27 +24,21 @@ public class AttributeViewProvider {

private static final Logger LOG = LoggerFactory.getLogger(AttributeViewProvider.class);

private final Provider<AttributeViewComponent.Builder> attrViewComponentBuilderProvider;
private final AttributeViewComponent.Factory attrViewComponentFactory;

@Inject
AttributeViewProvider(Provider<AttributeViewComponent.Builder> attrViewComponentBuilderProvider) {
this.attrViewComponentBuilderProvider = attrViewComponentBuilderProvider;
AttributeViewProvider(AttributeViewComponent.Factory attrViewComponentFactory) {
this.attrViewComponentFactory = attrViewComponentFactory;
}

/**
* @param cleartextPath the unencrypted path to the file
* @param type the Class object corresponding to the file attribute view
* @param type the Class object corresponding to the file attribute view
* @return a file attribute view of the specified type, or <code>null</code> if the attribute view type is not available
* @see Files#getFileAttributeView(java.nio.file.Path, Class, java.nio.file.LinkOption...)
*/
public <A extends FileAttributeView> A getAttributeView(CryptoPath cleartextPath, Class<A> type, LinkOption... options) {
AttributeViewComponent.Builder builder = attrViewComponentBuilderProvider.get();
Optional<FileAttributeView> view = builder //
.cleartextPath(cleartextPath) //
.viewType(type) //
.linkOptions(options) //
.build() //
.attributeView();
Optional<FileAttributeView> view = attrViewComponentFactory.create(cleartextPath, type, options).attributeView();
if (view.isPresent() && type.isInstance(view.get())) {
return type.cast(view.get());
} else {
Expand Down
27 changes: 8 additions & 19 deletions src/main/java/org/cryptomator/cryptofs/ch/ChannelComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ public interface ChannelComponent {

CleartextFileChannel channel();

@Subcomponent.Builder
interface Builder {

@BindsInstance
Builder openOptions(EffectiveOpenOptions options);

@BindsInstance
Builder onClose(ChannelCloseListener listener);

@BindsInstance
Builder ciphertextChannel(FileChannel ciphertextChannel);

@BindsInstance
Builder mustWriteHeader(@MustWriteHeader boolean mustWriteHeader);

@BindsInstance
Builder fileHeader(FileHeader fileHeader);

ChannelComponent build();
@Subcomponent.Factory
interface Factory {

ChannelComponent create(@BindsInstance FileChannel ciphertextChannel, //
@BindsInstance FileHeader fileHeader, //
@BindsInstance @MustWriteHeader boolean mustWriteHeader, //
@BindsInstance EffectiveOpenOptions options, //
@BindsInstance ChannelCloseListener listener); //
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected boolean isReadable() {
}

@Override
protected int readLocked(ByteBuffer dst, long position) throws IOException {
protected synchronized int readLocked(ByteBuffer dst, long position) throws IOException {
int origLimit = dst.limit();
long limitConsideringEof = fileSize.get() - position;
if (limitConsideringEof < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,14 @@ public interface DirectoryStreamComponent {

CryptoDirectoryStream directoryStream();

@Subcomponent.Builder
interface Builder {

@BindsInstance
Builder cleartextPath(@Named("cleartextPath") Path cleartextPath);

@BindsInstance
Builder dirId(@Named("dirId") String dirId);

@BindsInstance
Builder ciphertextDirectoryStream(DirectoryStream<Path> ciphertextDirectoryStream);

@BindsInstance
Builder filter(DirectoryStream.Filter<? super Path> filter);

@BindsInstance
Builder onClose(Consumer<CryptoDirectoryStream> onClose);

DirectoryStreamComponent build();
@Subcomponent.Factory
interface Factory {

DirectoryStreamComponent create(@BindsInstance @Named("cleartextPath") Path cleartextPath, //
@BindsInstance @Named("dirId") String dirId, //
@BindsInstance DirectoryStream<Path> ciphertextDirectoryStream, //
@BindsInstance DirectoryStream.Filter<? super Path> filter, //
@BindsInstance Consumer<CryptoDirectoryStream> onClose);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@
public class DirectoryStreamFactory {

private final CryptoPathMapper cryptoPathMapper;
private final DirectoryStreamComponent.Builder directoryStreamComponentBuilder; // sharing reusable builder via synchronized
private final DirectoryStreamComponent.Factory directoryStreamComponentFactory;
private final Map<CryptoDirectoryStream, DirectoryStream<Path>> streams = new HashMap<>();

private volatile boolean closed = false;

@Inject
public DirectoryStreamFactory(CryptoPathMapper cryptoPathMapper, DirectoryStreamComponent.Builder directoryStreamComponentBuilder) {
public DirectoryStreamFactory(CryptoPathMapper cryptoPathMapper, DirectoryStreamComponent.Factory directoryStreamComponentFactory) {
this.cryptoPathMapper = cryptoPathMapper;
this.directoryStreamComponentBuilder = directoryStreamComponentBuilder;
this.directoryStreamComponentFactory = directoryStreamComponentFactory;
}

//TODO: is synchronized still needed? One reason was, that a dagger builder was used (replaced by thread safe factory)
public synchronized CryptoDirectoryStream newDirectoryStream(CryptoPath cleartextDir, Filter<? super Path> filter) throws IOException {
if (closed) {
throw new ClosedFileSystemException();
}
CiphertextDirectory ciphertextDir = cryptoPathMapper.getCiphertextDir(cleartextDir);
DirectoryStream<Path> ciphertextDirStream = Files.newDirectoryStream(ciphertextDir.path, this::matchesEncryptedContentPattern);
CryptoDirectoryStream cleartextDirStream = directoryStreamComponentBuilder //
.dirId(ciphertextDir.dirId) //
.ciphertextDirectoryStream(ciphertextDirStream) //
.cleartextPath(cleartextDir) //
.filter(filter) //
.onClose(streams::remove) //
.build() //
.directoryStream();
var cleartextDirStream = directoryStreamComponentFactory.create(cleartextDir, ciphertextDir.dirId, ciphertextDirStream, filter, streams::remove).directoryStream();
streams.put(cleartextDirStream, ciphertextDirStream);
return cleartextDirStream;
}
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.cryptomator.cryptofs.fh;

import org.cryptomator.cryptofs.EffectiveOpenOptions;
import org.cryptomator.cryptofs.ch.ChannelComponent;
import org.cryptomator.cryptofs.ch.CleartextFileChannel;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
Expand Down Expand Up @@ -87,14 +86,9 @@ public synchronized FileChannel newFileChannel(EffectiveOpenOptions options, Fil
isNewHeader = false;
}
initFileSize(ciphertextFileChannel);
ChannelComponent channelComponent = component.newChannelComponent() //
.ciphertextChannel(ciphertextFileChannel) //
.openOptions(options) //
.onClose(this::channelClosed) //
.mustWriteHeader(isNewHeader) //
.fileHeader(header) //
.build();
cleartextFileChannel = channelComponent.channel();
cleartextFileChannel = component.newChannelComponent() //
.create(ciphertextFileChannel, header, isNewHeader, options, this::channelClosed) //
.channel();
} finally {
if (cleartextFileChannel == null) { // i.e. something didn't work
closeQuietly(ciphertextFileChannel);
Expand Down
Loading

0 comments on commit 470bcb5

Please sign in to comment.