mbedtls error/verify code decode 13/29613/4
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Wed, 17 Jul 2019 13:07:58 +0000 (16:07 +0300)
committerAleksey Volkov <a.volkov@samsung.com>
Thu, 25 Jul 2019 07:41:51 +0000 (07:41 +0000)
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: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
resource/c_common/mbedtls_messages.h [new file with mode: 0644]
resource/csdk/security/include/srmutility.h
resource/csdk/security/src/certhelpers.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/occertutility.c

diff --git a/resource/c_common/mbedtls_messages.h b/resource/c_common/mbedtls_messages.h
new file mode 100644 (file)
index 0000000..8d34ed6
--- /dev/null
@@ -0,0 +1,105 @@
+/******************************************************************
+ *
+ * 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__
index 2efde24..18f4d0d 100644 (file)
@@ -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.
  *
index 340b720..2ec2e5b 100644 (file)
@@ -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"
index 1cfd589..fd21d05 100644 (file)
@@ -57,6 +57,7 @@
 #include "secureresourcemanager.h"
 #include "ocstackinternal.h"
 #include "deviceonboardingstate.h"
+#include "mbedtls_messages.h"
 
 #ifdef __unix__
 #include <sys/types.h>
index 5eaa23a..4dd71bc 100644 (file)
@@ -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"