Add security payload type to a request/response
authorSakthivel Samidurai <sakthivel.samidurai@intel.com>
Tue, 15 Sep 2015 01:54:00 +0000 (18:54 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Wed, 16 Sep 2015 19:44:08 +0000 (19:44 +0000)
After removing the OCPayloadType from the payload, the stack has to
fill the appropriate payload type for security and non-security
payload type. Added PAYLOAD_TYPE_SECURITY as a payload type for
security resource request in HandleResourceWithEntityHandler
and response in HandleCAResponses.

Change-Id: I3007a1e79ad25b4e557ab15edb038a22cb9e85c3
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2539
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
resource/csdk/security/include/internal/secureresourcemanager.h
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/src/secureresourcemanager.c
resource/csdk/stack/include/internal/ocserverrequest.h
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c

index 6fc5b42..750da2d 100644 (file)
@@ -94,6 +94,13 @@ typedef bool (*SPResponseCallback) (const CAEndpoint_t *object,
  */
 void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler);
 
+/**
+ * @brief   Check the security resource URI.
+ * @param   uri [IN] Pointers to security resource URI.
+ * @return  true if the URI is one of security resources, otherwise false.
+ */
+bool SRMIsSecurityResourceURI(const char* uri);
+
 #ifdef __cplusplus
 }
 #endif
index eac476a..ae2fb00 100644 (file)
@@ -356,6 +356,7 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
             }
 
             OCProvisionDev_t** ppDevicesList = (OCProvisionDev_t**) ctx;
+            OC_LOG_V(INFO, TAG, "UpdateSecurePortOfDevice with %d",  securePort);
 
             OCStackResult res = UpdateSecurePortOfDevice(ppDevicesList, clientResponse->devAddr.addr,
                                                          clientResponse->devAddr.port, securePort);
@@ -453,7 +454,7 @@ static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNU
                 cbData.cb = &SecurePortDiscoveryHandler;
                 cbData.context = ctx;
                 cbData.cd = NULL;
