blob: efc7e9fff987e9913ab9f5341afb84d83907bce2 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file debug.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +00004 * \brief Functions for controlling and providing debug output from the library.
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02007 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000027 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
Paul Bakker5121ce52009-01-03 21:22:43 +000048 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#ifndef MBEDTLS_DEBUG_H
50#define MBEDTLS_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000053#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#endif
Rich Evans00ab4702015-02-06 13:43:58 +000057
Paul Bakker314052f2011-08-15 09:07:52 +000058#include "ssl.h"
Rich Evans00ab4702015-02-06 13:43:58 +000059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010061#include "ecp.h"
62#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000065
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020066#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +020069 mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +020070 MBEDTLS_DEBUG_STRIP_PARENS args )
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020073 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
Paul Bakker5121ce52009-01-03 21:22:43 +000074
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020076 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
Paul Bakker5121ce52009-01-03 21:22:43 +000077
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#if defined(MBEDTLS_BIGNUM_C)
79#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020080 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020081#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if defined(MBEDTLS_ECP_C)
84#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020085 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020086#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010087
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_X509_CRT_PARSE_C)
89#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020090 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Paul Bakkered27a042013-04-18 22:46:23 +020091#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000092
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000094
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
96#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
97#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
98#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
99#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
100#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
Paul Bakkerc73079a2014-04-25 16:34:30 +0200108/**
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000109 * \brief Set the threshold error level to handle globally all debug output.
110 * Debug messages that have a level over the threshold value are
111 * discarded.
112 * (Default value: 0 = No debug )
Paul Bakkerc73079a2014-04-25 16:34:30 +0200113 *
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000114 * \param threshold theshold level of messages to filter on. Messages at a
115 * higher level will be discarded.
116 * - Debug levels
117 * - 0 No debug
118 * - 1 Error
119 * - 2 State change
120 * - 3 Informational
121 * - 4 Verbose
Paul Bakkerc73079a2014-04-25 16:34:30 +0200122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +0200124
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000125/**
Janos Follathd75b7822016-03-18 16:28:20 +0000126 * \brief Print a message to the debug output. This function is always used
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000127 * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
128 * context, file and line number parameters.
129 *
130 * \param ssl SSL context
131 * \param level error level of the debug message
132 * \param file file the message has occurred in
133 * \param line line number the message has occurred at
134 * \param format format specifier, in printf format
135 * \param ... variables used by the format specifier
136 *
137 * \attention This function is intended for INTERNAL usage within the
138 * library only.
139 */
Manuel Pégourié-Gonnarda16e7c42015-06-29 20:14:19 +0200140void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Manuel Pégourié-Gonnardb74c2452015-06-29 20:08:23 +0200141 const char *file, int line,
142 const char *format, ... );
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +0200143
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000144/**
145 * \brief Print the return value of a function to the debug output. This
146 * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
147 * which supplies the ssl context, file and line number parameters.
148 *
149 * \param ssl SSL context
150 * \param level error level of the debug message
151 * \param file file the error has occurred in
152 * \param line line number the error has occurred in
153 * \param text the name of the function that returned the error
154 * \param ret the return code value
155 *
156 * \attention This function is intended for INTERNAL usage within the
157 * library only.
158 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000160 const char *file, int line,
161 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000162
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000163/**
164 * \brief Output a buffer of size len bytes to the debug output. This function
165 * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
166 * which supplies the ssl context, file and line number parameters.
167 *
168 * \param ssl SSL context
169 * \param level error level of the debug message
170 * \param file file the error has occurred in
171 * \param line line number the error has occurred in
172 * \param text a name or label for the buffer being dumped. Normally the
173 * variable or buffer name
174 * \param buf the buffer to be outputted
175 * \param len length of the buffer
176 *
177 * \attention This function is intended for INTERNAL usage within the
178 * library only.
179 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000181 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000182 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000183
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184#if defined(MBEDTLS_BIGNUM_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000185/**
186 * \brief Print a MPI variable to the debug output. This function is always
187 * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
188 * ssl context, file and line number parameters.
189 *
190 * \param ssl SSL context
191 * \param level error level of the debug message
192 * \param file file the error has occurred in
193 * \param line line number the error has occurred in
194 * \param text a name or label for the MPI being output. Normally the
195 * variable name
196 * \param X the MPI variable
197 *
198 * \attention This function is intended for INTERNAL usage within the
199 * library only.
200 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000202 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200204#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206#if defined(MBEDTLS_ECP_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000207/**
208 * \brief Print an ECP point to the debug output. This function is always
209 * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
210 * ssl context, file and line number parameters.
211 *
212 * \param ssl SSL context
213 * \param level error level of the debug message
214 * \param file file the error has occurred in
215 * \param line line number the error has occurred in
216 * \param text a name or label for the ECP point being output. Normally the
217 * variable name
218 * \param X the ECP point
219 *
220 * \attention This function is intended for INTERNAL usage within the
221 * library only.
222 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100224 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100226#endif
227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228#if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000229/**
230 * \brief Print a X.509 certificate structure to the debug output. This
231 * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
232 * which supplies the ssl context, file and line number parameters.
233 *
234 * \param ssl SSL context
235 * \param level error level of the debug message
236 * \param file file the error has occurred in
237 * \param line line number the error has occurred in
238 * \param text a name or label for the certificate being output
239 * \param crt X.509 certificate structure
240 *
241 * \attention This function is intended for INTERNAL usage within the
242 * library only.
243 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000245 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200247#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000248
249#ifdef __cplusplus
250}
251#endif
252
253#endif /* debug.h */
Simon Butcher7ef5cf32016-02-13 22:20:04 +0000254