author | jnimeh |
Wed, 06 Jun 2018 23:53:47 -0700 | |
branch | JDK-8145252-TLS13-branch |
changeset 56686 | 07dc566630ee |
parent 56660 | 66c803c3ce32 |
child 56784 | 6210466cf1ac |
permissions | -rw-r--r-- |
56542 | 1 |
/* |
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.nio.ByteBuffer; |
|
30 |
import java.security.GeneralSecurityException; |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
31 |
import java.text.MessageFormat; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
32 |
import java.util.Locale; |
56542 | 33 |
|
34 |
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
35 |
import sun.security.ssl.SSLCipher.SSLReadCipher; |
|
36 |
import sun.security.ssl.SSLCipher.SSLWriteCipher; |
|
37 |
||
38 |
import javax.crypto.SecretKey; |
|
39 |
import javax.crypto.spec.IvParameterSpec; |
|
40 |
||
41 |
/** |
|
42 |
* Pack of the KeyUpdate handshake message. |
|
43 |
*/ |
|
44 |
final class KeyUpdate { |
|
45 |
static final SSLProducer kickstartProducer = |
|
46 |
new KeyUpdateKickstartProducer(); |
|
47 |
||
48 |
static final SSLConsumer handshakeConsumer = |
|
49 |
new KeyUpdateConsumer(); |
|
50 |
static final HandshakeProducer handshakeProducer = |
|
51 |
new KeyUpdateProducer(); |
|
52 |
||
53 |
/** |
|
54 |
* The KeyUpdate handshake message. |
|
55 |
* |
|
56 |
* The KeyUpdate handshake message is used to indicate that the sender is |
|
57 |
* updating its sending cryptographic keys. |
|
58 |
* |
|
59 |
* enum { |
|
60 |
* update_not_requested(0), update_requested(1), (255) |
|
61 |
* } KeyUpdateRequest; |
|
62 |
* |
|
63 |
* struct { |
|
64 |
* KeyUpdateRequest request_update; |
|
65 |
* } KeyUpdate; |
|
66 |
*/ |
|
67 |
static final class KeyUpdateMessage extends HandshakeMessage { |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
68 |
private final KeyUpdateRequest status; |
56542 | 69 |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
70 |
KeyUpdateMessage(PostHandshakeContext context, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
71 |
KeyUpdateRequest status) { |
56542 | 72 |
super(context); |
73 |
this.status = status; |
|
74 |
} |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
75 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
76 |
KeyUpdateMessage(PostHandshakeContext context, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
77 |
ByteBuffer m) throws IOException { |
56542 | 78 |
super(context); |
79 |
||
80 |
if (m.remaining() != 1) { |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
81 |
context.conContext.fatal(Alert.ILLEGAL_PARAMETER, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
82 |
"KeyUpdate has an unexpected length of "+ |
56542 | 83 |
m.remaining()); |
84 |
} |
|
85 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
86 |
byte request = m.get(); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
87 |
this.status = KeyUpdateRequest.valueOf(request); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
88 |
if (status == null) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
89 |
context.conContext.fatal(Alert.ILLEGAL_PARAMETER, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
90 |
"Invalid KeyUpdate message value: " + |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
91 |
KeyUpdateRequest.nameOf(request)); |
56542 | 92 |
} |
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
public SSLHandshake handshakeType() { |
|
97 |
return SSLHandshake.KEY_UPDATE; |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
public int messageLength() { |
|
102 |
// one byte enum |
|
103 |
return 1; |
|
104 |
} |
|
105 |
||
106 |
@Override |
|
107 |
public void send(HandshakeOutStream s) throws IOException { |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
108 |
s.putInt8(status.id); |
56542 | 109 |
} |
110 |
||
111 |
@Override |
|
112 |
public String toString() { |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
113 |
MessageFormat messageFormat = new MessageFormat( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
114 |
"\"KeyUpdate\": '{'\n" + |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
115 |
" \"request_update\": {0}\n" + |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
116 |
"'}'", |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
117 |
Locale.ENGLISH); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
118 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
119 |
Object[] messageFields = { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
120 |
status.name |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
121 |
}; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
122 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
123 |
return messageFormat.format(messageFields); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
124 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
125 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
126 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
127 |
enum KeyUpdateRequest { |
56686
07dc566630ee
Address TLS 1.3 comments output stream classes, go through JsseJce class to get Mac instance.
jnimeh
parents:
56660
diff
changeset
|
128 |
NOTREQUESTED ((byte)0, "update_not_requested"), |
07dc566630ee
Address TLS 1.3 comments output stream classes, go through JsseJce class to get Mac instance.
jnimeh
parents:
56660
diff
changeset
|
129 |
REQUESTED ((byte)1, "update_requested"); |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
130 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
131 |
final byte id; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
132 |
final String name; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
133 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
134 |
private KeyUpdateRequest(byte id, String name) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
135 |
this.id = id; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
136 |
this.name = name; |
56542 | 137 |
} |
138 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
139 |
static KeyUpdateRequest valueOf(byte id) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
140 |
for (KeyUpdateRequest kur : KeyUpdateRequest.values()) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
141 |
if (kur.id == id) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
142 |
return kur; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
143 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
144 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
145 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
146 |
return null; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
147 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
148 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
149 |
static String nameOf(byte id) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
150 |
for (KeyUpdateRequest kur : KeyUpdateRequest.values()) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
151 |
if (kur.id == id) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
152 |
return kur.name; |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
153 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
154 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
155 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
156 |
return "<UNKNOWN KeyUpdateRequest TYPE: " + (id & 0x0FF) + ">"; |
56542 | 157 |
} |
158 |
} |
|
159 |
||
160 |
private static final |
|
161 |
class KeyUpdateKickstartProducer implements SSLProducer { |
|
162 |
// Prevent instantiation of this class. |
|
163 |
private KeyUpdateKickstartProducer() { |
|
164 |
// blank |
|
165 |
} |
|
166 |
||
167 |
// Produce kickstart handshake message. |
|
168 |
@Override |
|
169 |
public byte[] produce(ConnectionContext context) throws IOException { |
|
56544
ad120e0dfcfb
start/beginHandshake and more post-handshake changes
ascarpino
parents:
56542
diff
changeset
|
170 |
PostHandshakeContext hc = (PostHandshakeContext)context; |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
171 |
return handshakeProducer.produce(context, |
56686
07dc566630ee
Address TLS 1.3 comments output stream classes, go through JsseJce class to get Mac instance.
jnimeh
parents:
56660
diff
changeset
|
172 |
new KeyUpdateMessage(hc, KeyUpdateRequest.REQUESTED)); |
56542 | 173 |
} |
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* The "KeyUpdate" handshake message consumer. |
|
178 |
*/ |
|
179 |
private static final class KeyUpdateConsumer implements SSLConsumer { |
|
180 |
// Prevent instantiation of this class. |
|
181 |
private KeyUpdateConsumer() { |
|
182 |
// blank |
|
183 |
} |
|
184 |
||
185 |
@Override |
|
186 |
public void consume(ConnectionContext context, |
|
187 |
ByteBuffer message) throws IOException { |
|
188 |
// The consuming happens in client side only. |
|
56544
ad120e0dfcfb
start/beginHandshake and more post-handshake changes
ascarpino
parents:
56542
diff
changeset
|
189 |
PostHandshakeContext hc = (PostHandshakeContext)context; |
56542 | 190 |
KeyUpdateMessage km = new KeyUpdateMessage(hc, message); |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
191 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
192 |
SSLLogger.fine( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
193 |
"Consuming KeyUpdate post-handshake message", km); |
56542 | 194 |
} |
195 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
196 |
// Update read key and IV. |
56542 | 197 |
SSLTrafficKeyDerivation kdg = |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
198 |
SSLTrafficKeyDerivation.valueOf(hc.conContext.protocolVersion); |
56542 | 199 |
if (kdg == null) { |
200 |
// unlikely |
|
201 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, |
|
202 |
"Not supported key derivation: " + |
|
203 |
hc.conContext.protocolVersion); |
|
204 |
return; |
|
205 |
} |
|
206 |
||
207 |
SSLKeyDerivation skd = kdg.createKeyDerivation(hc, |
|
208 |
hc.conContext.inputRecord.readCipher.baseSecret); |
|
209 |
if (skd == null) { |
|
210 |
// unlikely |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
211 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, "no key derivation"); |
56542 | 212 |
return; |
213 |
} |
|
214 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
215 |
SecretKey nplus1 = skd.deriveKey("TlsUpdateNplus1", null); |
56542 | 216 |
SSLKeyDerivation kd = kdg.createKeyDerivation(hc, nplus1); |
217 |
SecretKey key = kd.deriveKey("TlsKey", null); |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
218 |
IvParameterSpec ivSpec = new IvParameterSpec( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
219 |
kd.deriveKey("TlsIv", null).getEncoded()); |
56542 | 220 |
try { |
221 |
SSLReadCipher rc = |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
222 |
hc.negotiatedCipherSuite.bulkCipher.createReadCipher( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
223 |
Authenticator.valueOf(hc.conContext.protocolVersion), |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
224 |
hc.conContext.protocolVersion, key, ivSpec, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
225 |
hc.sslContext.getSecureRandom()); |
56542 | 226 |
hc.conContext.inputRecord.changeReadCiphers(rc); |
227 |
hc.conContext.inputRecord.readCipher.baseSecret = nplus1; |
|
228 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
229 |
SSLLogger.fine("KeyUpdate: read key updated"); |
|
230 |
} |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
231 |
} catch (GeneralSecurityException gse) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
232 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
233 |
"Failure to derive read secrets", gse); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
234 |
return; |
56542 | 235 |
} |
236 |
||
56686
07dc566630ee
Address TLS 1.3 comments output stream classes, go through JsseJce class to get Mac instance.
jnimeh
parents:
56660
diff
changeset
|
237 |
if (km.status == KeyUpdateRequest.REQUESTED) { |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
238 |
// Update the write key and IV. |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
239 |
handshakeProducer.produce(hc, |
56686
07dc566630ee
Address TLS 1.3 comments output stream classes, go through JsseJce class to get Mac instance.
jnimeh
parents:
56660
diff
changeset
|
240 |
new KeyUpdateMessage(hc, KeyUpdateRequest.NOTREQUESTED)); |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
241 |
} |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
242 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
243 |
// clean handshake context |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
244 |
hc.conContext.finishPostHandshake(); |
56542 | 245 |
} |
246 |
} |
|
247 |
||
248 |
/** |
|
249 |
* The "KeyUpdate" handshake message producer. |
|
250 |
*/ |
|
251 |
private static final class KeyUpdateProducer implements HandshakeProducer { |
|
252 |
// Prevent instantiation of this class. |
|
253 |
private KeyUpdateProducer() { |
|
254 |
// blank |
|
255 |
} |
|
256 |
||
257 |
@Override |
|
258 |
public byte[] produce(ConnectionContext context, |
|
259 |
HandshakeMessage message) throws IOException { |
|
260 |
// The producing happens in server side only. |
|
56544
ad120e0dfcfb
start/beginHandshake and more post-handshake changes
ascarpino
parents:
56542
diff
changeset
|
261 |
PostHandshakeContext hc = (PostHandshakeContext)context; |
56542 | 262 |
KeyUpdateMessage km = (KeyUpdateMessage)message; |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
263 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
264 |
SSLLogger.fine( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
265 |
"Produced KeyUpdate post-handshake message", km); |
56542 | 266 |
} |
267 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
268 |
// Update the write key and IV. |
56542 | 269 |
SSLTrafficKeyDerivation kdg = |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
270 |
SSLTrafficKeyDerivation.valueOf(hc.conContext.protocolVersion); |
56542 | 271 |
if (kdg == null) { |
272 |
// unlikely |
|
273 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, |
|
274 |
"Not supported key derivation: " + |
|
275 |
hc.conContext.protocolVersion); |
|
276 |
return null; |
|
277 |
} |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
278 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
279 |
SSLKeyDerivation skd = kdg.createKeyDerivation(hc, |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
280 |
hc.conContext.outputRecord.writeCipher.baseSecret); |
56542 | 281 |
if (skd == null) { |
282 |
// unlikely |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
283 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, "no key derivation"); |
56542 | 284 |
return null; |
285 |
} |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
286 |
|
56542 | 287 |
SecretKey nplus1 = skd.deriveKey("TlsUpdateNplus1", null); |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
288 |
SSLKeyDerivation kd = kdg.createKeyDerivation(hc, nplus1); |
56542 | 289 |
SecretKey key = kd.deriveKey("TlsKey", null); |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
290 |
IvParameterSpec ivSpec = new IvParameterSpec( |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
291 |
kd.deriveKey("TlsIv", null).getEncoded()); |
56542 | 292 |
|
293 |
SSLWriteCipher wc; |
|
294 |
try { |
|
295 |
wc = hc.negotiatedCipherSuite.bulkCipher.createWriteCipher( |
|
296 |
Authenticator.valueOf(hc.conContext.protocolVersion), |
|
297 |
hc.conContext.protocolVersion, key, ivSpec, |
|
298 |
hc.sslContext.getSecureRandom()); |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
299 |
} catch (GeneralSecurityException gse) { |
56542 | 300 |
hc.conContext.fatal(Alert.INTERNAL_ERROR, |
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
301 |
"Failure to derive write secrets", gse); |
56542 | 302 |
return null; |
303 |
} |
|
304 |
||
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
305 |
// Output the handshake message. |
56542 | 306 |
km.write(hc.handshakeOutput); |
307 |
hc.handshakeOutput.flush(); |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
308 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
309 |
// change write cipher |
56542 | 310 |
hc.conContext.outputRecord.changeWriteCiphers(wc, false); |
311 |
hc.conContext.outputRecord.writeCipher.baseSecret = nplus1; |
|
312 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
313 |
SSLLogger.fine("KeyUpdate: write key updated"); |
|
314 |
} |
|
56660
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
315 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
316 |
// clean handshake context |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
317 |
hc.conContext.finishPostHandshake(); |
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
318 |
|
66c803c3ce32
key and iv implementation update, and two tests correction
xuelei
parents:
56544
diff
changeset
|
319 |
// The handshake message has been delivered. |
56542 | 320 |
return null; |
321 |
} |
|
322 |
} |
|
323 |
} |