Fix tinyDTLS error codes in DTLS adapter
authorDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Tue, 5 Apr 2016 08:24:49 +0000 (11:24 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 6 Apr 2016 11:17:53 +0000 (11:17 +0000)
Related Jira issue: https://jira.iotivity.org/browse/IOT-1074

Change-Id: Idfc80167e3c6f80d2636d48cf28ac69d2c53395a
Signed-off-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7607
Reviewed-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-by: Kyungsun Cho <goodsun.cho@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jongsung Lee <js126.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c

index d64eea2..8caf45f 100644 (file)
 #include "timer.h"
 #include <netdb.h>
 
+/* tinyDTLS library error code */
+#define TINY_DTLS_ERROR (-1)
+/* tinyDTLS library success code */
+#define TINY_DTLS_SUCCESS (0)
+
 #ifdef __WITH_X509__
 #include "pki.h"
 #include "crl.h"
@@ -436,7 +441,7 @@ static int32_t CAReadDecryptedPayload(dtls_context_t *context,
     if (NULL == g_caDtlsContext)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "Context is NULL");
-        return 0;
+        return TINY_DTLS_ERROR;
     }
 
     int type = 0;
@@ -458,7 +463,7 @@ static int32_t CAReadDecryptedPayload(dtls_context_t *context,
     }
 
     OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
-    return 0;
+    return TINY_DTLS_SUCCESS;
 }
 
 static int32_t CASendSecureData(dtls_context_t *context,
@@ -561,7 +566,7 @@ static int32_t CAHandleSecureEvent(dtls_context_t *context,
     }
 
     OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
-    return 0;
+    return TINY_DTLS_SUCCESS;
 }
 
 
@@ -573,7 +578,7 @@ static int32_t CAGetPskCredentials(dtls_context_t *ctx,
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
 
-    int32_t ret  = -1;
+    int32_t ret = TINY_DTLS_ERROR;
     if(NULL == ctx || NULL == session || NULL == result)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "CAGetPskCredentials invalid parameters");
@@ -860,7 +865,7 @@ int CAInitX509()
 static int CAIsX509Active(struct dtls_context_t *ctx)
 {
     (void)ctx;
-    return 0;
+    return TINY_DTLS_SUCCESS;
 }
 
 static int CAGetDeviceKey(struct dtls_context_t *ctx,
@@ -870,13 +875,13 @@ static int CAGetDeviceKey(struct dtls_context_t *ctx,
     OIC_LOG(DEBUG, NET_DTLS_TAG, "CAGetDeviceKey");
     static dtls_ecc_key_t ecdsa_key = {DTLS_ECDH_CURVE_SECP256R1, NULL, NULL, NULL};
 
-    int ret = 1;
+    int ret = TINY_DTLS_ERROR;
     VERIFY_SUCCESS(CAInitX509(), 0);
 
     ecdsa_key.priv_key = g_X509Cred.devicePrivateKey;
     *result = &ecdsa_key;
 
-    ret = 0;
+    ret = TINY_DTLS_SUCCESS;
 exit:
     return ret;
 }
@@ -888,7 +893,7 @@ CAGetDeviceCertificate(struct dtls_context_t *ctx,
                     size_t *cert_size)
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "CAGetDeviceCertificate");
-    int ret = 1;
+    int ret = TINY_DTLS_ERROR;
 
     VERIFY_SUCCESS(CAInitX509(), 0);
 
@@ -899,7 +904,7 @@ CAGetDeviceCertificate(struct dtls_context_t *ctx,
     PRINT_BYTE_ARRAY("OWN CERT: \n", ownCert);
 #endif
 
-    ret = 0;
+    ret = TINY_DTLS_SUCCESS;
 exit:
     return ret;
 }
@@ -938,7 +943,7 @@ static int CAVerifyCertificate(struct dtls_context_t *ctx, const session_t *sess
 
     uint8_t chainLength;
 
-    int ret;
+    int ret = TINY_DTLS_ERROR;
     const unsigned char *ca_pub_x;
     const unsigned char *ca_pub_y;
     ByteArray certDerCode = BYTE_ARRAY_INITIALIZER;
@@ -947,7 +952,7 @@ static int CAVerifyCertificate(struct dtls_context_t *ctx, const session_t *sess
 
     if ( !ctx ||  !session ||  !cert || !x || !y)
     {
-        return -PKI_NULL_PASSED;
+        return TINY_DTLS_ERROR;
     }
 
     CAGetRootKey (&ca_pub_x, &ca_pub_y);
@@ -993,13 +998,14 @@ static int CAVerifyCertificate(struct dtls_context_t *ctx, const session_t *sess
 exit:
     if (ret != 0)
     {
-        OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification FAILED\n");
+        OIC_LOG(ERROR, NET_DTLS_TAG, "Certificate verification FAILED\n");
+        return TINY_DTLS_ERROR;
     }
     else
     {
         OIC_LOG(DEBUG, NET_DTLS_TAG, "Certificate verification SUCCESS\n");
+        return TINY_DTLS_SUCCESS;
     }
-    return -ret;
 }
 
 #endif