Skip to content

Commit a11b75c

Browse files
author
Armin Schrenk
committed
Merge branch 'release/0.4.0'
2 parents 10803cb + 178acf4 commit a11b75c

File tree

11 files changed

+295
-72
lines changed

11 files changed

+295
-72
lines changed

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build
2+
3+
on:
4+
[push]
5+
6+
jobs:
7+
build:
8+
name: Build and Test
9+
runs-on: ubuntu-latest
10+
outputs:
11+
artifact-version: ${{ steps.setversion.outputs.version }}
12+
env:
13+
BUILD_VERSION: SNAPSHOT
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-java@v1
17+
with:
18+
java-version: 14
19+
- uses: actions/cache@v1
20+
with:
21+
path: ~/.m2/repository
22+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
23+
restore-keys: |
24+
${{ runner.os }}-maven-
25+
- name: Ensure to use tagged version
26+
run: mvn versions:set --file ./pom.xml -DnewVersion=${GITHUB_REF##*/} # use shell parameter expansion to strip of 'refs/tags'
27+
if: startsWith(github.ref, 'refs/tags/')
28+
- name: Export the project version to the job environment and fix it as an ouput of this job
29+
id: setversion
30+
run: |
31+
v=$(mvn help:evaluate "-Dexpression=project.version" -q -DforceStdout)
32+
echo "::set-env name=BUILD_VERSION::${v}"
33+
echo "::set-output name=version::${v}"
34+
- name: Build and Test
35+
run: mvn -B install
36+
- name: Upload snapshot artifact cryptomator-cli-${{ env.BUILD_VERSION }}.jar
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: cryptomator-cli-${{ env.BUILD_VERSION }}.jar
40+
path: target/cryptomator-cli-*.jar
41+
42+
release:
43+
name: Draft a Release on GitHub Releases and uploads the build artifacts to it
44+
runs-on: ubuntu-latest
45+
needs: build
46+
if: startsWith(github.ref, 'refs/tags/')
47+
steps:
48+
- name: Download cryptomator-cli.jar
49+
uses: actions/download-artifact@v1
50+
with:
51+
name: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
52+
path: .
53+
- name: Create Release
54+
id: create_release
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: ${{ github.ref }}
60+
release_name: ${{ github.ref }}
61+
body: |
62+
:construction: Work in Progress
63+
draft: true
64+
prerelease: false
65+
- name: Upload cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar to GitHub Releases
66+
uses: actions/[email protected]
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
with:
70+
upload_url: ${{ steps.create_release.outputs.upload_url }}
71+
asset_path: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
72+
asset_name: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
73+
asset_content_type: application/jar

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ test-output/
1717
out/
1818
.idea_modules/
1919
*.iws
20+
21+
*.iml

.travis.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

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

3-
# Cryptomator CLI version
4+
# Cryptomator CLI
45

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

78
## Disclaimer
89

910
This project is in an early stage and not ready for production use. We recommend to use it only for testing and evaluation purposes.
1011

1112
## Download and Usage
1213

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

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

1718
```sh
1819
java -jar cryptomator-cli-x.y.z.jar \
1920
--vault demoVault=/path/to/vault --password demoVault=topSecret \
2021
--vault otherVault=/path/to/differentVault --passwordfile otherVault=/path/to/fileWithPassword \
21-
--bind 0.0.0.0 --port 8080
22+
--bind 127.0.0.1 --port 8080
2223
# you can now mount http://localhost:8080/demoVault/
2324
```
2425

26+
Then you can access the vault using any WebDAV client.
27+
28+
### Linux via davfs2
29+
30+
First, you need to create a mount point for your vault
31+
32+
```sh
33+
sudo mkdir /media/your/mounted/folder
34+
```
35+
36+
Then you can mount the vault
37+
38+
```sh
39+
sudo mount -t davfs http://localhost:8080/demoVault/ /media/your/mounted/folder
40+
```
41+
42+
To unmount the vault, run
43+
44+
```sh
45+
sudo umount /media/your/mounted/folder
46+
```
47+
48+
### macOS via AppleScript
49+
50+
Mount the vault with
51+
52+
```sh
53+
osascript -e 'mount volume "http://localhost:8080/demoVault/"'
54+
```
55+
56+
Unmount the vault with
57+
58+
```sh
59+
osascript -e 'tell application "Finder" to if "demoVault" exists then eject "demoVault"'
60+
```
61+
2562
## License
2663

2764
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/).

