Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.smartcardio/unix/classes/sun/security/smartcardio/PlatformPCSC.java
41159 views
1
/*
2
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.security.smartcardio;
27
28
import java.io.File;
29
import java.io.IOException;
30
31
import java.security.AccessController;
32
import java.security.PrivilegedAction;
33
34
import sun.security.util.Debug;
35
36
/**
37
* Platform specific code and functions for Unix / MUSCLE based PC/SC
38
* implementations.
39
*
40
* @since 1.6
41
* @author Andreas Sterbenz
42
*/
43
class PlatformPCSC {
44
45
static final Debug debug = Debug.getInstance("pcsc");
46
47
private final static String PROP_NAME = "sun.security.smartcardio.library";
48
49
private final static String LIB1 = "/usr/$LIBISA/libpcsclite.so";
50
private final static String LIB2 = "/usr/local/$LIBISA/libpcsclite.so";
51
private final static String PCSC_FRAMEWORK = "/System/Library/Frameworks/PCSC.framework/Versions/Current/PCSC";
52
53
PlatformPCSC() {
54
// empty
55
}
56
57
@SuppressWarnings("removal")
58
static final Throwable initException
59
= AccessController.doPrivileged(new PrivilegedAction<Throwable>() {
60
public Throwable run() {
61
try {
62
System.loadLibrary("j2pcsc");
63
String library = getLibraryName();
64
if (debug != null) {
65
debug.println("Using PC/SC library: " + library);
66
}
67
initialize(library);
68
return null;
69
} catch (Throwable e) {
70
return e;
71
}
72
}
73
});
74
75
// expand $LIBISA to the system specific directory name for libraries
76
private static String expand(String lib) {
77
int k = lib.indexOf("$LIBISA");
78
if (k == -1) {
79
return lib;
80
}
81
String s1 = lib.substring(0, k);
82
String s2 = lib.substring(k + 7);
83
String libDir;
84
if ("64".equals(System.getProperty("sun.arch.data.model"))) {
85
// assume Linux convention
86
libDir = "lib64";
87
} else {
88
// must be 32-bit
89
libDir = "lib";
90
}
91
String s = s1 + libDir + s2;
92
return s;
93
}
94
95
private static String getLibraryName() throws IOException {
96
// if system property is set, use that library
97
String lib = expand(System.getProperty(PROP_NAME, "").trim());
98
if (lib.length() != 0) {
99
return lib;
100
}
101
lib = expand(LIB1);
102
if (new File(lib).isFile()) {
103
// if LIB1 exists, use that
104
return lib;
105
}
106
lib = expand(LIB2);
107
if (new File(lib).isFile()) {
108
// if LIB2 exists, use that
109
return lib;
110
}
111
112
// As of macos 11, framework libraries have been removed from the file
113
// system, but in such a way that they can still be dlopen()ed, even
114
// though they can no longer be open()ed.
115
//
116
// https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
117
//
118
// """New in macOS Big Sur 11.0.1, the system ships with a built-in
119
// dynamic linker cache of all system-provided libraries. As part of
120
// this change, copies of dynamic libraries are no longer present on
121
// the filesystem. Code that attempts to check for dynamic library
122
// presence by looking for a file at a path or enumerating a directory
123
// will fail. Instead, check for library presence by attempting to
124
// dlopen() the path, which will correctly check for the library in the
125
// cache."""
126
//
127
// The directory structure remains otherwise intact, so check for
128
// existence of the containing directory instead of the file.
129
lib = PCSC_FRAMEWORK;
130
if (new File(lib).getParentFile().isDirectory()) {
131
// if PCSC.framework exists, use that
132
return lib;
133
}
134
throw new IOException("No PC/SC library found on this system");
135
}
136
137
private static native void initialize(String libraryName);
138
139
// PCSC constants defined differently under Windows and MUSCLE
140
// MUSCLE version
141
final static int SCARD_PROTOCOL_T0 = 0x0001;
142
final static int SCARD_PROTOCOL_T1 = 0x0002;
143
final static int SCARD_PROTOCOL_RAW = 0x0004;
144
145
final static int SCARD_UNKNOWN = 0x0001;
146
final static int SCARD_ABSENT = 0x0002;
147
final static int SCARD_PRESENT = 0x0004;
148
final static int SCARD_SWALLOWED = 0x0008;
149
final static int SCARD_POWERED = 0x0010;
150
final static int SCARD_NEGOTIABLE = 0x0020;
151
final static int SCARD_SPECIFIC = 0x0040;
152
153
}
154
155