Produced by Araxis Merge on 9/25/2018 2:13:12 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\security\auth\kerberos | KeyImpl.java | Mon Jan 22 14:46:54 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\security\auth\kerberos | KeyImpl.java | Wed Sep 12 17:23:20 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 484 |
Changed | 1 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 200 0, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package ja vax.securi ty.auth.ke rberos; | |
27 | ||
28 | import jav a.io.*; | |
29 | import jav a.util.Arr ays; | |
30 | import jav ax.crypto. SecretKey; | |
31 | import jav ax.securit y.auth.Des troyable; | |
32 | import jav ax.securit y.auth.Des troyFailed Exception; | |
33 | import sun .misc.HexD umpEncoder ; | |
34 | import sun .security. krb5.Asn1E xception; | |
35 | import sun .security. krb5.Princ ipalName; | |
36 | import sun .security. krb5.Encry ptionKey; | |
37 | import sun .security. krb5.Encry ptedData; | |
38 | import sun .security. krb5.KrbEx ception; | |
39 | import sun .security. krb5.KrbCr yptoExcept ion; | |
40 | import sun .security. util.DerVa lue; | |
41 | ||
42 | /** | |
43 | * This cl ass encaps ulates a K erberos en cryption k ey. It is not associ ated | |
44 | * with a principal and may re present an ephemeral session k ey. | |
45 | * | |
46 | * @author Mayank Up adhyay | |
47 | * @since 1.4 | |
48 | * | |
49 | * @serial include | |
50 | */ | |
51 | class KeyI mpl implem ents Secre tKey, Dest royable, S erializabl e { | |
52 | ||
53 | privat e static f inal long serialVers ionUID = - 7889313790 214321193L ; | |
54 | ||
55 | privat e transien t byte[] k eyBytes; | |
56 | privat e transien t int keyT ype; | |
57 | privat e transien t volatile boolean d estroyed = false; | |
58 | ||
59 | ||
60 | /** | |
61 | * Con structs a KeyImpl fr om the giv en bytes. | |
62 | * | |
63 | * @param k eyBytes th e raw byte s for the PW key | |
64 | * @param k eyType the key type for the PW key as def ined by th e | |
65 | * Ker beros prot ocol speci fication. | |
66 | */ | |
67 | public KeyImpl(b yte[] keyB ytes, | |
68 | int key Type) { | |
69 | th is.keyByte s = keyByt es.clone() ; | |
70 | th is.keyType = keyType ; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Con structs a KeyImpl fr om a passw ord. | |
75 | * | |
76 | * @pa ram princi pal the pr incipal fr om which t o derive t he salt | |
77 | * @pa ram passwo rd the pas sword that should be used to c ompute the | |
78 | * key . | |
79 | * @pa ram algori thm the na me for the algorithm that this key wil b e | |
80 | * use d for. Thi s paramete r may be n ull in whi ch case "D ES" will b e | |
81 | * ass umed. | |
82 | */ | |
83 | public KeyImpl(K erberosPri ncipal pri ncipal, | |
84 | c har[] pass word, | |
85 | S tring algo rithm) { | |
86 | ||
87 | tr y { | |
88 | Principa lName prin c = new Pr incipalNam e(principa l.getName( )); | |
89 | Encrypti onKey key = | |
90 | new Encryption Key(passwo rd, princ. getSalt(), algorithm ); | |
91 | this.key Bytes = ke y.getBytes (); | |
92 | this.key Type = key .getEType( ); | |
93 | } catch (Krb Exception e) { | |
94 | throw ne w IllegalA rgumentExc eption(e.g etMessage( )); | |
95 | } | |
96 | } | |
97 | ||
98 | /** | |
99 | * Ret urns the k eyType for this key as defined in the Ke rberos Spe c. | |
100 | */ | |
101 | public final int getKeyTyp e() { | |
102 | if (destroye d) | |
103 | throw ne w IllegalS tateExcept ion("This key is no longer val id"); | |
104 | re turn keyTy pe; | |
105 | } | |
106 | ||
107 | /* | |
108 | * Met hods from java.secur ity.Key | |
109 | */ | |
110 | ||
111 | public final Str ing getAlg orithm() { | |
112 | re turn getAl gorithmNam e(keyType) ; | |
113 | } | |
114 | ||
115 | privat e String g etAlgorith mName(int eType) { | |
116 | if (destroye d) | |
117 | throw ne w IllegalS tateExcept ion("This key is no longer val id"); | |
118 | ||
119 | sw itch (eTyp e) { | |
120 | ca se Encrypt edData.ETY PE_DES_CBC _CRC: | |
121 | ca se Encrypt edData.ETY PE_DES_CBC _MD5: | |
122 | return " DES"; | |
123 | ||
124 | ca se Encrypt edData.ETY PE_DES3_CB C_HMAC_SHA 1_KD: | |
125 | return " DESede"; | |
126 | ||
127 | ca se Encrypt edData.ETY PE_ARCFOUR _HMAC: | |
128 | return " ArcFourHma c"; | |
129 | ||
130 | ca se Encrypt edData.ETY PE_AES128_ CTS_HMAC_S HA1_96: | |
131 | return " AES128"; | |
132 | ||
133 | ca se Encrypt edData.ETY PE_AES256_ CTS_HMAC_S HA1_96: | |
134 | return " AES256"; | |
135 | ||
136 | ca se Encrypt edData.ETY PE_NULL: | |
137 | return " NULL"; | |
138 | ||
139 | de fault: | |
140 | throw ne w IllegalA rgumentExc eption( | |
141 | "Uns upported e ncryption type: " + eType); | |
142 | } | |
143 | } | |
144 | ||
145 | public final Str ing getFor mat() { | |
146 | if (destroye d) | |
147 | throw ne w IllegalS tateExcept ion("This key is no longer val id"); | |
148 | re turn "RAW" ; | |
149 | } | |
150 | ||
151 | public final byt e[] getEnc oded() { | |
152 | if (destroye d) | |
153 | throw ne w IllegalS tateExcept ion("This key is no longer val id"); | |
154 | re turn keyBy tes.clone( ); | |
155 | } | |
156 | ||
157 | public void dest roy() thro ws Destroy FailedExce ption { | |
158 | if (!destroy ed) { | |
159 | destroye d = true; | |
160 | Arrays.f ill(keyByt es, (byte) 0); | |
161 | } | |
162 | } | |
163 | ||
164 | public boolean i sDestroyed () { | |
165 | re turn destr oyed; | |
166 | } | |
167 | ||
168 | /** | |
169 | * @se rialData t his {@code KeyImpl} is seriali zed by | |
170 | * wri ting out t he ASN1 En coded byte s of the e ncryption key. | |
171 | * The ASN1 enco ding is de fined in R FC4120 and as follo ws: | |
172 | * Enc ryptionKey ::= SEQ UENCE { | |
173 | * keyt ype [0] Int32 -- actually e ncryption type --, | |
174 | * keyv alue [1] OCTET STR ING | |
175 | * } | |
176 | */ | |
177 | privat e void wri teObject(O bjectOutpu tStream oi s) | |
178 | thro ws IOExcep tion { | |
179 | if (destroye d) { | |
180 | throw new IOExcepti on("This k ey is no l onger vali d"); | |
181 | } | |
182 | ||
183 | tr y { | |
184 | ois.write Object((ne w Encrypti onKey(keyT ype, keyBy tes)).asn1 Encode()); | |
185 | } catch (Asn 1Exception ae) { | |
186 | throw new IOExcepti on(ae.getM essage()); | |
187 | } | |
188 | } | |
189 | ||
190 | privat e void rea dObject(Ob jectInputS tream ois) | |
191 | thro ws IOExcep tion, Clas sNotFoundE xception { | |
192 | tr y { | |
193 | Encrypti onKey encK ey = new E ncryptionK ey(new | |
194 | Der Value((byt e[])ois.re adObject() )); | |
195 | keyType = encKey.g etEType(); | |
196 | keyBytes = encKey. getBytes() ; | |
197 | } catch (Asn 1Exception ae) { | |
198 | throw ne w IOExcept ion(ae.get Message()) ; | |
199 | } | |
200 | } | |
201 | ||
202 | public String to String() { | |
203 | He xDumpEncod er hd = ne w HexDumpE ncoder(); | |
204 | re turn "Encr yptionKey: keyType=" + keyType | |
205 | + " keyBytes ( hex dump)= " | |
206 | + (k eyBytes == null || k eyBytes.le ngth == 0 ? | |
207 | " Empty Key " : | |
208 | ' \n' + hd.e ncodeBuffe r(keyBytes ) | |
209 | + '\ n'); | |
210 | ||
211 | ||
212 | } | |
213 | ||
214 | public int hashC ode() { | |
215 | in t result = 17; | |
216 | if (isDestroy ed()) { | |
217 | return r esult; | |
218 | } | |
219 | re sult = 37 * result + Arrays.ha shCode(key Bytes); | |
220 | re turn 37 * result + k eyType; | |
221 | } | |
222 | ||
223 | public boolean e quals(Obje ct other) { | |
224 | ||
225 | if (other == this) | |
226 | return t rue; | |
227 | ||
228 | if (! (other instanceo f KeyImpl) ) { | |
229 | return f alse; | |
230 | } | |
231 | ||
232 | Ke yImpl othe rKey = ((K eyImpl) ot her); | |
233 | if (isDestro yed() || o therKey.is Destroyed( )) { | |
234 | return f alse; | |
235 | } | |
236 | ||
237 | if (keyType ! = otherKey .getKeyTyp e() || | |
238 | !Arr ays.equals (keyBytes, otherKey. getEncoded ())) { | |
239 | return f alse; | |
240 | } | |
241 | ||
242 | re turn true; | |
243 | } | |
244 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.