summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2020-08-31 14:34:01 +0000
committertb <>2020-08-31 14:34:01 +0000
commitf9f2c6158d37416abbdd6c8cdf77912181bbbefc (patch)
treebe655ef886366f2677afd7c41a476decebc22620
parentf551307b25934acd84205155d6286b2d937e2479 (diff)
downloadopenbsd-f9f2c6158d37416abbdd6c8cdf77912181bbbefc.tar.gz
openbsd-f9f2c6158d37416abbdd6c8cdf77912181bbbefc.tar.bz2
openbsd-f9f2c6158d37416abbdd6c8cdf77912181bbbefc.zip
Return code tweaks for session ticket handlers
In tls1_process_ticket() and tls_decrypt_ticket() use #defines with descriptive names instead of hardcoding -1 1 2 3 4 and occasionally explaining the magic numbers with comments. ok beck inoguchi
-rw-r--r--src/lib/libssl/ssl_locl.h9
-rw-r--r--src/lib/libssl/ssl_sess.c16
-rw-r--r--src/lib/libssl/t1_lib.c73
3 files changed, 51 insertions, 47 deletions
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 036c1dacb2..18ff5b0c30 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.285 2020/08/31 14:04:51 tb Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.286 2020/08/31 14:34:01 tb 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 *
@@ -1397,6 +1397,13 @@ int ssl_check_clienthello_tlsext_early(SSL *s);
1397int ssl_check_clienthello_tlsext_late(SSL *s); 1397int ssl_check_clienthello_tlsext_late(SSL *s);
1398int ssl_check_serverhello_tlsext(SSL *s); 1398int ssl_check_serverhello_tlsext(SSL *s);
1399 1399
1400#define TLS1_TICKET_FATAL_ERROR -1
1401#define TLS1_TICKET_NONE 0
1402#define TLS1_TICKET_EMPTY 1
1403#define TLS1_TICKET_NOT_DECRYPTED 2
1404#define TLS1_TICKET_DECRYPTED 3
1405#define TLS1_TICKET_DECRYPTED_RENEW 4
1406
1400int tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, 1407int tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block,
1401 int *alert, SSL_SESSION **ret); 1408 int *alert, SSL_SESSION **ret);
1402 1409
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
index 827360176b..9e8edd93e8 100644
--- a/src/lib/libssl/ssl_sess.c
+++ b/src/lib/libssl/ssl_sess.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_sess.c,v 1.86 2020/08/31 14:04:51 tb Exp $ */ 1/* $OpenBSD: ssl_sess.c,v 1.87 2020/08/31 14:34:01 tb 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 *
@@ -440,7 +440,6 @@ ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert)
440 SSL_SESSION *ret = NULL; 440 SSL_SESSION *ret = NULL;
441 int alert_desc = SSL_AD_INTERNAL_ERROR, fatal = 0; 441 int alert_desc = SSL_AD_INTERNAL_ERROR, fatal = 0;
442 int try_session_cache = 1; 442 int try_session_cache = 1;
443 int r;
444 443
445 /* This is used only by servers. */ 444 /* This is used only by servers. */
446 445
@@ -451,16 +450,15 @@ ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert)
451 try_session_cache = 0; 450 try_session_cache = 0;
452 451
453 /* Sets s->internal->tlsext_ticket_expected. */ 452 /* Sets s->internal->tlsext_ticket_expected. */
454 r = tls1_process_ticket(s, session_id, ext_block, &alert_desc, &ret); 453 switch (tls1_process_ticket(s, session_id, ext_block, &alert_desc, &ret)) {
455 switch (r) { 454 case TLS1_TICKET_FATAL_ERROR:
456 case -1: /* Error during processing */
457 fatal = 1; 455 fatal = 1;
458 goto err; 456 goto err;
459 case 0: /* No ticket found */ 457 case TLS1_TICKET_NONE:
460 case 1: /* Zero length ticket found */ 458 case TLS1_TICKET_EMPTY:
461 break; /* Ok to carry on processing session id. */ 459 break; /* Ok to carry on processing session id. */
462 case 2: /* Ticket found but not decrypted. */ 460 case TLS1_TICKET_NOT_DECRYPTED:
463 case 3: /* Ticket decrypted, *ret has been set. */ 461 case TLS1_TICKET_DECRYPTED:
464 try_session_cache = 0; 462 try_session_cache = 0;
465 break; 463 break;
466 default: 464 default:
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index 59146eb767..b0fc630236 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_lib.c,v 1.170 2020/08/31 14:04:51 tb Exp $ */ 1/* $OpenBSD: t1_lib.c,v 1.171 2020/08/31 14:34:01 tb 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 *
@@ -765,13 +765,14 @@ ssl_check_serverhello_tlsext(SSL *s)
765 * never be decrypted, nor will s->internal->tlsext_ticket_expected be set to 1. 765 * never be decrypted, nor will s->internal->tlsext_ticket_expected be set to 1.
766 * 766 *
767 * Returns: 767 * Returns:
768 * -1: fatal error, either from parsing or decrypting the ticket. 768 * TLS1_TICKET_FATAL_ERROR: error from parsing or decrypting the ticket.
769 * 0: no ticket was found (or was ignored, based on settings). 769 * TLS1_TICKET_NONE: no ticket was found (or was ignored, based on settings).
770 * 1: a zero length extension was found, indicating that the client supports 770 * TLS1_TICKET_EMPTY: a zero length extension was found, indicating that the
771 * session tickets but doesn't currently have one to offer. 771 * client supports session tickets but doesn't currently have one to offer.
772 * 2: either s->internal->tls_session_secret_cb was set, or a ticket was offered but 772 * TLS1_TICKET_NOT_DECRYPTED: either s->internal->tls_session_secret_cb was
773 * couldn't be decrypted because of a non-fatal error. 773 * set, or a ticket was offered but couldn't be decrypted because of a
774 * 3: a ticket was successfully decrypted and *ret was set. 774 * non-fatal error.
775 * TLS1_TICKET_DECRYPTED: a ticket was successfully decrypted and *ret was set.
775 * 776 *
776 * Side effects: 777 * Side effects:
777 * Sets s->internal->tlsext_ticket_expected to 1 if the server will have to issue 778 * Sets s->internal->tlsext_ticket_expected to 1 if the server will have to issue
@@ -787,7 +788,6 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
787{ 788{
788 CBS extensions, ext_data; 789 CBS extensions, ext_data;
789 uint16_t ext_type = 0; 790 uint16_t ext_type = 0;
790 int r;
791 791
792 s->internal->tlsext_ticket_expected = 0; 792 s->internal->tlsext_ticket_expected = 0;
793 *ret = NULL; 793 *ret = NULL;
@@ -797,25 +797,25 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
797 * resumption. 797 * resumption.
798 */ 798 */
799 if (SSL_get_options(s) & SSL_OP_NO_TICKET) 799 if (SSL_get_options(s) & SSL_OP_NO_TICKET)
800 return 0; 800 return TLS1_TICKET_NONE;
801 801
802 /* 802 /*
803 * An empty extensions block is valid, but obviously does not contain 803 * An empty extensions block is valid, but obviously does not contain
804 * a session ticket. 804 * a session ticket.
805 */ 805 */
806 if (CBS_len(ext_block) == 0) 806 if (CBS_len(ext_block) == 0)
807 return 0; 807 return TLS1_TICKET_NONE;
808 808
809 if (!CBS_get_u16_length_prefixed(ext_block, &extensions)) { 809 if (!CBS_get_u16_length_prefixed(ext_block, &extensions)) {
810 *alert = SSL_AD_DECODE_ERROR; 810 *alert = SSL_AD_DECODE_ERROR;
811 return -1; 811 return TLS1_TICKET_FATAL_ERROR;
812 } 812 }
813 813
814 while (CBS_len(&extensions) > 0) { 814 while (CBS_len(&extensions) > 0) {
815 if (!CBS_get_u16(&extensions, &ext_type) || 815 if (!CBS_get_u16(&extensions, &ext_type) ||
816 !CBS_get_u16_length_prefixed(&extensions, &ext_data)) { 816 !CBS_get_u16_length_prefixed(&extensions, &ext_data)) {
817 *alert = SSL_AD_DECODE_ERROR; 817 *alert = SSL_AD_DECODE_ERROR;
818 return -1; 818 return TLS1_TICKET_FATAL_ERROR;
819 } 819 }
820 820
821 if (ext_type == TLSEXT_TYPE_session_ticket) 821 if (ext_type == TLSEXT_TYPE_session_ticket)
@@ -823,7 +823,7 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
823 } 823 }
824 824
825 if (ext_type != TLSEXT_TYPE_session_ticket) 825 if (ext_type != TLSEXT_TYPE_session_ticket)
826 return 0; 826 return TLS1_TICKET_NONE;
827 827
828 if (CBS_len(&ext_data) == 0) { 828 if (CBS_len(&ext_data) == 0) {
829 /* 829 /*
@@ -831,7 +831,7 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
831 * have one. 831 * have one.
832 */ 832 */
833 s->internal->tlsext_ticket_expected = 1; 833 s->internal->tlsext_ticket_expected = 1;
834 return 1; 834 return TLS1_TICKET_EMPTY;
835 } 835 }
836 836
837 if (s->internal->tls_session_secret_cb != NULL) { 837 if (s->internal->tls_session_secret_cb != NULL) {
@@ -841,21 +841,20 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
841 * handshake based on external mechanism to calculate the master 841 * handshake based on external mechanism to calculate the master
842 * secret later. 842 * secret later.
843 */ 843 */
844 return 2; 844 return TLS1_TICKET_NOT_DECRYPTED;
845 } 845 }
846 846
847 r = tls_decrypt_ticket(s, session_id, &ext_data, alert, ret); 847 switch (tls_decrypt_ticket(s, session_id, &ext_data, alert, ret)) {
848 switch (r) { 848 case TLS1_TICKET_NOT_DECRYPTED:
849 case 2: /* ticket couldn't be decrypted */
850 s->internal->tlsext_ticket_expected = 1; 849 s->internal->tlsext_ticket_expected = 1;
851 return 2; 850 return TLS1_TICKET_NOT_DECRYPTED;
852 case 3: /* ticket was decrypted */ 851 case TLS1_TICKET_DECRYPTED:
853 return r; 852 return TLS1_TICKET_DECRYPTED;
854 case 4: /* ticket decrypted but need to renew */ 853 case TLS1_TICKET_DECRYPTED_RENEW:
855 s->internal->tlsext_ticket_expected = 1; 854 s->internal->tlsext_ticket_expected = 1;
856 return 3; 855 return TLS1_TICKET_DECRYPTED;
857 default: /* fatal error */ 856 default:
858 return -1; 857 return TLS1_TICKET_FATAL_ERROR;
859 } 858 }
860} 859}
861 860
@@ -867,10 +866,10 @@ tls1_process_ticket(SSL *s, CBS *session_id, CBS *ext_block, int *alert,
867 * point to the resulting session. 866 * point to the resulting session.
868 * 867 *
869 * Returns: 868 * Returns:
870 * -1: fatal error, either from parsing or decrypting the ticket. 869 * TLS1_TICKET_FATAL_ERROR: error from parsing or decrypting the ticket.
871 * 2: the ticket couldn't be decrypted. 870 * TLS1_TICKET_NOT_DECRYPTED: the ticket couldn't be decrypted.
872 * 3: a ticket was successfully decrypted and *psess was set. 871 * TLS1_TICKET_DECRYPTED: a ticket was decrypted and *psess was set.
873 * 4: same as 3, but the ticket needs to be renewed. 872 * TLS1_TICKET_DECRYPTED_RENEW: same as 3, but the ticket needs to be renewed.
874 */ 873 */
875static int 874static int
876tls_decrypt_ticket(SSL *s, CBS *session_id, CBS *ticket, int *alert, 875tls_decrypt_ticket(SSL *s, CBS *session_id, CBS *ticket, int *alert,
@@ -887,9 +886,9 @@ tls_decrypt_ticket(SSL *s, CBS *session_id, CBS *ticket, int *alert,
887 EVP_CIPHER_CTX *cctx = NULL; 886 EVP_CIPHER_CTX *cctx = NULL;
888 SSL_CTX *tctx = s->initial_ctx; 887 SSL_CTX *tctx = s->initial_ctx;
889 int slen, hlen; 888 int slen, hlen;
890 int renew_ticket = 0;
891 int ret = -1;
892 int alert_desc = SSL_AD_INTERNAL_ERROR; 889 int alert_desc = SSL_AD_INTERNAL_ERROR;
890 int renew_ticket = 0;
891 int ret = TLS1_TICKET_FATAL_ERROR;
893 892
894 *psess = NULL; 893 *psess = NULL;
895 894
@@ -1018,19 +1017,19 @@ tls_decrypt_ticket(SSL *s, CBS *session_id, CBS *ticket, int *alert,
1018 sess = NULL; 1017 sess = NULL;
1019 1018
1020 if (renew_ticket) 1019 if (renew_ticket)
1021 ret = 4; 1020 ret = TLS1_TICKET_DECRYPTED_RENEW;
1022 else 1021 else
1023 ret = 3; 1022 ret = TLS1_TICKET_DECRYPTED;
1024 1023
1025 goto done; 1024 goto done;
1026 1025
1027 derr: 1026 derr:
1028 ret = 2; 1027 ret = TLS1_TICKET_NOT_DECRYPTED;
1029 goto done; 1028 goto done;
1030 1029
1031 err: 1030 err:
1032 *alert = alert_desc; 1031 *alert = alert_desc;
1033 ret = -1; 1032 ret = TLS1_TICKET_FATAL_ERROR;
1034 goto done; 1033 goto done;
1035 1034
1036 done: 1035 done:
@@ -1039,7 +1038,7 @@ tls_decrypt_ticket(SSL *s, CBS *session_id, CBS *ticket, int *alert,
1039 HMAC_CTX_free(hctx); 1038 HMAC_CTX_free(hctx);
1040 SSL_SESSION_free(sess); 1039 SSL_SESSION_free(sess);
1041 1040
1042 if (ret == 2) 1041 if (ret == TLS1_TICKET_NOT_DECRYPTED)
1043 ERR_clear_error(); 1042 ERR_clear_error();
1044 1043
1045 return ret; 1044 return ret;