Configure resource security
authorcc <ch79.cho@samsung.com>
Tue, 13 Sep 2016 04:21:28 +0000 (13:21 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 20 Sep 2016 11:16:45 +0000 (11:16 +0000)
A provider is able to create the secured resources
if the provider config is set by enabling resource security.

Change-Id: I007c0e115e8cc2841ca7203994fa81c54a545276
Signed-off-by: cc <ch79.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11729
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 2a851346faa28b61abef56ef5bdbbeb48a67ccde)
Reviewed-on: https://gerrit.iotivity.org/gerrit/11931

service/notification/SConscript
service/notification/include/NSProviderInterface.h
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderResource.c
service/notification/src/provider/NSProviderResource.h
service/notification/src/provider/NSProviderSystem.c

index ab866e8..5eb4b77 100755 (executable)
@@ -80,7 +80,10 @@ if 'CLIENT' in notification_env.get('RD_MODE'):
         notification_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
     
 if env.get('WITH_CLOUD') == True:      
-       notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])    
+       notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
+if env.get('SECURED') == '1':
+       notification_env.AppendUnique(CPPDEFINES = ['SECURED']) 
 
 ######################################################################
 # Source files and Targets
index 534d102..6958589 100644 (file)
@@ -65,6 +65,8 @@ typedef struct
     bool subControllability;\r
     /* User Information */\r
     char * userInfo;\r
+    /* Set on/off with SECURED build option */\r
+    bool resourceSecurity;\r
 \r
 } NSProviderConfig;\r
 \r
index 71fcab4..3c99457 100644 (file)
@@ -89,6 +89,17 @@ NSResult NSStartProvider(NSProviderConfig config)
         CARegisterNetworkMonitorHandler((CAAdapterStateChangedCB)NSProviderAdapterStateListener,
                 (CAConnectionStateChangedCB)NSProviderConnectionStateListener);
 
+        NS_LOG(DEBUG, "Check secured build option..");
+#ifdef SECURED
+        NS_LOG(DEBUG, "Built with SECURED");
+
+        if(!config.resourceSecurity)
+        {
+            NS_LOG(DEBUG, "Resource Security Off");
+        }
+        NSSetResourceSecurity(config.resourceSecurity);
+#endif
+
         NSInitialize();
         NSInitScheduler();
         NSStartScheduler();
index a056d68..a61ecc2 100644 (file)
@@ -72,12 +72,15 @@ NSResult NSPublishResourceToCloud(char *serverAddress)
 NSResult NSCreateResource(char *uri)
 {
     NS_LOG(DEBUG, "NSCreateResource - IN");
+
     if (!uri)
     {
         NS_LOG(NS_ERROR, "Resource URI cannot be NULL");
         return NS_ERROR;
     }
 
+    uint8_t resourceProperties;
+
     if (strcmp(uri, NS_ROOT_URI) == 0)
     {
         NotificationResource.policy = true;
@@ -88,8 +91,18 @@ NSResult NSCreateResource(char *uri)
         NotificationResource.version = VERSION;
         NotificationResource.handle = NULL;
 
+        if(NSGetResourceSecurity())
+        {
+            NS_LOG(DEBUG, "Create secured resource");
+            resourceProperties = OC_DISCOVERABLE | OC_SECURE;
+        }
+        else
+        {
+            resourceProperties = OC_DISCOVERABLE;
+        }
+
         if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_DEFAULT_INTERFACE,
-                NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK)
+                NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, resourceProperties) != OC_STACK_OK)
         {
             NS_LOG(NS_ERROR, "Fail to Create Notification Resource");
             return NS_ERROR;
@@ -110,9 +123,19 @@ NSResult NSCreateResource(char *uri)
         NotificationMessageResource.topicName = NULL;
         NotificationMessageResource.mediaContents = NULL;
 
+        if(NSGetResourceSecurity())
+        {
+            NS_LOG(DEBUG, "Create secured resource");
+            resourceProperties = OC_OBSERVABLE | OC_SECURE;
+        }
+        else
+        {
+            resourceProperties = OC_OBSERVABLE;
+        }
+
         if (OCCreateResource(&NotificationMessageResource.handle, NS_COLLECTION_MESSAGE_TYPE,
                 NS_DEFAULT_INTERFACE, NS_COLLECTION_MESSAGE_URI, NSEntityHandlerMessageCb, NULL,
-                OC_OBSERVABLE) != OC_STACK_OK)
+                resourceProperties) != OC_STACK_OK)
         {
             NS_LOG(NS_ERROR, "Fail to Create Notification Message Resource");
             return NS_ERROR;
@@ -125,9 +148,19 @@ NSResult NSCreateResource(char *uri)
         NotificationSyncResource.state = NULL;
         NotificationSyncResource.handle = NULL;
 
+        if(NSGetResourceSecurity())
+        {
+            NS_LOG(DEBUG, "Create secured resource");
+            resourceProperties = OC_OBSERVABLE | OC_SECURE;
+        }
+        else
+        {
+            resourceProperties = OC_OBSERVABLE;
+        }
+
         if (OCCreateResource(&(NotificationSyncResource.handle), NS_COLLECTION_SYNC_TYPE,
                 NS_DEFAULT_INTERFACE, NS_COLLECTION_SYNC_URI, NSEntityHandlerSyncCb, NULL,
-                OC_OBSERVABLE) != OC_STACK_OK)
+                resourceProperties) != OC_STACK_OK)
         {
             NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource");
             return NS_ERROR;
@@ -140,9 +173,19 @@ NSResult NSCreateResource(char *uri)
         NotificationTopicResource.TopicList = NULL;
         NotificationTopicResource.handle = NULL;
 
+        if(NSGetResourceSecurity())
+        {
+            NS_LOG(DEBUG, "Create secured resource");
+            resourceProperties = OC_DISCOVERABLE | OC_SECURE;
+        }
+        else
+        {
+            resourceProperties = OC_DISCOVERABLE;
+        }
+
         if (OCCreateResource(&(NotificationTopicResource.handle), NS_COLLECTION_TOPIC_TYPE,
                 NS_DEFAULT_INTERFACE, NS_COLLECTION_TOPIC_URI, NSEntityHandlerTopicCb, NULL,
-                OC_DISCOVERABLE) != OC_STACK_OK)
+                resourceProperties) != OC_STACK_OK)
         {
             NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource");
             return NS_ERROR;
index b5bc6de..3ab510c 100644 (file)
@@ -25,6 +25,7 @@
 #include "logger.h"
 #include "NSCommon.h"
 #include "NSProviderListener.h"
+#include "NSProviderSystem.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
 
index deeb4c5..e76243d 100644 (file)
@@ -28,6 +28,7 @@ static NSConnectionState NSProviderConnectionState;
 \r
 NSProviderInfo * providerInfo;\r
 bool NSPolicy = true;\r
+bool NSResourceSecurity = true;\r
 \r
 void NSSetProviderConnectionState(NSConnectionState state)\r
 {\r
@@ -129,6 +130,16 @@ void NSSetPolicy(bool policy)
     NSPolicy = policy;\r
 }\r
 \r
+bool NSGetResourceSecurity()\r
+{\r
+    return NSResourceSecurity;\r
+}\r
+\r
+void NSSetResourceSecurity(bool secured)\r
+{\r
+    NSResourceSecurity = secured;\r
+}\r
+\r
 const char * NSGetUserInfo()\r
 {\r
     return providerInfo->providerName;\r