svace fix
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Sat, 24 Sep 2016 15:56:50 +0000 (18:56 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Fri, 30 Sep 2016 08:39:17 +0000 (08:39 +0000)
Change-Id: Ibcc7b545bfefb6861bdfecf954ca24b158229150
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12179
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/src/credresource.c

index 402e823..4b6d958 100644 (file)
@@ -92,7 +92,7 @@ static int g_unown_cnt;
 static bool g_doneCB;
 #ifdef __WITH_TLS__
 static int secure_protocol = 1;
-static void setDevProtocol(const OCProvisionDev_t* dev_lst);
+static void setDevProtocol(OCProvisionDev_t* dev_lst);
 #endif
 // function declaration(s) for calling them before implementing
 static OicSecAcl_t* createAcl(const int);
@@ -1588,16 +1588,14 @@ static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
 
 #ifdef __WITH_TLS__
 
-static void setDevProtocol(const OCProvisionDev_t* dev_lst)
+static void setDevProtocol(OCProvisionDev_t* lst)
 {
-    if(!dev_lst)
+    if(!lst)
     {
         printf("     Device List is Empty..\n\n");
         return;
     }
 
-    OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
-
     for( ; lst; )
     {
         if(2 == secure_protocol)
index 54b9fc8..b64e84d 100644 (file)
@@ -356,12 +356,11 @@ static OCStackResult RemoveDeviceInfoFromLocal(const OCProvisionDev_t* pTargetDe
 
     // TODO: We need to add new mechanism to clean up the stale state of the device.
 
-    //Close the DTLS session of the removed device.
-    CAEndpoint_tendpoint = (CAEndpoint_t *)&pTargetDev->endpoint;
+    // Close the DTLS session of the removed device.
+    CAEndpoint_t *endpoint = (CAEndpoint_t *)&pTargetDev->endpoint;
     endpoint->port = pTargetDev->securePort;
     CAResult_t caResult = CACloseDtlsSession(endpoint);
-    if(CA_STATUS_OK != caResult)
-    {
+    if (CA_STATUS_OK != caResult) {
         OIC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close DTLS session : %d", caResult);
     }
 
index eec02f3..ce91f8c 100644 (file)
@@ -244,16 +244,22 @@ static void SetResult(OTMContext_t* otmCtx, const OCStackResult res)
         //Revert psk_info callback and new deivce uuid in case of random PIN OxM
         if(OIC_RANDOM_DEVICE_PIN == otmCtx->selectedDeviceInfo->doxm->oxmSel)
         {
-#ifdef __WITH_TLS__
-            if(CA_STATUS_OK != CAregisterTlsCredentialsHandler(GetDtlsPskCredentials))
+            if(CA_ADAPTER_IP == ((CAEndpoint_t*)(&otmCtx->selectedDeviceInfo->endpoint))->adapter)
             {
-                OIC_LOG(WARNING, TAG, "Failed to revert  is TLS credential handler.");
+                if(CA_STATUS_OK != CARegisterDTLSCredentialsHandler(GetDtlsPskCredentials))
+                {
+                    OIC_LOG(WARNING, TAG, "Failed to register DTLS handshake callback.");
+                }
             }
-#endif
-            if(CA_STATUS_OK != CARegisterDTLSCredentialsHandler(GetDtlsPskCredentials))
+#ifdef __WITH_TLS__
+            else
             {
-                OIC_LOG(WARNING, TAG, "Failed to revert  is DTLS credential handler.");
+                if(CA_STATUS_OK != CAregisterTlsCredentialsHandler(GetDtlsPskCredentials))
+                {
+                    OIC_LOG(WARNING, TAG, "Failed to register TLS handshake callback.");
+                }
             }
+#endif
             OicUuid_t emptyUuid = { .id={0}};
             SetUuidForRandomPinOxm(&emptyUuid);
         }
@@ -413,7 +419,7 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     }
 
     uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {0};
-    OicSecKey_t ownerKey = {ownerPSK, OWNER_PSK_LENGTH_128};
+    OicSecKey_t ownerKey = {ownerPSK, OWNER_PSK_LENGTH_128, OIC_ENCODING_UNKNOW};
 
     //Generating OwnerPSK
     CAResult_t pskRet = CAGenerateOwnerPSK(&endpoint,
@@ -1354,17 +1360,23 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
     }
 
     //Register DTLS event handler to catch the dtls event while handshake
-    if(CA_STATUS_OK != CARegisterDTLSHandshakeCallback(DTLSHandshakeCB))
+    if(CA_ADAPTER_IP == ((CAEndpoint_t*)(&otmCtx->selectedDeviceInfo->endpoint))->adapter)
     {
-        OIC_LOG(WARNING, TAG, "StartOwnershipTransfer : Failed to register DTLS handshake callback.");
+        if(CA_STATUS_OK != CARegisterDTLSCredentialsHandler(GetDtlsPskCredentials))
+        {
+            OIC_LOG(WARNING, TAG, "Failed to register DTLS handshake callback.");
+        }
     }
 #ifdef __WITH_TLS__
-    //Register TLS event handler to catch the tls event while handshake
-    if(CA_STATUS_OK != CAregisterTlsHandshakeCallback(DTLSHandshakeCB))
+    else
     {
-        OIC_LOG(WARNING, TAG, "StartOwnershipTransfer : Failed to register TLS handshake callback.");
+        if(CA_STATUS_OK != CAregisterTlsCredentialsHandler(GetDtlsPskCredentials))
+        {
+            OIC_LOG(WARNING, TAG, "Failed to register TLS handshake callback.");
+        }
     }
 #endif
+
     OIC_LOG(INFO, TAG, "OUT StartOwnershipTransfer");
 
     return res;
index d62a32a..1b27b84 100644 (file)
@@ -1921,12 +1921,6 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type,
                 }
             }
             break;
-
-        default:
-            {
-                OIC_LOG (ERROR, TAG, "Wrong value passed for CADtlsPskCredType_t.");
-            }
-            break;
     }
 
     return ret;
@@ -2132,7 +2126,7 @@ void GetDerCaCert(ByteArray * crt)
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     LL_FOREACH(gCred, temp)
     {
-        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), TRUST_CA, sizeof(TRUST_CA)))
+        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), TRUST_CA, strlen(TRUST_CA) + 1))
         {
             OIC_LOG_V(DEBUG, TAG, "len: %d, crt len: %d", temp->optionalData.len, crt->len);
             if(OIC_ENCODING_BASE64 == temp->optionalData.encoding)
@@ -2185,7 +2179,7 @@ void GetDerOwnCert(ByteArray * crt)
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     LL_FOREACH(gCred, temp)
     {
-        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), PRIMARY_CERT, sizeof(PRIMARY_CERT)))
+        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), PRIMARY_CERT, strlen(PRIMARY_CERT) + 1))
         {
             OIC_LOG_V(DEBUG, TAG, "len: %d, crt len: %d", temp->publicData.len, crt->len);
             crt->data = OICRealloc(crt->data, crt->len + temp->publicData.len);
@@ -2216,7 +2210,7 @@ void GetDerKey(ByteArray * key)
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     LL_FOREACH(gCred, temp)
     {
-        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), PRIMARY_CERT, sizeof(PRIMARY_CERT)))
+        if (SIGNED_ASYMMETRIC_KEY == temp->credType && 0 == memcmp((temp->credUsage), PRIMARY_CERT, strlen(PRIMARY_CERT) + 1))
         {
             OIC_LOG_V(DEBUG, TAG, "len: %d, key len: %d", temp->privateData.len, key->len);
             key->data = OICRealloc(key->data, key->len + temp->privateData.len);