pom.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.cryptomator</groupId>
44
<artifactId>cli</artifactId>
5-
<version>0.3.1</version>
5+
<version>0.4.0</version>
66
<name>Cryptomator CLI</name>
77
<description>Command line program to access encrypted files via WebDAV.</description>
88
<url>https://github.com/cryptomator/cli</url>
99

1010
<properties>
11-
<cryptofs.version>1.4.0</cryptofs.version>
12-
<webdav-nio.version>0.6.2</webdav-nio.version>
13-
<commons.cli.version>1.3.1</commons.cli.version>
14-
<logback.version>1.2.2</logback.version>
11+
<cryptofs.version>1.9.10</cryptofs.version>
12+
<webdav-nio.version>1.0.11</webdav-nio.version>
13+
<commons.cli.version>1.4</commons.cli.version>
14+
<logback.version>1.2.3</logback.version>
1515

16-
<java.version>1.8</java.version>
16+
<java.version>11</java.version>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

@@ -71,17 +71,18 @@
7171
<plugins>
7272
<plugin>
7373
<artifactId>maven-compiler-plugin</artifactId>
74-
<version>3.6.1</version>
74+
<version>3.8.1</version>
7575
<configuration>
7676
<source>${java.version}</source>
7777
<target>${java.version}</target>
78+
<release>${java.version}</release>
7879
<showWarnings>true</showWarnings>
7980
</configuration>
8081
</plugin>
8182

8283
<plugin>
8384
<artifactId>maven-assembly-plugin</artifactId>
84-
<version>3.0.0</version>
85+
<version>3.3.0</version>
8586
<executions>
8687
<execution>
8788
<id>make-assembly</id>

src/main/java/org/cryptomator/cli/Args.java

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
*******************************************************************************/
99
package org.cryptomator.cli;
1010

11-
import java.io.IOException;
12-
import java.nio.file.Files;
13-
import java.nio.file.Path;
1411
import java.nio.file.Paths;
12+
import java.util.HashMap;
13+
import java.util.Map;
1514
import java.util.Properties;
1615
import java.util.Set;
1716
import java.util.stream.Collectors;
18-
import java.util.stream.Stream;
1917

2018
import org.apache.commons.cli.CommandLine;
2119
import org.apache.commons.cli.DefaultParser;
2220
import org.apache.commons.cli.HelpFormatter;
2321
import org.apache.commons.cli.Option;
2422
import org.apache.commons.cli.Options;
2523
import org.apache.commons.cli.ParseException;
24+
import org.cryptomator.cli.pwd.PasswordFromFileStrategy;
25+
import org.cryptomator.cli.pwd.PasswordFromStdInputStrategy;
26+
import org.cryptomator.cli.pwd.PasswordStrategy;
27+
import org.cryptomator.cli.pwd.PasswordFromPropertyStrategy;
2628

