1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
18 #include "platform/ssl_port.h"
24 #ifdef CONFIG_OPENSSL_DEBUG_LEVEL
25 #define SSL_DEBUG_LEVEL CONFIG_OPENSSL_DEBUG_LEVEL
27 #define SSL_DEBUG_LEVEL 0
30 #define SSL_DEBUG_ON (SSL_DEBUG_LEVEL + 1)
31 #define SSL_DEBUG_OFF (SSL_DEBUG_LEVEL - 1)
33 #ifdef CONFIG_OPENSSL_DEBUG
35 #error "SSL_DEBUG_LOG is not defined"
39 #define SSL_DEBUG_FL "\n"
42 #define SSL_SHOW_LOCATION() \
43 SSL_DEBUG_LOG("SSL assert : %s %d\n", \
46 #define SSL_DEBUG(level, fmt, ...) \
48 if (level > SSL_DEBUG_LEVEL) { \
49 SSL_DEBUG_LOG(fmt SSL_DEBUG_FL, ##__VA_ARGS__); \
52 #else /* CONFIG_OPENSSL_DEBUG */
53 #define SSL_SHOW_LOCATION()
55 #define SSL_DEBUG(level, fmt, ...)
56 #endif /* CONFIG_OPENSSL_DEBUG */
59 * OpenSSL assert function
61 * if select "CONFIG_OPENSSL_ASSERT_DEBUG", SSL_ASSERT* will show error file name and line
62 * if select "CONFIG_OPENSSL_ASSERT_EXIT", SSL_ASSERT* will just return error code.
63 * if select "CONFIG_OPENSSL_ASSERT_DEBUG_EXIT" SSL_ASSERT* will show error file name and line,
64 * then return error code.
65 * if select "CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK", SSL_ASSERT* will show error file name and line,
66 * then block here with "while (1)"
68 * SSL_ASSERT1 may will return "-1", so function's return argument is integer.
69 * SSL_ASSERT2 may will return "NULL", so function's return argument is a point.
70 * SSL_ASSERT2 may will return nothing, so function's return argument is "void".
72 #if defined(CONFIG_OPENSSL_ASSERT_DEBUG)
73 #define SSL_ASSERT1(s) \
76 SSL_SHOW_LOCATION(); \
80 #define SSL_ASSERT2(s) \
83 SSL_SHOW_LOCATION(); \
87 #define SSL_ASSERT3(s) \
90 SSL_SHOW_LOCATION(); \
93 #elif defined(CONFIG_OPENSSL_ASSERT_EXIT)
94 #define SSL_ASSERT1(s) \
101 #define SSL_ASSERT2(s) \
108 #define SSL_ASSERT3(s) \
114 #elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_EXIT)
115 #define SSL_ASSERT1(s) \
118 SSL_SHOW_LOCATION(); \
123 #define SSL_ASSERT2(s) \
126 SSL_SHOW_LOCATION(); \
131 #define SSL_ASSERT3(s) \
134 SSL_SHOW_LOCATION(); \
138 #elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK)
139 #define SSL_ASSERT1(s) \
142 SSL_SHOW_LOCATION(); \
147 #define SSL_ASSERT2(s) \
150 SSL_SHOW_LOCATION(); \
155 #define SSL_ASSERT3(s) \
158 SSL_SHOW_LOCATION(); \
163 #define SSL_ASSERT1(s)
164 #define SSL_ASSERT2(s)
165 #define SSL_ASSERT3(s)
168 #define SSL_PLATFORM_DEBUG_LEVEL SSL_DEBUG_OFF
169 #define SSL_PLATFORM_ERROR_LEVEL SSL_DEBUG_ON
171 #define SSL_CERT_DEBUG_LEVEL SSL_DEBUG_OFF
172 #define SSL_CERT_ERROR_LEVEL SSL_DEBUG_ON
174 #define SSL_PKEY_DEBUG_LEVEL SSL_DEBUG_OFF
175 #define SSL_PKEY_ERROR_LEVEL SSL_DEBUG_ON
177 #define SSL_X509_DEBUG_LEVEL SSL_DEBUG_OFF
178 #define SSL_X509_ERROR_LEVEL SSL_DEBUG_ON
180 #define SSL_LIB_DEBUG_LEVEL SSL_DEBUG_OFF
181 #define SSL_LIB_ERROR_LEVEL SSL_DEBUG_ON
183 #define SSL_STACK_DEBUG_LEVEL SSL_DEBUG_OFF
184 #define SSL_STACK_ERROR_LEVEL SSL_DEBUG_ON