blob: 753fc0faab20256de2473b3c3c9072d4e253daa4 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Debugging routines
3 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00006 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Paul Bakker5121ce52009-01-03 21:22:43 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker40e46942009-01-03 21:51:57 +000024#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000028
Paul Bakker40e46942009-01-03 21:51:57 +000029#if defined(POLARSSL_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Paul Bakker40e46942009-01-03 21:51:57 +000031#include "polarssl/debug.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000032
33#include <stdarg.h>
Paul Bakkerfa6a6202013-10-28 18:48:30 +010034#include <stdio.h>
Rich Evans00ab4702015-02-06 13:43:58 +000035#include <string.h>
Paul Bakkerfa6a6202013-10-28 18:48:30 +010036
Paul Bakker6edcd412013-10-29 15:22:54 +010037#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
38#if !defined snprintf
Paul Bakker5121ce52009-01-03 21:22:43 +000039#define snprintf _snprintf
40#endif
41
Paul Bakker6edcd412013-10-29 15:22:54 +010042#if !defined vsnprintf
Paul Bakker5121ce52009-01-03 21:22:43 +000043#define vsnprintf _vsnprintf
44#endif
Paul Bakker6edcd412013-10-29 15:22:54 +010045#endif /* _MSC_VER */
Paul Bakker5121ce52009-01-03 21:22:43 +000046
Rich Evans2387c7d2015-01-30 11:10:20 +000047#if defined(POLARSSL_PLATFORM_C)
48#include "polarssl/platform.h"
49#else
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020050#define polarssl_snprintf snprintf
51#define polarssl_malloc malloc
52#define polarssl_free free
Rich Evans2387c7d2015-01-30 11:10:20 +000053#endif
54
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020055#define DEBUG_BUF_SIZE 512
56
Paul Bakkereaebbd52014-04-25 15:04:14 +020057static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
Paul Bakkerc73079a2014-04-25 16:34:30 +020058static int debug_threshold = 0;
Paul Bakkereaebbd52014-04-25 15:04:14 +020059
60void debug_set_log_mode( int log_mode )
61{
62 debug_log_mode = log_mode;
63}
64
Paul Bakkerc73079a2014-04-25 16:34:30 +020065void debug_set_threshold( int threshold )
66{
67 debug_threshold = threshold;
68}
69
Paul Bakker5121ce52009-01-03 21:22:43 +000070char *debug_fmt( const char *format, ... )
71{
72 va_list argp;
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020073 char *str = polarssl_malloc( DEBUG_BUF_SIZE );
74
75 if( str == NULL )
76 return;
Paul Bakker5121ce52009-01-03 21:22:43 +000077
78 va_start( argp, format );
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020079 vsnprintf( str, DEBUG_BUF_SIZE - 1, format, argp );
Paul Bakker5121ce52009-01-03 21:22:43 +000080 va_end( argp );
81
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020082 str[DEBUG_BUF_SIZE - 1] = '\0';
Paul Bakker5121ce52009-01-03 21:22:43 +000083 return( str );
84}
85
Manuel Pégourié-Gonnard6c3ccf52015-06-29 14:57:45 +020086void debug_print_msg_free( const ssl_context *ssl, int level,
87 const char *file, int line, char *text )
88{
89 if( text != NULL )
90 debug_print_msg( ssl, level, file, line, text );
91
92 polarssl_free( text );
93}
94
Paul Bakkerff60ee62010-03-16 21:09:09 +000095void debug_print_msg( const ssl_context *ssl, int level,
96 const char *file, int line, const char *text )
Paul Bakker5121ce52009-01-03 21:22:43 +000097{
98 char str[512];
99 int maxlen = sizeof( str ) - 1;
100
Paul Bakkerc73079a2014-04-25 16:34:30 +0200101 if( ssl->f_dbg == NULL || level > debug_threshold )
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 return;
103
Paul Bakkereaebbd52014-04-25 15:04:14 +0200104 if( debug_log_mode == POLARSSL_DEBUG_LOG_RAW )
105 {
Paul Bakker5593f7c2014-05-06 10:29:28 +0200106 ssl->f_dbg( ssl->p_dbg, level, text );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200107 return;
108 }
109
Rich Evans2387c7d2015-01-30 11:10:20 +0000110 polarssl_snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
Paul Bakker5121ce52009-01-03 21:22:43 +0000111 str[maxlen] = '\0';
112 ssl->f_dbg( ssl->p_dbg, level, str );
113}
114
Paul Bakkerff60ee62010-03-16 21:09:09 +0000115void debug_print_ret( const ssl_context *ssl, int level,
116 const char *file, int line,
117 const char *text, int ret )
Paul Bakker5121ce52009-01-03 21:22:43 +0000118{
119 char str[512];
120 int maxlen = sizeof( str ) - 1;
Paul Bakkereaebbd52014-04-25 15:04:14 +0200121 size_t idx = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000122
Paul Bakkerc73079a2014-04-25 16:34:30 +0200123 if( ssl->f_dbg == NULL || level > debug_threshold )
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 return;
125
Paul Bakkereaebbd52014-04-25 15:04:14 +0200126 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000127 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200128
Rich Evans2387c7d2015-01-30 11:10:20 +0000129 polarssl_snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
Paul Bakkereaebbd52014-04-25 15:04:14 +0200130 text, ret, -ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000131
132 str[maxlen] = '\0';
133 ssl->f_dbg( ssl->p_dbg, level, str );
134}
135
Paul Bakkerff60ee62010-03-16 21:09:09 +0000136void debug_print_buf( const ssl_context *ssl, int level,
137 const char *file, int line, const char *text,
Paul Bakker23986e52011-04-24 08:57:21 +0000138 unsigned char *buf, size_t len )
Paul Bakker5121ce52009-01-03 21:22:43 +0000139{
140 char str[512];
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100141 char txt[17];
Paul Bakkereaebbd52014-04-25 15:04:14 +0200142 size_t i, maxlen = sizeof( str ) - 1, idx = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
Paul Bakkerc73079a2014-04-25 16:34:30 +0200144 if( ssl->f_dbg == NULL || level > debug_threshold )
Paul Bakker5121ce52009-01-03 21:22:43 +0000145 return;
146
Paul Bakkereaebbd52014-04-25 15:04:14 +0200147 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000148 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200149
Rich Evans2387c7d2015-01-30 11:10:20 +0000150 polarssl_snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
Paul Bakkereaebbd52014-04-25 15:04:14 +0200151 text, (unsigned int) len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000152
153 str[maxlen] = '\0';
154 ssl->f_dbg( ssl->p_dbg, level, str );
155
Paul Bakker92478c32014-04-25 15:18:34 +0200156 idx = 0;
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100157 memset( txt, 0, sizeof( txt ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000158 for( i = 0; i < len; i++ )
159 {
160 if( i >= 4096 )
161 break;
162
163 if( i % 16 == 0 )
164 {
165 if( i > 0 )
Paul Bakker92478c32014-04-25 15:18:34 +0200166 {
Rich Evans2387c7d2015-01-30 11:10:20 +0000167 polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
Paul Bakker92478c32014-04-25 15:18:34 +0200168 ssl->f_dbg( ssl->p_dbg, level, str );
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100169
Paul Bakker92478c32014-04-25 15:18:34 +0200170 idx = 0;
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100171 memset( txt, 0, sizeof( txt ) );
Paul Bakker92478c32014-04-25 15:18:34 +0200172 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000173
Paul Bakkereaebbd52014-04-25 15:04:14 +0200174 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000175 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200176
Rich Evans2387c7d2015-01-30 11:10:20 +0000177 idx += polarssl_snprintf( str + idx, maxlen - idx, "%04x: ",
Paul Bakker92478c32014-04-25 15:18:34 +0200178 (unsigned int) i );
Paul Bakker5121ce52009-01-03 21:22:43 +0000179
Paul Bakker5121ce52009-01-03 21:22:43 +0000180 }
181
Rich Evans2387c7d2015-01-30 11:10:20 +0000182 idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x",
Paul Bakker92478c32014-04-25 15:18:34 +0200183 (unsigned int) buf[i] );
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100184 txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
Paul Bakker5121ce52009-01-03 21:22:43 +0000185 }
186
187 if( len > 0 )
Paul Bakker92478c32014-04-25 15:18:34 +0200188 {
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100189 for( /* i = i */; i % 16 != 0; i++ )
Rich Evans2387c7d2015-01-30 11:10:20 +0000190 idx += polarssl_snprintf( str + idx, maxlen - idx, " " );
Manuel Pégourié-Gonnard8c9223d2014-11-19 10:17:21 +0100191
Rich Evans2387c7d2015-01-30 11:10:20 +0000192 polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
Paul Bakker92478c32014-04-25 15:18:34 +0200193 ssl->f_dbg( ssl->p_dbg, level, str );
194 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000195}
196
Paul Bakker41c83d32013-03-20 14:39:14 +0100197#if defined(POLARSSL_ECP_C)
198void debug_print_ecp( const ssl_context *ssl, int level,
199 const char *file, int line,
200 const char *text, const ecp_point *X )
201{
202 char str[512];
203 int maxlen = sizeof( str ) - 1;
204
Paul Bakkerc73079a2014-04-25 16:34:30 +0200205 if( ssl->f_dbg == NULL || level > debug_threshold )
206 return;
207
Rich Evans2387c7d2015-01-30 11:10:20 +0000208 polarssl_snprintf( str, maxlen, "%s(X)", text );
Paul Bakker41c83d32013-03-20 14:39:14 +0100209 str[maxlen] = '\0';
210 debug_print_mpi( ssl, level, file, line, str, &X->X );
211
Rich Evans2387c7d2015-01-30 11:10:20 +0000212 polarssl_snprintf( str, maxlen, "%s(Y)", text );
Paul Bakker41c83d32013-03-20 14:39:14 +0100213 str[maxlen] = '\0';
214 debug_print_mpi( ssl, level, file, line, str, &X->Y );
Paul Bakker41c83d32013-03-20 14:39:14 +0100215}
216#endif /* POLARSSL_ECP_C */
217
Paul Bakkered27a042013-04-18 22:46:23 +0200218#if defined(POLARSSL_BIGNUM_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000219void debug_print_mpi( const ssl_context *ssl, int level,
220 const char *file, int line,
221 const char *text, const mpi *X )
Paul Bakker5121ce52009-01-03 21:22:43 +0000222{
223 char str[512];
Paul Bakker23986e52011-04-24 08:57:21 +0000224 int j, k, maxlen = sizeof( str ) - 1, zeros = 1;
Paul Bakkereaebbd52014-04-25 15:04:14 +0200225 size_t i, n, idx = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000226
Paul Bakkerc73079a2014-04-25 16:34:30 +0200227 if( ssl->f_dbg == NULL || X == NULL || level > debug_threshold )
Paul Bakker5121ce52009-01-03 21:22:43 +0000228 return;
229
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000230 for( n = X->n - 1; n > 0; n-- )
Paul Bakker5121ce52009-01-03 21:22:43 +0000231 if( X->p[n] != 0 )
232 break;
233
Paul Bakkera755ca12011-04-24 09:11:17 +0000234 for( j = ( sizeof(t_uint) << 3 ) - 1; j >= 0; j-- )
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000235 if( ( ( X->p[n] >> j ) & 1 ) != 0 )
236 break;
237
Paul Bakkereaebbd52014-04-25 15:04:14 +0200238 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000239 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200240
Rich Evans2387c7d2015-01-30 11:10:20 +0000241 polarssl_snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
Paul Bakkereaebbd52014-04-25 15:04:14 +0200242 text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000243
244 str[maxlen] = '\0';
245 ssl->f_dbg( ssl->p_dbg, level, str );
246
Paul Bakker92478c32014-04-25 15:18:34 +0200247 idx = 0;
Paul Bakker23986e52011-04-24 08:57:21 +0000248 for( i = n + 1, j = 0; i > 0; i-- )
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 {
Paul Bakker23986e52011-04-24 08:57:21 +0000250 if( zeros && X->p[i - 1] == 0 )
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000251 continue;
Paul Bakker5121ce52009-01-03 21:22:43 +0000252
Paul Bakkera755ca12011-04-24 09:11:17 +0000253 for( k = sizeof( t_uint ) - 1; k >= 0; k-- )
Paul Bakker5121ce52009-01-03 21:22:43 +0000254 {
Paul Bakker66d5d072014-06-17 16:39:18 +0200255 if( zeros && ( ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF ) == 0 )
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000256 continue;
257 else
258 zeros = 0;
259
260 if( j % 16 == 0 )
261 {
262 if( j > 0 )
Paul Bakker92478c32014-04-25 15:18:34 +0200263 {
Rich Evans2387c7d2015-01-30 11:10:20 +0000264 polarssl_snprintf( str + idx, maxlen - idx, "\n" );
Paul Bakker92478c32014-04-25 15:18:34 +0200265 ssl->f_dbg( ssl->p_dbg, level, str );
266 idx = 0;
267 }
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000268
Paul Bakkereaebbd52014-04-25 15:04:14 +0200269 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000270 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000271 }
272
Rich Evans2387c7d2015-01-30 11:10:20 +0000273 idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
Paul Bakker66d5d072014-06-17 16:39:18 +0200274 ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000275
276 j++;
Paul Bakker5121ce52009-01-03 21:22:43 +0000277 }
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000278
279 }
280
281 if( zeros == 1 )
282 {
Paul Bakkereaebbd52014-04-25 15:04:14 +0200283 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
284 {
Rich Evans2387c7d2015-01-30 11:10:20 +0000285 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkerbe4e7dc2011-03-14 20:41:31 +0000286
Paul Bakkereaebbd52014-04-25 15:04:14 +0200287 }
Rich Evans2387c7d2015-01-30 11:10:20 +0000288 idx += polarssl_snprintf( str + idx, maxlen - idx, " 00" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000289 }
290
Rich Evans2387c7d2015-01-30 11:10:20 +0000291 polarssl_snprintf( str + idx, maxlen - idx, "\n" );
Paul Bakker92478c32014-04-25 15:18:34 +0200292 ssl->f_dbg( ssl->p_dbg, level, str );
Paul Bakker5121ce52009-01-03 21:22:43 +0000293}
Paul Bakkered27a042013-04-18 22:46:23 +0200294#endif /* POLARSSL_BIGNUM_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000295
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200296#if defined(POLARSSL_X509_CRT_PARSE_C)
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200297static void debug_print_pk( const ssl_context *ssl, int level,
298 const char *file, int line,
299 const char *text, const pk_context *pk )
300{
301 size_t i;
302 pk_debug_item items[POLARSSL_PK_DEBUG_MAX_ITEMS];
303 char name[16];
304
305 memset( items, 0, sizeof( items ) );
306
307 if( pk_debug( pk, items ) != 0 )
308 {
309 debug_print_msg( ssl, level, file, line, "invalid PK context" );
310 return;
311 }
312
Paul Bakker0e4f9112014-04-17 12:39:05 +0200313 for( i = 0; i < POLARSSL_PK_DEBUG_MAX_ITEMS; i++ )
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200314 {
315 if( items[i].type == POLARSSL_PK_DEBUG_NONE )
316 return;
317
Rich Evans2387c7d2015-01-30 11:10:20 +0000318 polarssl_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200319 name[sizeof( name ) - 1] = '\0';
320
321 if( items[i].type == POLARSSL_PK_DEBUG_MPI )
322 debug_print_mpi( ssl, level, file, line, name, items[i].value );
Manuel Pégourié-Gonnardbac0e3b2013-10-15 11:54:47 +0200323 else
324#if defined(POLARSSL_ECP_C)
325 if( items[i].type == POLARSSL_PK_DEBUG_ECP )
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200326 debug_print_ecp( ssl, level, file, line, name, items[i].value );
327 else
Manuel Pégourié-Gonnardbac0e3b2013-10-15 11:54:47 +0200328#endif
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200329 debug_print_msg( ssl, level, file, line, "should not happen" );
330 }
331}
332
Paul Bakkerff60ee62010-03-16 21:09:09 +0000333void debug_print_crt( const ssl_context *ssl, int level,
334 const char *file, int line,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200335 const char *text, const x509_crt *crt )
Paul Bakker5121ce52009-01-03 21:22:43 +0000336{
Paul Bakkerd98030e2009-05-02 15:13:40 +0000337 char str[1024], prefix[64];
Paul Bakkereaebbd52014-04-25 15:04:14 +0200338 int i = 0, maxlen = sizeof( prefix ) - 1, idx = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000339
Paul Bakkerc73079a2014-04-25 16:34:30 +0200340 if( ssl->f_dbg == NULL || crt == NULL || level > debug_threshold )
Paul Bakker5121ce52009-01-03 21:22:43 +0000341 return;
342
Paul Bakkereaebbd52014-04-25 15:04:14 +0200343 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
344 {
Rich Evans2387c7d2015-01-30 11:10:20 +0000345 polarssl_snprintf( prefix, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200346 prefix[maxlen] = '\0';
347 }
348 else
349 prefix[0] = '\0';
350
Paul Bakker5121ce52009-01-03 21:22:43 +0000351 maxlen = sizeof( str ) - 1;
352
Paul Bakker29087132010-03-21 21:03:34 +0000353 while( crt != NULL )
Paul Bakker5121ce52009-01-03 21:22:43 +0000354 {
Paul Bakkerd98030e2009-05-02 15:13:40 +0000355 char buf[1024];
Paul Bakkerddf26b42013-09-18 13:46:23 +0200356 x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
Paul Bakker5121ce52009-01-03 21:22:43 +0000357
Paul Bakkereaebbd52014-04-25 15:04:14 +0200358 if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
Rich Evans2387c7d2015-01-30 11:10:20 +0000359 idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
Paul Bakkereaebbd52014-04-25 15:04:14 +0200360
Rich Evans2387c7d2015-01-30 11:10:20 +0000361 polarssl_snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
Paul Bakkereaebbd52014-04-25 15:04:14 +0200362 text, ++i, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000363
364 str[maxlen] = '\0';
365 ssl->f_dbg( ssl->p_dbg, level, str );
366
Manuel Pégourié-Gonnardc6ac8872013-08-14 18:04:18 +0200367 debug_print_pk( ssl, level, file, line, "crt->", &crt->pk );
Paul Bakker5121ce52009-01-03 21:22:43 +0000368
369 crt = crt->next;
370 }
371}
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200372#endif /* POLARSSL_X509_CRT_PARSE_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000373
Paul Bakker9af723c2014-05-01 13:03:14 +0200374#endif /* POLARSSL_DEBUG_C */