Skip to content

Commit

Permalink
Merge pull request #4464 from chimp1984/show-popup-for-osx-key-logger…
Browse files Browse the repository at this point in the history
…-warning

Show popup about key-logger warning if OSX version is >= 10.14
  • Loading branch information
ripcurlx authored Sep 3, 2020
2 parents 5812103 + ef0e895 commit 3df9428
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
24 changes: 24 additions & 0 deletions common/src/main/java/bisq/common/util/InvalidVersionException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.common.util;

public class InvalidVersionException extends Exception {
public InvalidVersionException(String msg) {
super(msg);
}
}
32 changes: 30 additions & 2 deletions common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package bisq.common.util;

import bisq.common.crypto.LimitedKeyStrengthException;

import org.bitcoinj.core.Utils;

import com.google.gson.ExclusionStrategy;
Expand Down Expand Up @@ -71,6 +69,7 @@

import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.awt.Desktop.Action;
import static java.awt.Desktop.getDesktop;
Expand Down Expand Up @@ -182,6 +181,34 @@ private static String getOSName() {
return System.getProperty("os.name").toLowerCase(Locale.US);
}

public static String getOSVersion() {
return System.getProperty("os.version").toLowerCase(Locale.US);
}

public static int getMinorVersion() throws InvalidVersionException {
String version = getOSVersion();
String[] tokens = version.split("\\.");
try {
checkArgument(tokens.length > 1);
return Integer.parseInt(tokens[1]);
} catch (IllegalArgumentException e) {
printSysInfo();
throw new InvalidVersionException("Version is not in expected format. Version=" + version);
}
}

public static int getMajorVersion() throws InvalidVersionException {
String version = getOSVersion();
String[] tokens = version.split("\\.");
try {
checkArgument(tokens.length > 0);
return Integer.parseInt(tokens[0]);
} catch (IllegalArgumentException e) {
printSysInfo();
throw new InvalidVersionException("Version is not in expected format. Version=" + version);
}
}

public static String getOSArchitecture() {
String osArch = System.getProperty("os.arch");
if (isWindows()) {
Expand Down Expand Up @@ -462,4 +489,5 @@ public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtr
Map<Object, Boolean> map = new ConcurrentHashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}

}
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected void setupHandlers() {
bisqSetup.setRejectedTxErrorMessageHandler(errorMessage -> log.warn("setRejectedTxErrorMessageHandler. errorMessage={}", errorMessage));
bisqSetup.setShowPopupIfInvalidBtcConfigHandler(() -> log.error("onShowPopupIfInvalidBtcConfigHandler"));
bisqSetup.setRevolutAccountsUpdateHandler(revolutAccountList -> log.info("setRevolutAccountsUpdateHandler: revolutAccountList={}", revolutAccountList));
bisqSetup.setOsxKeyLoggerWarningHandler(() -> log.info("setOsxKeyLoggerWarningHandler"));

//TODO move to bisqSetup
corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> log.warn("getCorruptedDatabaseFiles. files={}", files));
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.SealedAndSigned;
import bisq.common.proto.ProtobufferException;
import bisq.common.util.InvalidVersionException;
import bisq.common.util.Utilities;

import org.bitcoinj.core.Coin;
Expand Down Expand Up @@ -225,6 +226,9 @@ default void onRequestWalletPassword() {
@Setter
@Nullable
private Consumer<List<RevolutAccount>> revolutAccountsUpdateHandler;
@Setter
@Nullable
private Runnable osxKeyLoggerWarningHandler;

@Getter
final BooleanProperty newVersionAvailableProperty = new SimpleBooleanProperty(false);
Expand Down Expand Up @@ -347,6 +351,7 @@ private void step2() {
readMapsFromResources(this::step3);
checkCryptoSetup();
checkForCorrectOSArchitecture();
checkOSXVersion();
}

private void step3() {
Expand Down Expand Up @@ -655,6 +660,19 @@ private void checkForCorrectOSArchitecture() {
}
}

private void checkOSXVersion() {
if (Utilities.isOSX() && osxKeyLoggerWarningHandler != null) {
try {
// Seems it was introduced at 10.14: https://github.com/wesnoth/wesnoth/issues/4109
if (Utilities.getMajorVersion() >= 10 && Utilities.getMinorVersion() >= 14) {
osxKeyLoggerWarningHandler.run();
}
} catch (InvalidVersionException | NumberFormatException e) {
log.warn(e.getMessage());
}
}
}

private void initDomainServices() {
log.info("initDomainServices");

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,12 @@ error.closedTradeWithNoDepositTx=The deposit transaction of the closed trade wit
Please restart the application to clean up the closed trades list.

popup.warning.walletNotInitialized=The wallet is not initialized yet
popup.warning.osxKeyLoggerWarning=Due to stricter security measures in macOS 10.14 and above, launching a Java application \
(Bisq uses Java) causes a popup warning in macOS ('Bisq would like to receive keystrokes from any application').\n\n\
To avoid that issue please open your 'macOS Settings' and go to 'Security & Privacy' -> 'Privacy' -> \
'Input Monitoring' and Remove 'Bisq' from the list on the right side.\n\n\
Bisq will upgrade to a newer Java version to avoid that issue as soon the technical limitations \
(Java packager for the required Java version is not shipped yet) are resolved.
popup.warning.wrongVersion=You probably have the wrong Bisq version for this computer.\n\
Your computer''s architecture is: {0}.\n\
The Bisq binary you installed is: {1}.\n\
Expand Down
6 changes: 5 additions & 1 deletion desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ private void setupHandlers() {
// We copy the array as we will mutate it later
showRevolutAccountUpdateWindow(new ArrayList<>(revolutAccountList));
});

bisqSetup.setOsxKeyLoggerWarningHandler(() -> {
new Popup().warning(Res.get("popup.warning.osxKeyLoggerWarning"))
.closeButtonText(Res.get("shared.iUnderstand"))
.show();
});

corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> new Popup()
.warning(Res.get("popup.warning.incompatibleDB", files.toString(), config.appDataDir))
Expand Down

0 comments on commit 3df9428

Please sign in to comment.