Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/security/smartcardio/PlatformPCSC.java
32288 views
/*1* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.smartcardio;2627import java.io.File;28import java.io.IOException;2930import java.security.AccessController;31import java.security.PrivilegedAction;3233import sun.security.util.Debug;3435/**36* Platform specific code and functions for Unix / MUSCLE based PC/SC37* implementations.38*39* @since 1.640* @author Andreas Sterbenz41*/42class PlatformPCSC {4344static final Debug debug = Debug.getInstance("pcsc");4546static final Throwable initException;4748private final static String PROP_NAME = "sun.security.smartcardio.library";4950private final static String LIB1 = "/usr/$LIBISA/libpcsclite.so";51private final static String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";52private final static String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";5354PlatformPCSC() {55// empty56}5758static {59initException = AccessController.doPrivileged(new PrivilegedAction<Throwable>() {60public Throwable run() {61try {62System.loadLibrary("j2pcsc");63String library = getLibraryName();64if (debug != null) {65debug.println("Using PC/SC library: " + library);66}67initialize(library);68return null;69} catch (Throwable e) {70return e;71}72}73});74}7576// expand $LIBISA to the system specific directory name for libraries77private static String expand(String lib) {78int k = lib.indexOf("$LIBISA");79if (k == -1) {80return lib;81}82String s1 = lib.substring(0, k);83String s2 = lib.substring(k + 7);84String libDir;85if ("64".equals(System.getProperty("sun.arch.data.model"))) {86if ("SunOS".equals(System.getProperty("os.name"))) {87libDir = "lib/64";88} else {89// assume Linux convention90libDir = "lib64";91}92} else {93// must be 32-bit94libDir = "lib";95}96String s = s1 + libDir + s2;97return s;98}99100private static String getLibraryName() throws IOException {101// if system property is set, use that library102String lib = expand(System.getProperty(PROP_NAME, "").trim());103if (lib.length() != 0) {104return lib;105}106lib = expand(LIB1);107if (new File(lib).isFile()) {108// if LIB1 exists, use that109return lib;110}111lib = expand(LIB2);112if (new File(lib).isFile()) {113// if LIB2 exists, use that114return lib;115}116lib = PCSC_FRAMEWORK;117if (new File(lib).isFile()) {118// if PCSC.framework exists, use that119return lib;120}121throw new IOException("No PC/SC library found on this system");122}123124private static native void initialize(String libraryName);125126// PCSC constants defined differently under Windows and MUSCLE127// MUSCLE version128final static int SCARD_PROTOCOL_T0 = 0x0001;129final static int SCARD_PROTOCOL_T1 = 0x0002;130final static int SCARD_PROTOCOL_RAW = 0x0004;131132final static int SCARD_UNKNOWN = 0x0001;133final static int SCARD_ABSENT = 0x0002;134final static int SCARD_PRESENT = 0x0004;135final static int SCARD_SWALLOWED = 0x0008;136final static int SCARD_POWERED = 0x0010;137final static int SCARD_NEGOTIABLE = 0x0020;138final static int SCARD_SPECIFIC = 0x0040;139140}141142143