BA / Mbed OS BaBoRo_test2
Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:02dd72d1d465 1 /*
borlanic 0:02dd72d1d465 2 * Debugging routines
borlanic 0:02dd72d1d465 3 *
borlanic 0:02dd72d1d465 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
borlanic 0:02dd72d1d465 5 * SPDX-License-Identifier: Apache-2.0
borlanic 0:02dd72d1d465 6 *
borlanic 0:02dd72d1d465 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
borlanic 0:02dd72d1d465 8 * not use this file except in compliance with the License.
borlanic 0:02dd72d1d465 9 * You may obtain a copy of the License at
borlanic 0:02dd72d1d465 10 *
borlanic 0:02dd72d1d465 11 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:02dd72d1d465 12 *
borlanic 0:02dd72d1d465 13 * Unless required by applicable law or agreed to in writing, software
borlanic 0:02dd72d1d465 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
borlanic 0:02dd72d1d465 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:02dd72d1d465 16 * See the License for the specific language governing permissions and
borlanic 0:02dd72d1d465 17 * limitations under the License.
borlanic 0:02dd72d1d465 18 *
borlanic 0:02dd72d1d465 19 * This file is part of mbed TLS (https://tls.mbed.org)
borlanic 0:02dd72d1d465 20 */
borlanic 0:02dd72d1d465 21
borlanic 0:02dd72d1d465 22 #if !defined(MBEDTLS_CONFIG_FILE)
borlanic 0:02dd72d1d465 23 #include "mbedtls/config.h"
borlanic 0:02dd72d1d465 24 #else
borlanic 0:02dd72d1d465 25 #include MBEDTLS_CONFIG_FILE
borlanic 0:02dd72d1d465 26 #endif
borlanic 0:02dd72d1d465 27
borlanic 0:02dd72d1d465 28 #if defined(MBEDTLS_DEBUG_C)
borlanic 0:02dd72d1d465 29
borlanic 0:02dd72d1d465 30 #if defined(MBEDTLS_PLATFORM_C)
borlanic 0:02dd72d1d465 31 #include "mbedtls/platform.h"
borlanic 0:02dd72d1d465 32 #else
borlanic 0:02dd72d1d465 33 #include <stdlib.h>
borlanic 0:02dd72d1d465 34 #define mbedtls_calloc calloc
borlanic 0:02dd72d1d465 35 #define mbedtls_free free
borlanic 0:02dd72d1d465 36 #define mbedtls_time_t time_t
borlanic 0:02dd72d1d465 37 #define mbedtls_snprintf snprintf
borlanic 0:02dd72d1d465 38 #endif
borlanic 0:02dd72d1d465 39
borlanic 0:02dd72d1d465 40 #include "mbedtls/debug.h"
borlanic 0:02dd72d1d465 41
borlanic 0:02dd72d1d465 42 #include <stdarg.h>
borlanic 0:02dd72d1d465 43 #include <stdio.h>
borlanic 0:02dd72d1d465 44 #include <string.h>
borlanic 0:02dd72d1d465 45
borlanic 0:02dd72d1d465 46 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
borlanic 0:02dd72d1d465 47 !defined(inline) && !defined(__cplusplus)
borlanic 0:02dd72d1d465 48 #define inline __inline
borlanic 0:02dd72d1d465 49 #endif
borlanic 0:02dd72d1d465 50
borlanic 0:02dd72d1d465 51 #define DEBUG_BUF_SIZE 512
borlanic 0:02dd72d1d465 52
borlanic 0:02dd72d1d465 53 static int debug_threshold = 0;
borlanic 0:02dd72d1d465 54
borlanic 0:02dd72d1d465 55 void mbedtls_debug_set_threshold( int threshold )
borlanic 0:02dd72d1d465 56 {
borlanic 0:02dd72d1d465 57 debug_threshold = threshold;
borlanic 0:02dd72d1d465 58 }
borlanic 0:02dd72d1d465 59
borlanic 0:02dd72d1d465 60 /*
borlanic 0:02dd72d1d465 61 * All calls to f_dbg must be made via this function
borlanic 0:02dd72d1d465 62 */
borlanic 0:02dd72d1d465 63 static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 64 const char *file, int line,
borlanic 0:02dd72d1d465 65 const char *str )
borlanic 0:02dd72d1d465 66 {
borlanic 0:02dd72d1d465 67 /*
borlanic 0:02dd72d1d465 68 * If in a threaded environment, we need a thread identifier.
borlanic 0:02dd72d1d465 69 * Since there is no portable way to get one, use the address of the ssl
borlanic 0:02dd72d1d465 70 * context instead, as it shouldn't be shared between threads.
borlanic 0:02dd72d1d465 71 */
borlanic 0:02dd72d1d465 72 #if defined(MBEDTLS_THREADING_C)
borlanic 0:02dd72d1d465 73 char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
borlanic 0:02dd72d1d465 74 mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
borlanic 0:02dd72d1d465 75 ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
borlanic 0:02dd72d1d465 76 #else
borlanic 0:02dd72d1d465 77 ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
borlanic 0:02dd72d1d465 78 #endif
borlanic 0:02dd72d1d465 79 }
borlanic 0:02dd72d1d465 80
borlanic 0:02dd72d1d465 81 void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 82 const char *file, int line,
borlanic 0:02dd72d1d465 83 const char *format, ... )
borlanic 0:02dd72d1d465 84 {
borlanic 0:02dd72d1d465 85 va_list argp;
borlanic 0:02dd72d1d465 86 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 87 int ret;
borlanic 0:02dd72d1d465 88
borlanic 0:02dd72d1d465 89 if( NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold )
borlanic 0:02dd72d1d465 90 return;
borlanic 0:02dd72d1d465 91
borlanic 0:02dd72d1d465 92 va_start( argp, format );
borlanic 0:02dd72d1d465 93 #if defined(_WIN32)
borlanic 0:02dd72d1d465 94 #if defined(_TRUNCATE)
borlanic 0:02dd72d1d465 95 ret = _vsnprintf_s( str, DEBUG_BUF_SIZE, _TRUNCATE, format, argp );
borlanic 0:02dd72d1d465 96 #else
borlanic 0:02dd72d1d465 97 ret = _vsnprintf( str, DEBUG_BUF_SIZE, format, argp );
borlanic 0:02dd72d1d465 98 if( ret < 0 || (size_t) ret == DEBUG_BUF_SIZE )
borlanic 0:02dd72d1d465 99 {
borlanic 0:02dd72d1d465 100 str[DEBUG_BUF_SIZE-1] = '\0';
borlanic 0:02dd72d1d465 101 ret = -1;
borlanic 0:02dd72d1d465 102 }
borlanic 0:02dd72d1d465 103 #endif
borlanic 0:02dd72d1d465 104 #else
borlanic 0:02dd72d1d465 105 ret = vsnprintf( str, DEBUG_BUF_SIZE, format, argp );
borlanic 0:02dd72d1d465 106 #endif
borlanic 0:02dd72d1d465 107 va_end( argp );
borlanic 0:02dd72d1d465 108
borlanic 0:02dd72d1d465 109 if( ret >= 0 && ret < DEBUG_BUF_SIZE - 1 )
borlanic 0:02dd72d1d465 110 {
borlanic 0:02dd72d1d465 111 str[ret] = '\n';
borlanic 0:02dd72d1d465 112 str[ret + 1] = '\0';
borlanic 0:02dd72d1d465 113 }
borlanic 0:02dd72d1d465 114
borlanic 0:02dd72d1d465 115 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 116 }
borlanic 0:02dd72d1d465 117
borlanic 0:02dd72d1d465 118 void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 119 const char *file, int line,
borlanic 0:02dd72d1d465 120 const char *text, int ret )
borlanic 0:02dd72d1d465 121 {
borlanic 0:02dd72d1d465 122 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 123
borlanic 0:02dd72d1d465 124 if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
borlanic 0:02dd72d1d465 125 return;
borlanic 0:02dd72d1d465 126
borlanic 0:02dd72d1d465 127 /*
borlanic 0:02dd72d1d465 128 * With non-blocking I/O and examples that just retry immediately,
borlanic 0:02dd72d1d465 129 * the logs would be quickly flooded with WANT_READ, so ignore that.
borlanic 0:02dd72d1d465 130 * Don't ignore WANT_WRITE however, since is is usually rare.
borlanic 0:02dd72d1d465 131 */
borlanic 0:02dd72d1d465 132 if( ret == MBEDTLS_ERR_SSL_WANT_READ )
borlanic 0:02dd72d1d465 133 return;
borlanic 0:02dd72d1d465 134
borlanic 0:02dd72d1d465 135 mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
borlanic 0:02dd72d1d465 136 text, ret, -ret );
borlanic 0:02dd72d1d465 137
borlanic 0:02dd72d1d465 138 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 139 }
borlanic 0:02dd72d1d465 140
borlanic 0:02dd72d1d465 141 void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 142 const char *file, int line, const char *text,
borlanic 0:02dd72d1d465 143 const unsigned char *buf, size_t len )
borlanic 0:02dd72d1d465 144 {
borlanic 0:02dd72d1d465 145 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 146 char txt[17];
borlanic 0:02dd72d1d465 147 size_t i, idx = 0;
borlanic 0:02dd72d1d465 148
borlanic 0:02dd72d1d465 149 if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
borlanic 0:02dd72d1d465 150 return;
borlanic 0:02dd72d1d465 151
borlanic 0:02dd72d1d465 152 mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
borlanic 0:02dd72d1d465 153 text, (unsigned int) len );
borlanic 0:02dd72d1d465 154
borlanic 0:02dd72d1d465 155 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 156
borlanic 0:02dd72d1d465 157 idx = 0;
borlanic 0:02dd72d1d465 158 memset( txt, 0, sizeof( txt ) );
borlanic 0:02dd72d1d465 159 for( i = 0; i < len; i++ )
borlanic 0:02dd72d1d465 160 {
borlanic 0:02dd72d1d465 161 if( i >= 4096 )
borlanic 0:02dd72d1d465 162 break;
borlanic 0:02dd72d1d465 163
borlanic 0:02dd72d1d465 164 if( i % 16 == 0 )
borlanic 0:02dd72d1d465 165 {
borlanic 0:02dd72d1d465 166 if( i > 0 )
borlanic 0:02dd72d1d465 167 {
borlanic 0:02dd72d1d465 168 mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
borlanic 0:02dd72d1d465 169 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 170
borlanic 0:02dd72d1d465 171 idx = 0;
borlanic 0:02dd72d1d465 172 memset( txt, 0, sizeof( txt ) );
borlanic 0:02dd72d1d465 173 }
borlanic 0:02dd72d1d465 174
borlanic 0:02dd72d1d465 175 idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
borlanic 0:02dd72d1d465 176 (unsigned int) i );
borlanic 0:02dd72d1d465 177
borlanic 0:02dd72d1d465 178 }
borlanic 0:02dd72d1d465 179
borlanic 0:02dd72d1d465 180 idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x",
borlanic 0:02dd72d1d465 181 (unsigned int) buf[i] );
borlanic 0:02dd72d1d465 182 txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
borlanic 0:02dd72d1d465 183 }
borlanic 0:02dd72d1d465 184
borlanic 0:02dd72d1d465 185 if( len > 0 )
borlanic 0:02dd72d1d465 186 {
borlanic 0:02dd72d1d465 187 for( /* i = i */; i % 16 != 0; i++ )
borlanic 0:02dd72d1d465 188 idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
borlanic 0:02dd72d1d465 189
borlanic 0:02dd72d1d465 190 mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
borlanic 0:02dd72d1d465 191 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 192 }
borlanic 0:02dd72d1d465 193 }
borlanic 0:02dd72d1d465 194
borlanic 0:02dd72d1d465 195 #if defined(MBEDTLS_ECP_C)
borlanic 0:02dd72d1d465 196 void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 197 const char *file, int line,
borlanic 0:02dd72d1d465 198 const char *text, const mbedtls_ecp_point *X )
borlanic 0:02dd72d1d465 199 {
borlanic 0:02dd72d1d465 200 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 201
borlanic 0:02dd72d1d465 202 if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
borlanic 0:02dd72d1d465 203 return;
borlanic 0:02dd72d1d465 204
borlanic 0:02dd72d1d465 205 mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
borlanic 0:02dd72d1d465 206 mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
borlanic 0:02dd72d1d465 207
borlanic 0:02dd72d1d465 208 mbedtls_snprintf( str, sizeof( str ), "%s(Y)", text );
borlanic 0:02dd72d1d465 209 mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->Y );
borlanic 0:02dd72d1d465 210 }
borlanic 0:02dd72d1d465 211 #endif /* MBEDTLS_ECP_C */
borlanic 0:02dd72d1d465 212
borlanic 0:02dd72d1d465 213 #if defined(MBEDTLS_BIGNUM_C)
borlanic 0:02dd72d1d465 214 void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 215 const char *file, int line,
borlanic 0:02dd72d1d465 216 const char *text, const mbedtls_mpi *X )
borlanic 0:02dd72d1d465 217 {
borlanic 0:02dd72d1d465 218 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 219 int j, k, zeros = 1;
borlanic 0:02dd72d1d465 220 size_t i, n, idx = 0;
borlanic 0:02dd72d1d465 221
borlanic 0:02dd72d1d465 222 if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || X == NULL || level > debug_threshold )
borlanic 0:02dd72d1d465 223 return;
borlanic 0:02dd72d1d465 224
borlanic 0:02dd72d1d465 225 for( n = X->n - 1; n > 0; n-- )
borlanic 0:02dd72d1d465 226 if( X->p[n] != 0 )
borlanic 0:02dd72d1d465 227 break;
borlanic 0:02dd72d1d465 228
borlanic 0:02dd72d1d465 229 for( j = ( sizeof(mbedtls_mpi_uint) << 3 ) - 1; j >= 0; j-- )
borlanic 0:02dd72d1d465 230 if( ( ( X->p[n] >> j ) & 1 ) != 0 )
borlanic 0:02dd72d1d465 231 break;
borlanic 0:02dd72d1d465 232
borlanic 0:02dd72d1d465 233 mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
borlanic 0:02dd72d1d465 234 text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
borlanic 0:02dd72d1d465 235
borlanic 0:02dd72d1d465 236 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 237
borlanic 0:02dd72d1d465 238 idx = 0;
borlanic 0:02dd72d1d465 239 for( i = n + 1, j = 0; i > 0; i-- )
borlanic 0:02dd72d1d465 240 {
borlanic 0:02dd72d1d465 241 if( zeros && X->p[i - 1] == 0 )
borlanic 0:02dd72d1d465 242 continue;
borlanic 0:02dd72d1d465 243
borlanic 0:02dd72d1d465 244 for( k = sizeof( mbedtls_mpi_uint ) - 1; k >= 0; k-- )
borlanic 0:02dd72d1d465 245 {
borlanic 0:02dd72d1d465 246 if( zeros && ( ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF ) == 0 )
borlanic 0:02dd72d1d465 247 continue;
borlanic 0:02dd72d1d465 248 else
borlanic 0:02dd72d1d465 249 zeros = 0;
borlanic 0:02dd72d1d465 250
borlanic 0:02dd72d1d465 251 if( j % 16 == 0 )
borlanic 0:02dd72d1d465 252 {
borlanic 0:02dd72d1d465 253 if( j > 0 )
borlanic 0:02dd72d1d465 254 {
borlanic 0:02dd72d1d465 255 mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
borlanic 0:02dd72d1d465 256 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 257 idx = 0;
borlanic 0:02dd72d1d465 258 }
borlanic 0:02dd72d1d465 259 }
borlanic 0:02dd72d1d465 260
borlanic 0:02dd72d1d465 261 idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
borlanic 0:02dd72d1d465 262 ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
borlanic 0:02dd72d1d465 263
borlanic 0:02dd72d1d465 264 j++;
borlanic 0:02dd72d1d465 265 }
borlanic 0:02dd72d1d465 266
borlanic 0:02dd72d1d465 267 }
borlanic 0:02dd72d1d465 268
borlanic 0:02dd72d1d465 269 if( zeros == 1 )
borlanic 0:02dd72d1d465 270 idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
borlanic 0:02dd72d1d465 271
borlanic 0:02dd72d1d465 272 mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
borlanic 0:02dd72d1d465 273 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 274 }
borlanic 0:02dd72d1d465 275 #endif /* MBEDTLS_BIGNUM_C */
borlanic 0:02dd72d1d465 276
borlanic 0:02dd72d1d465 277 #if defined(MBEDTLS_X509_CRT_PARSE_C)
borlanic 0:02dd72d1d465 278 static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 279 const char *file, int line,
borlanic 0:02dd72d1d465 280 const char *text, const mbedtls_pk_context *pk )
borlanic 0:02dd72d1d465 281 {
borlanic 0:02dd72d1d465 282 size_t i;
borlanic 0:02dd72d1d465 283 mbedtls_pk_debug_item items[MBEDTLS_PK_DEBUG_MAX_ITEMS];
borlanic 0:02dd72d1d465 284 char name[16];
borlanic 0:02dd72d1d465 285
borlanic 0:02dd72d1d465 286 memset( items, 0, sizeof( items ) );
borlanic 0:02dd72d1d465 287
borlanic 0:02dd72d1d465 288 if( mbedtls_pk_debug( pk, items ) != 0 )
borlanic 0:02dd72d1d465 289 {
borlanic 0:02dd72d1d465 290 debug_send_line( ssl, level, file, line,
borlanic 0:02dd72d1d465 291 "invalid PK context\n" );
borlanic 0:02dd72d1d465 292 return;
borlanic 0:02dd72d1d465 293 }
borlanic 0:02dd72d1d465 294
borlanic 0:02dd72d1d465 295 for( i = 0; i < MBEDTLS_PK_DEBUG_MAX_ITEMS; i++ )
borlanic 0:02dd72d1d465 296 {
borlanic 0:02dd72d1d465 297 if( items[i].type == MBEDTLS_PK_DEBUG_NONE )
borlanic 0:02dd72d1d465 298 return;
borlanic 0:02dd72d1d465 299
borlanic 0:02dd72d1d465 300 mbedtls_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
borlanic 0:02dd72d1d465 301 name[sizeof( name ) - 1] = '\0';
borlanic 0:02dd72d1d465 302
borlanic 0:02dd72d1d465 303 if( items[i].type == MBEDTLS_PK_DEBUG_MPI )
borlanic 0:02dd72d1d465 304 mbedtls_debug_print_mpi( ssl, level, file, line, name, items[i].value );
borlanic 0:02dd72d1d465 305 else
borlanic 0:02dd72d1d465 306 #if defined(MBEDTLS_ECP_C)
borlanic 0:02dd72d1d465 307 if( items[i].type == MBEDTLS_PK_DEBUG_ECP )
borlanic 0:02dd72d1d465 308 mbedtls_debug_print_ecp( ssl, level, file, line, name, items[i].value );
borlanic 0:02dd72d1d465 309 else
borlanic 0:02dd72d1d465 310 #endif
borlanic 0:02dd72d1d465 311 debug_send_line( ssl, level, file, line,
borlanic 0:02dd72d1d465 312 "should not happen\n" );
borlanic 0:02dd72d1d465 313 }
borlanic 0:02dd72d1d465 314 }
borlanic 0:02dd72d1d465 315
borlanic 0:02dd72d1d465 316 static void debug_print_line_by_line( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 317 const char *file, int line, const char *text )
borlanic 0:02dd72d1d465 318 {
borlanic 0:02dd72d1d465 319 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 320 const char *start, *cur;
borlanic 0:02dd72d1d465 321
borlanic 0:02dd72d1d465 322 start = text;
borlanic 0:02dd72d1d465 323 for( cur = text; *cur != '\0'; cur++ )
borlanic 0:02dd72d1d465 324 {
borlanic 0:02dd72d1d465 325 if( *cur == '\n' )
borlanic 0:02dd72d1d465 326 {
borlanic 0:02dd72d1d465 327 size_t len = cur - start + 1;
borlanic 0:02dd72d1d465 328 if( len > DEBUG_BUF_SIZE - 1 )
borlanic 0:02dd72d1d465 329 len = DEBUG_BUF_SIZE - 1;
borlanic 0:02dd72d1d465 330
borlanic 0:02dd72d1d465 331 memcpy( str, start, len );
borlanic 0:02dd72d1d465 332 str[len] = '\0';
borlanic 0:02dd72d1d465 333
borlanic 0:02dd72d1d465 334 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 335
borlanic 0:02dd72d1d465 336 start = cur + 1;
borlanic 0:02dd72d1d465 337 }
borlanic 0:02dd72d1d465 338 }
borlanic 0:02dd72d1d465 339 }
borlanic 0:02dd72d1d465 340
borlanic 0:02dd72d1d465 341 void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
borlanic 0:02dd72d1d465 342 const char *file, int line,
borlanic 0:02dd72d1d465 343 const char *text, const mbedtls_x509_crt *crt )
borlanic 0:02dd72d1d465 344 {
borlanic 0:02dd72d1d465 345 char str[DEBUG_BUF_SIZE];
borlanic 0:02dd72d1d465 346 int i = 0;
borlanic 0:02dd72d1d465 347
borlanic 0:02dd72d1d465 348 if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || crt == NULL || level > debug_threshold )
borlanic 0:02dd72d1d465 349 return;
borlanic 0:02dd72d1d465 350
borlanic 0:02dd72d1d465 351 while( crt != NULL )
borlanic 0:02dd72d1d465 352 {
borlanic 0:02dd72d1d465 353 char buf[1024];
borlanic 0:02dd72d1d465 354
borlanic 0:02dd72d1d465 355 mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
borlanic 0:02dd72d1d465 356 debug_send_line( ssl, level, file, line, str );
borlanic 0:02dd72d1d465 357
borlanic 0:02dd72d1d465 358 mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
borlanic 0:02dd72d1d465 359 debug_print_line_by_line( ssl, level, file, line, buf );
borlanic 0:02dd72d1d465 360
borlanic 0:02dd72d1d465 361 debug_print_pk( ssl, level, file, line, "crt->", &crt->pk );
borlanic 0:02dd72d1d465 362
borlanic 0:02dd72d1d465 363 crt = crt->next;
borlanic 0:02dd72d1d465 364 }
borlanic 0:02dd72d1d465 365 }
borlanic 0:02dd72d1d465 366 #endif /* MBEDTLS_X509_CRT_PARSE_C */
borlanic 0:02dd72d1d465 367
borlanic 0:02dd72d1d465 368 #endif /* MBEDTLS_DEBUG_C */