2016-05-17 18:18:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2009-11-09 19:03:34 +00:00
|
|
|
*
|
2016-05-17 18:18:30 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2009-11-09 19:03:34 +00:00
|
|
|
*/
|
2016-05-17 18:18:30 +00:00
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include "ssl_locl.h"
|
|
|
|
|
|
|
|
/* Add the client's renegotiation binding */
|
|
|
|
int ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
|
2015-01-22 03:40:55 +00:00
|
|
|
int maxlen)
|
|
|
|
{
|
|
|
|
if (p) {
|
|
|
|
if ((s->s3->previous_client_finished_len + 1) > maxlen) {
|
|
|
|
SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATE_EXT_TOO_LONG);
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
/* Length byte */
|
2015-01-22 03:40:55 +00:00
|
|
|
*p = s->s3->previous_client_finished_len;
|
2009-11-09 19:03:34 +00:00
|
|
|
p++;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_client_finished,
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->previous_client_finished_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = s->s3->previous_client_finished_len + 1;
|
2009-12-08 13:14:03 +00:00
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Parse the client's renegotiation binding and abort if it's not right
|
|
|
|
*/
|
2015-04-16 09:06:25 +00:00
|
|
|
int ssl_parse_clienthello_renegotiate_ext(SSL *s, PACKET *pkt, int *al)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-04-16 09:06:25 +00:00
|
|
|
unsigned int ilen;
|
2016-02-01 14:26:18 +00:00
|
|
|
const unsigned char *d;
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
/* Parse the length byte */
|
2015-04-16 09:06:25 +00:00
|
|
|
if (!PACKET_get_1(pkt, &ilen)
|
|
|
|
|| !PACKET_get_bytes(pkt, &d, ilen)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
/* Check that the extension matches */
|
2015-01-22 03:40:55 +00:00
|
|
|
if (ilen != s->s3->previous_client_finished_len) {
|
|
|
|
SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(d, s->s3->previous_client_finished,
|
|
|
|
s->s3->previous_client_finished_len)) {
|
|
|
|
SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->send_connection_binding = 1;
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
/* Add the server's renegotiation binding */
|
|
|
|
int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
|
2015-01-22 03:40:55 +00:00
|
|
|
int maxlen)
|
|
|
|
{
|
|
|
|
if (p) {
|
|
|
|
if ((s->s3->previous_client_finished_len +
|
|
|
|
s->s3->previous_server_finished_len + 1) > maxlen) {
|
|
|
|
SSLerr(SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATE_EXT_TOO_LONG);
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
/* Length byte */
|
2015-01-22 03:40:55 +00:00
|
|
|
*p = s->s3->previous_client_finished_len +
|
|
|
|
s->s3->previous_server_finished_len;
|
2009-11-09 19:03:34 +00:00
|
|
|
p++;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_client_finished,
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->previous_client_finished_len);
|
2009-11-09 19:03:34 +00:00
|
|
|
p += s->s3->previous_client_finished_len;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_server_finished,
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->previous_server_finished_len);
|
2009-11-09 19:03:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
*len = s->s3->previous_client_finished_len
|
|
|
|
+ s->s3->previous_server_finished_len + 1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the server's renegotiation binding and abort if it's not right
|
|
|
|
*/
|
2015-08-04 16:36:02 +00:00
|
|
|
int ssl_parse_serverhello_renegotiate_ext(SSL *s, PACKET *pkt, int *al)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-08-04 16:36:02 +00:00
|
|
|
unsigned int expected_len = s->s3->previous_client_finished_len
|
2015-01-22 03:40:55 +00:00
|
|
|
+ s->s3->previous_server_finished_len;
|
2015-08-04 16:36:02 +00:00
|
|
|
unsigned int ilen;
|
2016-02-01 14:26:18 +00:00
|
|
|
const unsigned char *data;
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
/* Check for logic errors */
|
|
|
|
OPENSSL_assert(!expected_len || s->s3->previous_client_finished_len);
|
|
|
|
OPENSSL_assert(!expected_len || s->s3->previous_server_finished_len);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
/* Parse the length byte */
|
2015-08-04 16:36:02 +00:00
|
|
|
if (!PACKET_get_1(pkt, &ilen)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
/* Consistency check */
|
2015-08-04 16:36:02 +00:00
|
|
|
if (PACKET_remaining(pkt) != ilen) {
|
2015-01-22 03:40:55 +00:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 19:03:34 +00:00
|
|
|
/* Check that the extension matches */
|
2015-01-22 03:40:55 +00:00
|
|
|
if (ilen != expected_len) {
|
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
2015-08-04 16:36:02 +00:00
|
|
|
if (!PACKET_get_bytes(pkt, &data, s->s3->previous_client_finished_len)
|
|
|
|
|| memcmp(data, s->s3->previous_client_finished,
|
|
|
|
s->s3->previous_client_finished_len) != 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2009-11-09 19:03:34 +00:00
|
|
|
|
2015-08-04 16:36:02 +00:00
|
|
|
if (!PACKET_get_bytes(pkt, &data, s->s3->previous_server_finished_len)
|
|
|
|
|| memcmp(data, s->s3->previous_server_finished,
|
|
|
|
s->s3->previous_server_finished_len) != 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-09 19:03:34 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
s->s3->send_connection_binding = 1;
|
2009-11-09 19:03:34 +00:00
|
|
|
|
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|