8009550: PlatformPCSC should load versioned so

Reviewed-by: valeriep, stuefe
This commit is contained in:
Andrew John Hughes 2023-10-31 02:06:41 +00:00
parent d051f22284
commit 328b381075
2 changed files with 50 additions and 24 deletions

View File

@ -81,6 +81,7 @@ public class Debug {
System.err.println("logincontext login context results");
System.err.println("jca JCA engine class debugging");
System.err.println("keystore KeyStore debugging");
System.err.println("pcsc Smartcard library debugging");
System.err.println("policy loading and granting");
System.err.println("provider security provider debugging");
System.err.println("pkcs11 PKCS11 session manager debugging");

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,8 +47,14 @@ class PlatformPCSC {
private static final String PROP_NAME = "sun.security.smartcardio.library";
private static final String LIB1 = "/usr/$LIBISA/libpcsclite.so";
private static final String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";
// The architecture templates are for Debian-based systems: https://wiki.debian.org/Multiarch/Tuples
// 32-bit arm differs from the pattern of the rest and has to be specified explicitly
private static final String[] LIB_TEMPLATES = { "/usr/$LIBISA/libpcsclite.so",
"/usr/local/$LIBISA/libpcsclite.so",
"/usr/lib/$ARCH-linux-gnu/libpcsclite.so",
"/usr/lib/arm-linux-gnueabi/libpcsclite.so",
"/usr/lib/arm-linux-gnueabihf/libpcsclite.so" };
private static final String[] LIB_SUFFIXES = { ".1", ".0", "" };
private static final String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";
PlatformPCSC() {
@ -73,23 +80,38 @@ class PlatformPCSC {
});
// expand $LIBISA to the system specific directory name for libraries
// expand $ARCH to the Debian system architecture in use
private static String expand(String lib) {
int k = lib.indexOf("$LIBISA");
if (k == -1) {
return lib;
if (k != -1) {
String libDir;
if ("64".equals(System.getProperty("sun.arch.data.model"))) {
// assume Linux convention
libDir = "lib64";
} else {
// must be 32-bit
libDir = "lib";
}
lib = lib.replace("$LIBISA", libDir);
}
String s1 = lib.substring(0, k);
String s2 = lib.substring(k + 7);
String libDir;
if ("64".equals(System.getProperty("sun.arch.data.model"))) {
// assume Linux convention
libDir = "lib64";
} else {
// must be 32-bit
libDir = "lib";
k = lib.indexOf("$ARCH");
if (k != -1) {
String arch = System.getProperty("os.arch");
lib = lib.replace("$ARCH", getDebianArchitecture(arch));
}
String s = s1 + libDir + s2;
return s;
return lib;
}
private static String getDebianArchitecture(String jdkArch) {
return switch (jdkArch) {
case "amd64" -> "x86_64";
case "ppc" -> "powerpc";
case "ppc64" -> "powerpc64";
case "ppc64le" -> "powerpc64le";
default -> jdkArch;
};
}
private static String getLibraryName() throws IOException {
@ -98,15 +120,18 @@ class PlatformPCSC {
if (lib.length() != 0) {
return lib;
}
lib = expand(LIB1);
if (new File(lib).isFile()) {
// if LIB1 exists, use that
return lib;
}
lib = expand(LIB2);
if (new File(lib).isFile()) {
// if LIB2 exists, use that
return lib;
for (String template : LIB_TEMPLATES) {
for (String suffix : LIB_SUFFIXES) {
lib = expand(template) + suffix;
if (debug != null) {
debug.println("Looking for " + lib);
}
if (new File(lib).isFile()) {
// if library exists, use that
return lib;
}
}
}
// As of macos 11, framework libraries have been removed from the file