From 3298bcd35e815c828f1b9184b34d31b2c2e7065a Mon Sep 17 00:00:00 2001 From: Dmitriy Zhuravlev Date: Tue, 5 Apr 2016 11:24:49 +0300 Subject: [PATCH] Fix tinyDTLS error codes in DTLS adapter Related Jira issue: https://jira.iotivity.org/browse/IOT-1074 Change-Id: Idfc80167e3c6f80d2636d48cf28ac69d2c53395a Signed-off-by: Dmitriy Zhuravlev Reviewed-on: https://gerrit.iotivity.org/gerrit/7607 Reviewed-by: Chul Lee Reviewed-by: Kyungsun Cho Tested-by: jenkins-iotivity Reviewed-by: Jongsung Lee Reviewed-by: Randeep Singh --- .../src/adapter_util/caadapternetdtls.c | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c b/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c index d64eea2..8caf45f 100644 --- a/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c +++ b/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c @@ -27,6 +27,11 @@ #include "timer.h" #include +/* 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 -- 2.7.4