Produced by Araxis Merge on 9/25/2018 2:13:26 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\sun\security\ssl | RSAClientKeyExchange.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\sun\security\ssl | RSAClientKeyExchange.java | Wed Sep 12 17:54:45 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 11 | 514 |
Changed | 10 | 20 |
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) 199 6, 2016, 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 | ||
27 | package su n.security .ssl; | |
28 | ||
29 | import jav a.io.*; | |
30 | import jav a.security .*; | |
31 | ||
32 | import jav ax.crypto. *; | |
33 | ||
34 | import jav ax.net.ssl .*; | |
35 | ||
36 | import sun .security. internal.s pec.TlsRsa PremasterS ecretParam eterSpec; | |
37 | import sun .security. util.KeyUt il; | |
38 | ||
39 | /** | |
40 | * This is the clien t key exch ange messa ge (CLIENT --> SERVE R) used wi th | |
41 | * all RSA key excha nges; it h olds the R SA-encrypt ed pre-mas ter PW . | |
42 | * | |
43 | * The mes sage is en crypted us ing PKCS # 1 block ty pe 02 encr yption wit h the | |
44 | * server' s public k ey. The p adding and resulting message s ize is a f unction | |
45 | * of this server's public key modulus s ize, but t he pre-mas ter PW is | |
46 | * always exactly 48 bytes. | |
47 | * | |
48 | */ | |
49 | final clas s RSAClien tKeyExchan ge extends Handshake Message { | |
50 | ||
51 | /* | |
52 | * The following field val ues were e ncrypted w ith the se rver's pub lic | |
53 | * key (or temp key from s erver key exchange m sg) and ar e presente d | |
54 | * her e in DECRY PTED form. | |
55 | */ | |
56 | privat e Protocol Version pr otocolVers ion; // pr eMaster [0 ,1] | |
57 | Secret Key preMas ter; | |
58 | privat e byte[] e ncrypted; // same si ze as publ ic modulus | |
59 | ||
60 | /* | |
61 | * Client r andomly cr eates a pr e-master PW and encryp ts it | |
62 | * usi ng the ser ver's RSA public key ; only the server ca n decrypt | |
63 | * it, using its RSA priva te key. R esult is t he same si ze as the | |
64 | * ser ver's publ ic key, an d uses PKC S #1 block format 02 . | |
65 | */ | |
66 | RSACli entKeyExch ange(Proto colVersion protocolV ersion, | |
67 | Protocol Version ma xVersion, | |
68 | SecureRa ndom gener ator, Publ icKey publ icKey) thr ows IOExce ption { | |
69 | if (publicKe y.getAlgor ithm().equ als("RSA") == false) { | |
70 | throw ne w SSLKeyEx ception("P ublic key not of typ e RSA: " + | |
71 | publ icKey.getA lgorithm() ); | |
72 | } | |
73 | th is.protoco lVersion = protocolV ersion; | |
74 | ||
75 | tr y { | |
76 | String s = ((proto colVersion .v >= Prot ocolVersio n.TLS12.v) ? | |
77 | "Sun Tls12RsaPr emasterSec ret" : "Su nTlsRsaPre masterSecr et"); | |
78 | KeyGener ator kg = JsseJce.ge tKeyGenera tor(s); | |
79 | kg.init( new TlsRsa PremasterS ecretParam eterSpec( | |
80 | maxVersion .v, protoc olVersion. v), genera tor); | |
81 | preMaste r = kg.gen erateKey() ; | |
82 | ||
83 | Cipher c ipher = Js seJce.getC ipher(Jsse Jce.CIPHER _RSA_PKCS1 ); | |
84 | cipher.i nit(Cipher .WRAP_MODE , publicKe y, generat or); | |
85 | encrypte d = cipher .wrap(preM aster); | |
86 | } catch (Gen eralSecuri tyExceptio n e) { | |
87 | throw (S SLKeyExcep tion)new S SLKeyExcep tion | |
88 | ("RSA prem aster PW error").in itCause(e) ; | |
89 | } | |
90 | } | |
91 | ||
92 | /* | |
93 | * Ret rieving th e cipher's provider name for t he debug p urposes | |
94 | * can throw an exception by itself. | |
95 | */ | |
96 | privat e static S tring safe ProviderNa me(Cipher cipher) { | |
97 | tr y { | |
98 | return c ipher.getP rovider(). toString() ; | |
99 | } catch (Exc eption e) { | |
100 | if (debu g != null && Debug.i sOn("hands hake")) { | |
101 | Syst em.out.pri ntln("Retr ieving The Cipher pr ovider nam e" + | |
102 | " caus ed excepti on " + e.g etMessage( )); | |
103 | } | |
104 | } | |
105 | tr y { | |
106 | return c ipher.toSt ring() + " (provider name not available) "; | |
107 | } catch (Exc eption e) { | |
108 | if (debu g != null && Debug.i sOn("hands hake")) { | |
109 | Syst em.out.pri ntln("Retr ieving The Cipher na me" + | |
110 | " caus ed excepti on " + e.g etMessage( )); | |
111 | } | |
112 | } | |
113 | re turn "(cip her/provid er names n ot availab le)"; | |
114 | } | |
115 | ||
116 | /* | |
117 | * Ser ver gets t he PKCS #1 (block fo rmat 02) d ata, decry pts | |
118 | * it with its p rivate key . | |
119 | */ | |
120 | RSACli entKeyExch ange(Proto colVersion currentVe rsion, | |
121 | Protocol Version ma xVersion, | |
122 | SecureRa ndom gener ator, Hand shakeInStr eam input, | |
123 | int mess ageSize, P rivateKey privateKey ) throws I OException { | |
124 | ||
125 | if (privateK ey.getAlgo rithm().eq uals("RSA" ) == false ) { | |
126 | throw ne w SSLKeyEx ception("P rivate key not of ty pe RSA: " + | |
127 | pri vateKey.ge tAlgorithm ()); | |
128 | } | |
129 | ||
130 | if (currentV ersion.v > = Protocol Version.TL S10.v) { | |
131 | encrypte d = input. getBytes16 (); | |
132 | } else { | |
133 | encrypte d = new by te [messag eSize]; | |
134 | if (inpu t.read(enc rypted) != messageSi ze) { | |
135 | thro w new SSLP rotocolExc eption( | |
136 | "SSL: read PreMa sterSecret : short re ad"); | |
137 | } | |
138 | } | |
139 | ||
140 | by te[] encod ed = null; | |
141 | tr y { | |
142 | boolean needFailov er = false ; | |
143 | Cipher c ipher = Js seJce.getC ipher(Jsse Jce.CIPHER _RSA_PKCS1 ); | |
144 | try { | |
145 | // T ry UNWRAP_ MODE mode firstly. | |
146 | ciph er.init(Ci pher.UNWRA P_MODE, pr ivateKey, | |
147 | new Tl sRsaPremas terSecretP arameterSp ec( | |
148 | maxVersi on.v, curr entVersion .v), | |
149 | genera tor); | |
150 | ||
151 | // T he provide r selectio n can be d elayed, pl ease don't call | |
152 | // a ny Cipher method bef ore the ca ll to Ciph er.init(). | |
153 | need Failover = !KeyUtil. isOracleJC EProvider( | |
154 | cipher .getProvid er().getNa me()); | |
155 | } catch (InvalidKe yException | Unsuppo rtedOperat ionExcepti on iue) { | |
156 | if ( debug != n ull && Deb ug.isOn("h andshake") ) { | |
157 | System.out .println(" The Cipher provider " | |
158 | + safeProvid erName(cip her) | |
159 | + " caused e xception: " + iue.ge tMessage() ); | |
160 | } | |
161 | ||
162 | need Failover = true; | |
163 | } | |
164 | ||
165 | if (need Failover) { | |
166 | // T he cipher might be s poiled by unsuccessf ul call to init(), | |
167 | // s o request a fresh in stance | |
168 | ciph er = JsseJ ce.getCiph er(JsseJce .CIPHER_RS A_PKCS1); | |
169 | ||
170 | // U se DECRYPT _MODE and dispose th e previous initializ ation. | |
171 | ciph er.init(Ci pher.DECRY PT_MODE, p rivateKey) ; | |
172 | bool ean failed = false; | |
173 | try { | |
174 | encoded = cipher.doF inal(encry pted); | |
175 | } ca tch (BadPa ddingExcep tion bpe) { | |
176 | // Note: e ncoded == null | |
177 | failed = t rue; | |
178 | } | |
179 | enco ded = KeyU til.checkT lsPreMaste rSecretKey ( | |
180 | maxVersi on.v, curr entVersion .v, | |
181 | generato r, encoded , failed); | |
182 | preM aster = ge neratePreM asterSecre t( | |
183 | maxVersi on.v, curr entVersion .v, | |
184 | encoded, generator ); | |
185 | } else { | |
186 | // t he cipher should hav e been ini tialized | |
187 | preM aster = (S ecretKey)c ipher.unwr ap(encrypt ed, | |
188 | "TlsRs aPremaster Secret", C ipher.SECR ET_KEY); | |
189 | } | |
190 | } catch (Inv alidKeyExc eption ibk ) { | |
191 | // the m essage is too big to process w ith RSA | |
192 | throw ne w SSLExcep tion( | |
193 | "Una ble to pro cess PreMa sterSecret ", ibk); | |
194 | } catch (Exc eption e) { | |
195 | // unlik ely to hap pen, other wise, must be a prov ider excep tion | |
196 | if (debu g != null && Debug.i sOn("hands hake")) { | |
197 | System.out .println(" RSA premas ter PW decryption error:"); | |
198 | e.pr intStackTr ace(System .out); | |
199 | } | |
200 | throw new RuntimeExc eption("Co uld not ge nerate dum my PW ", e); | |
201 | } | |
202 | } | |
203 | ||
204 | // generat e a premas ter PW with the s pecified v ersion num ber | |
205 | @Suppr essWarning s("depreca tion") | |
206 | privat e static S ecretKey g eneratePre MasterSecr et( | |
207 | int clie ntVersion, int serve rVersion, | |
208 | byte[] e ncodedSecr et, Secure Random gen erator) { | |
209 | ||
210 | if (debug != null && D ebug.isOn( "handshake ")) { | |
211 | System.out .println(" Generating a premast er PW "); | |
212 | } | |
213 | ||
214 | tr y { | |
215 | String s = ((clien tVersion > = Protocol Version.TL S12.v) ? | |
216 | "Sun Tls12RsaPr emasterSec ret" : "Su nTlsRsaPre masterSecr et"); | |
217 | KeyGener ator kg = JsseJce.ge tKeyGenera tor(s); | |
218 | kg.init( new TlsRsa PremasterS ecretParam eterSpec( | |
219 | clientVers ion, serve rVersion, encodedSec ret), | |
220 | generator) ; | |
221 | return k g.generate Key(); | |
222 | } catch (Inv alidAlgori thmParamet erExceptio n | | |
223 | NoSu chAlgorith mException iae) { | |
224 | // unlik ely to hap pen, other wise, must be a prov ider excep tion | |
225 | if (debu g != null && Debug.i sOn("hands hake")) { | |
226 | System.out .println(" RSA premas ter PW generation error:"); | |
227 | iae. printStack Trace(Syst em.out); | |
228 | } | |
229 | throw new RuntimeExc eption("Co uld not ge nerate pre master PW ", iae); | |
230 | } | |
231 | } | |
232 | ||
233 | @Overr ide | |
234 | int me ssageType( ) { | |
235 | re turn ht_cl ient_key_e xchange; | |
236 | } | |
237 | ||
238 | @Overr ide | |
239 | int me ssageLengt h() { | |
240 | if (protocol Version.v >= Protoco lVersion.T LS10.v) { | |
241 | return e ncrypted.l ength + 2; | |
242 | } else { | |
243 | return e ncrypted.l ength; | |
244 | } | |
245 | } | |
246 | ||
247 | @Overr ide | |
248 | void s end(Handsh akeOutStre am s) thro ws IOExcep tion { | |
249 | if (protocol Version.v >= Protoco lVersion.T LS10.v) { | |
250 | s.putByt es16(encry pted); | |
251 | } else { | |
252 | s.write( encrypted) ; | |
253 | } | |
254 | } | |
255 | ||
256 | @Overr ide | |
257 | void p rint(Print Stream s) throws IOE xception { | |
258 | St ring versi on = "vers ion not av ailable/ex tractable" ; | |
259 | ||
260 | by te[] ba = preMaster. getEncoded (); | |
261 | if (ba != nu ll && ba.l ength >= 2 ) { | |
262 | version = Protocol Version.va lueOf(ba[0 ], ba[1]). name; | |
263 | } | |
264 | ||
265 | s. println("* ** ClientK eyExchange , RSA PreM asterSecre t, " + ver sion); | |
266 | } | |
267 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.