Commit a13861a0 authored by Oleksandr Dmytrenko's avatar Oleksandr Dmytrenko Committed by Aleksey

mbedtls error/verify code decode

mbedtls error/verify code decode macroses:
- LOG_MBED_ERROR(tag, ret, buf, bufSize, logLevel)
- LOG_MBEDTLS_VERIFY_ERROR(flags)
- LOG_MBEDTLS_ERROR(ret)
- LOG_MBEDTLS_ERROR_LOCAL(TAG, ret)

Change-Id: Iada2706ffb5fe558999f686396b2ee4f12ee82a6
Signed-off-by: default avatarOleksandr Dmytrenko <o.dmytrenko@samsung.com>
parent e64d33ff
/******************************************************************
*
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************/
#ifndef __MBEDTLS_MESSAGES__
#define __MBEDTLS_MESSAGES__
#if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
#include "mbedtls/error.h"
#define _BUF_SIZE_ 2048
#if !defined(lTAG)
#define lTAG "MBEDTLS"
#endif
/**
* Macro to log an mbedtls error
* For mbedtls functions that return 0 as non-error
* @note Invoker must provide message buffer, and must include "logger.h"
*/
#if !defined(LOG_MBED_ERROR)
#define LOG_MBED_ERROR(tag, ret, buf, bufSize, logLevel) \
do \
{ \
if (0!=(ret)) \
{ \
mbedtls_strerror((ret), (buf), (bufSize)); \
OIC_LOG_V((logLevel), (tag), "%s", (buf)); \
} \
} \
while(0)
#endif//LOG_MBED_ERROR
#if !defined(LOG_MBEDTLS_VERIFY_ERROR)
#define LOG_MBEDTLS_VERIFY_ERROR(flags) \
do \
{ \
if (0!=(flags)) \
{ \
char *_buf = (char*)OICCalloc(_BUF_SIZE_, sizeof(char));\
if (_buf) \
{ \
mbedtls_x509_crt_verify_info(_buf, _BUF_SIZE_, "", flags); \
OIC_LOG_V(ERROR, lTAG" VERIFY", "%s", _buf); \
OICFree(_buf); \
} \
} \
} \
while(0)
#endif//LOG_MBEDTLS_VERIFY_ERROR
#if !defined(LOG_MBEDTLS_ERROR)
#define LOG_MBEDTLS_ERROR(ret) \
do \
{ \
if (0!=(ret)) \
{ \
char *_buf = (char*)OICCalloc(_BUF_SIZE_, sizeof(char));\
if (_buf) \
{ \
mbedtls_strerror((ret), _buf, _BUF_SIZE_); \
OIC_LOG_V(ERROR, lTAG, "%s", _buf); \
OICFree(_buf); \
} \
} \
} \
while(0)
#endif//LOG_MBEDTLS_ERROR
#if !defined(LOG_MBEDTLS_ERROR_LOCAL)
#define LOG_MBEDTLS_ERROR_LOCAL(TAG, ret) \
do \
{ \
if (0!=(ret)) \
{ \
char *_buf = (char*)OICCalloc(_BUF_SIZE_, sizeof(char));\
if (_buf) \
{ \
mbedtls_strerror((ret), _buf, _BUF_SIZE_); \
OIC_LOG_V(ERROR, TAG, "%s", _buf); \
OICFree(_buf); \
} \
} \
} \
while(0)
#endif//LOG_MBEDTLS_ERROR
#endif //(__WITH_TLS__) || defined(__WITH_DTLS__)
#endif //__MBEDTLS_MESSAGES__
......@@ -35,9 +35,6 @@ extern "C"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
#include "mbedtls/error.h"
#endif
typedef struct OicParseQueryIter OicParseQueryIter_t;
/**
......@@ -112,41 +109,6 @@ struct OicParseQueryIter
#define VERIFY_NOT_NULL_RETURN(tag, arg, logLevel, retValue) do { if (NULL == (arg)) \
{ OIC_LOG((logLevel), tag, #arg " is NULL"); return retValue; } } while(0)
#endif
#if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
/**
* Macro to log an mbedtls error
* For mbedtls functions that return 0 as non-error
* @note Invoker must provide message buffer, and must include "mbedtls/error.h"
*/
#define LOG_MBED_ERROR(tag, ret, buf, bufSize, logLevel) do{ if (0!=(ret)) { \
mbedtls_strerror((ret), (buf), (bufSize)); \
OIC_LOG_V((logLevel), (tag), "mbedtls error: %s", (buf)); } }while(0)
#define LOG_MBEDTLS_ERROR(ret) do{ \
if (0!=(ret)) {\
char *_buf = (char*)OICCalloc(2048, 1);\
if (_buf)\
{\
mbedtls_strerror((ret), _buf, 2048); \
OIC_LOG_V(ERROR, TAG, "mbedtls error: %s", _buf); \
OICFree(_buf);\
}\
} }while(0)
#define LOG_MBEDTLS_VERIFY_ERROR(flags) do{ \
if (0!=(flags)) { \
char *_buf = (char*)OICCalloc(2048, 1); \
if (_buf) \
{ \
mbedtls_x509_crt_verify_info(_buf, 2048, "", flags); \
OIC_LOG_V(ERROR, TAG, "mbedtls verify error: %s", _buf); \
OICFree(_buf); \
} \
} }while(0)
#endif //(__WITH_TLS__) || defined(__WITH_DTLS__)
/**
* This method initializes the @ref OicParseQueryIter_t struct.
*
......
......@@ -35,6 +35,7 @@
#include "experimental/payload_logging.h"
#include "pmutility.h"
#include "srmutility.h"
#include "mbedtls_messages.h"
// headers required for mbed TLS
#include "mbedtls/config.h"
......
......@@ -57,6 +57,7 @@
#include "secureresourcemanager.h"
#include "ocstackinternal.h"
#include "deviceonboardingstate.h"
#include "mbedtls_messages.h"
#ifdef __unix__
#include <sys/types.h>
......
......@@ -38,6 +38,7 @@
#include "pmutility.h"
#include "srmutility.h"
#include "srmresourcestrings.h"
#include "mbedtls_messages.h"
// headers required for mbed TLS
#include "mbedtls/config.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment