2 * Copyright (C) 2001, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavroyanopoulos
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 /* This file contains the code for the Max Record Size TLS extension.
28 #include "gnutls_int.h"
29 #include "gnutls_errors.h"
30 #include "gnutls_num.h"
31 #include <ext_max_record.h>
34 * In case of a server: if a MAX_RECORD_SIZE extension type is received then it stores
35 * into the session the new value. The server may use gnutls_get_max_record_size(),
36 * in order to access it.
38 * In case of a client: If a different max record size (than the default) has
39 * been specified then it sends the extension.
44 _gnutls_max_record_recv_params (gnutls_session_t session
,
45 const opaque
* data
, size_t _data_size
)
48 ssize_t data_size
= _data_size
;
50 if (session
->security_parameters
.entity
== GNUTLS_SERVER
)
54 DECR_LEN (data_size
, 1);
56 new_size
= _gnutls_mre_num2record (data
[0]);
64 session
->security_parameters
.max_record_send_size
= new_size
;
65 session
->security_parameters
.max_record_recv_size
= new_size
;
69 { /* CLIENT SIDE - we must check if the sent record size is the right one
77 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH
;
80 new_size
= _gnutls_mre_num2record (data
[0]);
83 || new_size
!= session
->internals
.proposed_record_size
)
86 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
90 session
->security_parameters
.max_record_recv_size
=
91 session
->internals
.proposed_record_size
;
102 /* returns data_size or a negative number on failure
105 _gnutls_max_record_send_params (gnutls_session_t session
, opaque
* data
,
109 /* this function sends the client extension data (dnsname) */
110 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
113 if (session
->internals
.proposed_record_size
!= DEFAULT_MAX_RECORD_SIZE
)
119 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
123 (uint8_t) _gnutls_mre_record2num (session
->internals
.
124 proposed_record_size
);
132 if (session
->security_parameters
.max_record_recv_size
!=
133 DEFAULT_MAX_RECORD_SIZE
)
139 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
143 (uint8_t) _gnutls_mre_record2num (session
->
145 max_record_recv_size
);
155 /* Maps numbers to record sizes according to the
159 _gnutls_mre_num2record (int num
)
172 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
176 /* Maps record size to numbers according to the
180 _gnutls_mre_record2num (uint16_t record_size
)
193 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;