Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
41161 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.jgss.wrapper;
27
28
import java.util.HashMap;
29
import java.security.Provider;
30
import java.security.AccessController;
31
import java.security.PrivilegedAction;
32
import org.ietf.jgss.Oid;
33
import sun.security.action.PutAllAction;
34
import static sun.security.util.SecurityConstants.PROVIDER_VER;
35
36
/**
37
* Defines the Sun NativeGSS provider for plugging in the
38
* native GSS mechanisms to Java GSS.
39
*
40
* List of supported mechanisms depends on the local
41
* machine configuration.
42
*
43
* @author Yu-Ching Valerie Peng
44
*/
45
46
public final class SunNativeProvider extends Provider {
47
48
private static final long serialVersionUID = -238911724858694204L;
49
50
private static final String NAME = "SunNativeGSS";
51
private static final String INFO = "Sun Native GSS provider";
52
private static final String MF_CLASS =
53
"sun.security.jgss.wrapper.NativeGSSFactory";
54
static boolean DEBUG;
55
static void debug(String message) {
56
if (DEBUG) {
57
if (message == null) {
58
throw new NullPointerException();
59
}
60
System.out.println(NAME + ": " + message);
61
}
62
}
63
64
@SuppressWarnings("removal")
65
private static final HashMap<String, String> MECH_MAP =
66
AccessController.doPrivileged(
67
new PrivilegedAction<>() {
68
public HashMap<String, String> run() {
69
DEBUG = Boolean.parseBoolean(
70
System.getProperty("sun.security.nativegss.debug"));
71
try {
72
// Ensure the InetAddress class is loaded before
73
// loading j2gss. The library will access this class
74
// and a deadlock might happen. See JDK-8210373.
75
Class.forName("java.net.InetAddress");
76
System.loadLibrary("j2gss");
77
} catch (ClassNotFoundException | Error err) {
78
debug("No j2gss library found!");
79
if (DEBUG) err.printStackTrace();
80
return null;
81
}
82
String[] gssLibs;
83
String defaultLib
84
= System.getProperty("sun.security.jgss.lib");
85
if (defaultLib == null || defaultLib.trim().equals("")) {
86
String osname = System.getProperty("os.name");
87
if (osname.startsWith("Linux")) {
88
gssLibs = new String[]{
89
"libgssapi.so",
90
"libgssapi_krb5.so",
91
"libgssapi_krb5.so.2",
92
};
93
} else if (osname.contains("OS X")) {
94
gssLibs = new String[]{
95
"libgssapi_krb5.dylib",
96
"/usr/lib/sasl2/libgssapiv2.2.so",
97
};
98
} else if (osname.contains("Windows")) {
99
// Full path needed, DLL is in jre/bin
100
gssLibs = new String[]{ System.getProperty("java.home")
101
+ "\\bin\\sspi_bridge.dll" };
102
} else {
103
gssLibs = new String[0];
104
}
105
} else {
106
gssLibs = new String[]{ defaultLib };
107
}
108
for (String libName: gssLibs) {
109
if (GSSLibStub.init(libName, DEBUG)) {
110
debug("Loaded GSS library: " + libName);
111
Oid[] mechs = GSSLibStub.indicateMechs();
112
HashMap<String,String> map = new HashMap<>();
113
for (int i = 0; i < mechs.length; i++) {
114
debug("Native MF for " + mechs[i]);
115
map.put("GssApiMechanism." + mechs[i],
116
MF_CLASS);
117
}
118
return map;
119
}
120
}
121
return null;
122
}
123
});
124
125
// initialize INSTANCE after MECH_MAP is constructed
126
static final Provider INSTANCE = new SunNativeProvider();
127
128
@SuppressWarnings("removal")
129
public SunNativeProvider() {
130
/* We are the Sun NativeGSS provider */
131
super(NAME, PROVIDER_VER, INFO);
132
133
if (MECH_MAP != null) {
134
AccessController.doPrivileged(new PutAllAction(this, MECH_MAP));
135
}
136
}
137
}
138
139