Fix ownership transfer issues
authorJongmin Choi <jminl.choi@samsung.com>
Fri, 13 Jan 2017 06:41:34 +0000 (15:41 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 25 Jan 2017 04:26:54 +0000 (04:26 +0000)
Fix issues related to ownership transfer
- Port change after failed ownership transfer

Patch #1: initial upload
Patch #2: build error fix

Change-Id: Ia6df0e7b862f73fab166ccb2c8ceee6c348b8189
Signed-off-by: Jongmin Choi <jminl.choi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16371
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joonghwan Lee <jh05.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
(cherry picked from commit 75bd7cd65fc5bdd362120ca2ac10d5d09a7755c5)
Reviewed-on: https://gerrit.iotivity.org/gerrit/16417
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c

index 37a9d15..bc0a256 100644 (file)
@@ -235,21 +235,22 @@ if (0 != (ret) && MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != (int) (ret) &&
     MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL != (int) (ret))                                  \
 {                                                                                                  \
     OIC_LOG_V(ERROR, NET_SSL_TAG, "%s: -0x%x", (str), -(ret));                                     \
-    if ((int) MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != (int) (ret))                                  \
+    if ((int) MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != (int) (ret) &&                                \
+        (int) MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != (int) (ret))                                  \
     {                                                                                              \
         mbedtls_ssl_send_alert_message(&(peer)->ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, (msg));        \
     }                                                                                              \
-    SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE);                                               \
     RemovePeerFromList(&(peer)->sep.endpoint);                                                     \
     if (mutex)                                                                                     \
     {                                                                                              \
         oc_mutex_unlock(g_sslContextMutex);                                                        \
     }                                                                                              \
+    SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE);                                               \
     OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);                                             \
     if (-1 != error)                                                                               \
     {                                                                                              \
         return (error);                                                                            \
-    }                                                                                              \
+    }                                                                                             \
 }
 /**@def CONF_SSL(clientConf, serverConf, fn, ...)
  *
@@ -1841,7 +1842,6 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
 
         if (MBEDTLS_SSL_HANDSHAKE_OVER == peer->ssl.state)
         {
-            SSL_RES(peer, CA_STATUS_OK);
             if (MBEDTLS_SSL_IS_CLIENT == peer->ssl.conf->endpoint)
             {
                 SendCacheMessages(peer);
index 9fa52d9..24618ef 100644 (file)
@@ -463,9 +463,9 @@ static void SetResult(OTMContext_t* otmCtx, const OCStackResult res)
                 {
                     OIC_LOG(WARNING, TAG, "Internal error in PDMDeleteDevice");
                 }
-                CAEndpoint_t* endpoint = (CAEndpoint_t *)&otmCtx->selectedDeviceInfo->endpoint;
-                endpoint->port = otmCtx->selectedDeviceInfo->securePort;
-                if (CA_STATUS_OK != CAcloseSslConnection(endpoint))
+                CAEndpoint_t endpoint;
+                memcpy(&endpoint, &(otmCtx->selectedDeviceInfo->endpoint), sizeof(CAEndpoint_t));
+                if (CA_STATUS_OK != CAcloseSslConnection(&endpoint))
                 {
                     OIC_LOG(WARNING, TAG, "Failed to close Secure session");
                 }