2729
/**
2830
* Parses program arguments. Does not validate them.
@@ -76,17 +78,15 @@ public class Args {
7678
private final Properties vaultPaths;
7779
private final Properties vaultPasswords;
7880
private final Properties vaultPasswordFiles;
79-
80-
private boolean hasPasswordOrPasswordFile(Object vaultPath) {
81-
return vaultPasswords.containsKey(vaultPath) || vaultPasswordFiles.containsKey(vaultPath);
82-
}
81+
private final Map<String, PasswordStrategy> passwordStrategies;
8382

8483
public Args(CommandLine commandLine) throws ParseException {
8584
this.bindAddr = commandLine.getOptionValue("bind", "localhost");
8685
this.port = Integer.parseInt(commandLine.getOptionValue("port", "0"));
8786
this.vaultPaths = commandLine.getOptionProperties("vault");
8887
this.vaultPasswords = commandLine.getOptionProperties("password");
8988
this.vaultPasswordFiles = commandLine.getOptionProperties("passwordfile");
89+
this.passwordStrategies = new HashMap<>();
9090
}
9191

9292
public String getBindAddr() {
@@ -98,32 +98,13 @@ public int getPort() {
9898
}
9999

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

104104
public String getVaultPath(String vaultName) {
105105
return vaultPaths.getProperty(vaultName);
106106
}
107107

108-
public String getVaultPasswordPath(String vaultName) {
109-
return vaultPasswordFiles.getProperty(vaultName);
110-
}
111-
112-
public String getVaultPassword(String vaultName) {
113-
if (vaultPasswords.getProperty(vaultName) == null) {
114-
Path vaultPasswordPath = Paths.get(vaultPasswordFiles.getProperty(vaultName));
115-
if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)) {
116-
try (Stream<String> lines = Files.lines(vaultPasswordPath)) {
117-
return lines.findFirst().get().toString();
118-
} catch (IOException e) {
119-
return null;
120-
}
121-
}
122-
return null;
123-
}
124-
return vaultPasswords.getProperty(vaultName);
125-
}
126-
127108
public static Args parse(String[] arguments) throws ParseException {
128109
CommandLine commandLine = new DefaultParser().parse(OPTIONS, arguments);
129110
return new Args(commandLine);
@@ -133,4 +114,26 @@ public static void printUsage() {
133114
new HelpFormatter().printHelp(USAGE, OPTIONS);
134115
}
135116

117+
public PasswordStrategy addPasswortStrategy(final String vaultName) {
118+
PasswordStrategy passwordStrategy = new PasswordFromStdInputStrategy(vaultName);
119+
120+
if (vaultPasswords.getProperty(vaultName) != null) {
121+
passwordStrategy = new PasswordFromPropertyStrategy(
122+
vaultName,
123+
vaultPasswords.getProperty(vaultName)
124+
);
125+
} else if (vaultPasswordFiles.getProperty(vaultName) != null) {
126+
passwordStrategy = new PasswordFromFileStrategy(
127+
vaultName,
128+
Paths.get(vaultPasswordFiles.getProperty(vaultName))
129+
);
130+
}
131+
132+
this.passwordStrategies.put(vaultName, passwordStrategy);
133+
return passwordStrategy;
134+
}
135+
136+
public PasswordStrategy getPasswordStrategy(final String vaultName) {
137+
return passwordStrategies.get(vaultName);
138+
}
136139
}

src/main/java/org/cryptomator/cli/CryptomatorCli.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.nio.file.Files;
1313
import java.nio.file.Path;
1414
import java.nio.file.Paths;
15+
import java.util.Set;
1516

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

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

47-
if (args.getVaultNames().size() == 0) {
49+
if (vaultNames.size() == 0) {
4850
throw new IllegalArgumentException("No vault specified.");
4951
}
5052

51-
for (String vaultName : args.getVaultNames()) {
53+
for (String vaultName : vaultNames) {
5254
Path vaultPath = Paths.get(args.getVaultPath(vaultName));
53-
if ((args.getVaultPasswordPath(vaultName) != null) && args.getVaultPassword(vaultName) == null) {
54-
throw new IllegalArgumentException("Cannot read password from file: " + Paths.get(args.getVaultPasswordPath(vaultName)));
55-
}
5655
if (!Files.isDirectory(vaultPath)) {
5756
throw new IllegalArgumentException("Not a directory: " + vaultPath);
5857
}
58+
args.addPasswortStrategy(vaultName).validate();
5959
}
6060
}
6161

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

0 commit comments

Comments
 (0)