Skip to content

Commit

Permalink
Merge branch 'release/1.9.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Mar 25, 2020
2 parents 3accfd2 + b635d5c commit 35d483b
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
- secure: "LT4nMSKCu4qL+jQ80BdBIOqFO3GCyAPoxNkskS0q0wvscDpEx2bvFZa9KF6/dQxubhWnfACqWxxPKfF3VadfZoKn1z01TaZ/rKHkA5GedZweFO0wBIvi/gDIcAxVX0oPOkIruugYY3iDOzOqTUuBM686cW1XWs0LEV7qPTb6KM02/IeckQs+P9SSiarqSKROlQ8dABGdyxJTXheHHphFu4mDiQsi1vtub6OoQclKLLuK2MJvFiyDeZDYYXAnjFNC/pcBUBjr5b886zPB6HLLGgvQKRLvzQudedz08ZlJdnt3k6u7HvLINbs00U60fnD/+4krQQN4EEx0Natv4L1SxFjYO4wFK2FTCKoBMkVfjINqiWzmb/yhoG33Sw9VGiYdcV45QbH32CX1oiATohV+79gfIID6p3UOL1SZuELR2XzRq70K4Kw2BXig99a0+LjYCv4ynnzetqyWVZIdhBQ1Srf/4GxUwF21Urn9TJCNr2F5BcbqGrMUMvXNjTI0WqQCTMqM+Ha9Rbe27GG7ZMtMUHd83YWP0GDiSIg2S0T0lNL2e9iQGXsGBiX3Bz+E3HEWhnE4l6XKYVgn3NXrlDjwc2B6GTGeImZXkrbFFJwQihUSujj5H6l/+5a7NxbyA1MvzNwjeTaHzdNdYovTq6ywydVtF/Kt5h7oA2KmUoajaFs=" # CODACY_PROJECT_TOKEN
- secure: "atP4OKMKBLaixI1BiypWRxdQ1DJKpUcxQStwJpXteaZuXdkTMx31ts9WGhwwWJCjDaPJJRmWqhxTNKxJLThWFWLmBso1gHm8KDoHWBGM5jS1ua8Ly7s72HCpa7z+ABZ1/2LsoUXfQGLGDIPs1EdL/2E8OlaPSFUDFwgyquEIEm0hcKOO9q9MxjXwj8EO8OsfGt3PjiWEsh+JRaK5+hRPPVbG7TXidG84C/2cndzNSnin57LUSNkKDPoysRrQipGZQSLm12MpBagcota2HDdiuDXLHJLauNllCsr/NLnurGhwqeV3zVjPlN6z5TbZhbWvni+a8jVO9tMR3zCPs2MR++rJqXoQ4Gviy9yHQFc/RnVtCIRfCHhmh3XyhEM/Z5c1zEjhyZD1eGzr625/1F/RJLJEi0jb0kihKBpEKRgGw/ppt9BkdWQ4xJsMI8H9IQ5ZfzvRhLMXhbLDwqfyfyr3fX8pWg8T9lajEcDwnWMrYerAIF67lyQBjl3c3cGcGn909FTPGjum2PFSY7MuFfmbzzi41Y9ekssiRun4XrgNu563VtIywwuy/35N4ub1+oXS0I2PCG5XBY5uvxZbL8niqmoKiFFeyIhkMdGcbvIqA7PLapPqY5NxkY4+gRSP/eOMzMCnJv/No1ZaDV/8PW4/Q5IRxehVIIX/sXPiOvDSR58=" # BINTRAY_API_KEY
install:
- curl -o $HOME/.m2/settings.xml https://gist.githubusercontent.com/cryptobot/cf5fbd909c4782aaeeeb7c7f4a1a43da/raw/e60ee486e34ee0c79f89f947abe2c83b4290c6bb/settings.xml
- curl -o $HOME/.m2/settings.xml https://gist.githubusercontent.com/cryptobot/cf5fbd909c4782aaeeeb7c7f4a1a43da/raw/fb3fe9a6db00cdac09788285b108a3645193a45b/settings.xml
before_script:
- mvn -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN --update-snapshots dependency-check:check -Pdependency-check
- if [ -n "$TRAVIS_TAG" ]; then mvn versions:set -DnewVersion=${TRAVIS_TAG}; fi
Expand All @@ -22,7 +22,7 @@ script:
mvn clean test jacoco:report verify -Pcoverage
fi
after_success:
- curl -o ~/codacy-coverage-reporter.jar https://oss.sonatype.org/service/local/repositories/releases/content/com/codacy/codacy-coverage-reporter/6.0.7/codacy-coverage-reporter-6.0.7-assembly.jar
- curl -o ~/codacy-coverage-reporter.jar https://repo1.maven.org/maven2/com/codacy/codacy-coverage-reporter/7.1.0/codacy-coverage-reporter-7.1.0.jar
- $JAVA_HOME/bin/java -jar ~/codacy-coverage-reporter.jar report -l Java -r target/site/jacoco/jacoco.xml
cache:
directories:
Expand Down
14 changes: 7 additions & 7 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>1.9.3</version>
<version>1.9.4</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 @@ -15,12 +15,12 @@

