diff options
Diffstat (limited to 'src/lib/libssl/t1_enc.c')
-rw-r--r-- | src/lib/libssl/t1_enc.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index 6cdae0caed..e3cdcc134b 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t1_enc.c,v 1.141 2021/05/02 17:18:10 jsing Exp $ */ | 1 | /* $OpenBSD: t1_enc.c,v 1.142 2021/05/02 17:46:58 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -294,8 +294,8 @@ tls1_generate_key_block(SSL *s, uint8_t *key_block, size_t key_block_len) | |||
294 | NULL, 0, NULL, 0, key_block, key_block_len); | 294 | NULL, 0, NULL, 0, key_block, key_block_len); |
295 | } | 295 | } |
296 | 296 | ||
297 | int | 297 | static int |
298 | tls1_change_cipher_state(SSL *s, int which) | 298 | tls1_change_cipher_state(SSL *s, int is_write) |
299 | { | 299 | { |
300 | const unsigned char *client_write_mac_secret, *server_write_mac_secret; | 300 | const unsigned char *client_write_mac_secret, *server_write_mac_secret; |
301 | const unsigned char *client_write_key, *server_write_key; | 301 | const unsigned char *client_write_key, *server_write_key; |
@@ -305,26 +305,10 @@ tls1_change_cipher_state(SSL *s, int which) | |||
305 | unsigned char *key_block; | 305 | unsigned char *key_block; |
306 | const EVP_CIPHER *cipher; | 306 | const EVP_CIPHER *cipher; |
307 | const EVP_AEAD *aead; | 307 | const EVP_AEAD *aead; |
308 | char is_read, use_client_keys; | ||
309 | 308 | ||
310 | aead = tls12_record_layer_aead(s->internal->rl); | 309 | aead = tls12_record_layer_aead(s->internal->rl); |
311 | cipher = tls12_record_layer_cipher(s->internal->rl); | 310 | cipher = tls12_record_layer_cipher(s->internal->rl); |
312 | 311 | ||
313 | /* | ||
314 | * is_read is true if we have just read a ChangeCipherSpec message, | ||
315 | * that is we need to update the read cipherspec. Otherwise we have | ||
316 | * just written one. | ||
317 | */ | ||
318 | is_read = (which & SSL3_CC_READ) != 0; | ||
319 | |||
320 | /* | ||
321 | * use_client_keys is true if we wish to use the keys for the "client | ||
322 | * write" direction. This is the case if we're a client sending a | ||
323 | * ChangeCipherSpec, or a server reading a client's ChangeCipherSpec. | ||
324 | */ | ||
325 | use_client_keys = ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || | ||
326 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)); | ||
327 | |||
328 | if (aead != NULL) { | 312 | if (aead != NULL) { |
329 | key_len = EVP_AEAD_key_length(aead); | 313 | key_len = EVP_AEAD_key_length(aead); |
330 | iv_len = SSL_CIPHER_AEAD_FIXED_NONCE_LEN(S3I(s)->hs.cipher); | 314 | iv_len = SSL_CIPHER_AEAD_FIXED_NONCE_LEN(S3I(s)->hs.cipher); |
@@ -349,7 +333,8 @@ tls1_change_cipher_state(SSL *s, int which) | |||
349 | server_write_iv = key_block; | 333 | server_write_iv = key_block; |
350 | key_block += iv_len; | 334 | key_block += iv_len; |
351 | 335 | ||
352 | if (use_client_keys) { | 336 | /* Use client write keys on client write and server read. */ |
337 | if ((!s->server && is_write) || (s->server && !is_write)) { | ||
353 | mac_secret = client_write_mac_secret; | 338 | mac_secret = client_write_mac_secret; |
354 | key = client_write_key; | 339 | key = client_write_key; |
355 | iv = client_write_iv; | 340 | iv = client_write_iv; |
@@ -365,7 +350,7 @@ tls1_change_cipher_state(SSL *s, int which) | |||
365 | goto err; | 350 | goto err; |
366 | } | 351 | } |
367 | 352 | ||
368 | if (is_read) { | 353 | if (!is_write) { |
369 | if (!tls12_record_layer_change_read_cipher_state(s->internal->rl, | 354 | if (!tls12_record_layer_change_read_cipher_state(s->internal->rl, |
370 | mac_secret, mac_secret_size, key, key_len, iv, iv_len)) | 355 | mac_secret, mac_secret_size, key, key_len, iv, iv_len)) |
371 | goto err; | 356 | goto err; |
@@ -387,6 +372,18 @@ tls1_change_cipher_state(SSL *s, int which) | |||
387 | } | 372 | } |
388 | 373 | ||
389 | int | 374 | int |
375 | tls1_change_read_cipher_state(SSL *s) | ||
376 | { | ||
377 | return tls1_change_cipher_state(s, 0); | ||
378 | } | ||
379 | |||
380 | int | ||
381 | tls1_change_write_cipher_state(SSL *s) | ||
382 | { | ||
383 | return tls1_change_cipher_state(s, 1); | ||
384 | } | ||
385 | |||
386 | int | ||
390 | tls1_setup_key_block(SSL *s) | 387 | tls1_setup_key_block(SSL *s) |
391 | { | 388 | { |
392 | unsigned char *key_block; | 389 | unsigned char *key_block; |