0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.smartcardio;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/A
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/A
0N/Aimport sun.security.util.Debug;
0N/A
0N/A/**
0N/A * Platform specific code and functions for Unix / MUSCLE based PC/SC
0N/A * implementations.
0N/A *
0N/A * @since 1.6
0N/A * @author Andreas Sterbenz
0N/A */
0N/Aclass PlatformPCSC {
0N/A
0N/A static final Debug debug = Debug.getInstance("pcsc");
0N/A
0N/A static final Throwable initException;
0N/A
0N/A private final static String PROP_NAME = "sun.security.smartcardio.library";
0N/A
0N/A private final static String LIB1 = "/usr/$LIBISA/libpcsclite.so";
0N/A private final static String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";
4632N/A private final static String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";
0N/A
0N/A PlatformPCSC() {
0N/A // empty
0N/A }
0N/A
0N/A static {
0N/A initException = AccessController.doPrivileged(new PrivilegedAction<Throwable>() {
0N/A public Throwable run() {
0N/A try {
0N/A System.loadLibrary("j2pcsc");
0N/A String library = getLibraryName();
0N/A if (debug != null) {
0N/A debug.println("Using PC/SC library: " + library);
0N/A }
0N/A initialize(library);
0N/A return null;
0N/A } catch (Throwable e) {
0N/A return e;
0N/A }
0N/A }
0N/A });
0N/A }
0N/A
0N/A // expand $LIBISA to the system specific directory name for libraries
0N/A private static String expand(String lib) {
0N/A int k = lib.indexOf("$LIBISA");
0N/A if (k == -1) {
0N/A return lib;
0N/A }
0N/A String s1 = lib.substring(0, k);
0N/A String s2 = lib.substring(k + 7);
0N/A String libDir;
0N/A if ("64".equals(System.getProperty("sun.arch.data.model"))) {
0N/A if ("SunOS".equals(System.getProperty("os.name"))) {
0N/A libDir = "lib/64";
0N/A } else {
0N/A // assume Linux convention
0N/A libDir = "lib64";
0N/A }
0N/A } else {
0N/A // must be 32-bit
0N/A libDir = "lib";
0N/A }
0N/A String s = s1 + libDir + s2;
0N/A return s;
0N/A }
0N/A
0N/A private static String getLibraryName() throws IOException {
0N/A // if system property is set, use that library
0N/A String lib = expand(System.getProperty(PROP_NAME, "").trim());
0N/A if (lib.length() != 0) {
0N/A return lib;
0N/A }
0N/A lib = expand(LIB1);
0N/A if (new File(lib).isFile()) {
0N/A // if LIB1 exists, use that
0N/A return lib;
0N/A }
0N/A lib = expand(LIB2);
0N/A if (new File(lib).isFile()) {
0N/A // if LIB2 exists, use that
0N/A return lib;
0N/A }
4632N/A lib = PCSC_FRAMEWORK;
4632N/A if (new File(lib).isFile()) {
4632N/A // if PCSC.framework exists, use that
4632N/A return lib;
4632N/A }
0N/A throw new IOException("No PC/SC library found on this system");
0N/A }
0N/A
0N/A private static native void initialize(String libraryName);
0N/A
0N/A // PCSC constants defined differently under Windows and MUSCLE
0N/A // MUSCLE version
0N/A final static int SCARD_PROTOCOL_T0 = 0x0001;
0N/A final static int SCARD_PROTOCOL_T1 = 0x0002;
0N/A final static int SCARD_PROTOCOL_RAW = 0x0004;
0N/A
0N/A final static int SCARD_UNKNOWN = 0x0001;
0N/A final static int SCARD_ABSENT = 0x0002;
0N/A final static int SCARD_PRESENT = 0x0004;
0N/A final static int SCARD_SWALLOWED = 0x0008;
0N/A final static int SCARD_POWERED = 0x0010;
0N/A final static int SCARD_NEGOTIABLE = 0x0020;
0N/A final static int SCARD_SPECIFIC = 0x0040;
0N/A
0N/A}