From: cc Date: Tue, 13 Sep 2016 04:21:28 +0000 (+0900) Subject: Configure resource security X-Git-Tag: 1.2.0+RC3~116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3bcbf7c12d3ece6cf8a8e51eb566b1e0c7a6955;p=platform%2Fupstream%2Fiotivity.git Configure resource security 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/11729 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi (cherry picked from commit 2a851346faa28b61abef56ef5bdbbeb48a67ccde) Reviewed-on: https://gerrit.iotivity.org/gerrit/11931 --- diff --git a/service/notification/SConscript b/service/notification/SConscript index ab866e8..5eb4b77 100755 --- a/service/notification/SConscript +++ b/service/notification/SConscript @@ -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 diff --git a/service/notification/include/NSProviderInterface.h b/service/notification/include/NSProviderInterface.h index 534d102..6958589 100644 --- a/service/notification/include/NSProviderInterface.h +++ b/service/notification/include/NSProviderInterface.h @@ -65,6 +65,8 @@ typedef struct bool subControllability; /* User Information */ char * userInfo; + /* Set on/off with SECURED build option */ + bool resourceSecurity; } NSProviderConfig; diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index 71fcab4..3c99457 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -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(); diff --git a/service/notification/src/provider/NSProviderResource.c b/service/notification/src/provider/NSProviderResource.c index a056d68..a61ecc2 100644 --- a/service/notification/src/provider/NSProviderResource.c +++ b/service/notification/src/provider/NSProviderResource.c @@ -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; diff --git a/service/notification/src/provider/NSProviderResource.h b/service/notification/src/provider/NSProviderResource.h index b5bc6de..3ab510c 100644 --- a/service/notification/src/provider/NSProviderResource.h +++ b/service/notification/src/provider/NSProviderResource.h @@ -25,6 +25,7 @@ #include "logger.h" #include "NSCommon.h" #include "NSProviderListener.h" +#include "NSProviderSystem.h" #include "oic_malloc.h" #include "oic_string.h" diff --git a/service/notification/src/provider/NSProviderSystem.c b/service/notification/src/provider/NSProviderSystem.c index deeb4c5..e76243d 100644 --- a/service/notification/src/provider/NSProviderSystem.c +++ b/service/notification/src/provider/NSProviderSystem.c @@ -28,6 +28,7 @@ static NSConnectionState NSProviderConnectionState; NSProviderInfo * providerInfo; bool NSPolicy = true; +bool NSResourceSecurity = true; void NSSetProviderConnectionState(NSConnectionState state) { @@ -129,6 +130,16 @@ void NSSetPolicy(bool policy) NSPolicy = policy; } +bool NSGetResourceSecurity() +{ + return NSResourceSecurity; +} + +void NSSetResourceSecurity(bool secured) +{ + NSResourceSecurity = secured; +} + const char * NSGetUserInfo() { return providerInfo->providerName;