diff options
Diffstat (limited to 'src/lib/libssl/tls_key_share.c')
-rw-r--r-- | src/lib/libssl/tls_key_share.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/lib/libssl/tls_key_share.c b/src/lib/libssl/tls_key_share.c index eb30a0ea69..e5e6c304b6 100644 --- a/src/lib/libssl/tls_key_share.c +++ b/src/lib/libssl/tls_key_share.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_key_share.c,v 1.3 2022/01/07 15:46:30 jsing Exp $ */ | 1 | /* $OpenBSD: tls_key_share.c,v 1.4 2022/01/11 18:28:41 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -301,14 +301,15 @@ tls_key_share_public(struct tls_key_share *ks, CBB *cbb) | |||
301 | 301 | ||
302 | static int | 302 | static int |
303 | tls_key_share_peer_params_dhe(struct tls_key_share *ks, CBS *cbs, | 303 | tls_key_share_peer_params_dhe(struct tls_key_share *ks, CBS *cbs, |
304 | int *invalid_params) | 304 | int *decode_error, int *invalid_params) |
305 | { | 305 | { |
306 | if (ks->dhe != NULL || ks->dhe_peer != NULL) | 306 | if (ks->dhe != NULL || ks->dhe_peer != NULL) |
307 | return 0; | 307 | return 0; |
308 | 308 | ||
309 | if ((ks->dhe_peer = DH_new()) == NULL) | 309 | if ((ks->dhe_peer = DH_new()) == NULL) |
310 | return 0; | 310 | return 0; |
311 | if (!ssl_kex_peer_params_dhe(ks->dhe_peer, cbs, invalid_params)) | 311 | if (!ssl_kex_peer_params_dhe(ks->dhe_peer, cbs, decode_error, |
312 | invalid_params)) | ||
312 | return 0; | 313 | return 0; |
313 | if ((ks->dhe = DHparams_dup(ks->dhe_peer)) == NULL) | 314 | if ((ks->dhe = DHparams_dup(ks->dhe_peer)) == NULL) |
314 | return 0; | 315 | return 0; |
@@ -318,22 +319,24 @@ tls_key_share_peer_params_dhe(struct tls_key_share *ks, CBS *cbs, | |||
318 | 319 | ||
319 | int | 320 | int |
320 | tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs, | 321 | tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs, |
321 | int *invalid_params) | 322 | int *decode_error, int *invalid_params) |
322 | { | 323 | { |
323 | if (ks->nid != NID_dhKeyAgreement) | 324 | if (ks->nid != NID_dhKeyAgreement) |
324 | return 0; | 325 | return 0; |
325 | 326 | ||
326 | return tls_key_share_peer_params_dhe(ks, cbs, invalid_params); | 327 | return tls_key_share_peer_params_dhe(ks, cbs, decode_error, |
328 | invalid_params); | ||
327 | } | 329 | } |
328 | 330 | ||
329 | static int | 331 | static int |
330 | tls_key_share_peer_public_dhe(struct tls_key_share *ks, CBS *cbs, | 332 | tls_key_share_peer_public_dhe(struct tls_key_share *ks, CBS *cbs, |
331 | int *invalid_key) | 333 | int *decode_error, int *invalid_key) |
332 | { | 334 | { |
333 | if (ks->dhe_peer == NULL) | 335 | if (ks->dhe_peer == NULL) |
334 | return 0; | 336 | return 0; |
335 | 337 | ||
336 | return ssl_kex_peer_public_dhe(ks->dhe_peer, cbs, invalid_key); | 338 | return ssl_kex_peer_public_dhe(ks->dhe_peer, cbs, decode_error, |
339 | invalid_key); | ||
337 | } | 340 | } |
338 | 341 | ||
339 | static int | 342 | static int |
@@ -362,30 +365,39 @@ tls_key_share_peer_public_ecdhe_ecp(struct tls_key_share *ks, CBS *cbs) | |||
362 | } | 365 | } |
363 | 366 | ||
364 | static int | 367 | static int |
365 | tls_key_share_peer_public_x25519(struct tls_key_share *ks, CBS *cbs) | 368 | tls_key_share_peer_public_x25519(struct tls_key_share *ks, CBS *cbs, |
369 | int *decode_error) | ||
366 | { | 370 | { |
367 | size_t out_len; | 371 | size_t out_len; |
368 | 372 | ||
373 | *decode_error = 0; | ||
374 | |||
369 | if (ks->x25519_peer_public != NULL) | 375 | if (ks->x25519_peer_public != NULL) |
370 | return 0; | 376 | return 0; |
371 | 377 | ||
372 | if (CBS_len(cbs) != X25519_KEY_LENGTH) | 378 | if (CBS_len(cbs) != X25519_KEY_LENGTH) { |
379 | *decode_error = 1; | ||
373 | return 0; | 380 | return 0; |
381 | } | ||
374 | 382 | ||
375 | return CBS_stow(cbs, &ks->x25519_peer_public, &out_len); | 383 | return CBS_stow(cbs, &ks->x25519_peer_public, &out_len); |
376 | } | 384 | } |
377 | 385 | ||
378 | int | 386 | int |
379 | tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, int *invalid_key) | 387 | tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, int *decode_error, |
388 | int *invalid_key) | ||
380 | { | 389 | { |
390 | *decode_error = 0; | ||
391 | |||
381 | if (invalid_key != NULL) | 392 | if (invalid_key != NULL) |
382 | *invalid_key = 0; | 393 | *invalid_key = 0; |
383 | 394 | ||
384 | if (ks->nid == NID_dhKeyAgreement) | 395 | if (ks->nid == NID_dhKeyAgreement) |
385 | return tls_key_share_peer_public_dhe(ks, cbs, invalid_key); | 396 | return tls_key_share_peer_public_dhe(ks, cbs, decode_error, |
397 | invalid_key); | ||
386 | 398 | ||
387 | if (ks->nid == NID_X25519) | 399 | if (ks->nid == NID_X25519) |
388 | return tls_key_share_peer_public_x25519(ks, cbs); | 400 | return tls_key_share_peer_public_x25519(ks, cbs, decode_error); |
389 | 401 | ||
390 | return tls_key_share_peer_public_ecdhe_ecp(ks, cbs); | 402 | return tls_key_share_peer_public_ecdhe_ecp(ks, cbs); |
391 | } | 403 | } |