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/EncKrbPrivPart.java
41161 views
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
6
* published by the Free Software Foundation. Oracle designates this
7
* particular file as subject to the "Classpath" exception as provided
8
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
23
*/
24
25
/*
26
* (C) Copyright IBM Corp. 1999 All Rights Reserved.
27
* Copyright 1997 The Open Group Research Institute. All rights reserved.
28
*/
29
30
package sun.security.krb5.internal;
31
32
import sun.security.util.*;
33
import sun.security.krb5.Asn1Exception;
34
import java.util.Vector;
35
import java.io.IOException;
36
import java.math.BigInteger;
37
38
/**
39
* Implements the ASN.1 EncKrbPrivPart type.
40
*
41
* <pre>{@code
42
* EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE {
43
* user-data [0] OCTET STRING,
44
* timestamp [1] KerberosTime OPTIONAL,
45
* usec [2] Microseconds OPTIONAL,
46
* seq-number [3] UInt32 OPTIONAL,
47
* s-address [4] HostAddress -- sender's addr --,
48
* r-address [5] HostAddress OPTIONAL -- recip's addr
49
* }
50
* }</pre>
51
*
52
* <p>
53
* This definition reflects the Network Working Group RFC 4120
54
* specification available at
55
* <a href="http://www.ietf.org/rfc/rfc4120.txt">
56
* http://www.ietf.org/rfc/rfc4120.txt</a>.
57
*/
58
public class EncKrbPrivPart {
59
60
public byte[] userData = null;
61
public KerberosTime timestamp; //optional
62
public Integer usec; //optional
63
public Integer seqNumber; //optional
64
public HostAddress sAddress; //optional
65
public HostAddress rAddress; //optional
66
67
public EncKrbPrivPart(
68
byte[] new_userData,
69
KerberosTime new_timestamp,
70
Integer new_usec,
71
Integer new_seqNumber,
72
HostAddress new_sAddress,
73
HostAddress new_rAddress) {
74
if (new_userData != null) {
75
userData = new_userData.clone();
76
}
77
timestamp = new_timestamp;
78
usec = new_usec;
79
seqNumber = new_seqNumber;
80
sAddress = new_sAddress;
81
rAddress = new_rAddress;
82
}
83
84
public EncKrbPrivPart(byte[] data) throws Asn1Exception, IOException {
85
init(new DerValue(data));
86
}
87
88
public EncKrbPrivPart(DerValue encoding) throws Asn1Exception, IOException {
89
init(encoding);
90
}
91
92
/**
93
* Initializes an EncKrbPrivPart object.
94
* @param encoding a single DER-encoded value.
95
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
96
* @exception IOException if an I/O error occurs while reading encoded data.
97
*/
98
private void init(DerValue encoding) throws Asn1Exception, IOException {
99
DerValue der, subDer;
100
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C)
101
|| (encoding.isApplication() != true)
102
|| (encoding.isConstructed() != true)) {
103
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
104
}
105
der = encoding.getData().getDerValue();
106
if (der.getTag() != DerValue.tag_Sequence) {
107
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
108
}
109
subDer = der.getData().getDerValue();
110
if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
111
userData = subDer.getData().getOctetString();
112
} else {
113
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
114
}
115
timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
116
if ((der.getData().peekByte() & 0x1F) == 0x02) {
117
subDer = der.getData().getDerValue();
118
usec = subDer.getData().getBigInteger().intValue();
119
} else {
120
usec = null;
121
}
122
if ((der.getData().peekByte() & 0x1F) == 0x03) {
123
subDer = der.getData().getDerValue();
124
seqNumber = subDer.getData().getBigInteger().intValue();
125
} else {
126
seqNumber = null;
127
}
128
sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
129
if (der.getData().available() > 0) {
130
rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
131
}
132
if (der.getData().available() > 0) {
133
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
134
}
135
}
136
137
/**
138
* Encodes an EncKrbPrivPart object.
139
* @return byte array of encoded EncKrbPrivPart object.
140
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
141
* @exception IOException if an I/O error occurs while reading encoded data.
142
*/
143
public byte[] asn1Encode() throws Asn1Exception, IOException {
144
DerOutputStream temp = new DerOutputStream();
145
DerOutputStream bytes = new DerOutputStream();
146
147
temp.putOctetString(userData);
148
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
149
if (timestamp != null) {
150
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), timestamp.asn1Encode());
151
}
152
if (usec != null) {
153
temp = new DerOutputStream();
154
temp.putInteger(BigInteger.valueOf(usec.intValue()));
155
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), temp);
156
}
157
if (seqNumber != null) {
158
temp = new DerOutputStream();
159
// encode as an unsigned integer (UInt32)
160
temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
161
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), temp);
162
}
163
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), sAddress.asn1Encode());
164
if (rAddress != null) {
165
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), rAddress.asn1Encode());
166
}
167
temp = new DerOutputStream();
168
temp.write(DerValue.tag_Sequence, bytes);
169
bytes = new DerOutputStream();
170
bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x1C), temp);
171
return bytes.toByteArray();
172
}
173
}
174
175