2016-05-18 02:18:30 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2009-11-10 03:03:34 +08:00
|
|
|
*
|
2016-05-18 02:18:30 +08: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-10 03:03:34 +08:00
|
|
|
*/
|
2016-05-18 02:18:30 +08:00
|
|
|
|
2009-11-10 03:03:34 +08: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 11:40:55 +08: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-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2009-11-10 03:03:34 +08:00
|
|
|
/* Length byte */
|
2015-01-22 11:40:55 +08:00
|
|
|
*p = s->s3->previous_client_finished_len;
|
2009-11-10 03:03:34 +08:00
|
|
|
p++;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_client_finished,
|
2015-01-22 11:40:55 +08:00
|
|
|
s->s3->previous_client_finished_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = s->s3->previous_client_finished_len + 1;
|
2009-12-08 21:14:03 +08:00
|
|
|
|
2009-11-10 03:03:34 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* Parse the client's renegotiation binding and abort if it's not right
|
|
|
|
*/
|
2015-04-16 17:06:25 +08:00
|
|
|
int ssl_parse_clienthello_renegotiate_ext(SSL *s, PACKET *pkt, int *al)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2015-04-16 17:06:25 +08:00
|
|
|
unsigned int ilen;
|
2016-02-01 22:26:18 +08:00
|
|
|
const unsigned char *d;
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
/* Parse the length byte */
|
2015-04-16 17:06:25 +08:00
|
|
|
if (!PACKET_get_1(pkt, &ilen)
|
|
|
|
|| !PACKET_get_bytes(pkt, &d, ilen)) {
|
2015-01-22 11:40:55 +08:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
/* Check that the extension matches */
|
2015-01-22 11:40:55 +08: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-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08: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-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
s->s3->send_connection_binding = 1;
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
/* Add the server's renegotiation binding */
|
|
|
|
int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
|
2015-01-22 11:40:55 +08: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-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2009-11-10 03:03:34 +08:00
|
|
|
/* Length byte */
|
2015-01-22 11:40:55 +08:00
|
|
|
*p = s->s3->previous_client_finished_len +
|
|
|
|
s->s3->previous_server_finished_len;
|
2009-11-10 03:03:34 +08:00
|
|
|
p++;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_client_finished,
|
2015-01-22 11:40:55 +08:00
|
|
|
s->s3->previous_client_finished_len);
|
2009-11-10 03:03:34 +08:00
|
|
|
p += s->s3->previous_client_finished_len;
|
|
|
|
|
|
|
|
memcpy(p, s->s3->previous_server_finished,
|
2015-01-22 11:40:55 +08:00
|
|
|
s->s3->previous_server_finished_len);
|
2009-11-10 03:03:34 +08:00
|
|
|
}
|
|
|
|
|
2015-01-22 11:40:55 +08: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-05 00:36:02 +08:00
|
|
|
int ssl_parse_serverhello_renegotiate_ext(SSL *s, PACKET *pkt, int *al)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2015-08-05 00:36:02 +08:00
|
|
|
unsigned int expected_len = s->s3->previous_client_finished_len
|
2015-01-22 11:40:55 +08:00
|
|
|
+ s->s3->previous_server_finished_len;
|
2015-08-05 00:36:02 +08:00
|
|
|
unsigned int ilen;
|
2016-02-01 22:26:18 +08:00
|
|
|
const unsigned char *data;
|
2009-11-10 03:03:34 +08: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 11:40:55 +08:00
|
|
|
|
2009-11-10 03:03:34 +08:00
|
|
|
/* Parse the length byte */
|
2015-08-05 00:36:02 +08:00
|
|
|
if (!PACKET_get_1(pkt, &ilen)) {
|
2015-01-22 11:40:55 +08:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
/* Consistency check */
|
2015-08-05 00:36:02 +08:00
|
|
|
if (PACKET_remaining(pkt) != ilen) {
|
2015-01-22 11:40:55 +08:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_ENCODING_ERR);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2009-11-10 03:03:34 +08:00
|
|
|
/* Check that the extension matches */
|
2015-01-22 11:40:55 +08:00
|
|
|
if (ilen != expected_len) {
|
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
2015-08-05 00:36:02 +08: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 11:40:55 +08:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_HANDSHAKE_FAILURE;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2009-11-10 03:03:34 +08:00
|
|
|
|
2015-08-05 00:36:02 +08: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 11:40:55 +08:00
|
|
|
SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT,
|
|
|
|
SSL_R_RENEGOTIATION_MISMATCH);
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
2009-11-10 03:03:34 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
s->s3->send_connection_binding = 1;
|
2009-11-10 03:03:34 +08:00
|
|
|
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|