Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6726666
Fix CPU hogging when running in background. (#36)
ndob Nov 9, 2020
3c5fab4
Fixing docker parameters order
loicpirez Apr 12, 2021
0f01d70
Merge pull request #42 from loicpirez/develop
tobihagemann Apr 12, 2021
d014c24
Fixed CI build by replacing deprecated `set_env` command
tobihagemann Apr 12, 2021
1be7576
support vault format 8
CodinGhoul Dec 16, 2021
aed3f51
Update README.md
being-peace Aug 24, 2021
ea661b2
preparing 0.5.0
tobihagemann Dec 20, 2021
9d67cce
updated dependencies
tobihagemann Dec 20, 2021
c6e40a3
updated README
tobihagemann Dec 20, 2021
3d66033
Merge branch 'release/0.5.0'
tobihagemann Dec 20, 2021
33d0f8c
Merge branch 'release/0.5.0' into develop
tobihagemann Dec 20, 2021
079521d
trying to fix release build
tobihagemann Dec 20, 2021
286ec00
Merge branch 'release/0.5.0'
tobihagemann Dec 20, 2021
281cf31
Merge branch 'release/0.5.0' into develop
tobihagemann Dec 20, 2021
81ec0f2
trying to fix release build
tobihagemann Dec 20, 2021
44b118a
Merge branch 'release/0.5.0'
tobihagemann Dec 20, 2021
d96e444
Merge branch 'release/0.5.0' into develop
tobihagemann Dec 20, 2021
2c2a9bf
trying to fix release build
tobihagemann Dec 20, 2021
4a7544b
Merge branch 'release/0.5.0'
tobihagemann Dec 20, 2021
ff63f3d
Merge branch 'release/0.5.0' into develop
tobihagemann Dec 20, 2021
1e6a865
trying to fix release build
tobihagemann Dec 20, 2021
52693aa
trying to fix release build
tobihagemann Dec 20, 2021
5369d4d
trying to fix release build
tobihagemann Dec 20, 2021
b9c229b
Merge branch 'release/0.5.0'
tobihagemann Dec 20, 2021
65f96c3
Merge branch 'release/0.5.0' into develop
tobihagemann Dec 20, 2021
10f5304
fixes #48
overheadhunter Dec 21, 2021
8c42381
preparing 0.5.1
overheadhunter Dec 21, 2021
4d8f6a2
Merge branch 'release/0.5.1'
overheadhunter Dec 21, 2021
0e22420
Merge remote-tracking branch 'cryptomator-cli/main' into sync
quantum-byte Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ jobs:
#This check is case insensitive
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
outputs:
artifact-version: ${{ steps.setversion.outputs.version }}
env:
BUILD_VERSION: SNAPSHOT
artifactVersion: ${{ steps.setversion.outputs.version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 14
java-version: 17
- uses: actions/cache@v1
with:
path: ~/.m2/repository
Expand All @@ -27,18 +25,17 @@ jobs:
- 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
- name: Output project version
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}"
BUILD_VERSION=$(mvn help:evaluate "-Dexpression=project.version" -q -DforceStdout)
echo "::set-output name=version::${BUILD_VERSION}"
- name: Build and Test
run: mvn -B install
- name: Upload snapshot artifact cryptomator-cli-${{ env.BUILD_VERSION }}.jar
- name: Upload artifact cryptomator-cli-${{ steps.setversion.outputs.version }}.jar
uses: actions/upload-artifact@v2
with:
name: cryptomator-cli-${{ env.BUILD_VERSION }}.jar
name: cryptomator-cli-${{ steps.setversion.outputs.version }}.jar
path: target/cryptomator-cli-*.jar

release:
Expand All @@ -50,7 +47,7 @@ jobs:
- name: Download cryptomator-cli.jar
uses: actions/download-artifact@v1
with:
name: cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar
name: cryptomator-cli-${{ needs.build.outputs.artifactVersion }}.jar
path: .
- name: Create Release
id: create_release
Expand All @@ -64,12 +61,12 @@ jobs:
:construction: Work in Progress
draft: true
prerelease: false
- name: Upload cryptomator-cli-${{ needs.build.outputs.artifact-version }}.jar to GitHub Releases
- name: Upload cryptomator-cli-${{ needs.build.outputs.artifactVersion }}.jar to GitHub Releases
uses: actions/upload-release-asset@v1.0.1
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_path: cryptomator-cli-${{ needs.build.outputs.artifactVersion }}.jar
asset_name: cryptomator-cli-${{ needs.build.outputs.artifactVersion }}.jar
asset_content_type: application/jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ This project is a fork of https://github.com/cryptomator/cli and currently, it a
lead to data loss.
5. A saner API when unlocking a single vault and the example is:

```java -jar cryptomator-cli.jar --vault $VAULT_PATH --fusemount $MOUNT_PATH --mountFlags $FUSE_OPTIONS```
```java -jar cryptomator-cli.jar --vault $VAULT_PATH --fusemount $MOUNT_PATH --mountFlags $FUSE_OPTIONS```
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>cli</artifactId>
<version>0.5.0-SNAPSHOT</version>
<version>0.5.1</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.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>
<fuse-nio.version>1.2.4</fuse-nio.version>
<cryptofs.version>2.3.1</cryptofs.version>
<webdav-nio.version>1.2.6</webdav-nio.version>
<commons.cli.version>1.5.0</commons.cli.version>
<logback.version>1.2.9</logback.version>
<fuse-nio.version>1.3.3</fuse-nio.version>

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

Expand Down
48 changes: 44 additions & 4 deletions src/main/java/org/cryptomator/cli/CryptomatorCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Optional;
import java.util.Set;

import com.google.common.base.Preconditions;
import org.apache.commons.cli.ParseException;
import org.cryptomator.cryptofs.CryptoFileSystemProperties;
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
import org.cryptomator.cryptolib.common.MasterkeyFileAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,6 +59,9 @@ public class CryptomatorCli {

private static final Logger LOG = LoggerFactory.getLogger(CryptomatorCli.class);

private static final byte[] PEPPER = new byte[0];
private static final String SCHEME = "masterkeyfile";

public static void main(String[] rawArgs) throws IOException {
try {
if (rawArgs.length==1 && strEq(rawArgs[0], "--version")) {
Expand Down Expand Up @@ -102,12 +109,27 @@ private static void startup(Args args) throws IOException {
Optional<WebDav> server = initWebDavServer(args);
ArrayList<FuseMount> mounts = new ArrayList<>();
ArrayList<mountInfo> mInfo = new ArrayList<>();

SecureRandom secureRandom;
try {
secureRandom = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("A strong algorithm must exist in every Java platform.", e);
}
MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess(PEPPER, secureRandom);

for (String vaultName : args.getVaultNames()) {
Path vaultPath = Paths.get(args.getVaultPath(vaultName));
LOG.info("Unlocking vault \"{}\" located at {}", vaultName, vaultPath);
String vaultPassword = args.getPasswordStrategy(vaultName).password();
CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties()
.withPassphrase(vaultPassword).build();
.withKeyLoader(keyId -> {
Preconditions.checkArgument(SCHEME.equalsIgnoreCase(keyId.getScheme()), "Only supports keys with scheme " + SCHEME);
Path keyFilePath = vaultPath.resolve(keyId.getSchemeSpecificPart());
return masterkeyFileAccess.load(keyFilePath, vaultPassword);
})
.build();

Path vaultRoot = CryptoFileSystemProvider.newFileSystem(vaultPath, properties).getPath("/");

Path fuseMountPoint = args.getFuseMountPoint(vaultName);
Expand Down Expand Up @@ -177,16 +199,34 @@ private static boolean hasActiveMount(ArrayList<mountInfo> localList) {
}

private static void listenForUnMountEvents(ArrayList<mountInfo> mounts) {
while (true){
if (hasActiveMount(mounts)){
while (true) {
if (hasActiveMount(mounts)) {
sleep(2);
}else{
} else {
LOG.info("All vaults are locked, exiting");
break;
}
}
}

private static void waitForShutdown(Runnable runnable) {
Runtime.getRuntime().addShutdownHook(new Thread(runnable));
LOG.info("Press Ctrl+C to terminate.");

// Block the main thread infinitely as otherwise when using
// Fuse mounts the application quits immediately.
try {
Object mainThreadBlockLock = new Object();
synchronized (mainThreadBlockLock) {
while (true) {
mainThreadBlockLock.wait();
}
}
} catch (Exception e) {
LOG.error("Main thread blocking failed.");
}
}

private static void sleep(int interval) {
try {
Object mainThreadBlockLock = new Object();
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/org/cryptomator/cli/frontend/FuseMount.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Arrays;
import java.util.ArrayList;

import org.cryptomator.frontend.fuse.mount.CommandFailedException;
import org.cryptomator.frontend.fuse.mount.EnvironmentVariables;
import org.cryptomator.frontend.fuse.mount.FuseMountException;
import org.cryptomator.frontend.fuse.mount.FuseMountFactory;
import org.cryptomator.frontend.fuse.mount.Mount;
import org.cryptomator.frontend.fuse.mount.Mounter;
Expand Down Expand Up @@ -40,28 +40,32 @@ public boolean mount() {
try {
Mounter mounter = FuseMountFactory.getMounter();

EnvironmentVariables envVars ;

String[] parsedMountFlags;
if (mountFlags != null) {
ArrayList<String> defaultMountFlags = new ArrayList<String>(Arrays.asList(mounter.defaultMountFlags()));
ArrayList<String> defaultMountFlags = new ArrayList(Arrays.asList(mounter.defaultMountFlags()));
for (String it : mountFlags.split(",")) {
String m = it.replace(' ','=');
m = m.replace(encodeCharacterToString('='), "=");
defaultMountFlags.add("-o"+m);
defaultMountFlags.add(
"-o"+it
.replace(' ','=')
.replace(encodeCharacterToString('='), "=")
);
}
String[] newMountFlags = defaultMountFlags.toArray(new String[defaultMountFlags.size()]);
envVars = EnvironmentVariables.create().withFlags(newMountFlags)
.withMountPoint(mountPoint).build();
parsedMountFlags = defaultMountFlags.toArray(new String[defaultMountFlags.size()]);
}else{
envVars = EnvironmentVariables.create().withFlags(mounter.defaultMountFlags())
.withMountPoint(mountPoint).build();
parsedMountFlags = mounter.defaultMountFlags();
}

EnvironmentVariables envVars = EnvironmentVariables.create() //
.withFlags(parsedMountFlags) //
.withFileNameTranscoder(mounter.defaultFileNameTranscoder()) //
.withMountPoint(mountPoint).build();


mnt = mounter.mount(vaultRoot, envVars);
LOG.info("Mounted to {}", mountPoint);
LOG.info("Run fusermount -u \"{}\" to unmount", mountPoint);

} catch (CommandFailedException e) {
} catch (FuseMountException e) {
LOG.error("Can't mount: {}, error: {}", mountPoint, e.getMessage());
return false;
}
Expand All @@ -72,7 +76,7 @@ public void unmount() {
try {
mnt.unmount();
LOG.info("Unmounted {}", mountPoint);
} catch (CommandFailedException e) {
} catch (FuseMountException e) {
LOG.error("Can't unmount gracefully: {}. Force unmount.", e.getMessage());
forceUnmount();
}
Expand All @@ -82,7 +86,7 @@ private void forceUnmount() {
try {
mnt.unmountForced();
LOG.info("Unmounted {}", mountPoint);
} catch (CommandFailedException e) {
} catch (FuseMountException e) {
LOG.error("Force unmount failed: {}", e.getMessage());
}
}
Expand Down