[IOT-3260] SSL close callback 21/27921/7
authorOleksii Beketov <ol.beketov@samsung.com>
Thu, 14 Feb 2019 15:52:31 +0000 (17:52 +0200)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Tue, 26 Feb 2019 19:01:20 +0000 (19:01 +0000)
Added callback to return peer's UUID
on SSL connection closure

Change-Id: Ib31250c639b9c2633e1459f0d555424ca429fb26
Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com>
resource/csdk/connectivity/inc/ca_adapter_net_ssl.h
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c
resource/csdk/connectivity/test/ssladapter_test.cpp

index 85fc199..5d90c72 100644 (file)
@@ -83,6 +83,22 @@ void CAsetCredentialTypesCallback(CAgetCredentialTypesHandler credTypesCallback)
  */
 void CAsetSslCredentialsCallback(CAgetPskCredentialsHandler credCallback);
 
+/**
+ * Callback to return peer's UUID on SSL session closure
+ *
+ * @param[out] uuid     peer's UUID
+ * @param[out] uuidLen  peer's UUID length
+ *
+ * @return  CA_STATUS_OK or CA_STATUS_FAIL
+ */
+typedef CAResult_t (*CAcloseSslConnectionCallback)(const unsigned char *uuid, size_t uuidLen);
+
+/**
+ * Register callback that returns peer's UUID on SSL session closure
+ * @param[in] cb callback to return peer's UUID on SSL session closure
+ */
+void CAsetCloseSslConnectionCallback(CAcloseSslConnectionCallback cb);
+
 /**
  * Close the TLS session
  *
index 3661cbf..5651f1d 100644 (file)
@@ -418,6 +418,12 @@ static CAgetPkixInfoHandler g_getPkixInfoCallback = NULL;
  * @brief callback to retrieve acceptable UUID list
  */
 static CAgetIdentityHandler g_getIdentityCallback = NULL;
+/**
+ * @var g_closeSslConnectionCallback
+ *
+ * @brief callback to retrieve UUID on SSL connection closure
+ */
+static CAcloseSslConnectionCallback g_closeSslConnectionCallback = NULL;
 
 /**
  * @var g_dtlsContextMutex
@@ -504,6 +510,13 @@ void CAsetPeerCNVerifyCallback(PeerCNVerifyCallback cb)
     OIC_LOG_V(DEBUG, NET_SSL_TAG, "OUT %s", __func__);
 }
 
+void CAsetCloseSslConnectionCallback(CAcloseSslConnectionCallback closeSslCallback)
+{
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
+    g_closeSslConnectionCallback = closeSslCallback;
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+}
+
 /**
  * Sets SSL result for callback.
  *
@@ -1274,7 +1287,7 @@ CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint)
         ret = mbedtls_ssl_close_notify(&tep->ssl);
     }
     while (MBEDTLS_ERR_SSL_WANT_WRITE == ret);
-
+    g_closeSslConnectionCallback(tep->sep.identity.id, tep->sep.identity.id_length);
     RemovePeerFromList(&tep->sep.endpoint);
     oc_mutex_unlock(g_sslContextMutex);
 
index 2c09541..029574e 100644 (file)
@@ -49,6 +49,7 @@
 #define SetCASecureEndpointAttribute SetCASecureEndpointAttributeTest
 #define GetCASecureEndpointAttributes GetCASecureEndpointAttributesTest
 #define CAsetPeerCNVerifyCallback CAsetPeerCNVerifyCallbackTest
+#define CAsetCloseSslConnectionCallback CAsetCloseSslConnectionCallbackTest
 
 #include "../src/adapter_util/ca_adapter_net_ssl.c"