-                OCStackResult ret = OCDoResource(NULL, OC_REST_GET, query, 0, 0,
+                OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
                         clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
                 // TODO: Should we use the default secure port in case of error?
                 if(OC_STACK_OK != ret)
index f7beefd..979073c 100644 (file)
@@ -195,7 +195,8 @@ exit:
  */
 static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest * ehRequest)
 {
-    // Convert ACL data into JSON for transmission
+    OC_LOG (INFO, TAG, "HandlePstatGetRequest  processing GET request");
+   // Convert ACL data into JSON for transmission
     char* jsonStr = BinToPstatJSON(gPstat);
 
     // A device should always have a default pstat. Therefore, jsonStr should never be NULL.
@@ -217,6 +218,7 @@ static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest
 {
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
     cJSON *postJson = NULL;
+    OC_LOG (INFO, TAG, "HandlePstatPutRequest  processing PUT request");
 
     if (ehRequest->resource)
     {
index 2a7e395..1ae2dc2 100644 (file)
@@ -18,6 +18,7 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include <string.h>
 #include "ocstack.h"
 #include "logger.h"
 #include "cainterface.h"
@@ -26,7 +27,7 @@
 #include "credresource.h"
 #include "policyengine.h"
 #include "oic_string.h"
-#include <string.h>
+#include "srmresourcestrings.h"
 
 #define TAG  "SRM"
 
@@ -283,3 +284,26 @@ void SRMDeInitPolicyEngine()
 {
     return DeInitPolicyEngine(&g_policyEngineContext);
 }
+
+/**
+ * @brief   Check the security resource URI.
+ * @param   uri [IN] Pointers to security resource URI.
+ * @return  true if the URI is one of security resources, otherwise false.
+ */
+bool SRMIsSecurityResourceURI(const char* uri)
+{
+    bool result = false;
+    if (!uri)
+    {
+        return result;
+    }
+
+    if (strcmp(uri, OIC_RSRC_AMACL_URI) == 0 || strcmp(uri, OIC_RSRC_ACL_URI) == 0
+            || strcmp(uri, OIC_RSRC_PSTAT_URI) == 0
+            || strncmp(OIC_RSRC_DOXM_URI, uri, sizeof(OIC_RSRC_DOXM_URI) - 1) == 0
+            || strcmp(uri, OIC_RSRC_CRED_URI) == 0 || strcmp(uri, OIC_RSRC_SVC_URI) == 0)
+    {
+        result = true;
+    }
+    return result;
+}
index ac495cc..ee48b7e 100644 (file)
@@ -240,18 +240,19 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
  *     OCStackResult
  */
 OCStackResult FormOCEntityHandlerRequest(
-                                OCEntityHandlerRequest *entityHandlerRequest,
-                                OCRequestHandle request,
-                                OCMethod method,
-                                OCDevAddr *endpoint,
-                                OCResourceHandle resource,
-                                char *queryBuf,
-                                uint8_t *payload,
-                                size_t payloadSize,
-                                uint8_t numVendorOptions,
-                                OCHeaderOption *vendorOptions,
-                                OCObserveAction observeAction,
-                                OCObservationId observeID);
+        OCEntityHandlerRequest * entityHandlerRequest,
+        OCRequestHandle request,
+        OCMethod method,
+        OCDevAddr *endpoint,
+        OCResourceHandle resource,
+        char * queryBuf,
+        OCPayloadType payloadType,
+        uint8_t * payload,
+        size_t payloadSize,
+        uint8_t numVendorOptions,
+        OCHeaderOption * vendorOptions,
+        OCObserveAction observeAction,
+        OCObservationId observeID);
 
 /**
  * Find a server request in the server request list and delete
index bbd3370..3e6f6b0 100644 (file)
@@ -148,6 +148,7 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
                                     &request->devAddr,
                                     (OCResourceHandle) resPtr,
                                     request->query,
+                                    PAYLOAD_TYPE_REPRESENTATION,
                                     request->payload,
                                     request->payloadSize,
                                     request->numRcvdVendorSpecificHeaderOptions,
index f60c08b..d085fc1 100644 (file)
@@ -25,8 +25,8 @@
 // For POSIX.1-2001 base specification,
 // Refer http://pubs.opengroup.org/onlinepubs/009695399/
 #define _POSIX_C_SOURCE 200112L
-#include "ocresource.h"
 #include <string.h>
+#include "ocresource.h"
 #include "ocresourcehandler.h"
 #include "ocobserve.h"
 #include "occollection.h"
 #include "logger.h"
 #include "cJSON.h"
 #include "ocpayload.h"
-
+#include "secureresourcemanager.h"
 #include "cacommon.h"
 #include "cainterface.h"
 
-
 /// Module Name
 #define TAG "ocresource"
 #define VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
@@ -691,6 +690,7 @@ HandleDefaultDeviceEntityHandler (OCServerRequest *request)
                                         request->method,
                                         &request->devAddr,
                                         (OCResourceHandle) NULL, request->query,
+                                        PAYLOAD_TYPE_REPRESENTATION,
                                         request->payload,
                                         request->payloadSize,
                                         request->numRcvdVendorSpecificHeaderOptions,
@@ -735,13 +735,20 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
     OCEntityHandlerRequest ehRequest = {0};
 
     OC_LOG(INFO, TAG, "Entering HandleResourceWithEntityHandler");
+    OCPayloadType type = PAYLOAD_TYPE_REPRESENTATION;
+    // check the security resource
+    if (request && request->resourceUrl && SRMIsSecurityResourceURI(request->resourceUrl))
+    {
+        type = PAYLOAD_TYPE_SECURITY;
 
+    }
     result = FormOCEntityHandlerRequest(&ehRequest,
                                         (OCRequestHandle)request,
                                         request->method,
                                         &request->devAddr,
                                         (OCResourceHandle)resource,
                                         request->query,
+                                        type,
                                         request->payload,
                                         request->payloadSize,
                                         request->numRcvdVendorSpecificHeaderOptions,
@@ -857,6 +864,7 @@ HandleCollectionResourceDefaultEntityHandler (OCServerRequest *request,
                                         &request->devAddr,
                                         (OCResourceHandle)resource,
                                         request->query,
+                                        PAYLOAD_TYPE_REPRESENTATION,
                                         request->payload,
                                         request->payloadSize,
                                         request->numRcvdVendorSpecificHeaderOptions,
index 92c0593..5a6c498 100644 (file)
@@ -338,6 +338,7 @@ OCStackResult FormOCEntityHandlerRequest(
         OCDevAddr *endpoint,
         OCResourceHandle resource,
         char * queryBuf,
+        OCPayloadType payloadType,
         uint8_t * payload,
         size_t payloadSize,
         uint8_t numVendorOptions,
@@ -357,7 +358,7 @@ OCStackResult FormOCEntityHandlerRequest(
 
         if(payload && payloadSize)
         {
-            if(OCParsePayload(&entityHandlerRequest->payload, PAYLOAD_TYPE_REPRESENTATION,
+            if(OCParsePayload(&entityHandlerRequest->payload, payloadType,
                         payload, payloadSize) != OC_STACK_OK)
             {
                 return OC_STACK_ERROR;
index 3e1d404..509da33 100644 (file)
@@ -475,7 +475,8 @@ OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t stat
                                                 OC_REST_NOMETHOD,
                                                 &observer->devAddr,
                                                 (OCResourceHandle)NULL,
-                                                NULL, NULL, 0, 0, NULL,
+                                                NULL, PAYLOAD_TYPE_REPRESENTATION,
+                                                NULL, 0, 0, NULL,
                                                 OC_OBSERVE_DEREGISTER,
                                                 observer->observeId);
             if(result != OC_STACK_OK)
@@ -525,7 +526,8 @@ OCStackResult OCStackFeedBack(CAToken_t token, uint8_t tokenLength, uint8_t stat
                                                     OC_REST_NOMETHOD,
                                                     &observer->devAddr,
                                                     (OCResourceHandle)NULL,
-                                                    NULL, NULL, 0, 0, NULL,
+                                                    NULL, PAYLOAD_TYPE_REPRESENTATION,
+                                                    NULL, 0, 0, NULL,
                                                     OC_OBSERVE_DEREGISTER,
                                                     observer->observeId);
                 if(result != OC_STACK_OK)
@@ -1095,7 +1097,12 @@ void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* res
                responseInfo->info.payloadSize)
             {
                 OCPayloadType type = PAYLOAD_TYPE_INVALID;
-                if (cbNode->method == OC_REST_DISCOVER)
+                // check the security resource
+                if (SRMIsSecurityResourceURI(cbNode->requestUri))
+                {
+                    type = PAYLOAD_TYPE_SECURITY;
+                }
+                else if (cbNode->method == OC_REST_DISCOVER)
                 {
                     if (strncmp(OC_RSRVD_WELL_KNOWN_URI,cbNode->requestUri,
                                 sizeof(OC_RSRVD_WELL_KNOWN_URI) - 1) == 0)