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/GSSCredElement.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
package sun.security.jgss.wrapper;
26
27
import org.ietf.jgss.*;
28
import java.security.Provider;
29
import sun.security.jgss.GSSUtil;
30
import sun.security.jgss.spi.GSSCredentialSpi;
31
import sun.security.jgss.spi.GSSNameSpi;
32
33
/**
34
* This class is essentially a wrapper class for the gss_cred_id_t
35
* structure of the native GSS library.
36
* @author Valerie Peng
37
* @since 1.6
38
*/
39
public class GSSCredElement implements GSSCredentialSpi {
40
41
private int usage;
42
long pCred; // Pointer to the gss_cred_id_t structure
43
private GSSNameElement name = null;
44
private GSSLibStub cStub;
45
46
// Perform the necessary ServicePermission check on this cred
47
@SuppressWarnings("removal")
48
void doServicePermCheck() throws GSSException {
49
if (GSSUtil.isKerberosMech(cStub.getMech())) {
50
if (System.getSecurityManager() != null) {
51
if (isInitiatorCredential()) {
52
String tgsName = Krb5Util.getTGSName(name);
53
Krb5Util.checkServicePermission(tgsName, "initiate");
54
}
55
if (isAcceptorCredential() &&
56
name != GSSNameElement.DEF_ACCEPTOR) {
57
String krbName = name.getKrbName();
58
Krb5Util.checkServicePermission(krbName, "accept");
59
}
60
}
61
}
62
}
63
64
// Construct delegation cred using the actual context mech and srcName
65
// Warning: called by NativeUtil.c
66
GSSCredElement(long pCredentials, GSSNameElement srcName, Oid mech)
67
throws GSSException {
68
pCred = pCredentials;
69
cStub = GSSLibStub.getInstance(mech);
70
usage = GSSCredential.INITIATE_ONLY;
71
name = srcName;
72
}
73
74
GSSCredElement(GSSNameElement name, int lifetime, int usage,
75
GSSLibStub stub) throws GSSException {
76
cStub = stub;
77
this.usage = usage;
78
79
if (name != null) { // Could be GSSNameElement.DEF_ACCEPTOR
80
this.name = name;
81
doServicePermCheck();
82
pCred = cStub.acquireCred(this.name.pName, lifetime, usage);
83
} else {
84
pCred = cStub.acquireCred(0, lifetime, usage);
85
this.name = new GSSNameElement(cStub.getCredName(pCred), cStub);
86
doServicePermCheck();
87
}
88
}
89
90
public Provider getProvider() {
91
return SunNativeProvider.INSTANCE;
92
}
93
94
public void dispose() throws GSSException {
95
name = null;
96
if (pCred != 0) {
97
pCred = cStub.releaseCred(pCred);
98
}
99
}
100
101
public GSSNameElement getName() throws GSSException {
102
return (name == GSSNameElement.DEF_ACCEPTOR ?
103
null : name);
104
}
105
106
public int getInitLifetime() throws GSSException {
107
if (isInitiatorCredential()) {
108
return cStub.getCredTime(pCred);
109
} else return 0;
110
}
111
112
public int getAcceptLifetime() throws GSSException {
113
if (isAcceptorCredential()) {
114
return cStub.getCredTime(pCred);
115
} else return 0;
116
}
117
118
public boolean isInitiatorCredential() {
119
return (usage != GSSCredential.ACCEPT_ONLY);
120
}
121
122
public boolean isAcceptorCredential() {
123
return (usage != GSSCredential.INITIATE_ONLY);
124
}
125
126
public Oid getMechanism() {
127
return cStub.getMech();
128
}
129
130
public String toString() {
131
// No hex bytes available for native impl
132
return "N/A";
133
}
134
135
@SuppressWarnings("deprecation")
136
protected void finalize() throws Throwable {
137
dispose();
138
}
139
140
@Override
141
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
142
throw new GSSException(GSSException.FAILURE, -1,
143
"Not supported yet");
144
}
145
}
146
147