Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file debug.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 4 | * \brief Functions for controlling and providing debug output from the library. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 8 | * 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é-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 15 | * |
| 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 Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 27 | * |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 28 | * ********** |
| 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 | * ********** |
| 48 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 49 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 51 | #ifndef MBEDTLS_DEBUG_H |
| 52 | #define MBEDTLS_DEBUG_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 53 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 54 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 55 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 56 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 58 | #endif |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 59 | |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 60 | #include "ssl.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 61 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | #if defined(MBEDTLS_ECP_C) |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 63 | #include "ecp.h" |
| 64 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | #if defined(MBEDTLS_DEBUG_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 68 | #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__ |
| 69 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 70 | #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \ |
Manuel Pégourié-Gonnard | a16e7c4 | 2015-06-29 20:14:19 +0200 | [diff] [blame] | 71 | mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \ |
Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 72 | MBEDTLS_DEBUG_STRIP_PARENS args ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 73 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \ |
Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 75 | mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 76 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 77 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \ |
Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 78 | mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 79 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | #if defined(MBEDTLS_BIGNUM_C) |
| 81 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \ |
Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 82 | mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X ) |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 83 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 85 | #if defined(MBEDTLS_ECP_C) |
| 86 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \ |
Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 87 | mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X ) |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 88 | #endif |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 89 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
| 91 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \ |
Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 92 | mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ) |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 93 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 94 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 95 | #else /* MBEDTLS_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 96 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 97 | #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 ) |
| 98 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 ) |
| 99 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 ) |
| 100 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 ) |
| 101 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 ) |
| 102 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | #endif /* MBEDTLS_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 105 | |
| 106 | #ifdef __cplusplus |
| 107 | extern "C" { |
| 108 | #endif |
| 109 | |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 110 | /** |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 111 | * \brief Set the threshold error level to handle globally all debug output. |
| 112 | * Debug messages that have a level over the threshold value are |
| 113 | * discarded. |
| 114 | * (Default value: 0 = No debug ) |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 115 | * |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 116 | * \param threshold theshold level of messages to filter on. Messages at a |
| 117 | * higher level will be discarded. |
| 118 | * - Debug levels |
| 119 | * - 0 No debug |
| 120 | * - 1 Error |
| 121 | * - 2 State change |
| 122 | * - 3 Informational |
| 123 | * - 4 Verbose |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 124 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 125 | void mbedtls_debug_set_threshold( int threshold ); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 126 | |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 127 | /** |
Janos Follath | d75b782 | 2016-03-18 16:28:20 +0000 | [diff] [blame] | 128 | * \brief Print a message to the debug output. This function is always used |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 129 | * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl |
| 130 | * context, file and line number parameters. |
| 131 | * |
| 132 | * \param ssl SSL context |
| 133 | * \param level error level of the debug message |
| 134 | * \param file file the message has occurred in |
| 135 | * \param line line number the message has occurred at |
| 136 | * \param format format specifier, in printf format |
| 137 | * \param ... variables used by the format specifier |
| 138 | * |
| 139 | * \attention This function is intended for INTERNAL usage within the |
| 140 | * library only. |
| 141 | */ |
Manuel Pégourié-Gonnard | a16e7c4 | 2015-06-29 20:14:19 +0200 | [diff] [blame] | 142 | void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, |
Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 143 | const char *file, int line, |
| 144 | const char *format, ... ); |
Manuel Pégourié-Gonnard | d23f593 | 2015-06-23 12:04:52 +0200 | [diff] [blame] | 145 | |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 146 | /** |
| 147 | * \brief Print the return value of a function to the debug output. This |
| 148 | * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro, |
| 149 | * which supplies the ssl context, file and line number parameters. |
| 150 | * |
| 151 | * \param ssl SSL context |
| 152 | * \param level error level of the debug message |
| 153 | * \param file file the error has occurred in |
| 154 | * \param line line number the error has occurred in |
| 155 | * \param text the name of the function that returned the error |
| 156 | * \param ret the return code value |
| 157 | * |
| 158 | * \attention This function is intended for INTERNAL usage within the |
| 159 | * library only. |
| 160 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 161 | void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 162 | const char *file, int line, |
| 163 | const char *text, int ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 164 | |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 165 | /** |
| 166 | * \brief Output a buffer of size len bytes to the debug output. This function |
| 167 | * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro, |
| 168 | * which supplies the ssl context, file and line number parameters. |
| 169 | * |
| 170 | * \param ssl SSL context |
| 171 | * \param level error level of the debug message |
| 172 | * \param file file the error has occurred in |
| 173 | * \param line line number the error has occurred in |
| 174 | * \param text a name or label for the buffer being dumped. Normally the |
| 175 | * variable or buffer name |
| 176 | * \param buf the buffer to be outputted |
| 177 | * \param len length of the buffer |
| 178 | * |
| 179 | * \attention This function is intended for INTERNAL usage within the |
| 180 | * library only. |
| 181 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 183 | const char *file, int line, const char *text, |
Manuel Pégourié-Gonnard | a78b218 | 2015-03-19 17:16:11 +0000 | [diff] [blame] | 184 | const unsigned char *buf, size_t len ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 185 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 186 | #if defined(MBEDTLS_BIGNUM_C) |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 187 | /** |
| 188 | * \brief Print a MPI variable to the debug output. This function is always |
| 189 | * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the |
| 190 | * ssl context, file and line number parameters. |
| 191 | * |
| 192 | * \param ssl SSL context |
| 193 | * \param level error level of the debug message |
| 194 | * \param file file the error has occurred in |
| 195 | * \param line line number the error has occurred in |
| 196 | * \param text a name or label for the MPI being output. Normally the |
| 197 | * variable name |
| 198 | * \param X the MPI variable |
| 199 | * |
| 200 | * \attention This function is intended for INTERNAL usage within the |
| 201 | * library only. |
| 202 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 204 | const char *file, int line, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 205 | const char *text, const mbedtls_mpi *X ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 206 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 207 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 208 | #if defined(MBEDTLS_ECP_C) |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 209 | /** |
| 210 | * \brief Print an ECP point to the debug output. This function is always |
| 211 | * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the |
| 212 | * ssl context, file and line number parameters. |
| 213 | * |
| 214 | * \param ssl SSL context |
| 215 | * \param level error level of the debug message |
| 216 | * \param file file the error has occurred in |
| 217 | * \param line line number the error has occurred in |
| 218 | * \param text a name or label for the ECP point being output. Normally the |
| 219 | * variable name |
| 220 | * \param X the ECP point |
| 221 | * |
| 222 | * \attention This function is intended for INTERNAL usage within the |
| 223 | * library only. |
| 224 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 225 | void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level, |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 226 | const char *file, int line, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 227 | const char *text, const mbedtls_ecp_point *X ); |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 228 | #endif |
| 229 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 230 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 231 | /** |
| 232 | * \brief Print a X.509 certificate structure to the debug output. This |
| 233 | * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro, |
| 234 | * which supplies the ssl context, file and line number parameters. |
| 235 | * |
| 236 | * \param ssl SSL context |
| 237 | * \param level error level of the debug message |
| 238 | * \param file file the error has occurred in |
| 239 | * \param line line number the error has occurred in |
| 240 | * \param text a name or label for the certificate being output |
| 241 | * \param crt X.509 certificate structure |
| 242 | * |
| 243 | * \attention This function is intended for INTERNAL usage within the |
| 244 | * library only. |
| 245 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 247 | const char *file, int line, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 248 | const char *text, const mbedtls_x509_crt *crt ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 249 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 250 | |
| 251 | #ifdef __cplusplus |
| 252 | } |
| 253 | #endif |
| 254 | |
| 255 | #endif /* debug.h */ |
Simon Butcher | 7ef5cf3 | 2016-02-13 22:20:04 +0000 | [diff] [blame] | 256 | |