From 967cf0cdfa69ca7c9bd6c9bfa7d8ec348521ecca Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 6 Feb 2023 16:44:34 +0200 Subject: [PATCH] try to locate pcsc library on linux before searching for card terminals --- .../com/sparrowwallet/sparrow/io/CardApi.java | 24 +++++++++++++++++++ .../electrum/ElectrumServerService.java | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/io/CardApi.java b/src/main/java/com/sparrowwallet/sparrow/io/CardApi.java index 804ecf27..69456560 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/CardApi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/CardApi.java @@ -12,12 +12,14 @@ import com.sparrowwallet.drongo.wallet.WalletModel; import com.sparrowwallet.sparrow.io.ckcard.CkCardApi; import javafx.beans.property.StringProperty; import javafx.concurrent.Service; +import org.controlsfx.tools.Platform; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.smartcardio.CardException; import javax.smartcardio.CardTerminals; import javax.smartcardio.TerminalFactory; +import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Collections; @@ -26,6 +28,13 @@ import java.util.List; public abstract class CardApi { private static final Logger log = LoggerFactory.getLogger(CardApi.class); + private static File[] LINUX_PCSC_LIBS = new File[] { + new File("/usr/lib/libpcsclite.so.1"), + new File("/usr/local/lib/libpcsclite.so.1"), + new File("/lib/x86_64-linux-gnu/libpcsclite.so.1") }; + + private static boolean initialized; + public static List getConnectedCards() throws CardException { try { CkCardApi ckCardApi = new CkCardApi(null, null); @@ -80,6 +89,8 @@ public abstract class CardApi { public abstract void disconnect(); public static boolean isReaderAvailable() { + setLibrary(); + try { TerminalFactory tf = TerminalFactory.getDefault(); return !tf.terminals().list().isEmpty(); @@ -133,4 +144,17 @@ public abstract class CardApi { log.error("Failed to recover card service", e); } } + + private static void setLibrary() { + if(!initialized && Platform.getCurrent() == Platform.UNIX) { + for(File lib : LINUX_PCSC_LIBS) { + if(lib.exists()) { + System.setProperty("sun.security.smartcardio.library", lib.getAbsolutePath()); + break; + } + } + } + + initialized = true; + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/electrum/ElectrumServerService.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/electrum/ElectrumServerService.java index 7363425c..465dc888 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/electrum/ElectrumServerService.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/electrum/ElectrumServerService.java @@ -42,7 +42,7 @@ public class ElectrumServerService { @JsonRpcMethod("server.banner") public String getServerBanner() { - return SparrowWallet.APP_NAME + " " + SparrowWallet.APP_VERSION + "\n" + bitcoindClient.getNetworkInfo().subversion(); + return Cormorant.SERVER_NAME + " " + SparrowWallet.APP_VERSION + "\n" + bitcoindClient.getNetworkInfo().subversion(); } @JsonRpcMethod("blockchain.estimatefee")