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/krb5/internal/PaPacOptions.java
41161 views
1
/*
2
* Copyright (c) 2019, Red Hat, Inc.
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.krb5.internal;
27
28
import java.io.IOException;
29
import sun.security.krb5.Asn1Exception;
30
import sun.security.krb5.internal.util.KerberosFlags;
31
import sun.security.util.DerOutputStream;
32
import sun.security.util.DerValue;
33
34
/**
35
* Implements the ASN.1 PA-PAC-OPTIONS type.
36
*
37
* <pre>{@code
38
* PA-PAC-OPTIONS ::= SEQUENCE {
39
* KerberosFlags
40
* -- Claims (0)
41
* -- Branch Aware (1)
42
* -- Forward to Full DC (2)
43
* }
44
* Note: KerberosFlags ::= BIT STRING (SIZE (32..MAX))
45
* -- minimum number of bits shall be sent, but no fewer than 32
46
*
47
* PA-PAC-OPTIONS ::= KerberosFlags
48
* -- resource-based constrained delegation (3)
49
* }</pre>
50
*
51
* This definition reflects MS-KILE (section 2.2.10)
52
* and MS-SFU (section 2.2.5).
53
*/
54
55
public class PaPacOptions {
56
57
private static final int CLAIMS = 0;
58
private static final int BRANCH_AWARE = 1;
59
private static final int FORWARD_TO_FULL_DC = 2;
60
private static final int RESOURCE_BASED_CONSTRAINED_DELEGATION = 3;
61
62
private KerberosFlags flags;
63
64
public PaPacOptions() {
65
this.flags = new KerberosFlags(Krb5.AP_OPTS_MAX + 1);
66
}
67
68
/**
69
* Constructs a PA-PAC-OPTIONS object from a DER encoding.
70
* @param encoding the ASN.1 encoded input
71
* @throws Asn1Exception if invalid DER
72
* @throws IOException if there is an error reading the DER value
73
*/
74
public PaPacOptions(DerValue encoding) throws Asn1Exception, IOException {
75
if (encoding.getTag() != DerValue.tag_Sequence) {
76
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
77
}
78
79
DerValue der = encoding.getData().getDerValue();
80
if ((der.getTag() & 0x1F) == 0x00) {
81
flags = new KDCOptions(
82
der.getData().getDerValue());
83
} else {
84
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
85
}
86
}
87
88
/**
89
* Setter for the claims flag
90
* @param value whether the claims flag is set or not
91
* @return the same PaPacOptions instance
92
*/
93
public PaPacOptions setClaims(boolean value) {
94
flags.set(CLAIMS, value);
95
return this;
96
}
97
98
/**
99
* Getter for the claims flag
100
* @return the claims flag value
101
*/
102
public boolean getClaims() {
103
return flags.get(CLAIMS);
104
}
105
106
/**
107
* Setter for the branch-aware flag
108
* @param value whether the branch-aware flag is set or not
109
* @return the same PaPacOptions instance
110
*/
111
public PaPacOptions setBranchAware(boolean value) {
112
flags.set(BRANCH_AWARE, value);
113
return this;
114
}
115
116
/**
117
* Getter for the branch-aware flag
118
* @return the branch-aware flag value
119
*/
120
public boolean getBranchAware() {
121
return flags.get(BRANCH_AWARE);
122
}
123
124
/**
125
* Setter for the forward-to-full-DC flag
126
* @param value whether the forward-to-full-DC flag is set or not
127
* @return the same PaPacOptions instance
128
*/
129
public PaPacOptions setForwardToFullDC(boolean value) {
130
flags.set(FORWARD_TO_FULL_DC, value);
131
return this;
132
}
133
134
/**
135
* Getter for the forward-to-full-DC flag
136
* @return the forward-to-full-DC flag value
137
*/
138
public boolean getForwardToFullDC() {
139
return flags.get(FORWARD_TO_FULL_DC);
140
}
141
142
/**
143
* Setter for the resource-based-constrained-delegation flag
144
* @param value whether the resource-based-constrained-delegation
145
* is set or not
146
* @return the same PaPacOptions instance
147
*/
148
public PaPacOptions setResourceBasedConstrainedDelegation(boolean value) {
149
flags.set(RESOURCE_BASED_CONSTRAINED_DELEGATION, value);
150
return this;
151
}
152
153
/**
154
* Getter for the resource-based-constrained-delegation flag
155
* @return the resource-based-constrained-delegation flag value
156
*/
157
public boolean getResourceBasedConstrainedDelegation() {
158
return flags.get(RESOURCE_BASED_CONSTRAINED_DELEGATION);
159
}
160
161
/**
162
* Encodes this PaPacOptions instance.
163
* @return an ASN.1 encoded PaPacOptions byte array
164
* @throws IOException if an I/O error occurs while encoding this
165
* PaPacOptions instance
166
*/
167
public byte[] asn1Encode() throws IOException {
168
byte[] bytes = null;
169
try(DerOutputStream temp = new DerOutputStream()) {
170
temp.write(
171
DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00),
172
flags.asn1Encode());
173
bytes = temp.toByteArray();
174
}
175
try(DerOutputStream temp = new DerOutputStream()) {
176
temp.write(DerValue.tag_Sequence, bytes);
177
return temp.toByteArray();
178
}
179
}
180
181
@Override
182
public String toString() {
183
return flags.toString();
184
}
185
}
186
187