diff --git a/.github/workflows/win-exe.yml b/.github/workflows/win-exe.yml index f1a2b3515..244cbfc36 100644 --- a/.github/workflows/win-exe.yml +++ b/.github/workflows/win-exe.yml @@ -98,6 +98,7 @@ jobs: --java-options "-Dcryptomator.p12Path=\"~/AppData/Roaming/Cryptomator/key.p12\"" --java-options "-Dcryptomator.ipcSocketPath=\"~/AppData/Roaming/Cryptomator/ipc.socket\"" --java-options "-Dcryptomator.mountPointsDir=\"~/Cryptomator\"" + --java-options "-Dcryptomator.loopbackAlias=\"${{ env.LOOPBACK_ALIAS }}\"" --java-options "-Dcryptomator.showTrayIcon=true" --java-options "-Dcryptomator.buildNumber=\"msi-${{ steps.versions.outputs.revNum }}\"" --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=\"Cryptomator\"" diff --git a/dist/win/build.ps1 b/dist/win/build.ps1 index 940384f64..565194e7d 100644 --- a/dist/win/build.ps1 +++ b/dist/win/build.ps1 @@ -35,6 +35,7 @@ Write-Output "`$buildDir=$buildDir" Write-Output "`$Env:JAVA_HOME=$Env:JAVA_HOME" $copyright = "(C) $CopyrightStartYear - $((Get-Date).Year) $Vendor" +$loopbackAlias = 'cryptomator-vault' # compile &mvn -B -f $buildDir/../../pom.xml clean package -DskipTests -Pwin @@ -85,6 +86,7 @@ if ($clean -and (Test-Path -Path $appPath)) { --java-options "-Dcryptomator.ipcSocketPath=`"~/AppData/Roaming/$AppName/ipc.socket`"" ` --java-options "-Dcryptomator.p12Path=`"~/AppData/Roaming/$AppName/key.p12`"" ` --java-options "-Dcryptomator.mountPointsDir=`"~/$AppName`"" ` + --java-options "-Dcryptomator.loopbackAlias=`"$loopbackAlias`"" ` --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=`"$AppName`"" ` --java-options "-Dcryptomator.integrationsWin.keychainPaths=`"~/AppData/Roaming/$AppName/keychain.json`"" ` --java-options "-Dcryptomator.showTrayIcon=true" ` @@ -107,9 +109,8 @@ Copy-Item "contrib\*" -Destination "$AppName" attrib -r "$AppName\$AppName.exe" # patch batch script to set hostfile $webDAVPatcher = "$AppName\patchWebDAV.bat" -$alias = 'cryptomator-vault' try { - (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$alias`"" | Set-Content $webDAVPatcher + (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$loopbackAlias`"" | Set-Content $webDAVPatcher } catch { Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat" exit 1 diff --git a/src/main/java/org/cryptomator/common/Environment.java b/src/main/java/org/cryptomator/common/Environment.java index 261750ad1..383261119 100644 --- a/src/main/java/org/cryptomator/common/Environment.java +++ b/src/main/java/org/cryptomator/common/Environment.java @@ -26,6 +26,7 @@ public class Environment { private static final String KEYCHAIN_PATHS_PROP_NAME = "cryptomator.integrationsWin.keychainPaths"; private static final String P12_PATH_PROP_NAME = "cryptomator.p12Path"; private static final String LOG_DIR_PROP_NAME = "cryptomator.logDir"; + private static final String LOOPBACK_ALIAS_PROP_NAME = "cryptomator.loopbackAlias"; private static final String MOUNTPOINT_DIR_PROP_NAME = "cryptomator.mountPointsDir"; private static final String MIN_PW_LENGTH_PROP_NAME = "cryptomator.minPwLength"; private static final String APP_VERSION_PROP_NAME = "cryptomator.appVersion"; @@ -45,6 +46,7 @@ public class Environment { logCryptomatorSystemProperty(IPC_SOCKET_PATH_PROP_NAME); logCryptomatorSystemProperty(KEYCHAIN_PATHS_PROP_NAME); logCryptomatorSystemProperty(LOG_DIR_PROP_NAME); + logCryptomatorSystemProperty(LOOPBACK_ALIAS_PROP_NAME); logCryptomatorSystemProperty(PLUGIN_DIR_PROP_NAME); logCryptomatorSystemProperty(MOUNTPOINT_DIR_PROP_NAME); logCryptomatorSystemProperty(MIN_PW_LENGTH_PROP_NAME); @@ -90,6 +92,10 @@ public class Environment { return getPath(LOG_DIR_PROP_NAME).map(this::replaceHomeDir); } + public Optional getLoopbackAlias() { + return Optional.ofNullable(System.getProperty(LOOPBACK_ALIAS_PROP_NAME)); + } + public Optional getPluginDir() { return getPath(PLUGIN_DIR_PROP_NAME).map(this::replaceHomeDir); } @@ -112,22 +118,13 @@ public class Environment { } public int getMinPwLength() { - return getInt(MIN_PW_LENGTH_PROP_NAME, DEFAULT_MIN_PW_LENGTH); + return Integer.getInteger(MIN_PW_LENGTH_PROP_NAME, DEFAULT_MIN_PW_LENGTH); } public boolean showTrayIcon() { return Boolean.getBoolean(TRAY_ICON_PROP_NAME); } - private int getInt(String propertyName, int defaultValue) { - String value = System.getProperty(propertyName); - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { // includes "null" values - return defaultValue; - } - } - private Optional getPath(String propertyName) { String value = System.getProperty(propertyName); return Optional.ofNullable(value).map(Paths::get); diff --git a/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java b/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java index 3ac1820d4..af7ca10f2 100644 --- a/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java +++ b/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java @@ -2,6 +2,7 @@ package org.cryptomator.common.vaults; import com.google.common.base.CharMatcher; +import org.cryptomator.common.Environment; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.common.settings.VolumeImpl; @@ -22,12 +23,11 @@ import java.util.function.Supplier; public class WebDavVolume implements Volume { - private static final String LOCALHOST_ALIAS = "cryptomator-vault"; - private final Provider serverProvider; private final VaultSettings vaultSettings; private final Settings settings; private final WindowsDriveLetters windowsDriveLetters; + private final Environment environment; private WebDavServer server; private WebDavServletController servlet; @@ -35,11 +35,12 @@ public class WebDavVolume implements Volume { private Consumer onExitAction; @Inject - public WebDavVolume(Provider serverProvider, VaultSettings vaultSettings, Settings settings, WindowsDriveLetters windowsDriveLetters) { + public WebDavVolume(Provider serverProvider, VaultSettings vaultSettings, Settings settings, WindowsDriveLetters windowsDriveLetters, Environment environment) { this.serverProvider = serverProvider; this.vaultSettings = vaultSettings; this.settings = settings; this.windowsDriveLetters = windowsDriveLetters; + this.environment = environment; } @Override @@ -129,16 +130,17 @@ public class WebDavVolume implements Volume { } private String getLocalhostAliasOrNull() { - try { - InetAddress alias = InetAddress.getByName(LOCALHOST_ALIAS); - if (alias.getHostAddress().equals("127.0.0.1")) { - return LOCALHOST_ALIAS; - } else { - return null; + return environment.getLoopbackAlias().map(alias -> { + try { + var address = InetAddress.getByName(alias); + if (address.getHostAddress().equals("127.0.0.1")) { + return alias; + } + } catch (UnknownHostException e) { + //no-op } - } catch (UnknownHostException e) { return null; - } + }).orElse(null); } private void cleanup() {