author | smarks |
Wed, 12 Jan 2011 13:52:09 -0800 | |
changeset 7977 | f47f211cd627 |
parent 5506 | 202f599c92aa |
child 13247 | 74902cfeb9c6 |
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.*; |
|
34 |
import sun.security.util.*; |
|
35 |
import java.util.Vector; |
|
36 |
import java.io.IOException; |
|
37 |
||
38 |
/** |
|
39 |
* Implements the ASN.1 KrbCredInfo type. |
|
40 |
* |
|
41 |
* <xmp> |
|
42 |
* KrbCredInfo ::= SEQUENCE { |
|
43 |
* key [0] EncryptionKey, |
|
44 |
* prealm [1] Realm OPTIONAL, |
|
45 |
* pname [2] PrincipalName OPTIONAL, |
|
46 |
* flags [3] TicketFlags OPTIONAL, |
|
47 |
* authtime [4] KerberosTime OPTIONAL, |
|
48 |
* starttime [5] KerberosTime OPTIONAL, |
|
49 |
* endtime [6] KerberosTime OPTIONAL, |
|
50 |
* renew-till [7] KerberosTime OPTIONAL, |
|
51 |
* srealm [8] Realm OPTIONAL, |
|
52 |
* sname [9] PrincipalName OPTIONAL, |
|
53 |
* caddr [10] HostAddresses OPTIONAL |
|
54 |
* } |
|
55 |
* </xmp> |
|
56 |
* |
|
57 |
* <p> |
|
58 |
* This definition reflects the Network Working Group RFC 4120 |
|
59 |
* specification available at |
|
60 |
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> |
|
61 |
* http://www.ietf.org/rfc/rfc4120.txt</a>. |
|
62 |
*/ |
|
63 |
||
64 |
public class KrbCredInfo { |
|
65 |
public EncryptionKey key; |
|
66 |
public Realm prealm; //optional |
|
67 |
public PrincipalName pname; //optional |
|
68 |
public TicketFlags flags; //optional |
|
69 |
public KerberosTime authtime; //optional |
|
70 |
public KerberosTime starttime; //optional |
|
71 |
public KerberosTime endtime; //optional |
|
72 |
public KerberosTime renewTill; //optional |
|
73 |
public Realm srealm; //optional |
|
74 |
public PrincipalName sname; //optional |
|
75 |
public HostAddresses caddr; //optional |
|
76 |
||
77 |
private KrbCredInfo() { |
|
78 |
} |
|
79 |
||
80 |
public KrbCredInfo( |
|
81 |
EncryptionKey new_key, |
|
82 |
Realm new_prealm, |
|
83 |
PrincipalName new_pname, |
|
84 |
TicketFlags new_flags, |
|
85 |
KerberosTime new_authtime, |
|
86 |
KerberosTime new_starttime, |
|
87 |
KerberosTime new_endtime, |
|
88 |
KerberosTime new_renewTill, |
|
89 |
Realm new_srealm, |
|
90 |
PrincipalName new_sname, |
|
91 |
HostAddresses new_caddr |
|
92 |
) { |
|
93 |
key = new_key; |
|
94 |
prealm = new_prealm; |
|
95 |
pname = new_pname; |
|
96 |
flags = new_flags; |
|
97 |
authtime = new_authtime; |
|
98 |
starttime = new_starttime; |
|
99 |
endtime = new_endtime; |
|
100 |
renewTill = new_renewTill; |
|
101 |
srealm = new_srealm; |
|
102 |
sname = new_sname; |
|
103 |
caddr = new_caddr; |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Constructs a KrbCredInfo object. |
|
108 |
* @param encoding a Der-encoded data. |
|
109 |
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. |
|
110 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
111 |
* @exception RealmException if an error occurs while parsing a Realm object. |
|
112 |
*/ |
|
113 |
public KrbCredInfo(DerValue encoding) |
|
73 | 114 |
throws Asn1Exception, IOException, RealmException{ |
2 | 115 |
if (encoding.getTag() != DerValue.tag_Sequence) { |
116 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
117 |
} |
|
118 |
prealm = null; |
|
119 |
pname = null; |
|
120 |
flags = null; |
|
121 |
authtime = null; |
|
122 |
starttime = null; |
|
123 |
endtime = null; |
|
124 |
renewTill = null; |
|
125 |
srealm = null; |
|
126 |
sname = null; |
|
127 |
caddr = null; |
|
128 |
key = EncryptionKey.parse(encoding.getData(), (byte)0x00, false); |
|
129 |
if (encoding.getData().available() > 0) |
|
130 |
prealm = Realm.parse(encoding.getData(), (byte)0x01, true); |
|
131 |
if (encoding.getData().available() > 0) |
|
132 |
pname = PrincipalName.parse(encoding.getData(), (byte)0x02, true); |
|
133 |
if (encoding.getData().available() > 0) |
|
134 |
flags = TicketFlags.parse(encoding.getData(), (byte)0x03, true); |
|
135 |
if (encoding.getData().available() > 0) |
|
136 |
authtime = KerberosTime.parse(encoding.getData(), (byte)0x04, true); |
|
137 |
if (encoding.getData().available() > 0) |
|
138 |
starttime = KerberosTime.parse(encoding.getData(), (byte)0x05, true); |
|
139 |
if (encoding.getData().available() > 0) |
|
140 |
endtime = KerberosTime.parse(encoding.getData(), (byte)0x06, true); |
|
141 |
if (encoding.getData().available() > 0) |
|
142 |
renewTill = KerberosTime.parse(encoding.getData(), (byte)0x07, true); |
|
143 |
if (encoding.getData().available() > 0) |
|
144 |
srealm = Realm.parse(encoding.getData(), (byte)0x08, true); |
|
145 |
if (encoding.getData().available() > 0) |
|
146 |
sname = PrincipalName.parse(encoding.getData(), (byte)0x09, true); |
|
147 |
if (encoding.getData().available() > 0) |
|
148 |
caddr = HostAddresses.parse(encoding.getData(), (byte)0x0A, true); |
|
149 |
if (encoding.getData().available() > 0) |
|
150 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Encodes an KrbCredInfo object. |
|
155 |
* @return the byte array of encoded KrbCredInfo object. |
|
156 |
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data. |
|
157 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
158 |
*/ |
|
159 |
public byte[] asn1Encode() throws Asn1Exception, IOException { |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
5506
diff
changeset
|
160 |
Vector<DerValue> v = new Vector<>(); |
2 | 161 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode())); |
162 |
if (prealm != null) |
|
73 | 163 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), prealm.asn1Encode())); |
2 | 164 |
if (pname != null) |
73 | 165 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode())); |
2 | 166 |
if (flags != null) |
73 | 167 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode())); |
2 | 168 |
if (authtime != null) |
73 | 169 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authtime.asn1Encode())); |
2 | 170 |
if (starttime != null) |
73 | 171 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), starttime.asn1Encode())); |
2 | 172 |
if (endtime != null) |
73 | 173 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode())); |
2 | 174 |
if (renewTill != null) |
73 | 175 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode())); |
2 | 176 |
if (srealm != null) |
73 | 177 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), srealm.asn1Encode())); |
2 | 178 |
if (sname != null) |
73 | 179 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode())); |
2 | 180 |
if (caddr != null) |
73 | 181 |
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode())); |
2 | 182 |
DerValue der[] = new DerValue[v.size()]; |
183 |
v.copyInto(der); |
|
184 |
DerOutputStream out = new DerOutputStream(); |
|
185 |
out.putSequence(der); |
|
186 |
return out.toByteArray(); |
|
187 |
} |
|
188 |
||
189 |
public Object clone() { |
|
190 |
KrbCredInfo kcred = new KrbCredInfo(); |
|
191 |
kcred.key = (EncryptionKey)key.clone(); |
|
192 |
// optional fields |
|
193 |
if (prealm != null) |
|
194 |
kcred.prealm = (Realm)prealm.clone(); |
|
195 |
if (pname != null) |
|
196 |
kcred.pname = (PrincipalName)pname.clone(); |
|
197 |
if (flags != null) |
|
198 |
kcred.flags = (TicketFlags)flags.clone(); |
|
199 |
if (authtime != null) |
|
200 |
kcred.authtime = (KerberosTime)authtime.clone(); |
|
201 |
if (starttime != null) |
|
202 |
kcred.starttime = (KerberosTime)starttime.clone(); |
|
203 |
if (endtime != null) |
|
204 |
kcred.endtime = (KerberosTime)endtime.clone(); |
|
205 |
if (renewTill != null) |
|
206 |
kcred.renewTill = (KerberosTime)renewTill.clone(); |
|
207 |
if (srealm != null) |
|
208 |
kcred.srealm = (Realm)srealm.clone(); |
|
209 |
if (sname != null) |
|
210 |
kcred.sname = (PrincipalName)sname.clone(); |
|
211 |
if (caddr != null) |
|
212 |
kcred.caddr = (HostAddresses)caddr.clone(); |
|
213 |
return kcred; |
|
214 |
} |
|
215 |
||
216 |
} |