Easysetup - Security PDM db file init flow change & fix compilation issue in Java...
authorlankamadan <lanka.madan@samsung.com>
Wed, 24 Feb 2016 01:15:26 +0000 (10:15 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 24 Feb 2016 04:29:50 +0000 (04:29 +0000)
- Security PDM.db must be initialized from app and not from the EnrolleeSecurity.cpp. Changed it.
- Fixed compilation in Java EasySetup
- sconscript log fix

Change-Id: I2f884e37596b14837edd4533112d156809dbb546
Signed-off-by: lankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5135
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/easy-setup/SConscript
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceTest.java [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupStatusTest.java [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactoryTest.java [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupService.java [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/inc/esrichcommon.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp [changed mode: 0644->0755]
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/SConscript
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp

index 84574e0..b2d3760 100755 (executable)
@@ -30,7 +30,7 @@ es_target_enrollee = env.get('ES_TARGET_ENROLLEE')
 print "************************************************************************************"
 print " Easysetup device role --> %s " % es_role
 print "Target Platform --> %s " % es_target
-print "Target Enrollee platform --> %s " % es_target
+print "Target Enrollee platform --> %s " % es_target_enrollee
 print "************************************************************************************"
 
 #Go to build sample apps
old mode 100644 (file)
new mode 100755 (executable)
index f298bb7..5fb19cd
@@ -92,7 +92,7 @@ public class EasySetupServiceTest extends AndroidTestCase {
         assertTrue(mFactory != null);
 
         /* Create enrolling device */
-        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+        mDevice = mFactory.newEnrolleeDevice(mWiFiProvConfig, mWiFiOnBoardingConfig);
 
         /* Check if the the device is created successfully*/
         assertTrue(mDevice != null);
@@ -109,6 +109,9 @@ public class EasySetupServiceTest extends AndroidTestCase {
         } catch (IOException e) {
             assertTrue(false);
         }
+        catch (ESException e) {
+            assertTrue(false);
+        }
 
         try {
 
old mode 100644 (file)
new mode 100755 (executable)
index d1a1370..f3d9d1a
@@ -134,11 +134,13 @@ public class EasySetupStatusTest extends AndroidTestCase {
         mFactory = EnrolleeDeviceFactory.newInstance(getContext());
 
         /* Create enrolling device */
-        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+        mDevice = mFactory.newEnrolleeDevice(mWiFiProvConfig, mWiFiOnBoardingConfig);
 
         try {
             mService.startSetup(mDevice);
-        } catch (IOException e) {
+        } catch (ESException e) {
+        }
+        catch (IOException e) {
         }
 
         try {
old mode 100644 (file)
new mode 100755 (executable)
index b0f955c..f513fa0
@@ -57,7 +57,7 @@ public class EnrolleeDeviceFactoryTest extends AndroidTestCase {
         WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
 
         /* Create enrolling device */
-        EnrolleeDevice device = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+        EnrolleeDevice device = mFactory.newEnrolleeDevice(mWiFiProvConfig, mWiFiOnBoardingConfig);
 
         /* Check if the the device is created */
         assertTrue(device != null);
old mode 100644 (file)
new mode 100755 (executable)
index 538f664..9d280a9
@@ -58,8 +58,7 @@ namespace OIC
 
             EnrolleeSecState m_enrolleeSecState;std::shared_ptr< OC::OCSecureResource > m_securedResource;
 
-            std::shared_ptr< OC::OCSecureResource > findEnrollee(std::string host,
-                    OC::DeviceList_t &list);
+            std::shared_ptr< OC::OCSecureResource > getEnrollee(OC::DeviceList_t &list);
             void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
             void convertUUIDToString(OicUuid_t uuid, std::string& uuidString);
         };
old mode 100644 (file)
new mode 100755 (executable)
index 08b9821..95a61e1
@@ -334,12 +334,12 @@ namespace OIC
 
             }
 
-            ESResult& getESResult()
+            ESResult getESResult()
             {
                 return m_result;
             }
 
-            ESState& getESState()
+            ESState getESState()
             {
                 return m_esState;
             }
@@ -359,12 +359,12 @@ namespace OIC
 
             }
 
-            ProvConfig& getProvConfig()
+            ProvConfig getProvConfig()
             {
                 return m_ProvConfig;
             }
 
-            EasySetupState& getEasySetupState()
+            EasySetupState getEasySetupState()
             {
                 return m_easySetupState;
             }
old mode 100644 (file)
new mode 100755 (executable)
index a630ecd..6d72009
@@ -52,16 +52,6 @@ namespace OIC
         {
             m_enrolleeSecState = EnrolleeSecState::ES_SEC_UNKNOWN;
             m_remoteEnrolleeResource = remoteEnrolleeResource;
-
-            //Initializing the provisioning client stack using the db path provided by the
-            // application.
-            // Note : If the path is NULL or empty, the PDM.db should be present in the same path.
-            OCStackResult result = OCSecure::provisionInit(secDbPath);
-
-            if (result != OC_STACK_OK)
-            {
-                throw ESPlatformException(result);
-            }
         }
 
         ESResult EnrolleeSecurity::registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
@@ -75,8 +65,7 @@ namespace OIC
             return ES_ERROR;
         }
 
-        std::shared_ptr< OC::OCSecureResource > EnrolleeSecurity::findEnrollee(std::string host,
-                DeviceList_t &list)
+        std::shared_ptr< OC::OCSecureResource > EnrolleeSecurity::getEnrollee(DeviceList_t &list)
         {
             for (unsigned int i = 0; i < list.size(); i++)
             {
@@ -84,13 +73,13 @@ namespace OIC
                         list[i]->getDeviceID().c_str());
                 OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "From IP :%s", list[i]->getDevAddr().c_str());
 
-                if (list[i]->getDevAddr() == host)
-                {
-                    return list[i];
-                }
+                //Always return the first element of the unOwned devices. This is considering that Mediator is
+                // always connected with only one Enrollee for which ownership transfer is being performed.
+                // Incase of multiple Enrollee devices connected to the Mediator via any OnBoarding method (SoftAp
+                // for example), the Enrollee devices will be provisioned in the first come first serve basis in the order
+                // returned by the security layer.
+                return list[i];
             }
-
-            return nullptr;
         }
 
         void EnrolleeSecurity::convertUUIDToString(OicUuid_t uuid, std::string& uuidString)
@@ -161,7 +150,7 @@ namespace OIC
 
             //Developer note : Always test the mediator and enrollee applications on different devices. Running
             // Mediator and Enrollee in same device will result in returning the same device as already owned.
-            result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
+            /*result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
                     pOwnedDevList);
             if (result != OC_STACK_OK)
             {
@@ -175,11 +164,7 @@ namespace OIC
             {
                 OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Found owned devices. Count =%d",
                         pOwnedDevList.size());
-                std::shared_ptr< OC::OCSecureResource > ownedDevice =
-                        findEnrollee(
-                                std::string(
-                                        m_remoteEnrolleeResource->m_wifiOnboardingconn.ipAddress),
-                                pOwnedDevList);
+                std::shared_ptr< OC::OCSecureResource > ownedDevice = getEnrollee(pOwnedDevList);
                 if (ownedDevice)
                 {
                     ownershipStatus = DEVICE_OWNED;
@@ -190,7 +175,7 @@ namespace OIC
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No owned devices found.");
                 ownershipStatus = DEVICE_NOT_OWNED;
-            }
+            }*/
 
             result = OCSecure::discoverUnownedDevices(ES_SEC_DISCOVERY_TIMEOUT, pUnownedDevList);
             if (result != OC_STACK_OK)
@@ -206,10 +191,7 @@ namespace OIC
                 OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Found Unowned devices. Count =%d",
                         pUnownedDevList.size());
 
-                m_unownedDevice =
-                        findEnrollee(
-                                m_remoteEnrolleeResource->m_wifiOnboardingconn.ipAddress,
-                                pUnownedDevList);
+                m_unownedDevice = getEnrollee(pUnownedDevList);
                 if (m_unownedDevice)
                 {
                     OTMCallbackData_t justWorksCBData;
@@ -231,8 +213,7 @@ namespace OIC
                     {
                         OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransferCallback is failed");
                         ownershipStatus = DEVICE_NOT_OWNED;
-                        //Throw exception
-                        throw ESPlatformException(result);
+                        return ownershipStatus;
                     }
                     ownershipStatus = DEVICE_NOT_OWNED;
                 }
old mode 100644 (file)
new mode 100755 (executable)
index dc6a97a..cb6cb7a
@@ -129,7 +129,7 @@ namespace OIC
 
             if (m_isSecured)
             {
-                if (m_currentESState > CurrentESState::ES_OWNED)
+                if (m_currentESState >= CurrentESState::ES_OWNED)
                 {
                     goto CALLBACK_CHECK;
                 }
index c8c0750..086651e 100644 (file)
@@ -48,6 +48,8 @@ mediator_env.PrependUnique(CPPPATH = [
             env.get('SRC_DIR') + '/resource/oc_logger/include',
                        env.get('SRC_DIR') + '/resource/csdk/ocmalloc/include',         
                        env.get('SRC_DIR') + '/resource/csdk/stack/include',
+                       env.get('SRC_DIR') + '/resource/csdk/security/provisioning/include',
+                       env.get('SRC_DIR') + '/resource/csdk/security/provisioning/include/internal',
                        env.get('SRC_DIR') + '/resource/csdk/logger/include',
                        env.get('SRC_DIR') + '/resource/csdk/security/include',
                        env.get('SRC_DIR') + '/extlibs/cjson',
index 675e9c0..a1696c1 100755 (executable)
@@ -25,6 +25,8 @@
 #include "EasySetup.h"
 #include "OCPlatform.h"
 #include "logger.h"
+#include "OCProvisioningManager.h"
+
 
 #define ES_SAMPLE_APP_TAG "ES_SAMPLE_APP_TAG"
 #define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }
@@ -178,8 +180,19 @@ int main()
     {
         OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos, &ps
     };
+
     OCPlatform::Configure(config);
 
+#ifdef __WITH_DTLS__
+    //Initializing the provisioning client stack using the db path provided by the application.
+    OCStackResult result = OCSecure::provisionInit("");
+
+    if (result != OC_STACK_OK)
+    {
+        return -1;
+    }
+#endif
+
     g_currentRun = runEasySetupMenu;
 
     while (true)