Removed dependency on rrec from heartbeat processing
Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
bd2e3a9512
commit
2c60ed0452
@ -1347,16 +1347,12 @@ int dtls1_shutdown(SSL *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_HEARTBEATS
|
#ifndef OPENSSL_NO_HEARTBEATS
|
||||||
int dtls1_process_heartbeat(SSL *s)
|
int dtls1_process_heartbeat(SSL *s, unsigned char *p, unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned char *p, *pl;
|
unsigned char *pl;
|
||||||
unsigned short hbtype;
|
unsigned short hbtype;
|
||||||
unsigned int payload;
|
unsigned int payload;
|
||||||
unsigned int padding = 16; /* Use minimum padding */
|
unsigned int padding = 16; /* Use minimum padding */
|
||||||
unsigned int length;
|
|
||||||
|
|
||||||
p = SSL3_RECORD_get_data(RECORD_LAYER_get_rrec(&s->rlayer));
|
|
||||||
length = SSL3_RECORD_get_length(RECORD_LAYER_get_rrec(&s->rlayer));
|
|
||||||
|
|
||||||
if (s->msg_callback)
|
if (s->msg_callback)
|
||||||
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
|
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
|
||||||
|
@ -60,7 +60,7 @@ typedef struct heartbeat_test_fixture {
|
|||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx;
|
||||||
SSL *s;
|
SSL *s;
|
||||||
const char *test_case_name;
|
const char *test_case_name;
|
||||||
int (*process_heartbeat) (SSL *s);
|
int (*process_heartbeat) (SSL *s, unsigned char *p, unsigned int length);
|
||||||
unsigned char *payload;
|
unsigned char *payload;
|
||||||
int sent_payload_len;
|
int sent_payload_len;
|
||||||
int expected_return_value;
|
int expected_return_value;
|
||||||
@ -112,7 +112,7 @@ static HEARTBEAT_TEST_FIXTURE set_up(const char *const test_case_name,
|
|||||||
* zeroed in opt mode and will cause spurious test failures that will
|
* zeroed in opt mode and will cause spurious test failures that will
|
||||||
* change with each execution.
|
* change with each execution.
|
||||||
*/
|
*/
|
||||||
memset(fixture.s->s3->wbuf.buf, 0, fixture.s->s3->wbuf.len);
|
memset(fixture.s->rlayer.wbuf.buf, 0, fixture.s->rlayer.wbuf.len);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (!setup_ok) {
|
if (!setup_ok) {
|
||||||
@ -202,8 +202,8 @@ static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture)
|
|||||||
unsigned const char *p;
|
unsigned const char *p;
|
||||||
int actual_payload_len;
|
int actual_payload_len;
|
||||||
|
|
||||||
s->s3->rrec.data = payload;
|
s->rlayer.rrec.data = payload;
|
||||||
s->s3->rrec.length = strlen((const char *)payload);
|
s->rlayer.rrec.length = strlen((const char *)payload);
|
||||||
*payload++ = TLS1_HB_REQUEST;
|
*payload++ = TLS1_HB_REQUEST;
|
||||||
s2n(fixture.sent_payload_len, payload);
|
s2n(fixture.sent_payload_len, payload);
|
||||||
|
|
||||||
@ -213,7 +213,8 @@ static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture)
|
|||||||
*/
|
*/
|
||||||
memcpy((char *)sent_buf, (const char *)payload, sizeof(sent_buf));
|
memcpy((char *)sent_buf, (const char *)payload, sizeof(sent_buf));
|
||||||
|
|
||||||
return_value = fixture.process_heartbeat(s);
|
return_value = fixture.process_heartbeat(s, s->rlayer.rrec.data,
|
||||||
|
s->rlayer.rrec.length);
|
||||||
|
|
||||||
if (return_value != fixture.expected_return_value) {
|
if (return_value != fixture.expected_return_value) {
|
||||||
printf("%s failed: expected return value %d, received %d\n",
|
printf("%s failed: expected return value %d, received %d\n",
|
||||||
@ -225,8 +226,8 @@ static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture)
|
|||||||
/*
|
/*
|
||||||
* If there is any byte alignment, it will be stored in wbuf.offset.
|
* If there is any byte alignment, it will be stored in wbuf.offset.
|
||||||
*/
|
*/
|
||||||
p = &(s->s3->
|
p = &(s->rlayer.
|
||||||
wbuf.buf[fixture.return_payload_offset + s->s3->wbuf.offset]);
|
wbuf.buf[fixture.return_payload_offset + s->rlayer.wbuf.offset]);
|
||||||
actual_payload_len = 0;
|
actual_payload_len = 0;
|
||||||
n2s(p, actual_payload_len);
|
n2s(p, actual_payload_len);
|
||||||
|
|
||||||
|
@ -585,10 +585,10 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
|
|||||||
#ifndef OPENSSL_NO_HEARTBEATS
|
#ifndef OPENSSL_NO_HEARTBEATS
|
||||||
else if (rr->type == TLS1_RT_HEARTBEAT) {
|
else if (rr->type == TLS1_RT_HEARTBEAT) {
|
||||||
/* We allow a 0 return */
|
/* We allow a 0 return */
|
||||||
if(dtls1_process_heartbeat(s) < 0) {
|
if(dtls1_process_heartbeat(s, SSL3_RECORD_get_data(&s->rlayer.rrec),
|
||||||
|
SSL3_RECORD_get_length(&s->rlayer.rrec)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit and notify application to read again */
|
/* Exit and notify application to read again */
|
||||||
rr->length = 0;
|
rr->length = 0;
|
||||||
s->rwstate = SSL_READING;
|
s->rwstate = SSL_READING;
|
||||||
|
@ -1054,7 +1054,8 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
|
|||||||
#ifndef OPENSSL_NO_HEARTBEATS
|
#ifndef OPENSSL_NO_HEARTBEATS
|
||||||
else if (rr->type == TLS1_RT_HEARTBEAT) {
|
else if (rr->type == TLS1_RT_HEARTBEAT) {
|
||||||
/* We can ignore 0 return values */
|
/* We can ignore 0 return values */
|
||||||
if(tls1_process_heartbeat(s) < 0) {
|
if(tls1_process_heartbeat(s, SSL3_RECORD_get_data(&s->rlayer.rrec),
|
||||||
|
SSL3_RECORD_get_length(&s->rlayer.rrec)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1979,8 +1979,10 @@ const SSL_METHOD *func_name(void) \
|
|||||||
struct openssl_ssl_test_functions {
|
struct openssl_ssl_test_functions {
|
||||||
int (*p_ssl_init_wbio_buffer) (SSL *s, int push);
|
int (*p_ssl_init_wbio_buffer) (SSL *s, int push);
|
||||||
int (*p_ssl3_setup_buffers) (SSL *s);
|
int (*p_ssl3_setup_buffers) (SSL *s);
|
||||||
int (*p_tls1_process_heartbeat) (SSL *s);
|
int (*p_tls1_process_heartbeat) (SSL *s,
|
||||||
int (*p_dtls1_process_heartbeat) (SSL *s);
|
unsigned char *p, unsigned int length);
|
||||||
|
int (*p_dtls1_process_heartbeat) (SSL *s,
|
||||||
|
unsigned char *p, unsigned int length);
|
||||||
};
|
};
|
||||||
|
|
||||||
# ifndef OPENSSL_UNIT_TEST
|
# ifndef OPENSSL_UNIT_TEST
|
||||||
@ -2267,8 +2269,8 @@ __owur int ssl_prepare_serverhello_tlsext(SSL *s);
|
|||||||
# ifndef OPENSSL_NO_HEARTBEATS
|
# ifndef OPENSSL_NO_HEARTBEATS
|
||||||
__owur int tls1_heartbeat(SSL *s);
|
__owur int tls1_heartbeat(SSL *s);
|
||||||
__owur int dtls1_heartbeat(SSL *s);
|
__owur int dtls1_heartbeat(SSL *s);
|
||||||
__owur int tls1_process_heartbeat(SSL *s);
|
__owur int tls1_process_heartbeat(SSL *s, unsigned char *p, unsigned int length);
|
||||||
__owur int dtls1_process_heartbeat(SSL *s);
|
__owur int dtls1_process_heartbeat(SSL *s, unsigned char *p, unsigned int length);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
__owur int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
|
__owur int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
|
||||||
|
@ -3592,16 +3592,12 @@ int SSL_get_shared_sigalgs(SSL *s, int idx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ifndef OPENSSL_NO_HEARTBEATS
|
# ifndef OPENSSL_NO_HEARTBEATS
|
||||||
int tls1_process_heartbeat(SSL *s)
|
int tls1_process_heartbeat(SSL *s, unsigned char *p, unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned char *p, *pl;
|
unsigned char *pl;
|
||||||
unsigned short hbtype;
|
unsigned short hbtype;
|
||||||
unsigned int payload;
|
unsigned int payload;
|
||||||
unsigned int padding = 16; /* Use minimum padding */
|
unsigned int padding = 16; /* Use minimum padding */
|
||||||
unsigned int length;
|
|
||||||
|
|
||||||
p = SSL3_RECORD_get_data(RECORD_LAYER_get_rrec(&s->rlayer));
|
|
||||||
length = SSL3_RECORD_get_length(RECORD_LAYER_get_rrec(&s->rlayer));
|
|
||||||
|
|
||||||
if (s->msg_callback)
|
if (s->msg_callback)
|
||||||
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
|
s->msg_callback(0, s->version, TLS1_RT_HEARTBEAT,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user