Merge branch 'development' into dtls

* development: (46 commits)
  Fix url again
  Fix small bug in base64_encode()
  Fix depend that was checked but not documented
  Fix dependency that was not checked
  Minor gitginore fixes
  Move some ignore patterns to subdirectories
  Ignore CMake/MSVC-related build files.
  Re-categorize changelog entry
  Fix misattribution
  Minor nits with stdout/stderr.
  Add cmake compatibility targets
  Add script for polarssl symlink creation
  Fix more stdio inclusion issues
  Add debug info for cert/suite selection
  Fix possible portability issue
  Fix bug in ssl_get_verify_result()
  aescrypt2.c local char array not initial
  Update Changelog
  Fix mips64 bignum implementation
  Fix usage string of ssl_client2
  ...

Conflicts:
	include/polarssl/ssl.h
	library/CMakeLists.txt
	library/Makefile
	programs/Makefile
	programs/ssl/ssl_client2.c
	programs/ssl/ssl_server2.c
	visualc/VS2010/PolarSSL.sln
	visualc/VS2010/mbedTLS.vcxproj
	visualc/VS6/mbedtls.dsp
	visualc/VS6/mbedtls.dsw
This commit is contained in:
Manuel Pégourié-Gonnard 2015-01-29 11:29:12 +00:00
commit 2a0718d947
267 changed files with 5475 additions and 3350 deletions

View file

