try to locate pcsc library on linux before searching for card terminals

This commit is contained in:
Craig Raw 2023-02-06 16:44:34 +02:00
parent 41ba8455a0
commit 967cf0cdfa
2 changed files with 25 additions and 1 deletions

View file

@ -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<WalletModel> 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;
}
}

View file

@ -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")