Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Schrenk committed May 19, 2020
2 parents 10803cb + 178acf4 commit a11b75c
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 72 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build

on:
[push]

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
outputs:
artifact-version: ${{ steps.setversion.outputs.version }}
env:
BUILD_VERSION: SNAPSHOT
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 14
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Ensure to use tagged version
run: mvn versions:set --file ./pom.xml -DnewVersion=${GITHUB_REF##*/} # use shell parameter expansion to strip of 'refs/tags'
if: startsWith(github.ref, 'refs/tags/')
- name: Export the project version to the job environment and fix it as an ouput of this job
id: setversion
run: |
v=$(mvn help:evaluate "-Dexpression=project.version" -q -DforceStdout)
echo "::set-env name=BUILD_VERSION::${v}"
echo "::set-output name=version::${v}"
- name: Build and Test
run: mvn -B install
- name: Upload snapshot artifact cryptomator-cli-${{ env.BUILD_VERSION }}.jar
uses: actions/upload-artifact@v2
with:
name: cryptomator-cli-${{ env.BUILD_VERSION }}.jar
path: target/cryptomator-cli-*.jar

release:
name: Draft a Release on GitHub Releases and uploads the build artifacts to it
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download cryptomator-cli.jar
uses: actions/download-artifact@v1
with:
name: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
path: .
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: |
:construction: Work in Progress
draft: true
prerelease: false
- name: Upload cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar to GitHub Releases
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
asset_name: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
asset_content_type: application/jar
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ test-output/
out/
.idea_modules/
*.iws

*.iml
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,64 @@
[![Build Status](https://travis-ci.org/cryptomator/cli.svg?branch=develop)](https://travis-ci.org/cryptomator/cli)
[![Build](https://github.com/cryptomator/cli/workflows/Build/badge.svg)](https://github.com/cryptomator/cli/actions?query=workflow%3ABuild)
[![Latest Release](https://img.shields.io/github/release/cryptomator/cli/all.svg)](https://github.com/cryptomator/cli/releases/latest)

# Cryptomator CLI version
# Cryptomator CLI

This is a minimal command line program which unlocks vaults, which can then be accessed via an embedded WebDAV server.
This is a minimal command-line program that unlocks vaults which can then be accessed via an embedded WebDAV server.

## 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.

## Download and Usage

Download the jar file via [GitHub Releases](https://github.com/cryptomator/cli/releases)
Download the jar file via [GitHub Releases](https://github.com/cryptomator/cli/releases).

Cryptomator CLI depends on a Java 8 JRE. In addition the JCE unlimited strength policy files (needed for 256-bit keys) must be installed.
Cryptomator CLI requires that at least JDK 11 is present on your system.

```sh
java -jar cryptomator-cli-x.y.z.jar \
--vault demoVault=/path/to/vault --password demoVault=topSecret \
--vault otherVault=/path/to/differentVault --passwordfile otherVault=/path/to/fileWithPassword \
--bind 0.0.0.0 --port 8080
--bind 127.0.0.1 --port 8080
# you can now mount http://localhost:8080/demoVault/
```

Then you can access the vault using any WebDAV client.

### Linux via davfs2

First, you need to create a mount point for your vault

```sh
sudo mkdir /media/your/mounted/folder
```

Then you can mount the vault

```sh
sudo mount -t davfs http://localhost:8080/demoVault/ /media/your/mounted/folder
```

To unmount the vault, run

```sh
sudo umount /media/your/mounted/folder
```

### macOS via AppleScript

Mount the vault with

```sh
osascript -e 'mount volume "http://localhost:8080/demoVault/"'
```

Unmount the vault with

```sh
osascript -e 'tell application "Finder" to if "demoVault" exists then eject "demoVault"'
```

## License

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 [support team](https://cryptomator.org/help/).
17 changes: 9 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>cli</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
<name>Cryptomator CLI</name>
<description>Command line program to access encrypted files via WebDAV.</description>
<url>https://github.com/cryptomator/cli</url>

<properties>
<cryptofs.version>1.4.0</cryptofs.version>
<webdav-nio.version>0.6.2</webdav-nio.version>
<commons.cli.version>1.3.1</commons.cli.version>
<logback.version>1.2.2</logback.version>
<cryptofs.version>1.9.10</cryptofs.version>
<webdav-nio.version>1.0.11</webdav-nio.version>
<commons.cli.version>1.4</commons.cli.version>
<logback.version>1.2.3</logback.version>

<java.version>1.8</java.version>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -71,17 +71,18 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<version>3.3.0</version>
<executions>
<execution>
<id>make-assembly</id>
Expand Down
59 changes: 31 additions & 28 deletions src/main/java/org/cryptomator/cli/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
*******************************************************************************/
package org.cryptomator.cli;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.cryptomator.cli.pwd.PasswordFromFileStrategy;
import org.cryptomator.cli.pwd.PasswordFromStdInputStrategy;
import org.cryptomator.cli.pwd.PasswordStrategy;
import org.cryptomator.cli.pwd.PasswordFromPropertyStrategy;

/**
* Parses program arguments. Does not validate them.
Expand Down Expand Up @@ -76,17 +78,15 @@ public class Args {
private final Properties vaultPaths;
private final Properties vaultPasswords;
private final Properties vaultPasswordFiles;

private boolean hasPasswordOrPasswordFile(Object vaultPath) {
return vaultPasswords.containsKey(vaultPath) || vaultPasswordFiles.containsKey(vaultPath);
}
private final Map<String, PasswordStrategy> passwordStrategies;

public Args(CommandLine commandLine) throws ParseException {
this.bindAddr = commandLine.getOptionValue("bind", "localhost");
this.port = Integer.parseInt(commandLine.getOptionValue("port", "0"));
this.vaultPaths = commandLine.getOptionProperties("vault");
this.vaultPasswords = commandLine.getOptionProperties("password");
this.vaultPasswordFiles = commandLine.getOptionProperties("passwordfile");
this.passwordStrategies = new HashMap<>();
}

public String getBindAddr() {
Expand All @@ -98,32 +98,13 @@ public int getPort() {
}

public Set<String> getVaultNames() {
return vaultPaths.keySet().stream().filter(this::hasPasswordOrPasswordFile).map(String.class::cast).collect(Collectors.toSet());
return vaultPaths.keySet().stream().map(String.class::cast).collect(Collectors.toSet());
}

public String getVaultPath(String vaultName) {
return vaultPaths.getProperty(vaultName);
}

public String getVaultPasswordPath(String vaultName) {
return vaultPasswordFiles.getProperty(vaultName);
}

public String getVaultPassword(String vaultName) {
if (vaultPasswords.getProperty(vaultName) == null) {
Path vaultPasswordPath = Paths.get(vaultPasswordFiles.getProperty(vaultName));
if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)) {
try (Stream<String> lines = Files.lines(vaultPasswordPath)) {
return lines.findFirst().get().toString();
} catch (IOException e) {
return null;
}
}
return null;
}
return vaultPasswords.getProperty(vaultName);
}

public static Args parse(String[] arguments) throws ParseException {
CommandLine commandLine = new DefaultParser().parse(OPTIONS, arguments);
return new Args(commandLine);
Expand All @@ -133,4 +114,26 @@ public static void printUsage() {
new HelpFormatter().printHelp(USAGE, OPTIONS);
}

public PasswordStrategy addPasswortStrategy(final String vaultName) {
PasswordStrategy passwordStrategy = new PasswordFromStdInputStrategy(vaultName);

if (vaultPasswords.getProperty(vaultName) != null) {
passwordStrategy = new PasswordFromPropertyStrategy(
vaultName,
vaultPasswords.getProperty(vaultName)
);
} else if (vaultPasswordFiles.getProperty(vaultName) != null) {
passwordStrategy = new PasswordFromFileStrategy(
vaultName,
Paths.get(vaultPasswordFiles.getProperty(vaultName))
);
}

this.passwordStrategies.put(vaultName, passwordStrategy);
return passwordStrategy;
}

public PasswordStrategy getPasswordStrategy(final String vaultName) {
return passwordStrategies.get(vaultName);
}
}
12 changes: 6 additions & 6 deletions src/main/java/org/cryptomator/cli/CryptomatorCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;

import org.apache.commons.cli.ParseException;
import org.cryptomator.cryptofs.CryptoFileSystemProperties;
Expand Down Expand Up @@ -40,22 +41,21 @@ public static void main(String[] rawArgs) throws IOException {
}

private static void validate(Args args) throws IllegalArgumentException {
Set<String> vaultNames = args.getVaultNames();
if (args.getPort() < 0 || args.getPort() > 65536) {
throw new IllegalArgumentException("Invalid WebDAV Port.");
}

if (args.getVaultNames().size() == 0) {
if (vaultNames.size() == 0) {
throw new IllegalArgumentException("No vault specified.");
}

for (String vaultName : args.getVaultNames()) {
for (String vaultName : vaultNames) {
Path vaultPath = Paths.get(args.getVaultPath(vaultName));
if ((args.getVaultPasswordPath(vaultName) != null) && args.getVaultPassword(vaultName) == null) {
throw new IllegalArgumentException("Cannot read password from file: " + Paths.get(args.getVaultPasswordPath(vaultName)));
}
if (!Files.isDirectory(vaultPath)) {
throw new IllegalArgumentException("Not a directory: " + vaultPath);
}
args.addPasswortStrategy(vaultName).validate();
}
}

Expand All @@ -67,7 +67,7 @@ private static void startup(Args args) throws IOException {
for (String vaultName : args.getVaultNames()) {
Path vaultPath = Paths.get(args.getVaultPath(vaultName));
LOG.info("Unlocking vault \"{}\" located at {}", vaultName, vaultPath);
String vaultPassword = args.getVaultPassword(vaultName);
String vaultPassword = args.getPasswordStrategy(vaultName).password();
CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(vaultPassword).build();
Path vaultRoot = CryptoFileSystemProvider.newFileSystem(vaultPath, properties).getPath("/");
WebDavServletController servlet = server.createWebDavServlet(vaultRoot, vaultName);
Expand Down
Loading

0 comments on commit a11b75c

Please sign in to comment.