<properties>
<cryptolib.version>1.3.0</cryptolib.version>
<dagger.version>2.26</dagger.version>
<dagger.version>2.27</dagger.version>
<guava.version>28.2-jre</guava.version>
<slf4j.version>1.7.30</slf4j.version>

<junit.jupiter.version>5.6.0</junit.jupiter.version>
<mockito.version>3.2.4</mockito.version>
<junit.jupiter.version>5.6.1</junit.jupiter.version>
<mockito.version>3.3.3</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -158,7 +158,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>5.2.4</version>
<version>5.3.1</version>
<configuration>
<cveValidForHours>24</cveValidForHours>
<failBuildOnCVSS>0</failBuildOnCVSS>
Expand Down Expand Up @@ -229,7 +229,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -275,7 +275,7 @@
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
<executions>
<execution>
<id>generate-dependency-list</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import dagger.Module;
import dagger.Provides;
import org.cryptomator.cryptofs.attr.AttributeComponent;
import org.cryptomator.cryptofs.attr.AttributeViewComponent;
import org.cryptomator.cryptofs.common.Constants;
import org.cryptomator.cryptofs.common.MasterkeyBackupFileHasher;
Expand All @@ -23,7 +24,7 @@

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

@Module(subcomponents = {AttributeViewComponent.class, OpenCryptoFileComponent.class, DirectoryStreamComponent.class})
@Module(subcomponents = {AttributeComponent.class, AttributeViewComponent.class, OpenCryptoFileComponent.class, DirectoryStreamComponent.class})
class CryptoFileSystemModule {

@Provides
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/Symlinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ private void assertIsSymlink(CryptoPath cleartextPath, Path ciphertextSymlinkFil
}
}

