summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordoug <>2015-06-20 18:19:56 +0000
committerdoug <>2015-06-20 18:19:56 +0000
commit432767f47a21becad33b3d167c69e632685ceefb (patch)
tree51fb01014b4ae591e1b6971e22414df506777a2e
parent1e278b53e5192b62f8a45a7ad46d153ea92e2938 (diff)
downloadopenbsd-432767f47a21becad33b3d167c69e632685ceefb.tar.gz
openbsd-432767f47a21becad33b3d167c69e632685ceefb.tar.bz2
openbsd-432767f47a21becad33b3d167c69e632685ceefb.zip
Convert ssl3_get_new_session_ticket to CBS.
tweak + ok miod@ jsing@
-rw-r--r--src/lib/libssl/s3_clnt.c48
-rw-r--r--src/lib/libssl/src/ssl/s3_clnt.c48
2 files changed, 48 insertions, 48 deletions
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
index 76c0c488c5..0ef17d0067 100644
--- a/src/lib/libssl/s3_clnt.c
+++ b/src/lib/libssl/s3_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_clnt.c,v 1.112 2015/06/15 05:32:58 doug Exp $ */ 1/* $OpenBSD: s3_clnt.c,v 1.113 2015/06/20 18:19:56 doug 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 *
@@ -148,6 +148,8 @@
148 * OTHERWISE. 148 * OTHERWISE.
149 */ 149 */
150 150
151#include <limits.h>
152#include <stdint.h>
151#include <stdio.h> 153#include <stdio.h>
152 154
153#include "ssl_locl.h" 155#include "ssl_locl.h"
@@ -166,6 +168,8 @@
166#include <openssl/gost.h> 168#include <openssl/gost.h>
167#endif 169#endif
168 170
171#include "bytestring.h"
172
169static const SSL_METHOD *ssl3_get_client_method(int ver); 173static const SSL_METHOD *ssl3_get_client_method(int ver);
170static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b); 174static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b);
171 175
@@ -1706,10 +1710,10 @@ ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
1706int 1710int
1707ssl3_get_new_session_ticket(SSL *s) 1711ssl3_get_new_session_ticket(SSL *s)
1708{ 1712{
1709 int ok, al, ret = 0, ticklen; 1713 int ok, al, ret = 0;
1714 uint32_t lifetime_hint;
1710 long n; 1715 long n;
1711 const unsigned char *p; 1716 CBS cbs, session_ticket;
1712 unsigned char *d;
1713 1717
1714 n = s->method->ssl_get_message(s, SSL3_ST_CR_SESSION_TICKET_A, 1718 n = s->method->ssl_get_message(s, SSL3_ST_CR_SESSION_TICKET_A,
1715 SSL3_ST_CR_SESSION_TICKET_B, -1, 16384, &ok); 1719 SSL3_ST_CR_SESSION_TICKET_B, -1, 16384, &ok);
@@ -1726,34 +1730,29 @@ ssl3_get_new_session_ticket(SSL *s)
1726 SSL_R_BAD_MESSAGE_TYPE); 1730 SSL_R_BAD_MESSAGE_TYPE);
1727 goto f_err; 1731 goto f_err;
1728 } 1732 }
1729 if (n < 6) {
1730 /* need at least ticket_lifetime_hint + ticket length */
1731 al = SSL_AD_DECODE_ERROR;
1732 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1733 SSL_R_LENGTH_MISMATCH);
1734 goto f_err;
1735 }
1736 1733
1737 p = d = (unsigned char *)s->init_msg; 1734 CBS_init(&cbs, s->init_msg, n);
1738 n2l(p, s->session->tlsext_tick_lifetime_hint); 1735
1739 n2s(p, ticklen); 1736 if (n < 0 || !CBS_get_u32(&cbs, &lifetime_hint) ||
1740 /* ticket_lifetime_hint + ticket_length + ticket */ 1737#if UINT32_MAX > LONG_MAX
1741 if (ticklen + 6 != n) { 1738 lifetime_hint > LONG_MAX ||
1739#endif
1740 !CBS_get_u16_length_prefixed(&cbs, &session_ticket) ||
1741 CBS_len(&cbs) != 0) {
1742 al = SSL_AD_DECODE_ERROR; 1742 al = SSL_AD_DECODE_ERROR;
1743 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, 1743 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1744 SSL_R_LENGTH_MISMATCH); 1744 SSL_R_LENGTH_MISMATCH);
1745 goto f_err; 1745 goto f_err;
1746 } 1746 }
1747 free(s->session->tlsext_tick); 1747 s->session->tlsext_tick_lifetime_hint = (long)lifetime_hint;
1748 s->session->tlsext_ticklen = 0; 1748
1749 s->session->tlsext_tick = malloc(ticklen); 1749 if (!CBS_stow(&session_ticket, &s->session->tlsext_tick,
1750 if (!s->session->tlsext_tick) { 1750 &s->session->tlsext_ticklen)) {
1751 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, 1751 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1752 ERR_R_MALLOC_FAILURE); 1752 ERR_R_MALLOC_FAILURE);
1753 goto err; 1753 goto err;
1754 } 1754 }
1755 memcpy(s->session->tlsext_tick, p, ticklen); 1755
1756 s->session->tlsext_ticklen = ticklen;
1757 /* 1756 /*
1758 * There are two ways to detect a resumed ticket sesion. 1757 * There are two ways to detect a resumed ticket sesion.
1759 * One is to set an appropriate session ID and then the server 1758 * One is to set an appropriate session ID and then the server
@@ -1770,8 +1769,9 @@ ssl3_get_new_session_ticket(SSL *s)
1770 * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the 1769 * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the
1771 * ticket. 1770 * ticket.
1772 */ 1771 */
1773 EVP_Digest(p, ticklen, s->session->session_id, 1772 EVP_Digest(CBS_data(&session_ticket), CBS_len(&session_ticket),
1774 &s->session->session_id_length, EVP_sha256(), NULL); 1773 s->session->session_id, &s->session->session_id_length,
1774 EVP_sha256(), NULL);
1775 ret = 1; 1775 ret = 1;
1776 return (ret); 1776 return (ret);
1777f_err: 1777f_err:
diff --git a/src/lib/libssl/src/ssl/s3_clnt.c b/src/lib/libssl/src/ssl/s3_clnt.c
index 76c0c488c5..0ef17d0067 100644
--- a/src/lib/libssl/src/ssl/s3_clnt.c
+++ b/src/lib/libssl/src/ssl/s3_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_clnt.c,v 1.112 2015/06/15 05:32:58 doug Exp $ */ 1/* $OpenBSD: s3_clnt.c,v 1.113 2015/06/20 18:19:56 doug 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 *
@@ -148,6 +148,8 @@
148 * OTHERWISE. 148 * OTHERWISE.
149 */ 149 */
150 150
151#include <limits.h>
152#include <stdint.h>
151#include <stdio.h> 153#include <stdio.h>
152 154
153#include "ssl_locl.h" 155#include "ssl_locl.h"
@@ -166,6 +168,8 @@
166#include <openssl/gost.h> 168#include <openssl/gost.h>
167#endif 169#endif
168 170
171#include "bytestring.h"
172
169static const SSL_METHOD *ssl3_get_client_method(int ver); 173static const SSL_METHOD *ssl3_get_client_method(int ver);
170static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b); 174static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b);
171 175
@@ -1706,10 +1710,10 @@ ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
1706int 1710int
1707ssl3_get_new_session_ticket(SSL *s) 1711ssl3_get_new_session_ticket(SSL *s)
1708{ 1712{
1709 int ok, al, ret = 0, ticklen; 1713 int ok, al, ret = 0;
1714 uint32_t lifetime_hint;
1710 long n; 1715 long n;
1711 const unsigned char *p; 1716 CBS cbs, session_ticket;
1712 unsigned char *d;
1713 1717
1714 n = s->method->ssl_get_message(s, SSL3_ST_CR_SESSION_TICKET_A, 1718 n = s->method->ssl_get_message(s, SSL3_ST_CR_SESSION_TICKET_A,
1715 SSL3_ST_CR_SESSION_TICKET_B, -1, 16384, &ok); 1719 SSL3_ST_CR_SESSION_TICKET_B, -1, 16384, &ok);
@@ -1726,34 +1730,29 @@ ssl3_get_new_session_ticket(SSL *s)
1726 SSL_R_BAD_MESSAGE_TYPE); 1730 SSL_R_BAD_MESSAGE_TYPE);
1727 goto f_err; 1731 goto f_err;
1728 } 1732 }
1729 if (n < 6) {
1730 /* need at least ticket_lifetime_hint + ticket length */
1731 al = SSL_AD_DECODE_ERROR;
1732 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1733 SSL_R_LENGTH_MISMATCH);
1734 goto f_err;
1735 }
1736 1733
1737 p = d = (unsigned char *)s->init_msg; 1734 CBS_init(&cbs, s->init_msg, n);
1738 n2l(p, s->session->tlsext_tick_lifetime_hint); 1735
1739 n2s(p, ticklen); 1736 if (n < 0 || !CBS_get_u32(&cbs, &lifetime_hint) ||
1740 /* ticket_lifetime_hint + ticket_length + ticket */ 1737#if UINT32_MAX > LONG_MAX
1741 if (ticklen + 6 != n) { 1738 lifetime_hint > LONG_MAX ||
1739#endif
1740 !CBS_get_u16_length_prefixed(&cbs, &session_ticket) ||
1741 CBS_len(&cbs) != 0) {
1742 al = SSL_AD_DECODE_ERROR; 1742 al = SSL_AD_DECODE_ERROR;
1743 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, 1743 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1744 SSL_R_LENGTH_MISMATCH); 1744 SSL_R_LENGTH_MISMATCH);
1745 goto f_err; 1745 goto f_err;
1746 } 1746 }
1747 free(s->session->tlsext_tick); 1747 s->session->tlsext_tick_lifetime_hint = (long)lifetime_hint;
1748 s->session->tlsext_ticklen = 0; 1748
1749 s->session->tlsext_tick = malloc(ticklen); 1749 if (!CBS_stow(&session_ticket, &s->session->tlsext_tick,
1750 if (!s->session->tlsext_tick) { 1750 &s->session->tlsext_ticklen)) {
1751 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET, 1751 SSLerr(SSL_F_SSL3_GET_NEW_SESSION_TICKET,
1752 ERR_R_MALLOC_FAILURE); 1752 ERR_R_MALLOC_FAILURE);
1753 goto err; 1753 goto err;
1754 } 1754 }
1755 memcpy(s->session->tlsext_tick, p, ticklen); 1755
1756 s->session->tlsext_ticklen = ticklen;
1757 /* 1756 /*
1758 * There are two ways to detect a resumed ticket sesion. 1757 * There are two ways to detect a resumed ticket sesion.
1759 * One is to set an appropriate session ID and then the server 1758 * One is to set an appropriate session ID and then the server
@@ -1770,8 +1769,9 @@ ssl3_get_new_session_ticket(SSL *s)
1770 * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the 1769 * to the SHA256 (or SHA1 is SHA256 is disabled) hash of the
1771 * ticket. 1770 * ticket.
1772 */ 1771 */
1773 EVP_Digest(p, ticklen, s->session->session_id, 1772 EVP_Digest(CBS_data(&session_ticket), CBS_len(&session_ticket),
1774 &s->session->session_id_length, EVP_sha256(), NULL); 1773 s->session->session_id, &s->session->session_id_length,
1774 EVP_sha256(), NULL);
1775 ret = 1; 1775 ret = 1;
1776 return (ret); 1776 return (ret);
1777f_err: 1777f_err: