Allow requests of size larger than 16384 in ssl_client2
This commit is contained in:
parent
5175ac6e13
commit
e4ad3e8803
1 changed files with 19 additions and 7 deletions
|
@ -63,6 +63,9 @@ int main( void )
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_REQUEST_SIZE 20000
|
||||
#define MAX_REQUEST_SIZE_STR "20000"
|
||||
|
||||
#define DFL_SERVER_NAME "localhost"
|
||||
#define DFL_SERVER_ADDR NULL
|
||||
#define DFL_SERVER_PORT "4433"
|
||||
|
@ -242,8 +245,8 @@ int main( void )
|
|||
" server_addr=%%s default: given by name\n" \
|
||||
" server_port=%%d default: 4433\n" \
|
||||
" request_page=%%s default: \".\"\n" \
|
||||
" request_size=%%d default: about 34 (basic request)\n" \
|
||||
" (minimum: 0, max: 16384)\n" \
|
||||
" request_size=%%d default: about 34 (basic request)\n" \
|
||||
" (minimum: 0, max: " MAX_REQUEST_SIZE_STR " )\n" \
|
||||
" debug_level=%%d default: 0 (disabled)\n" \
|
||||
" nbio=%%d default: 0 (blocking I/O)\n" \
|
||||
" options: 1 (non-blocking), 2 (added delays)\n" \
|
||||
|
@ -437,7 +440,9 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
||||
mbedtls_net_context server_fd;
|
||||
unsigned char buf[MBEDTLS_SSL_MAX_CONTENT_LEN + 1];
|
||||
|
||||
unsigned char buf[MAX_REQUEST_SIZE + 1];
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
|
||||
size_t psk_len = 0;
|
||||
|
@ -602,7 +607,8 @@ int main( int argc, char *argv[] )
|
|||
else if( strcmp( p, "request_size" ) == 0 )
|
||||
{
|
||||
opt.request_size = atoi( q );
|
||||
if( opt.request_size < 0 || opt.request_size > MBEDTLS_SSL_MAX_CONTENT_LEN )
|
||||
if( opt.request_size < 0 ||
|
||||
opt.request_size > MAX_REQUEST_SIZE )
|
||||
goto usage;
|
||||
}
|
||||
else if( strcmp( p, "ca_file" ) == 0 )
|
||||
|
@ -1494,8 +1500,8 @@ send_request:
|
|||
mbedtls_printf( " > Write to server:" );
|
||||
fflush( stdout );
|
||||
|
||||
len = mbedtls_snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
|
||||
opt.request_page );
|
||||
len = mbedtls_snprintf( (char *) buf, sizeof( buf ) - 1, GET_REQUEST,
|
||||
opt.request_page );
|
||||
tail_len = (int) strlen( GET_REQUEST_END );
|
||||
|
||||
/* Add padding to GET request to reach opt.request_size in length */
|
||||
|
@ -1506,7 +1512,7 @@ send_request:
|
|||
len += opt.request_size - len - tail_len;
|
||||
}
|
||||
|
||||
strncpy( (char *) buf + len, GET_REQUEST_END, sizeof(buf) - len - 1 );
|
||||
strncpy( (char *) buf + len, GET_REQUEST_END, sizeof( buf ) - len - 1 );
|
||||
len += tail_len;
|
||||
|
||||
/* Truncate if request size is smaller than the "natural" size */
|
||||
|
@ -1550,6 +1556,12 @@ send_request:
|
|||
|
||||
frags = 1;
|
||||
written = ret;
|
||||
|
||||
if( written < len )
|
||||
{
|
||||
mbedtls_printf( " warning\n ! request didn't fit into single datagram and "
|
||||
"was truncated to size %u", (unsigned) written );
|
||||
}
|
||||
}
|
||||
|
||||
buf[written] = '\0';
|
||||
|
|
Loading…
Reference in a new issue