author | mbalao |
Wed, 05 Jun 2019 01:42:11 -0300 | |
changeset 55258 | d65d3c37232c |
parent 47216 | 71c04702a3d5 |
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 |
* (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 |
* |
|
32003 | 41 |
* <pre>{@code |
2 | 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 |
* } |
|
32003 | 50 |
* }</pre> |
2 | 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 |
*/ |
|
73 | 58 |
public class EncKrbPrivPart { |
2 | 59 |
|
73 | 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 |
|
2 | 66 |
|
73 | 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(); |
|
2 | 76 |
} |
73 | 77 |
timestamp = new_timestamp; |
78 |
usec = new_usec; |
|
79 |
seqNumber = new_seqNumber; |
|
80 |
sAddress = new_sAddress; |
|
81 |
rAddress = new_rAddress; |
|
82 |
} |
|
2 | 83 |
|
73 | 84 |
public EncKrbPrivPart(byte[] data) throws Asn1Exception, IOException { |
85 |
init(new DerValue(data)); |
|
86 |
} |
|
2 | 87 |
|
73 | 88 |
public EncKrbPrivPart(DerValue encoding) throws Asn1Exception, IOException { |
89 |
init(encoding); |
|
90 |
} |
|
2 | 91 |
|
73 | 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 { |
|
2 | 99 |
DerValue der, subDer; |
73 | 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 { |
|
2 | 113 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
73 | 114 |
} |
115 |
timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true); |
|
116 |
if ((der.getData().peekByte() & 0x1F) == 0x02) { |
|
117 |
subDer = der.getData().getDerValue(); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
5506
diff
changeset
|
118 |
usec = subDer.getData().getBigInteger().intValue(); |
73 | 119 |
} else { |
120 |
usec = null; |
|
121 |
} |
|
122 |
if ((der.getData().peekByte() & 0x1F) == 0x03) { |
|
123 |
subDer = der.getData().getDerValue(); |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
5506
diff
changeset
|
124 |
seqNumber = subDer.getData().getBigInteger().intValue(); |
73 | 125 |
} else { |
126 |
seqNumber = null; |
|
2 | 127 |
} |
73 | 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 |
} |
|
2 | 136 |
|
73 | 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 { |
|
2 | 144 |
DerOutputStream temp = new DerOutputStream(); |
145 |
DerOutputStream bytes = new DerOutputStream(); |
|
146 |
||
73 | 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); |
|
2 | 156 |
} |
73 | 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 |
} |
|
2 | 173 |
} |