@ -4,7 +4,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
* This file is part of mbed TLS (https://www.polarssl.org)
* This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,6 +27,13 @@
#include POLARSSL_CONFIG_FILE
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#define polarssl_fprintf fprintf
#endif
#if defined(_WIN32)
#include <windows.h>
#endif
@ -48,7 +55,7 @@
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
#include "polarssl/memory.h"
#include "polarssl/memory_buffer_alloc.h"
#endif
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
@ -62,7 +69,7 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
@ -86,7 +93,7 @@ static void my_mutexed_debug( void *ctx, int level, const char *str )
polarssl_mutex_lock( &debug_mutex );
if( level < DEBUG_LEVEL )
{
fprintf( (FILE *) ctx, "%s", str );
polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
polarssl_mutex_unlock( &debug_mutex );
@ -131,8 +138,8 @@ static void *handle_ssl_connection( void *data )
memset( &ctr_drbg, 0, sizeof( ctr_drbg_context ) );
snprintf( pers, sizeof(pers), "SSL Pthread Thread %d", thread_id );
printf( " [ #%d ] Client FD %d\n", thread_id, client_fd );
printf( " [ #%d ] Seeding the random number generator...\n", thread_id );
polarssl_printf( " [ #%d ] Client FD %d\n", thread_id, client_fd );
polarssl_printf( " [ #%d ] Seeding the random number generator...\n", thread_id );
/* entropy_func() is thread-safe if POLARSSL_THREADING_C is set
*/
@ -140,21 +147,21 @@ static void *handle_ssl_connection( void *data )
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
printf( " [ #%d ] failed: ctr_drbg_init returned -0x%04x\n",
polarssl_printf( " [ #%d ] failed: ctr_drbg_init returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
printf( " [ #%d ] ok\n", thread_id );
polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 4. Setup stuff
*/
printf( " [ #%d ] Setting up the SSL data....\n", thread_id );
polarssl_printf( " [ #%d ] Setting up the SSL data....\n", thread_id );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
printf( " [ #%d ] failed: ssl_init returned -0x%04x\n",
polarssl_printf( " [ #%d ] failed: ssl_init returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
@ -181,38 +188,38 @@ static void *handle_ssl_connection( void *data )
ssl_set_ca_chain( &ssl, thread_info->ca_chain, NULL, NULL );
if( ( ret = ssl_set_own_cert( &ssl, thread_info->server_cert, thread_info->server_key ) ) != 0 )
{
printf( " failed\n ! ssl_set_own_cert returned %d\n\n", ret );
polarssl_printf( " failed\n ! ssl_set_own_cert returned %d\n\n", ret );
goto thread_exit;
}
printf( " [ #%d ] ok\n", thread_id );
polarssl_printf( " [ #%d ] ok\n", thread_id );
ssl_set_bio( &ssl, net_recv, &client_fd,
net_send, &client_fd );
printf( " [ #%d ] ok\n", thread_id );
polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 5. Handshake
*/
printf( " [ #%d ] Performing the SSL/TLS handshake\n", thread_id );
polarssl_printf( " [ #%d ] Performing the SSL/TLS handshake\n", thread_id );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " [ #%d ] failed: ssl_handshake returned -0x%04x\n",
polarssl_printf( " [ #%d ] failed: ssl_handshake returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
}
printf( " [ #%d ] ok\n", thread_id );
polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 6. Read the HTTP Request
*/
printf( " [ #%d ] < Read from client\n", thread_id );
polarssl_printf( " [ #%d ] < Read from client\n", thread_id );
do
{
@ -228,24 +235,24 @@ static void *handle_ssl_connection( void *data )
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
printf( " [ #%d ] connection was closed gracefully\n",
polarssl_printf( " [ #%d ] connection was closed gracefully\n",
thread_id );
goto thread_exit;
case POLARSSL_ERR_NET_CONN_RESET:
printf( " [ #%d ] connection was reset by peer\n",
polarssl_printf( " [ #%d ] connection was reset by peer\n",
thread_id );
goto thread_exit;
default:
printf( " [ #%d ] ssl_read returned -0x%04x\n",
polarssl_printf( " [ #%d ] ssl_read returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
}
len = ret;
printf( " [ #%d ] %d bytes read\n=====\n%s\n=====\n",
polarssl_printf( " [ #%d ] %d bytes read\n=====\n%s\n=====\n",
thread_id, len, (char *) buf );
if( ret > 0 )
@ -256,7 +263,7 @@ static void *handle_ssl_connection( void *data )
/*
* 7. Write the 200 Response
*/
printf( " [ #%d ] > Write to client:\n", thread_id );
polarssl_printf( " [ #%d ] > Write to client:\n", thread_id );
len = sprintf( (char *) buf, HTTP_RESPONSE,
ssl_get_ciphersuite( &ssl ) );
@ -265,37 +272,37 @@ static void *handle_ssl_connection( void *data )
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
printf( " [ #%d ] failed: peer closed the connection\n",
polarssl_printf( " [ #%d ] failed: peer closed the connection\n",
thread_id );
goto thread_exit;
}
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " [ #%d ] failed: ssl_write returned -0x%04x\n",
polarssl_printf( " [ #%d ] failed: ssl_write returned -0x%04x\n",
thread_id, ret );
goto thread_exit;
}
}
len = ret;
printf( " [ #%d ] %d bytes written\n=====\n%s\n=====\n",
polarssl_printf( " [ #%d ] %d bytes written\n=====\n%s\n=====\n",
thread_id, len, (char *) buf );
printf( " [ #%d ] . Closing the connection...", thread_id );
polarssl_printf( " [ #%d ] . Closing the connection...", thread_id );
while( ( ret = ssl_close_notify( &ssl ) ) < 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " [ #%d ] failed: ssl_close_notify returned -0x%04x\n",
polarssl_printf( " [ #%d ] failed: ssl_close_notify returned -0x%04x\n",
thread_id, ret );
goto thread_exit;
}
}
printf( " ok\n" );
polarssl_printf( " ok\n" );
ret = 0;
@ -306,7 +313,7 @@ thread_exit:
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
printf(" [ #%d ] Last error was: -0x%04x - %s\n\n",
polarssl_printf(" [ #%d ] Last error was: -0x%04x - %s\n\n",
thread_id, -ret, error_buf );
}
#endif
@ -334,7 +341,7 @@ static int thread_create( int client_fd )
if( threads[i].data.thread_complete == 1 )
{
printf( " [ main ] Cleaning up thread %d\n", i );
polarssl_printf( " [ main ] Cleaning up thread %d\n", i );
pthread_join(threads[i].thread, NULL );
memset( &threads[i], 0, sizeof(pthread_info_t) );
break;
@ -400,7 +407,7 @@ int main( int argc, char *argv[] )
/*
* 1. Load the certificates and private RSA key
*/
printf( "\n . Loading the server cert. and key..." );
polarssl_printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
x509_crt_init( &srvcert );
@ -414,7 +421,7 @@ int main( int argc, char *argv[] )
strlen( test_srv_crt ) );
if( ret != 0 )
{
printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@ -422,7 +429,7 @@ int main( int argc, char *argv[] )
strlen( test_ca_list ) );
if( ret != 0 )
{
printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@ -431,7 +438,7 @@ int main( int argc, char *argv[] )
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
@ -439,21 +446,21 @@ int main( int argc, char *argv[] )
base_info.server_cert = &srvcert;
base_info.server_key = &pkey;
printf( " ok\n" );
polarssl_printf( " ok\n" );
/*
* 2. Setup the listening TCP socket
*/
printf( " . Bind on https://localhost:4433/ ..." );
polarssl_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = net_bind( &listen_fd, NULL, 4433, NET_PROTO_TCP ) ) != 0 )
{
printf( " failed\n ! net_bind returned %d\n\n", ret );
polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
goto exit;
}
printf( " ok\n" );
polarssl_printf( " ok\n" );
reset:
#ifdef POLARSSL_ERROR_C
@ -461,7 +468,7 @@ reset:
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
printf( " [ main ] Last error was: -0x%04x - %s\n", -ret, error_buf );
polarssl_printf( " [ main ] Last error was: -0x%04x - %s\n", -ret, error_buf );
}
#endif
@ -470,20 +477,20 @@ reset:
*/
client_fd = -1;
printf( " [ main ] Waiting for a remote connection\n" );
polarssl_printf( " [ main ] Waiting for a remote connection\n" );
if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
{
printf( " [ main ] failed: net_accept returned -0x%04x\n", ret );
polarssl_printf( " [ main ] failed: net_accept returned -0x%04x\n", ret );
goto exit;
}
printf( " [ main ] ok\n" );
printf( " [ main ] Creating a new thread\n" );
polarssl_printf( " [ main ] ok\n" );
polarssl_printf( " [ main ] Creating a new thread\n" );
if( ( ret = thread_create( client_fd ) ) != 0 )
{
printf( " [ main ] failed: thread_create returned %d\n", ret );
polarssl_printf( " [ main ] failed: thread_create returned %d\n", ret );
net_close( client_fd );
goto reset;
}
@ -506,7 +513,7 @@ exit:
#endif
#if defined(_WIN32)
printf( " Press Enter to exit this program.\n" );
polarssl_printf( " Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif