1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

Merge remote-tracking branch 'rich/platform' into development

* rich/platform:
  Remove dependency on sscanf in lib x509
  Fix extra guard in memory_buffer_alloc
  rebase from development
  implemented macro overriding for polarssl_* library functions
  fix bug introduced by the addition of snprintf and assert macro which caused tests to fail without polarssl_platform_c defined
  add initial symbols to config and checks to check_config to allow use of macros to define standard functions
  reformat and arrange additions to config alphabetically
  add missing checks to check_config
  add macro definition of assert using polarssl_exit
  modify library/memory_buffer_alloc.c, benchmark.c and the tests main code to use polarssl_exit
  add POLARSSL_PLATFORM_EXIT_ALT
  modify scripts/* and tests/* to use polarssl_snprintf
  modify programs/*.c to use polarssl_snprintf
  modify library/debug.c to use polarssl_snprintf
  modify library/x509*.c to use polarssl_snprintf
  modify library/net.c to use polarssl_snprintf
  modify oid.c to use polarssl_snprintf
  add platform_set_snprintf

Conflicts:
	library/memory_buffer_alloc.c
	programs/pkey/pk_sign.c
	programs/pkey/pk_verify.c
	programs/pkey/rsa_sign_pss.c
	programs/pkey/rsa_verify_pss.c
	programs/ssl/ssl_client2.c
	programs/ssl/ssl_pthread_server.c
	programs/test/benchmark.c
	programs/test/ssl_cert_test.c
This commit is contained in:
Manuel Pégourié-Gonnard
2015-02-13 15:11:24 +00:00
25 changed files with 528 additions and 175 deletions

View File

@@ -44,6 +44,12 @@
#endif
#endif /* _MSC_VER */
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_snprintf snprintf
#endif
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
static int debug_threshold = 0;
@@ -86,7 +92,7 @@ void debug_print_msg( const ssl_context *ssl, int level,
return;
}
snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
polarssl_snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
}
@@ -103,9 +109,9 @@ void debug_print_ret( const ssl_context *ssl, int level,
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
polarssl_snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
text, ret, -ret );
str[maxlen] = '\0';
@@ -124,9 +130,9 @@ void debug_print_buf( const ssl_context *ssl, int level,
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
polarssl_snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
str[maxlen] = '\0';
@@ -143,7 +149,7 @@ void debug_print_buf( const ssl_context *ssl, int level,
{
if( i > 0 )
{
snprintf( str + idx, maxlen - idx, " %s\n", txt );
polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
@@ -151,14 +157,14 @@ void debug_print_buf( const ssl_context *ssl, int level,
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
idx += snprintf( str + idx, maxlen - idx, "%04x: ",
idx += polarssl_snprintf( str + idx, maxlen - idx, "%04x: ",
(unsigned int) i );
}
idx += snprintf( str + idx, maxlen - idx, " %02x",
idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x",
(unsigned int) buf[i] );
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
}
@@ -166,9 +172,9 @@ void debug_print_buf( const ssl_context *ssl, int level,
if( len > 0 )
{
for( /* i = i */; i % 16 != 0; i++ )
idx += snprintf( str + idx, maxlen - idx, " " );
idx += polarssl_snprintf( str + idx, maxlen - idx, " " );
snprintf( str + idx, maxlen - idx, " %s\n", txt );
polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
}
}
@@ -184,11 +190,11 @@ void debug_print_ecp( const ssl_context *ssl, int level,
if( ssl->f_dbg == NULL || level > debug_threshold )
return;
snprintf( str, maxlen, "%s(X)", text );
polarssl_snprintf( str, maxlen, "%s(X)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->X );
snprintf( str, maxlen, "%s(Y)", text );
polarssl_snprintf( str, maxlen, "%s(Y)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->Y );
}
@@ -215,9 +221,9 @@ void debug_print_mpi( const ssl_context *ssl, int level,
break;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
polarssl_snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
str[maxlen] = '\0';
@@ -240,16 +246,16 @@ void debug_print_mpi( const ssl_context *ssl, int level,
{
if( j > 0 )
{
snprintf( str + idx, maxlen - idx, "\n" );
polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++;
@@ -261,13 +267,13 @@ void debug_print_mpi( const ssl_context *ssl, int level,
{
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
idx += snprintf( str + idx, maxlen - idx, " 00" );
idx += polarssl_snprintf( str + idx, maxlen - idx, " 00" );
}
snprintf( str + idx, maxlen - idx, "\n" );
polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
}
#endif /* POLARSSL_BIGNUM_C */
@@ -294,7 +300,7 @@ static void debug_print_pk( const ssl_context *ssl, int level,
if( items[i].type == POLARSSL_PK_DEBUG_NONE )
return;
snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
polarssl_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
name[sizeof( name ) - 1] = '\0';
if( items[i].type == POLARSSL_PK_DEBUG_MPI )
@@ -321,7 +327,7 @@ void debug_print_crt( const ssl_context *ssl, int level,
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
snprintf( prefix, maxlen, "%s(%04d): ", file, line );
polarssl_snprintf( prefix, maxlen, "%s(%04d): ", file, line );
prefix[maxlen] = '\0';
}
else
@@ -335,9 +341,9 @@ void debug_print_crt( const ssl_context *ssl, int level,
x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
polarssl_snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
text, ++i, buf );
str[maxlen] = '\0';

View File

@@ -27,7 +27,6 @@
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
#include "polarssl/memory_buffer_alloc.h"
/* No need for the header guard as POLARSSL_MEMORY_BUFFER_ALLOC_C
@@ -269,7 +268,7 @@ static void *buffer_alloc_malloc( size_t len )
polarssl_fprintf( stderr, "FATAL: block in free_list but allocated "
"data\n" );
#endif
exit( 1 );
polarssl_exit( 1 );
}
#if defined(POLARSSL_MEMORY_DEBUG)
@@ -308,7 +307,7 @@ static void *buffer_alloc_malloc( size_t len )
#endif
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
exit( 1 );
polarssl_exit( 1 );
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
}
@@ -363,7 +362,7 @@ static void *buffer_alloc_malloc( size_t len )
#endif
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
exit( 1 );
polarssl_exit( 1 );
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
}
@@ -382,14 +381,14 @@ static void buffer_alloc_free( void *ptr )
polarssl_fprintf( stderr, "FATAL: polarssl_free() outside of managed "
"space\n" );
#endif
exit( 1 );
polarssl_exit( 1 );
}
p -= sizeof(memory_header);
hdr = (memory_header *) p;
if( verify_header( hdr ) != 0 )
exit( 1 );
polarssl_exit( 1 );
if( hdr->alloc != 1 )
{
@@ -397,7 +396,7 @@ static void buffer_alloc_free( void *ptr )
polarssl_fprintf( stderr, "FATAL: polarssl_free() on unallocated "
"data\n" );
#endif
exit( 1 );
polarssl_exit( 1 );
}
hdr->alloc = 0;
@@ -487,7 +486,7 @@ static void buffer_alloc_free( void *ptr )
#endif
if( ( heap.verify & MEMORY_VERIFY_FREE ) && verify_chain() != 0 )
exit( 1 );
polarssl_exit( 1 );
}
void memory_buffer_set_verify( int verify )

View File

@@ -129,6 +129,12 @@ typedef UINT32 uint32_t;
(((unsigned long )(n) & 0xFF000000) >> 24))
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_snprintf snprintf
#endif
unsigned short net_htons( unsigned short n );
unsigned long net_htonl( unsigned long n );
#define net_htons(n) POLARSSL_HTONS(n)
@@ -173,7 +179,7 @@ int net_connect( int *fd, const char *host, int port )
/* getaddrinfo expects port as a string */
memset( port_str, 0, sizeof( port_str ) );
snprintf( port_str, sizeof( port_str ), "%d", port );
polarssl_snprintf( port_str, sizeof( port_str ), "%d", port );
/* Do name resolution with both IPv6 and IPv4, but only TCP */
memset( &hints, 0, sizeof( hints ) );
@@ -259,7 +265,7 @@ int net_bind( int *fd, const char *bind_ip, int port )
/* getaddrinfo expects port as a string */
memset( port_str, 0, sizeof( port_str ) );
snprintf( port_str, sizeof( port_str ), "%d", port );
polarssl_snprintf( port_str, sizeof( port_str ), "%d", port );
/* Bind to IPv6 and/or IPv4, but only in TCP */
memset( &hints, 0, sizeof( hints ) );

View File

@@ -36,6 +36,12 @@
#include <stdio.h>
#include <string.h>
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
#include "polarssl/x509.h"
#endif
@@ -653,7 +659,7 @@ int oid_get_numeric_string( char *buf, size_t size,
/* First byte contains first two dots */
if( oid->len > 0 )
{
ret = snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
ret = polarssl_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
SAFE_SNPRINTF();
}
@@ -670,7 +676,7 @@ int oid_get_numeric_string( char *buf, size_t size,
if( !( oid->p[i] & 0x80 ) )
{
/* Last byte */
ret = snprintf( p, n, ".%d", value );
ret = polarssl_snprintf( p, n, ".%d", value );
SAFE_SNPRINTF();
value = 0;
}

View File

@@ -62,6 +62,36 @@ int platform_set_malloc_free( void * (*malloc_func)( size_t ),
}
#endif /* POLARSSL_PLATFORM_MEMORY */
#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
#if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
/*
* Make dummy function to prevent NULL pointer dereferences
*/
static int platform_snprintf_uninit( char * s, size_t n,
const char * format, ... )
{
((void) s);
((void) n);
((void) format)
return( 0 );
}
#define POLARSSL_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
#endif /* !POLARSSL_PLATFORM_STD_SNPRINTF */
int (*polarssl_snprintf)( char * s, size_t n,
const char * format,
... ) = POLARSSL_PLATFORM_STD_SNPRINTF;
int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
const char * format,
... ) )
{
polarssl_snprintf = snprintf_func;
return( 0 );
}
#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
/*
@@ -110,4 +140,27 @@ int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
}
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
#if defined(POLARSSL_PLATFORM_EXIT_ALT)
#if !defined(POLARSSL_STD_EXIT)
/*
* Make dummy function to prevent NULL pointer dereferences
*/
static void platform_exit_uninit( int status )
{
((void) status);
return( 0 );
}
#define POLARSSL_STD_EXIT platform_exit_uninit
#endif /* !POLARSSL_STD_EXIT */
int (*polarssl_exit)( int status ) = POLARSSL_STD_EXIT;
int platform_set_exit( void (*exit_func)( int status ) )
{
polarssl_exit = exit_func;
return( 0 );
}
#endif /* POLARSSL_PLATFORM_EXIT_ALT */
#endif /* POLARSSL_PLATFORM_C */

View File

@@ -54,9 +54,10 @@
#else
#include <stdio.h>
#include <stdlib.h>
#define polarssl_printf printf
#define polarssl_malloc malloc
#define polarssl_free free
#define polarssl_malloc malloc
#define polarssl_printf printf
#define polarssl_snprintf snprintf
#endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
@@ -74,6 +75,8 @@
#endif
#endif
#define CHECK(code) if( ( ret = code ) != 0 ){ return( ret ); }
/*
* CertificateSerialNumber ::= INTEGER
*/
@@ -475,6 +478,16 @@ int x509_get_name( unsigned char **p, const unsigned char *end,
}
}
static int x509_parse_int(unsigned char **p, unsigned n, int *res){
*res = 0;
for( ; n > 0; --n ){
if( ( **p < '0') || ( **p > '9' ) ) return POLARSSL_ERR_X509_INVALID_DATE;
*res *= 10;
*res += (*(*p)++ - '0');
}
return 0;
}
/*
* Time ::= CHOICE {
* utcTime UTCTime,
@@ -485,7 +498,6 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
{
int ret;
size_t len;
char date[64];
unsigned char tag;
if( ( end - *p ) < 1 )
@@ -502,20 +514,19 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
if( ret != 0 )
return( POLARSSL_ERR_X509_INVALID_DATE + ret );
memset( date, 0, sizeof( date ) );
memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
len : sizeof( date ) - 1 );
if( sscanf( date, "%2d%2d%2d%2d%2d%2dZ",
&time->year, &time->mon, &time->day,
&time->hour, &time->min, &time->sec ) < 5 )
CHECK( x509_parse_int( p, 2, &time->year ) );
CHECK( x509_parse_int( p, 2, &time->mon ) );
CHECK( x509_parse_int( p, 2, &time->day ) );
CHECK( x509_parse_int( p, 2, &time->hour ) );
CHECK( x509_parse_int( p, 2, &time->min ) );
if( len > 10 )
CHECK( x509_parse_int( p, 2, &time->sec ) );
if( len > 12 && *(*p)++ != 'Z' )
return( POLARSSL_ERR_X509_INVALID_DATE );
time->year += 100 * ( time->year < 50 );
time->year += 1900;
*p += len;
return( 0 );
}
else if( tag == ASN1_GENERALIZED_TIME )
@@ -526,17 +537,16 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
if( ret != 0 )
return( POLARSSL_ERR_X509_INVALID_DATE + ret );
memset( date, 0, sizeof( date ) );
memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
len : sizeof( date ) - 1 );
if( sscanf( date, "%4d%2d%2d%2d%2d%2dZ",
&time->year, &time->mon, &time->day,
&time->hour, &time->min, &time->sec ) < 5 )
CHECK( x509_parse_int( p, 4, &time->year ) );
CHECK( x509_parse_int( p, 2, &time->mon ) );
CHECK( x509_parse_int( p, 2, &time->day ) );
CHECK( x509_parse_int( p, 2, &time->hour ) );
CHECK( x509_parse_int( p, 2, &time->min ) );
if( len > 12 )
CHECK( x509_parse_int( p, 2, &time->sec ) );
if( len > 14 && *(*p)++ != 'Z' )
return( POLARSSL_ERR_X509_INVALID_DATE );
*p += len;
return( 0 );
}
else
@@ -736,16 +746,16 @@ int x509_dn_gets( char *buf, size_t size, const x509_name *dn )
if( name != dn )
{
ret = snprintf( p, n, merge ? " + " : ", " );
ret = polarssl_snprintf( p, n, merge ? " + " : ", " );
SAFE_SNPRINTF();
}
ret = oid_get_attr_short_name( &name->oid, &short_name );
if( ret == 0 )
ret = snprintf( p, n, "%s=", short_name );
ret = polarssl_snprintf( p, n, "%s=", short_name );
else
ret = snprintf( p, n, "\?\?=" );
ret = polarssl_snprintf( p, n, "\?\?=" );
SAFE_SNPRINTF();
for( i = 0; i < name->val.len; i++ )
@@ -759,7 +769,7 @@ int x509_dn_gets( char *buf, size_t size, const x509_name *dn )
else s[i] = c;
}
s[i] = '\0';
ret = snprintf( p, n, "%s", s );
ret = polarssl_snprintf( p, n, "%s", s );
SAFE_SNPRINTF();
merge = name->next_merged;
@@ -790,14 +800,14 @@ int x509_serial_gets( char *buf, size_t size, const x509_buf *serial )
if( i == 0 && nr > 1 && serial->p[i] == 0x0 )
continue;
ret = snprintf( p, n, "%02X%s",
ret = polarssl_snprintf( p, n, "%02X%s",
serial->p[i], ( i < nr - 1 ) ? ":" : "" );
SAFE_SNPRINTF();
}
if( nr != serial->len )
{
ret = snprintf( p, n, "...." );
ret = polarssl_snprintf( p, n, "...." );
SAFE_SNPRINTF();
}
@@ -818,9 +828,9 @@ int x509_sig_alg_gets( char *buf, size_t size, const x509_buf *sig_oid,
ret = oid_get_sig_alg_desc( sig_oid, &desc );
if( ret != 0 )
ret = snprintf( p, n, "???" );
ret = polarssl_snprintf( p, n, "???" );
else
ret = snprintf( p, n, "%s", desc );
ret = polarssl_snprintf( p, n, "%s", desc );
SAFE_SNPRINTF();
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
@@ -834,7 +844,7 @@ int x509_sig_alg_gets( char *buf, size_t size, const x509_buf *sig_oid,
md_info = md_info_from_type( md_alg );
mgf_md_info = md_info_from_type( pss_opts->mgf1_hash_id );
ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
ret = polarssl_snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
md_info ? md_info->name : "???",
mgf_md_info ? mgf_md_info->name : "???",
pss_opts->expected_salt_len );
@@ -861,7 +871,7 @@ int x509_key_size_helper( char *buf, size_t size, const char *name )
if( strlen( name ) + sizeof( " key size" ) > size )
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL );
ret = snprintf( p, n, "%s key size", name );
ret = polarssl_snprintf( p, n, "%s key size", name );
SAFE_SNPRINTF();
return( 0 );

View File

@@ -51,8 +51,9 @@
#include "polarssl/platform.h"
#else
#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#define polarssl_malloc malloc
#define polarssl_snprintf snprintf
#endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
@@ -630,23 +631,23 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
p = buf;
n = size;
ret = snprintf( p, n, "%sCRL version : %d",
ret = polarssl_snprintf( p, n, "%sCRL version : %d",
prefix, crl->version );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sissuer name : ", prefix );
ret = polarssl_snprintf( p, n, "\n%sissuer name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crl->issuer );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sthis update : " \
ret = polarssl_snprintf( p, n, "\n%sthis update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->this_update.year, crl->this_update.mon,
crl->this_update.day, crl->this_update.hour,
crl->this_update.min, crl->this_update.sec );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%snext update : " \
ret = polarssl_snprintf( p, n, "\n%snext update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->next_update.year, crl->next_update.mon,
crl->next_update.day, crl->next_update.hour,
@@ -655,20 +656,20 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
entry = &crl->entry;
ret = snprintf( p, n, "\n%sRevoked certificates:",
ret = polarssl_snprintf( p, n, "\n%sRevoked certificates:",
prefix );
SAFE_SNPRINTF();
while( entry != NULL && entry->raw.len != 0 )
{
ret = snprintf( p, n, "\n%sserial number: ",
ret = polarssl_snprintf( p, n, "\n%sserial number: ",
prefix );
SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &entry->serial );
SAFE_SNPRINTF();
ret = snprintf( p, n, " revocation date: " \
ret = polarssl_snprintf( p, n, " revocation date: " \
"%04d-%02d-%02d %02d:%02d:%02d",
entry->revocation_date.year, entry->revocation_date.mon,
entry->revocation_date.day, entry->revocation_date.hour,
@@ -678,14 +679,14 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
entry = entry->next;
}
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &crl->sig_oid1, crl->sig_pk, crl->sig_md,
crl->sig_opts );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n" );
ret = polarssl_snprintf( p, n, "\n" );
SAFE_SNPRINTF();
return( (int) ( size - n ) );

View File

@@ -52,8 +52,9 @@
#include "polarssl/platform.h"
#else
#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#define polarssl_malloc malloc
#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_THREADING_C)
@@ -1040,7 +1041,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
while( ( entry = readdir( dir ) ) != NULL )
{
snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
polarssl_snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
if( stat( entry_name, &sb ) == -1 )
{
@@ -1166,7 +1167,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size,
#define PRINT_ITEM(i) \
{ \
ret = snprintf( p, n, "%s" i, sep ); \
ret = polarssl_snprintf( p, n, "%s" i, sep ); \
SAFE_SNPRINTF(); \
sep = ", "; \
}
@@ -1239,7 +1240,7 @@ static int x509_info_ext_key_usage( char **buf, size_t *size,
if( oid_get_extended_key_usage( &cur->buf, &desc ) != 0 )
desc = "???";
ret = snprintf( p, n, "%s%s", sep, desc );
ret = polarssl_snprintf( p, n, "%s%s", sep, desc );
SAFE_SNPRINTF();
sep = ", ";
@@ -1269,41 +1270,41 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
p = buf;
n = size;
ret = snprintf( p, n, "%scert. version : %d\n",
ret = polarssl_snprintf( p, n, "%scert. version : %d\n",
prefix, crt->version );
SAFE_SNPRINTF();
ret = snprintf( p, n, "%sserial number : ",
ret = polarssl_snprintf( p, n, "%sserial number : ",
prefix );
SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &crt->serial );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sissuer name : ", prefix );
ret = polarssl_snprintf( p, n, "\n%sissuer name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crt->issuer );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%ssubject name : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssubject name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crt->subject );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sissued on : " \
ret = polarssl_snprintf( p, n, "\n%sissued on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_from.year, crt->valid_from.mon,
crt->valid_from.day, crt->valid_from.hour,
crt->valid_from.min, crt->valid_from.sec );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sexpires on : " \
ret = polarssl_snprintf( p, n, "\n%sexpires on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_to.year, crt->valid_to.mon,
crt->valid_to.day, crt->valid_to.hour,
crt->valid_to.min, crt->valid_to.sec );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &crt->sig_oid1, crt->sig_pk,
@@ -1317,7 +1318,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
return( ret );
}
ret = snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
ret = polarssl_snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
(int) pk_get_size( &crt->pk ) );
SAFE_SNPRINTF();
@@ -1327,20 +1328,20 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & EXT_BASIC_CONSTRAINTS )
{
ret = snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
ret = polarssl_snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
crt->ca_istrue ? "true" : "false" );
SAFE_SNPRINTF();
if( crt->max_pathlen > 0 )
{
ret = snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
ret = polarssl_snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
SAFE_SNPRINTF();
}
}
if( crt->ext_types & EXT_SUBJECT_ALT_NAME )
{
ret = snprintf( p, n, "\n%ssubject alt name : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssubject alt name : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_subject_alt_name( &p, &n,
@@ -1350,7 +1351,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & EXT_NS_CERT_TYPE )
{
ret = snprintf( p, n, "\n%scert. type : ", prefix );
ret = polarssl_snprintf( p, n, "\n%scert. type : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_cert_type( &p, &n, crt->ns_cert_type ) ) != 0 )
@@ -1359,7 +1360,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & EXT_KEY_USAGE )
{
ret = snprintf( p, n, "\n%skey usage : ", prefix );
ret = polarssl_snprintf( p, n, "\n%skey usage : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_key_usage( &p, &n, crt->key_usage ) ) != 0 )
@@ -1368,7 +1369,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & EXT_EXTENDED_KEY_USAGE )
{
ret = snprintf( p, n, "\n%sext key usage : ", prefix );
ret = polarssl_snprintf( p, n, "\n%sext key usage : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_ext_key_usage( &p, &n,
@@ -1376,7 +1377,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
return( ret );
}
ret = snprintf( p, n, "\n" );
ret = polarssl_snprintf( p, n, "\n" );
SAFE_SNPRINTF();
return( (int) ( size - n ) );

View File

@@ -51,8 +51,9 @@
#include "polarssl/platform.h"
#else
#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#define polarssl_malloc malloc
#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32)
@@ -388,16 +389,16 @@ int x509_csr_info( char *buf, size_t size, const char *prefix,
p = buf;
n = size;
ret = snprintf( p, n, "%sCSR version : %d",
ret = polarssl_snprintf( p, n, "%sCSR version : %d",
prefix, csr->version );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%ssubject name : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssubject name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &csr->subject );
SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%ssigned using : ", prefix );
ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &csr->sig_oid, csr->sig_pk, csr->sig_md,
@@ -410,7 +411,7 @@ int x509_csr_info( char *buf, size_t size, const char *prefix,
return( ret );
}
ret = snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
ret = polarssl_snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
(int) pk_get_size( &csr->pk ) );
SAFE_SNPRINTF();