Skip to content

Commit

Permalink
Merge branch 'release/1.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
markuskreusch committed Nov 10, 2017
2 parents 96beb1c + 7557e57 commit f7b6fee
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 80 deletions.
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/7248ca7d466843f785f79f33374302c2)](https://www.codacy.com/app/cryptomator/cryptofs?utm_source=github.com&utm_medium=referral&utm_content=cryptomator/cryptofs&utm_campaign=Badge_Coverage)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/10006/badge.svg)](https://scan.coverity.com/projects/cryptomator-cryptofs)

**CryptoFS** - Implementation of the [Cryptomator](https://github.com/cryptomator/cryptomator) encryption scheme.

## Disclaimer

This project is in an early stage and not ready for production use. We recommend to use it only for testing and evaluation purposes.
**CryptoFS:** Implementation of the [Cryptomator](https://github.com/cryptomator/cryptomator) encryption scheme.

## Features

- Access Cryptomator encrypted vaults from within your Java application
- Uses a ``java.nio.file.FileSystem`` so code written against the java.nio.file API can easily be adapted to work with encrypted data
- Uses a `java.nio.file.FileSystem` so code written against the `java.nio.file` API can easily be adapted to work with encrypted data
- Open Source means: No backdoors, control is better than trust

### Security Architecture

For more information on the security details visit [cryptomator.org](https://cryptomator.org/architecture/).
For more information on the security details, visit [cryptomator.org](https://cryptomator.org/architecture/).

## Usage

CryptoFS depends on a Java 8 JRE/JDK. In addition the JCE unlimited strength policy files (needed for 256-bit keys) must be installed.
CryptoFS depends on Java 8 JRE/JDK. In addition, the JCE unlimited strength policy files (needed for 256-bit keys) must be installed.

### Vault initialization
### Vault Initialization

```java
Path storageLocation = Paths.get("/home/cryptobot/vault");
Files.createDirectories(storageLocation);
CryptoFileSystemProvider.initialize(storageLocation, "masterkey.cryptomator", "password");
```

### Obtaining a FileSystem instance
### Obtaining a FileSystem Instance

You have the option to use the convenience method ``CryptoFileSystemProvider#newFileSystem`` as follows:
You have the option to use the convenience method `CryptoFileSystemProvider#newFileSystem` as follows:

```java
FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(
Expand All @@ -46,7 +42,7 @@ FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(
.build());
```

or to use one of the standard methods from ``FileSystems#newFileSystem``:
or to use one of the standard methods from `FileSystems#newFileSystem`:

```java
URI uri = CryptoFileSystemUri.create(storageLocation);
Expand All @@ -58,11 +54,11 @@ FileSystem fileSystem = FileSystems.newFileSystem(
.build());
```

**Note** - Instead of CryptoFileSystemProperties you can always pass in a ``java.util.Map`` with entries set accordingly.
**Note:** Instead of `CryptoFileSystemProperties`, you can always pass in a `java.util.Map` with entries set accordingly.

For more details on construction have a look at the javadoc of ``CryptoFileSytemProvider``, ``CryptoFileSytemProperties`` and ``CryptoFileSytemUris``.
For more details on construction, have a look at the javadoc of `CryptoFileSytemProvider`, `CryptoFileSytemProperties`, and `CryptoFileSytemUris`.

### Using the constructed file system
### Using the Constructed FileSystem

```java
try (FileSystem fileSystem = ...) { // see above
Expand All @@ -84,7 +80,7 @@ try (FileSystem fileSystem = ...) { // see above
}
```

For more details on how to use the constructed file system you may consult the [javadocs of the java.nio.file package](http://docs.oracle.com/javase/8/docs/api/java/nio/file/package-summary.html).
For more details on how to use the constructed `FileSystem`, you may consult the [javadocs of the `java.nio.file` package](http://docs.oracle.com/javase/8/docs/api/java/nio/file/package-summary.html).

## Building

Expand All @@ -101,12 +97,12 @@ mvn clean install

## Contributing to CryptoFS

Please read our [contribution guide](https://github.com/cryptomator/cryptomator/blob/master/CONTRIBUTING.md), if you would like to report a bug, ask a question or help us with coding.
Please read our [contribution guide](https://github.com/cryptomator/cryptomator/blob/master/CONTRIBUTING.md) if you would like to report a bug, ask a question, or help us with coding.

## Code of Conduct

Help us keep Cryptomator open and inclusive. Please read and follow our [Code of Conduct](https://github.com/cryptomator/cryptomator/blob/master/CODE_OF_CONDUCT.md).

## License

Distributed under the AGPLv3. See the `LICENSE.txt` file for more info.
This project is dual-licensed under the AGPLv3 for FOSS projects as well as a commercial license derived from the LGPL for independent software vendors and resellers. If you want to use this library in applications that are *not* licensed under the AGPL, feel free to contact our [sales team](https://cryptomator.org/enterprise/).
18 changes: 9 additions & 9 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.4.2</version>
<version>1.4.3</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,9 +15,9 @@

<properties>
<java.version>1.8</java.version>
<cryptolib.version>1.1.6</cryptolib.version>
<dagger.version>2.11</dagger.version>
<guava.version>23.0</guava.version>
<cryptolib.version>1.1.7</cryptolib.version>
<dagger.version>2.13</dagger.version>
<guava.version>23.4-jre</guava.version>
<slf4j.version>1.7.25</slf4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -102,7 +102,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.8.47</version>
<version>2.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -137,7 +137,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand All @@ -162,7 +162,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>2.1.0</version>
<version>3.0.1</version>
<configuration>
<cveValidForHours>24</cveValidForHours>
<failBuildOnCVSS>0</failBuildOnCVSS>
Expand All @@ -185,7 +185,7 @@
<dependency>
<groupId>com.codacy</groupId>
<artifactId>codacy-coverage-reporter</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<classifier>assembly</classifier>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -276,7 +276,7 @@
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<executions>
<execution>
<id>generate-dependency-list</id>
Expand Down
118 changes: 118 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/CiphertextDirectoryDeleter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.cryptomator.cryptofs;

import static java.nio.file.FileVisitResult.CONTINUE;
import static java.util.stream.Collectors.toSet;
import static org.cryptomator.cryptofs.CiphertextDirectoryDeleter.DeleteResult.NO_FILES_DELETED;
import static org.cryptomator.cryptofs.CiphertextDirectoryDeleter.DeleteResult.SOME_FILES_DELETED;

import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Set;

import javax.inject.Inject;

@PerFileSystem
class CiphertextDirectoryDeleter {

private final DirectoryStreamFactory directoryStreamFactory;

@Inject
public CiphertextDirectoryDeleter(DirectoryStreamFactory directoryStreamFactory) {
this.directoryStreamFactory = directoryStreamFactory;
}

public void deleteCiphertextDirIncludingNonCiphertextFiles(Path ciphertextDir, CryptoPath cleartextDir) throws IOException {
try {
Files.deleteIfExists(ciphertextDir);
} catch (DirectoryNotEmptyException e) {
switch (deleteNonCiphertextFiles(ciphertextDir, cleartextDir)) {
case NO_FILES_DELETED:
throw e;
case SOME_FILES_DELETED:
Files.delete(ciphertextDir);
break;
default:
throw new IllegalStateException("Unexpected enum constant");
}
}
}

private DeleteResult deleteNonCiphertextFiles(Path ciphertextDir, CryptoPath cleartextDir) throws IOException {
NonCiphertextFilesDeletingFileVisitor visitor;
try (CryptoDirectoryStream directoryStream = directoryStreamFactory.newDirectoryStream(cleartextDir, ignored -> true)) {
Set<Path> ciphertextFiles = directoryStream.ciphertextDirectoryListing().collect(toSet());
visitor = new NonCiphertextFilesDeletingFileVisitor(ciphertextFiles);
}
Files.walkFileTree(ciphertextDir, visitor);
return visitor.getNumDeleted() == 0 //
? NO_FILES_DELETED //
: SOME_FILES_DELETED;
}

static enum DeleteResult {
NO_FILES_DELETED, SOME_FILES_DELETED
}

private static class NonCiphertextFilesDeletingFileVisitor implements FileVisitor<Path> {

private final Set<Path> ciphertextFiles;

private int numDeleted = 0;
private int level = 0;

public NonCiphertextFilesDeletingFileVisitor(Set<Path> ciphertextFiles) {
this.ciphertextFiles = ciphertextFiles;
}

public int getNumDeleted() {
return numDeleted;
}

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
level++;
return CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!isOnRootLevel() || !isCiphertextFile(file)) {
Files.delete(file);
numDeleted++;
}
return CONTINUE;
}

private boolean isOnRootLevel() {
return level == 1;
}

private boolean isCiphertextFile(Path file) throws IOException {
return ciphertextFiles.contains(file);
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
throw exc;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null) {
throw exc;
}
level--;
if (level > 0) {
Files.delete(dir);
numDeleted++;
}
return CONTINUE;
}
};

}
Loading

0 comments on commit f7b6fee

Please sign in to comment.