/**
* Gets the target of a symlink. Recursive, if the target is a symlink itself.
* @param cleartextPath A cleartext path. Might be a symlink, otherwise this method is no-op.
* @return The resolved cleartext path. Might be the same as <code>cleartextPath</code> if it wasn't a symlink in the first place.
* @throws IOException
*/
public CryptoPath resolveRecursively(CryptoPath cleartextPath) throws IOException {
return resolveRecursively(new HashSet<>(), cleartextPath);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cryptomator.cryptofs.attr;

import dagger.BindsInstance;
import dagger.Subcomponent;
import org.cryptomator.cryptofs.common.CiphertextFileType;

import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Optional;

@AttributeScoped
@Subcomponent(modules = {AttributeModule.class})
public interface AttributeComponent {

Optional<BasicFileAttributes> attributes();

@Subcomponent.Builder
interface Builder {

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

@BindsInstance
Builder ciphertextPath(Path ciphertextPath);

@BindsInstance
Builder ciphertextFileType(CiphertextFileType ciphertextFileType);

@BindsInstance
Builder ciphertextAttributes(BasicFileAttributes ciphertextAttributes);

AttributeComponent build();
}
}
77 changes: 77 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/attr/AttributeModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.cryptomator.cryptofs.attr;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ClassKey;
import dagger.multibindings.IntoMap;
import org.cryptomator.cryptofs.fh.OpenCryptoFile;
import org.cryptomator.cryptofs.fh.OpenCryptoFiles;

import javax.inject.Provider;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.util.Map;
import java.util.Optional;

@Module
abstract class AttributeModule {

@Provides
@AttributeScoped
public static Optional<OpenCryptoFile> provideOpenCryptoFile(OpenCryptoFiles openCryptoFiles, Path ciphertextPath) {
return openCryptoFiles.get(ciphertextPath);
}

@Provides
@AttributeScoped
public static PosixFileAttributes providePosixFileAttributes(BasicFileAttributes ciphertextAttributes) {
if (ciphertextAttributes instanceof PosixFileAttributes) {
return (PosixFileAttributes) ciphertextAttributes;
} else {
throw new IllegalStateException("Attempted to inject instance of type " + ciphertextAttributes.getClass() + " but expected PosixFileAttributes.");
}
}

@Provides
@AttributeScoped
public static DosFileAttributes provideDosFileAttributes(BasicFileAttributes ciphertextAttributes) {
if (ciphertextAttributes instanceof DosFileAttributes) {
return (DosFileAttributes) ciphertextAttributes;
} else {
throw new IllegalStateException("Attempted to inject instance of type " + ciphertextAttributes.getClass() + " but expected DosFileAttributes.");
}
}

@Binds
@IntoMap
@ClassKey(BasicFileAttributes.class)
@AttributeScoped
public abstract BasicFileAttributes bindCryptoBasicFileAttributes(CryptoBasicFileAttributes view);

@Binds
@IntoMap
@ClassKey(PosixFileAttributes.class)
@AttributeScoped
public abstract BasicFileAttributes bindCryptoPosixFileAttributes(CryptoPosixFileAttributes view);

@Binds
@IntoMap
@ClassKey(DosFileAttributes.class)
@AttributeScoped
public abstract BasicFileAttributes bindCryptoDosFileAttributes(CryptoDosFileAttributes view);

@Provides
@AttributeScoped
public static Optional<BasicFileAttributes> provideAttributes(Map<Class<?>, Provider<BasicFileAttributes>> providers, Class<? extends BasicFileAttributes> requestedType) {
Provider<BasicFileAttributes> provider = providers.get(requestedType);
if (provider == null) {
return Optional.empty();
} else {
return Optional.of(provider.get());
}
}

}
92 changes: 33 additions & 59 deletions src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,68 @@
*******************************************************************************/
package org.cryptomator.cryptofs.attr;

import org.cryptomator.cryptofs.common.ArrayUtils;
import org.cryptomator.cryptofs.common.CiphertextFileType;
import org.cryptomator.cryptofs.CryptoFileSystemProperties;
import org.cryptomator.cryptofs.CryptoFileSystemScoped;
import org.cryptomator.cryptofs.CryptoPath;
import org.cryptomator.cryptofs.CryptoPathMapper;
import org.cryptomator.cryptofs.fh.OpenCryptoFiles;
import org.cryptomator.cryptofs.CryptoFileSystemScoped;
import org.cryptomator.cryptofs.Symlinks;
import org.cryptomator.cryptofs.fh.OpenCryptoFile;
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptofs.common.ArrayUtils;
import org.cryptomator.cryptofs.common.CiphertextFileType;

import javax.inject.Inject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@CryptoFileSystemScoped
public class AttributeProvider {

private static final Map<Class<? extends BasicFileAttributes>, AttributesConstructor<? extends BasicFileAttributes>> ATTR_CONSTRUCTORS;

static {
ATTR_CONSTRUCTORS = new HashMap<>();
ATTR_CONSTRUCTORS.put(BasicFileAttributes.class, (AttributesConstructor<BasicFileAttributes>) CryptoBasicFileAttributes::new);
ATTR_CONSTRUCTORS.put(PosixFileAttributes.class, (AttributesConstructor<PosixFileAttributes>) CryptoPosixFileAttributes::new);
ATTR_CONSTRUCTORS.put(DosFileAttributes.class, (AttributesConstructor<DosFileAttributes>) CryptoDosFileAttributes::new);
}

private final Cryptor cryptor;
private final AttributeComponent.Builder attributeComponentBuilder;
private final CryptoPathMapper pathMapper;
private final OpenCryptoFiles openCryptoFiles;
private final CryptoFileSystemProperties fileSystemProperties;
private final Symlinks symlinks;

@Inject
AttributeProvider(Cryptor cryptor, CryptoPathMapper pathMapper, OpenCryptoFiles openCryptoFiles, CryptoFileSystemProperties fileSystemProperties, Symlinks symlinks) {
this.cryptor = cryptor;
AttributeProvider(AttributeComponent.Builder attributeComponentBuilder, CryptoPathMapper pathMapper, Symlinks symlinks) {
this.attributeComponentBuilder = attributeComponentBuilder;
this.pathMapper = pathMapper;
this.openCryptoFiles = openCryptoFiles;
this.fileSystemProperties = fileSystemProperties;
this.symlinks = symlinks;
}

public <A extends BasicFileAttributes> A readAttributes(CryptoPath cleartextPath, Class<A> type, LinkOption... options) throws IOException {
if (!ATTR_CONSTRUCTORS.containsKey(type)) {
throw new UnsupportedOperationException("Unsupported file attribute type: " + type);
}
CiphertextFileType ciphertextFileType = pathMapper.getCiphertextFileType(cleartextPath);
switch (ciphertextFileType) {
case SYMLINK: {
if (ArrayUtils.contains(options, LinkOption.NOFOLLOW_LINKS)) {
Path ciphertextPath = pathMapper.getCiphertextFilePath(cleartextPath).getSymlinkFilePath();
return readAttributes(ciphertextFileType, ciphertextPath, type);
} else {
CryptoPath resolved = symlinks.resolveRecursively(cleartextPath);
return readAttributes(resolved, type, options);
}
}
case DIRECTORY: {
Path ciphertextPath = pathMapper.getCiphertextDir(cleartextPath).path;
return readAttributes(ciphertextFileType, ciphertextPath, type);
}
case FILE: {
Path ciphertextPath = pathMapper.getCiphertextFilePath(cleartextPath).getFilePath();
return readAttributes(ciphertextFileType, ciphertextPath, type);
}
default:
throw new UnsupportedOperationException("Unhandled node type " + ciphertextFileType);
if (ciphertextFileType == CiphertextFileType.SYMLINK && !ArrayUtils.contains(options, LinkOption.NOFOLLOW_LINKS)) {
cleartextPath = symlinks.resolveRecursively(cleartextPath);
ciphertextFileType = pathMapper.getCiphertextFileType(cleartextPath);
}
}

private <A extends BasicFileAttributes> A readAttributes(CiphertextFileType ciphertextFileType, Path ciphertextPath, Class<A> type) throws IOException {
assert ATTR_CONSTRUCTORS.containsKey(type);
Path ciphertextPath = getCiphertextPath(cleartextPath, ciphertextFileType);
A ciphertextAttrs = Files.readAttributes(ciphertextPath, type);
AttributesConstructor<A> constructor = (AttributesConstructor<A>) ATTR_CONSTRUCTORS.get(type);
return constructor.construct(ciphertextAttrs, ciphertextFileType, ciphertextPath, cryptor, openCryptoFiles.get(ciphertextPath), fileSystemProperties.readonly());
Optional<BasicFileAttributes> cleartextAttrs = attributeComponentBuilder //
.type(type) //
.ciphertextFileType(ciphertextFileType) //
.ciphertextPath(ciphertextPath) //
.ciphertextAttributes(ciphertextAttrs) //
.build() //
.attributes();
if (cleartextAttrs.isPresent() && type.isInstance(cleartextAttrs.get())) {
return type.cast(cleartextAttrs.get());
} else {
throw new UnsupportedOperationException("Unsupported file attribute type: " + type);
}
}

@FunctionalInterface
private interface AttributesConstructor<A extends BasicFileAttributes> {
A construct(A delegate, CiphertextFileType ciphertextFileType, Path ciphertextPath, Cryptor cryptor, Optional<OpenCryptoFile> openCryptoFile, boolean readonlyFileSystem);
private Path getCiphertextPath(CryptoPath path, CiphertextFileType type) throws IOException {
switch (type) {
case SYMLINK:
return pathMapper.getCiphertextFilePath(path).getSymlinkFilePath();
case DIRECTORY:
return pathMapper.getCiphertextDir(path).path;
case FILE:
return pathMapper.getCiphertextFilePath(path).getFilePath();
default:
throw new UnsupportedOperationException("Unhandled node type " + type);
}
}

}
14 changes: 14 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/attr/AttributeScoped.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cryptomator.cryptofs.attr;

import javax.inject.Scope;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Scope
@Documented
@Retention(RUNTIME)
@interface AttributeScoped {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Scope
@Documented
@Retention(RUNTIME)
public @interface AttributeViewScoped {
@interface AttributeViewScoped {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.Optional;

@AttributeScoped
class CryptoBasicFileAttributes implements BasicFileAttributes {

private static final Logger LOG = LoggerFactory.getLogger(CryptoBasicFileAttributes.class);
Expand All @@ -32,7 +34,8 @@ class CryptoBasicFileAttributes implements BasicFileAttributes {
private final FileTime creationTime;
private final Object fileKey;

public CryptoBasicFileAttributes(BasicFileAttributes delegate, CiphertextFileType ciphertextFileType, Path ciphertextPath, Cryptor cryptor, Optional<OpenCryptoFile> openCryptoFile, @SuppressWarnings("unused") boolean readonlyFileSystem) {
@Inject
public CryptoBasicFileAttributes(BasicFileAttributes delegate, CiphertextFileType ciphertextFileType, Path ciphertextPath, Cryptor cryptor, Optional<OpenCryptoFile> openCryptoFile) {
this.ciphertextFileType = ciphertextFileType;
switch (ciphertextFileType) {
case SYMLINK:
Expand Down
Loading

0 comments on commit 35d483b

Please sign in to comment.