author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58331 | e4ce29f6094e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* |
|
27 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
28 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
29 |
*/ |
|
30 |
||
31 |
package sun.security.krb5.internal; |
|
32 |
||
33 |
import sun.security.krb5.Asn1Exception; |
|
34 |
import sun.security.krb5.internal.util.KerberosFlags; |
|
35 |
import sun.security.util.*; |
|
36 |
import java.io.IOException; |
|
37 |
||
38 |
/** |
|
39 |
* Implements the ASN.1TicketFlags type. |
|
40 |
* |
|
41 |
* TicketFlags ::= BIT STRING |
|
42 |
* { |
|
43 |
* reserved(0), |
|
44 |
* forwardable(1), |
|
45 |
* forwarded(2), |
|
46 |
* proxiable(3), |
|
47 |
* proxy(4), |
|
48 |
* may-postdate(5), |
|
49 |
* postdated(6), |
|
50 |
* invalid(7), |
|
51 |
* renewable(8), |
|
52 |
* initial(9), |
|
53 |
* pre-authent(10), |
|
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
54 |
* hw-authent(11), |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
55 |
* enc-pa-rep(15) |
2 | 56 |
* } |
57 |
*/ |
|
58 |
public class TicketFlags extends KerberosFlags { |
|
59 |
public TicketFlags() { |
|
60 |
super(Krb5.TKT_OPTS_MAX + 1); |
|
61 |
} |
|
62 |
||
63 |
public TicketFlags (boolean[] flags) throws Asn1Exception { |
|
64 |
super(flags); |
|
65 |
if (flags.length > Krb5.TKT_OPTS_MAX + 1) { |
|
66 |
throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH); |
|
67 |
} |
|
68 |
} |
|
69 |
||
58331
e4ce29f6094e
8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents:
55258
diff
changeset
|
70 |
// Warning: called by NativeCreds.c and nativeccache.c |
2 | 71 |
public TicketFlags(int size, byte[] data) throws Asn1Exception { |
72 |
super(size, data); |
|
73 |
if ((size > data.length * BITS_PER_UNIT) || (size > Krb5.TKT_OPTS_MAX + 1)) |
|
74 |
throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH); |
|
75 |
} |
|
76 |
||
77 |
public TicketFlags(DerValue encoding) throws IOException, Asn1Exception { |
|
78 |
this(encoding.getUnalignedBitString(true).toBooleanArray()); |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Parse (unmarshal) a ticket flag from a DER input stream. This form |
|
83 |
* parsing might be used when expanding a value which is part of |
|
84 |
* a constructed sequence and uses explicitly tagged type. |
|
85 |
* |
|
86 |
* @exception Asn1Exception on error. |
|
87 |
* @param data the Der input stream value, which contains one or more marshaled value. |
|
88 |
* @param explicitTag tag number. |
|
89 |
* @param optional indicate if this data field is optional |
|
90 |
* @return an instance of TicketFlags. |
|
91 |
* |
|
92 |
*/ |
|
93 |
public static TicketFlags parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException { |
|
94 |
if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) |
|
95 |
return null; |
|
96 |
DerValue der = data.getDerValue(); |
|
97 |
if (explicitTag != (der.getTag() & (byte)0x1F)) { |
|
98 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
99 |
} |
|
100 |
else { |
|
101 |
DerValue subDer = der.getData().getDerValue(); |
|
102 |
return new TicketFlags(subDer); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
public Object clone() { |
|
107 |
try { |
|
108 |
return new TicketFlags(this.toBooleanArray()); |
|
109 |
} |
|
110 |
catch (Exception e) { |
|
111 |
return null; |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
public boolean match(LoginOptions options) { |
|
116 |
boolean matched = false; |
|
117 |
//We currently only consider if forwardable renewable and proxiable are match |
|
118 |
if (this.get(Krb5.TKT_OPTS_FORWARDABLE) == (options.get(KDCOptions.FORWARDABLE))) { |
|
119 |
if (this.get(Krb5.TKT_OPTS_PROXIABLE) == (options.get(KDCOptions.PROXIABLE))) { |
|
120 |
if (this.get(Krb5.TKT_OPTS_RENEWABLE) == (options.get(KDCOptions.RENEWABLE))) { |
|
121 |
matched = true; |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
return matched; |
|
126 |
} |
|
127 |
public boolean match(TicketFlags flags) { |
|
128 |
boolean matched = true; |
|
129 |
for (int i = 0; i <= Krb5.TKT_OPTS_MAX; i++) { |
|
130 |
if (this.get(i) != flags.get(i)) { |
|
131 |
return false; |
|
132 |
} |
|
133 |
} |
|
134 |
return matched; |
|
135 |
} |
|
136 |
||
137 |
||
138 |
/** |
|
139 |
* Returns the string representative of ticket flags. |
|
140 |
*/ |
|
141 |
public String toString() { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
5506
diff
changeset
|
142 |
StringBuilder sb = new StringBuilder(); |
2 | 143 |
boolean[] flags = toBooleanArray(); |
144 |
for (int i = 0; i < flags.length; i++) { |
|
145 |
if (flags[i] == true) { |
|
146 |
switch (i) { |
|
147 |
case 0: |
|
148 |
sb.append("RESERVED;"); |
|
149 |
break; |
|
150 |
case 1: |
|
151 |
sb.append("FORWARDABLE;"); |
|
152 |
break; |
|
153 |
case 2: |
|
154 |
sb.append("FORWARDED;"); |
|
155 |
break; |
|
156 |
case 3: |
|
157 |
sb.append("PROXIABLE;"); |
|
158 |
break; |
|
159 |
case 4: |
|
160 |
sb.append("PROXY;"); |
|
161 |
break; |
|
162 |
case 5: |
|
163 |
sb.append("MAY-POSTDATE;"); |
|
164 |
break; |
|
165 |
case 6: |
|
166 |
sb.append("POSTDATED;"); |
|
167 |
break; |
|
168 |
case 7: |
|
169 |
sb.append("INVALID;"); |
|
170 |
break; |
|
171 |
case 8: |
|
172 |
sb.append("RENEWABLE;"); |
|
173 |
break; |
|
174 |
case 9: |
|
175 |
sb.append("INITIAL;"); |
|
176 |
break; |
|
177 |
case 10: |
|
178 |
sb.append("PRE-AUTHENT;"); |
|
179 |
break; |
|
180 |
case 11: |
|
181 |
sb.append("HW-AUTHENT;"); |
|
182 |
break; |
|
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
183 |
case 15: |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
184 |
sb.append("ENC-PA-REP;"); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
185 |
break; |
2 | 186 |
} |
187 |
} |
|
188 |
} |
|
189 |
String result = sb.toString(); |
|
190 |
if (result.length() > 0) { |
|
191 |
result = result.substring(0, result.length() - 1); |
|
192 |
} |
|
193 |
return result; |
|
194 |
} |
|
195 |
} |