From e1862314e79e7fa7e6e3bf3fd7a96564dbeb1b26 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 6 Mar 2017 16:50:05 +0100 Subject: [PATCH 1/6] Updated dependencies --- pom.xml | 12 ++++++------ .../java/org/cryptomator/cli/CryptomatorCli.java | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 209cd71..a070fc3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ 1.8 1.3.1 - 1.0.1 - 0.2.3 + 1.1.0 + 0.4.0 UTF-8 @@ -56,21 +56,20 @@ org.apache.logging.log4j log4j-slf4j-impl - 2.7 + 2.8 org.apache.logging.log4j log4j-core - 2.7 + 2.8 - org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.6.1 ${java.version} ${java.version} @@ -80,6 +79,7 @@ maven-assembly-plugin + 3.0.0 make-assembly diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index 59fcc2f..dc85b97 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -56,7 +56,8 @@ private static void validate(Args args) throws IllegalArgumentException { } private static void startup(Args args) throws IOException { - WebDavServer server = WebDavServer.create(args.getBindAddr(), args.getPort()); + WebDavServer server = WebDavServer.create(); + server.bind(args.getBindAddr(), args.getPort()); server.start(); for (String vaultName : args.getVaultNames()) { @@ -65,7 +66,7 @@ private static void startup(Args args) throws IOException { String vaultPassword = args.getVaultPassword(vaultName); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(vaultPassword).build(); Path vaultRoot = CryptoFileSystemProvider.newFileSystem(vaultPath, properties).getPath("/"); - server.startWebDavServlet(vaultRoot, vaultName); + server.createWebDavServlet(vaultRoot, vaultName); } waitForShutdown(() -> { From 409c69af2cfa6e191c49f5a45dd618a350a1accc Mon Sep 17 00:00:00 2001 From: Felix Zachlod Date: Wed, 29 Mar 2017 13:40:57 +0200 Subject: [PATCH 2/6] Adding passwordfile option to securely read password for each vault from a corresponding password file. Works the same way as the password option does. Just uses a file instead to read the password from the first line. password trumps passwordfile. --- src/main/java/org/cryptomator/cli/Args.java | 38 ++++++++++++++++++- .../org/cryptomator/cli/CryptomatorCli.java | 4 ++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/cli/Args.java b/src/main/java/org/cryptomator/cli/Args.java index d6d23f0..226c1ef 100644 --- a/src/main/java/org/cryptomator/cli/Args.java +++ b/src/main/java/org/cryptomator/cli/Args.java @@ -8,9 +8,14 @@ *******************************************************************************/ 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.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; @@ -27,7 +32,8 @@ public class Args { private static final String USAGE = "java -jar cryptomator-cli.jar" // + " --bind localhost --port 8080" // + " --vault mySecretVault=/path/to/vault --password mySecretVault=FooBar3000" // - + " --vault myOtherVault=/path/to/other/vault --password myOtherVault=BarFoo4000"; + + " --vault myOtherVault=/path/to/other/vault --password myOtherVault=BarFoo4000" + + " --vault myThirdVault=/path/to/third/vault --passwordfile myThirdVault=/path/to/passwordfile"; private static final Options OPTIONS = new Options(); static { OPTIONS.addOption(Option.builder() // @@ -56,18 +62,27 @@ public class Args { .valueSeparator() // .hasArgs() // .build()); + OPTIONS.addOption(Option.builder() // + .longOpt("passwordfile") // + .argName("Passwordfile for a vault") // + .desc("Format must be vaultName=passwordfile") // + .valueSeparator() // + .hasArgs() // + .build()); } private final String bindAddr; private final int port; private final Properties vaultPaths; private final Properties vaultPasswords; + private final Properties vaultPasswordfiles; 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"); } public String getBindAddr() { @@ -79,14 +94,33 @@ public int getPort() { } public Set getVaultNames() { - return vaultPaths.keySet().stream().filter(vaultPasswords::containsKey).map(String.class::cast).collect(Collectors.toSet()); + Set filteredVaults = vaultPaths.keySet().stream().filter(vaultPasswords::containsKey).map(String.class::cast).collect(Collectors.toSet()); + filteredVaults.addAll(vaultPaths.keySet().stream().filter(vaultPasswordfiles::containsKey).map(String.class::cast).collect(Collectors.toSet())); + return filteredVaults; } 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 lines = Files.lines(vaultPasswordPath)) { + String vaultPassword = lines.findFirst().get().toString(); + if (vaultPassword != "") { + return vaultPassword; + } + return null; + } catch (IOException e) { + return null; + } + } + return null; + } return vaultPasswords.getProperty(vaultName); } diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index dc85b97..ac4a372 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -49,6 +49,10 @@ private static void validate(Args args) throws IllegalArgumentException { for (String vaultName : args.getVaultNames()) { 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); } From 78f2d743ba63c07e6f91e374226f62f1d659e610 Mon Sep 17 00:00:00 2001 From: Felix Zachlod Date: Wed, 29 Mar 2017 14:58:21 +0200 Subject: [PATCH 3/6] requested changes to last commit --- src/main/java/org/cryptomator/cli/Args.java | 24 +++++++++---------- .../org/cryptomator/cli/CryptomatorCli.java | 3 +-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/cryptomator/cli/Args.java b/src/main/java/org/cryptomator/cli/Args.java index 226c1ef..8d97b98 100644 --- a/src/main/java/org/cryptomator/cli/Args.java +++ b/src/main/java/org/cryptomator/cli/Args.java @@ -75,14 +75,18 @@ public class Args { private final int port; private final Properties vaultPaths; private final Properties vaultPasswords; - private final Properties vaultPasswordfiles; + private final Properties vaultPasswordFiles; + + private boolean hasPasswordOrPasswordFile(Object vaultPath) { + return vaultPasswords.containsKey(vaultPath) || vaultPasswordFiles.containsKey(vaultPath); + } 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.vaultPasswordFiles = commandLine.getOptionProperties("passwordfile"); } public String getBindAddr() { @@ -94,27 +98,23 @@ public int getPort() { } public Set getVaultNames() { - Set filteredVaults = vaultPaths.keySet().stream().filter(vaultPasswords::containsKey).map(String.class::cast).collect(Collectors.toSet()); - filteredVaults.addAll(vaultPaths.keySet().stream().filter(vaultPasswordfiles::containsKey).map(String.class::cast).collect(Collectors.toSet())); - return filteredVaults; + return vaultPaths.keySet().stream().filter(this::hasPasswordOrPasswordFile).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 getVaultPasswordPath(String vaultName) { + return vaultPasswordFiles.getProperty(vaultName); + } public String getVaultPassword(String vaultName) { if (vaultPasswords.getProperty(vaultName) == null){ - Path vaultPasswordPath = Paths.get(vaultPasswordfiles.getProperty(vaultName)); + Path vaultPasswordPath = Paths.get(vaultPasswordFiles.getProperty(vaultName)); if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)){ try (Stream lines = Files.lines(vaultPasswordPath)) { - String vaultPassword = lines.findFirst().get().toString(); - if (vaultPassword != "") { - return vaultPassword; - } - return null; + return lines.findFirst().get().toString(); } catch (IOException e) { return null; } diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index ac4a372..a59a85a 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -49,8 +49,7 @@ private static void validate(Args args) throws IllegalArgumentException { for (String vaultName : args.getVaultNames()) { Path vaultPath = Paths.get(args.getVaultPath(vaultName)); - if ((args.getVaultPasswordPath(vaultName) != null) && args.getVaultPassword(vaultName) == null) - { + 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)) { From 4b3022e8c93f5420a86923c437d8da87ac753964 Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Wed, 29 Mar 2017 18:34:45 +0200 Subject: [PATCH 4/6] code format --- src/main/java/org/cryptomator/cli/Args.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/cryptomator/cli/Args.java b/src/main/java/org/cryptomator/cli/Args.java index 8d97b98..c87b0cf 100644 --- a/src/main/java/org/cryptomator/cli/Args.java +++ b/src/main/java/org/cryptomator/cli/Args.java @@ -32,8 +32,8 @@ public class Args { private static final String USAGE = "java -jar cryptomator-cli.jar" // + " --bind localhost --port 8080" // + " --vault mySecretVault=/path/to/vault --password mySecretVault=FooBar3000" // - + " --vault myOtherVault=/path/to/other/vault --password myOtherVault=BarFoo4000" - + " --vault myThirdVault=/path/to/third/vault --passwordfile myThirdVault=/path/to/passwordfile"; + + " --vault myOtherVault=/path/to/other/vault --password myOtherVault=BarFoo4000" // + + " --vault myThirdVault=/path/to/third/vault --passwordfile myThirdVault=/path/to/passwordfile"; private static final Options OPTIONS = new Options(); static { OPTIONS.addOption(Option.builder() // @@ -110,9 +110,9 @@ public String getVaultPasswordPath(String vaultName) { } public String getVaultPassword(String vaultName) { - if (vaultPasswords.getProperty(vaultName) == null){ + if (vaultPasswords.getProperty(vaultName) == null) { Path vaultPasswordPath = Paths.get(vaultPasswordFiles.getProperty(vaultName)); - if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)){ + if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)) { try (Stream lines = Files.lines(vaultPasswordPath)) { return lines.findFirst().get().toString(); } catch (IOException e) { From d5f395eb44800ded4bd650b85311d67e6bc15289 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Tue, 13 Jun 2017 12:12:52 +0200 Subject: [PATCH 5/6] Updated cryptofs --- pom.xml | 2 +- src/main/java/org/cryptomator/cli/CryptomatorCli.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a070fc3..d5512e7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 1.8 1.3.1 - 1.1.0 + 1.3.1 0.4.0 UTF-8 diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index a59a85a..76ec3df 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -17,6 +17,7 @@ import org.cryptomator.cryptofs.CryptoFileSystemProperties; import org.cryptomator.cryptofs.CryptoFileSystemProvider; import org.cryptomator.frontend.webdav.WebDavServer; +import org.cryptomator.frontend.webdav.servlet.WebDavServletController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +70,8 @@ private static void startup(Args args) throws IOException { String vaultPassword = args.getVaultPassword(vaultName); CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withPassphrase(vaultPassword).build(); Path vaultRoot = CryptoFileSystemProvider.newFileSystem(vaultPath, properties).getPath("/"); - server.createWebDavServlet(vaultRoot, vaultName); + WebDavServletController servlet = server.createWebDavServlet(vaultRoot, vaultName); + servlet.start(); } waitForShutdown(() -> { From a7fe127af25858dd3fe5083292d58078312e383d Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Tue, 13 Jun 2017 12:14:05 +0200 Subject: [PATCH 6/6] Preaparing 0.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d5512e7..00ad58c 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.cryptomator cli - 0.3.0-SNAPSHOT + 0.3.0 Cryptomator CLI Command line program to access encrypted files via WebDAV. https://github.com/cryptomator/cli