svace fixes
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / adapter_util / ca_adapter_net_ssl.c
index 47e2199..ce4765a 100644 (file)
@@ -928,6 +928,10 @@ static int ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, size_t bufLen
             else
             {
                 unsigned char * lastCert = (unsigned char *)OICMalloc((len + 1) * sizeof(unsigned char));
+                if (lastCert == NULL)
+                {
+                    goto exit;
+                }
                 memcpy(lastCert, buf + pos, len);
                 lastCert[len] = 0x00;
                 ret = mbedtls_x509_crt_parse(crt, lastCert, len + 1);
@@ -1360,6 +1364,35 @@ const CASecureEndpoint_t *GetCASecureEndpointData(const CAEndpoint_t* peer)
 }
 #endif
 
+CAResult_t SetCASecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid)
+{
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
+    VERIFY_NON_NULL(peer, NET_SSL_TAG, "peer");
+    VERIFY_NON_NULL(peer, NET_SSL_TAG, "uuid");
+
+    oc_mutex_lock(g_sslContextMutex);
+    SslEndPoint_t *sslPeer = GetSslPeer(peer);
+    if (NULL == sslPeer)
+    {
+        OIC_LOG(ERROR, NET_SSL_TAG, "Peer not found");
+        oc_mutex_unlock(g_sslContextMutex);
+        return CA_STATUS_FAILED;
+    }
+
+    OCRandomUuidResult ret = OCConvertStringToUuid(uuid, sslPeer->sep.identity.id);
+    oc_mutex_unlock(g_sslContextMutex);
+
+    if (RAND_UUID_OK != ret)
+    {
+        OIC_LOG(ERROR, NET_SSL_TAG, "Failed to convert uuid");
+        return CA_STATUS_FAILED;
+    }
+
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+
+    return CA_STATUS_OK;
+}
+
 /**
  * Deletes cached message.
  *
@@ -2450,6 +2483,12 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
     VERIFY_NON_NULL_RET(sep, NET_SSL_TAG, "endpoint is NULL" , CA_STATUS_INVALID_PARAM);
     VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "Param data is NULL" , CA_STATUS_INVALID_PARAM);
 
+    if (0 == dataLen)
+    {
+        OIC_LOG(ERROR, NET_SSL_TAG, "dataLen is zero");
+        return CA_STATUS_FAILED;
+    }
+
     oc_mutex_lock(g_sslContextMutex);
     if (NULL == g_caSslContext)
     {