src/java.smartcardio/unix/classes/sun/security/smartcardio/PlatformPCSC.java
author fyang
Thu, 24 May 2018 07:20:10 +0800
changeset 50242 9a87afc49148
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203041: AArch64: fix overflow in immediate cmp/cmn instruction Summary: fix overflow in immediate cmp/cmn instruction for AArch64 Reviewed-by: aph, dpochepk, drwhite Contributed-by: joshua.zhu@arm.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12047
diff changeset
     2
 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.smartcardio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Platform specific code and functions for Unix / MUSCLE based PC/SC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class PlatformPCSC {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final Debug debug = Debug.getInstance("pcsc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final Throwable initException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final static String PROP_NAME = "sun.security.smartcardio.library";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final static String LIB1 = "/usr/$LIBISA/libpcsclite.so";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final static String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    53
    private final static String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    PlatformPCSC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        initException = AccessController.doPrivileged(new PrivilegedAction<Throwable>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            public Throwable run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    System.loadLibrary("j2pcsc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                    String library = getLibraryName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                        debug.println("Using PC/SC library: " + library);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                    initialize(library);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // expand $LIBISA to the system specific directory name for libraries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static String expand(String lib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int k = lib.indexOf("$LIBISA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (k == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return lib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String s1 = lib.substring(0, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        String s2 = lib.substring(k + 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        String libDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if ("64".equals(System.getProperty("sun.arch.data.model"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            if ("SunOS".equals(System.getProperty("os.name"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                libDir = "lib/64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                // assume Linux convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                libDir = "lib64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            // must be 32-bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            libDir = "lib";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        String s = s1 + libDir + s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static String getLibraryName() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // if system property is set, use that library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        String lib = expand(System.getProperty(PROP_NAME, "").trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (lib.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return lib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        lib = expand(LIB1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (new File(lib).isFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            // if LIB1 exists, use that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return lib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        lib = expand(LIB2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (new File(lib).isFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            // if LIB2 exists, use that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return lib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   117
        lib = PCSC_FRAMEWORK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   118
        if (new File(lib).isFile()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   119
            // if PCSC.framework exists, use that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   120
            return lib;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   121
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        throw new IOException("No PC/SC library found on this system");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static native void initialize(String libraryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // PCSC constants defined differently under Windows and MUSCLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // MUSCLE version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    final static int SCARD_PROTOCOL_T0     =  0x0001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    final static int SCARD_PROTOCOL_T1     =  0x0002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    final static int SCARD_PROTOCOL_RAW    =  0x0004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    final static int SCARD_UNKNOWN         =  0x0001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    final static int SCARD_ABSENT          =  0x0002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    final static int SCARD_PRESENT         =  0x0004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    final static int SCARD_SWALLOWED       =  0x0008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    final static int SCARD_POWERED         =  0x0010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    final static int SCARD_NEGOTIABLE      =  0x0020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    final static int SCARD_SPECIFIC        =  0x0040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}