[IOT-2219] Fix provisioning to support dual stack
authorDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Thu, 8 Jun 2017 15:28:01 +0000 (18:28 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Fri, 14 Jul 2017 11:49:06 +0000 (11:49 +0000)
1. Added ability to discover spec. version
in Provisioning Client to support OIC 1.1 in addition to OCF 1.0
2. Security version mechanism replaced by icv

Change-Id: I2c3aabe9ed78593fa97d13c1c528a571f34ffc0d
Signed-off-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20651
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Oleksii Beketov <ol.beketov@samsung.com>
Reviewed-by: Vadym Riznyk <v.riznyk@samsung.com>
Reviewed-by: Jongmin Choi <jminl.choi@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
18 files changed:
resource/csdk/security/SConscript
resource/csdk/security/include/internal/srmresourcestrings.h
resource/csdk/security/include/internal/verresource.h [deleted file]
resource/csdk/security/include/securevirtualresourcetypes.h
resource/csdk/security/provisioning/include/pmtypes.h
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp
resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp
resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/src/resourcemanager.c
resource/csdk/security/src/srmresourcestrings.c
resource/csdk/security/src/verresource.c [deleted file]

index 131bf0f..860a289 100644 (file)
@@ -103,7 +103,6 @@ libocsrm_src = [
     OCSRM_SRC + 'secureresourcemanager.c',
     OCSRM_SRC + 'resourcemanager.c',
     OCSRM_SRC + 'aclresource.c',
-    OCSRM_SRC + 'verresource.c',
     OCSRM_SRC + 'amaclresource.c',
     OCSRM_SRC + 'pstatresource.c',
     OCSRM_SRC + 'doxmresource.c',
index f29924a..f2c6d36 100644 (file)
@@ -229,7 +229,7 @@ extern const char * OIC_SEC_REST_QUERY_SEPARATOR;
 extern char OIC_SEC_REST_QUERY_DELIMETER;
 
 //Security Version
-extern const char * DEFAULT_SEC_VERSION;
+extern const char * DEFAULT_SPEC_VERSION;
 
 // Preconfigured Pin credential usage
 #ifdef MULTIPLE_OWNER
diff --git a/resource/csdk/security/include/internal/verresource.h b/resource/csdk/security/include/internal/verresource.h
deleted file mode 100644 (file)
index db050d3..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/* *****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * *****************************************************************/
-
-#ifndef IOTVT_SRM_VER_H
-#define IOTVT_SRM_VER_H
-
-#include "octypes.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Initialize VER resource by loading data from persistent storage.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult InitVerResource();
-
-/**
- * Perform cleanup for VER resources.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult DeInitVerResource();
-
-/**
- * This method is used by SRM to retrieve VER resource data.
- *
- * @return reference to @ref OicSecDoxm_t, binary format of Doxm resource data.
- */
-const OicSecVer_t* GetVerResourceData();
-
-/**
- * This method converts CBOR VER into binary VER.
- * The CBOR VER can be from persistent database or
- * or received as PUT/POST request.
- *
- * @param cborPayload is a ver data in cbor.
- * @note Caller needs to invoke OCFree after done using the return pointer.
- * @param size of the cborPayload. In case value is 0, CBOR_SIZE value is assigned.
- * @param ver is the pointer to @ref OicSecVer_t.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult CBORPayloadToVer(const uint8_t *cborPayload, size_t size,
-                                OicSecVer_t **ver);
-
-/**
- * This method converts VER data into CBOR format.
- * Caller needs to invoke 'free' when finished done using
- * return string.
- *
- * @param ver Pointer to @ref OicSecVer_t.
- * @note Caller needs to invoke OCFree after done using the return pointer.
- * @param cborPayload is the payload of the cbor.
- * @param cborSize is the size of the cbor payload. Passed parameter should not be NULL.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult VerToCBORPayload(const OicSecVer_t * ver, uint8_t **cborPayload,
-                                size_t *cborSize);
-
-/**
- * Get the security version.
- *
- * @return the version string of security.
- */
-const char* GetSecVersion();
-
-/** This function deallocates the memory for OicSecVer_t .
- *
- * @param ver is the pointer to @ref OicSecVer_t.
- */
-void DeleteVerBinData(OicSecVer_t* ver);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //IOTVT_SRM_VER_H
index 2210295..74a8e7c 100644 (file)
@@ -709,22 +709,19 @@ struct OicSecDpairing
     OicUuid_t           rownerID;          // 2:R:S:Y:oic.uuid
 };
 
-#define OIC_SEC_MAX_VER_LEN 16 // Security Version length. i.e., 00.00.000 + reserved space
-
+#define SPEC_MAX_VER_LEN (sizeof("core.x.x.x") + 1) // Spec Version length.
 /**
- * @brief   security version data type
+ * @def GET_ACL_VER(specVer)
+ * Gets ACL version depending on spec. version.
+ * Version value has "ocf.x.x.x" for ocf device and "core.x.x.x" for oic device.
+ *
+ * @param specVer spec. version string
+ * @return ACL version
  */
-typedef struct OicSecVer OicSecVer_t;
 
-/**
- * @brief   /oic/sec/ver (Security Version) data type
- */
-struct OicSecVer
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    char              secv[OIC_SEC_MAX_VER_LEN];          // 0:R:S:Y:String
-    OicUuid_t       deviceID;     // 1:R:S:Y:oic.uuid
-};
+#define GET_ACL_VER(specVer) ((specVer)[0] == 'o' && (specVer)[1] == 'c' && (specVer)[2] == 'f' ?      \
+                             OIC_SEC_ACL_V2 : OIC_SEC_ACL_V1)
+#define IS_OIC(specVer) ((specVer)[0] == 'c' && (specVer)[1] == 'o' && (specVer)[2] == 'r' && (specVer)[3] == 'e')
 
 #ifdef __cplusplus
 }
index 384d57f..5e73fff 100644 (file)
@@ -71,7 +71,7 @@ typedef struct OCProvisionDev
     uint16_t        tcpPort;         /**< tcp port **/
     uint16_t        tcpSecurePort;   /**< secure tcp port **/
 #endif
-    char            secVer[OIC_SEC_MAX_VER_LEN];         /**< security version **/
+    char            specVer[SPEC_MAX_VER_LEN];         /**< spec version **/
     DeviceStatus    devStatus;       /**< status of device **/
     OCDoHandle      handle;
     bool            ownerAclUnauthorizedRequest;        /**< true if the provisioning client has already re-tried posting the Owner ACE **/
index 3755d18..4ef507e 100644 (file)
@@ -2526,6 +2526,7 @@ static int printDevList(const OCProvisionDev_t* dev_lst)
     {
         printf("     [%d] ", ++lst_cnt);
         printUuid((const OicUuid_t*) &lst->doxm->deviceID);
+        printf("    %s", lst->specVer);
         printf("\n");
         lst = lst->next;
     }
index 20a0c4a..090a42f 100644 (file)
@@ -48,6 +48,7 @@
 
 #define TAG "SAMPLE_JUSTWORKS"
 
+const char * specVersion = "ocf.1.1.0";
 int gQuitFlag = 0;
 
 /* Structure to represent a LED resource */
@@ -433,6 +434,7 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+    OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
      * Declare and create the example resource: LED
index 586d237..00fab0c 100644 (file)
@@ -48,6 +48,7 @@
 #define TAG "SAMPLE_MANUFACTURER_CERT"
 
 int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
 
 /* Structure to represent a LED resource */
 typedef struct LEDRESOURCE{
@@ -431,6 +432,7 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+    OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
      * Declare and create the example resource: LED
index e6fdd97..3e62601 100644 (file)
@@ -50,6 +50,7 @@
 #define TAG "SAMPLE_MV_JUSTWORKS"
 
 int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
 
 /* Structure to represent a LED resource */
 typedef struct LEDRESOURCE{
@@ -484,6 +485,7 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+    OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
      * Declare and create the example resource: LED
index cb553c5..2e7f9cd 100644 (file)
@@ -49,6 +49,7 @@
 #define TAG "SAMPLE_PRECONF_PIN"
 
 int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
 
 /* Structure to represent a LED resource */
 typedef struct LEDRESOURCE{
@@ -433,6 +434,7 @@ int main()
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
+    OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
      * Declare and create the example resource: LED
index 6bfb85e..26914a2 100644 (file)
@@ -48,6 +48,7 @@
 #define TAG "SAMPLE_RANDOMPIN"
 
 int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
 
 /* Structure to represent a LED resource */
 typedef struct LEDRESOURCE{
@@ -513,6 +514,7 @@ int main()
         OIC_LOG(ERROR, TAG, "Failed to setting PIN policy");
         return 0;
     }
+    OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
 
     /*
      * Declare and create the example resource: LED
index 8c197b3..6c9ab00 100644 (file)
@@ -362,7 +362,7 @@ OCStackResult OC_CALL OCProvisionACL(void* ctx, const OCProvisionDev_t *selected
      * since we may be provisioning an IoTivity 1.2 or earlier device.
      * TODO IOT-2219 - reintroduce OIC 1.1 /acl (v1) support
      */
-    OicSecAclVersion_t aclVersion = OIC_SEC_ACL_V2;
+    OicSecAclVersion_t aclVersion = GET_ACL_VER(selectedDeviceInfo->specVer);
     if (acl->aces != NULL)
     {
         /* If any of the aces have the role subject, the ACL is v2 */
@@ -1105,7 +1105,7 @@ static void AclProv1CB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool
     UpdateLinkResults(link, 1, arr[0].res);
     if (NULL != link->pDev2Acl)
     {
-        OCStackResult res =  SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, OIC_SEC_ACL_V2, &AclProv2CB);
+        OCStackResult res =  SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, GET_ACL_VER(link->pDev2->specVer), &AclProv2CB);
         if (OC_STACK_OK!=res)
         {
              UpdateLinkResults(link, 2, res);
@@ -1154,7 +1154,7 @@ static void ProvisionCredsCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr,
     }
     if (NULL != link->pDev1Acl)
     {
-        OCStackResult res =  SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, OIC_SEC_ACL_V2, &AclProv1CB);
+        OCStackResult res =  SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, GET_ACL_VER(link->pDev1->specVer), &AclProv1CB);
         if (OC_STACK_OK!=res)
         {
              OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
@@ -1170,7 +1170,7 @@ static void ProvisionCredsCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr,
     {
         OIC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
 
-        OCStackResult res =  SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, OIC_SEC_ACL_V2, &AclProv2CB);
+        OCStackResult res =  SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, GET_ACL_VER(link->pDev2->specVer), &AclProv2CB);
         if (OC_STACK_OK!=res)
         {
              OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
index 68dc33c..d0250e5 100644 (file)
@@ -401,7 +401,7 @@ static OCStackResult PostOwnerCredential(OTMContext_t* otmCtx);
  * @param[in]  otmCtx  Context value of ownership transfer.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx, OicSecAclVersion_t aclVer);
 
 /**
  * Function to send ownerShip info.
@@ -1229,7 +1229,7 @@ static OCStackApplicationResult OwnerCredentialHandler(void *ctx, OCDoHandle UNU
 #ifdef __WITH_TLS__
             otmCtx->selectedDeviceInfo->connType |= CT_FLAG_SECURE;
 #endif
-            res = PostOwnerAcl(otmCtx);
+            res = PostOwnerAcl(otmCtx, GET_ACL_VER(otmCtx->selectedDeviceInfo->specVer));
             if(OC_STACK_OK != res)
             {
                 OIC_LOG(ERROR, TAG, "Failed to update owner ACL to new device");
@@ -1289,31 +1289,6 @@ static OCStackApplicationResult OwnerAclHandler(void *ctx, OCDoHandle UNUSED,
             }
         }
     }
-    else if((OC_STACK_UNAUTHORIZED_REQ == res) &&
-            (NULL != selectedDeviceInfo) &&
-            !selectedDeviceInfo->ownerAclUnauthorizedRequest)
-    {
-        OIC_LOG_V(WARNING, TAG, "%s: UNAUTHORIZED_REQ. Assuming server is based on OIC 1.1",
-            __func__);
-        selectedDeviceInfo->ownerAclUnauthorizedRequest = true;
-
-        //Close the temporal secure session and re-connect using the owner credential
-        if(!CloseSslConnection(selectedDeviceInfo))
-        {
-            //Cannot make progress reliably, so return the error code from the previous request.
-            SetResult(otmCtx, OC_STACK_UNAUTHORIZED_REQ);
-        }
-        else
-        {
-            res = PostOwnerAcl(otmCtx);
-            if(OC_STACK_OK != res)
-            {
-                OIC_LOG_V(ERROR, TAG, "%s: Failed to update owner ACL to new device, res = %d",
-                    __func__, res);
-                SetResult(otmCtx, res);
-            }
-        }
-    }
     else
     {
         OIC_LOG_V(ERROR, TAG, "OwnerAclHandler : Unexpected result %d", res);
@@ -1326,7 +1301,6 @@ exit:
     return  OC_STACK_DELETE_TRANSACTION;
 }
 
-
 /**
  * Response handler for update owner information request.
  *
@@ -1730,9 +1704,10 @@ error:
  * Function to update the owner ACL to new device.
  *
  * @param[in]  otmCtx  Context value of ownership transfer.
+ * @param[in]  aclVer  ACL version.
  * @return  OC_STACK_OK on success
  */
-static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx, OicSecAclVersion_t aclVer)
 {
     OCStackResult res = OC_STACK_ERROR;
 
@@ -1743,7 +1718,7 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
         OIC_LOG(ERROR, TAG, "Invalid parameters");
         return OC_STACK_INVALID_PARAM;
     }
-
+    const char * aclUri = (OIC_SEC_ACL_V2 == aclVer ? OIC_RSRC_ACL2_URI : OIC_RSRC_ACL_URI);
     OCProvisionDev_t* deviceInfo = otmCtx->selectedDeviceInfo;
     char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
     OicSecAcl_t* ownerAcl = NULL;
@@ -1772,7 +1747,7 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
     if(!PMGenerateQuery(true,
                         deviceInfo->endpoint.addr, deviceInfo->securePort,
                         deviceInfo->connType,
-                        query, sizeof(query), OIC_RSRC_ACL2_URI))
+                        query, sizeof(query), aclUri))
     {
         OIC_LOG(ERROR, TAG, "Failed to generate query");
         return OC_STACK_ERROR;
@@ -1804,8 +1779,7 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
         goto error;
     }
 
-    // TODO IOT-2052 change to V2
-    res = AclToCBORPayload(ownerAcl, OIC_SEC_ACL_V2, &secPayload->securityData, &secPayload->payloadSize);
+    res = AclToCBORPayload(ownerAcl, aclVer, &secPayload->securityData, &secPayload->payloadSize);
     if (OC_STACK_OK != res)
     {
         OICFree(secPayload);
@@ -1819,7 +1793,7 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
 
     //Send owner ACL to new device : POST /oic/sec/cred [ owner credential ]
     OCCallbackData cbData;
-    cbData.cb = &OwnerAclHandler;
+    cbData.cb = OwnerAclHandler;
     cbData.context = (void *)otmCtx;
     cbData.cd = NULL;
     res = OCDoResource(&otmCtx->ocDoHandle, OC_REST_POST, query,
index 8998992..4045c0e 100644 (file)
@@ -41,7 +41,6 @@
 #include "srmresourcestrings.h" //@note: SRM's internal header
 #include "doxmresource.h"       //@note: SRM's internal header
 #include "pstatresource.h"      //@note: SRM's internal header
-#include "verresource.h"      //@note: SRM's internal header
 
 #include "pmtypes.h"
 #include "pmutility.h"
@@ -87,7 +86,7 @@ static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNU
  * Since security version discovery does not used anymore, disable security version discovery.
  * Need to discussion to removing all version discovery related codes.
  */
-#if 0
+
 /*
  * Function to discover security version information through unicast
  *
@@ -96,9 +95,9 @@ static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNU
  *
  * @return OC_STACK_OK on success otherwise error.
  */
-static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
+static OCStackResult SpecVersionDiscovery(DiscoveryInfo* discoveryInfo,
                                               const OCClientResponse *clientResponse);
-
+#if 0
 /**
  * Callback handler for getting secure port information using /oic/res discovery.
  *
@@ -304,7 +303,7 @@ OCStackResult AddDevice(OCProvisionDev_t **ppDevicesList, OCDevAddr* endpoint,
         ptr->next = NULL;
         ptr->connType = connType;
         ptr->devStatus = DEV_STATUS_ON; //AddDevice is called when discovery(=alive)
-        OICStrcpy(ptr->secVer, OIC_SEC_MAX_VER_LEN, DEFAULT_SEC_VERSION); // version initialization
+        OICStrcpy(ptr->specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION); // version initialization
         ptr->handle = NULL;
 
         LL_PREPEND(*ppDevicesList, ptr);
@@ -385,14 +384,14 @@ static OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList,
  * @param[in] pList         List of OCProvisionDev_t.
  * @param[in] addr          address of target device.
  * @param[in] port          port of remote server.
- * @param[in] secVer    security version information.
+ * @param[in] specVer    security version information.
  *
  * @return OC_STACK_OK for success and errorcode otherwise.
  */
-OCStackResult UpdateSecVersionOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
-                                       uint16_t port, const char* secVer)
+static OCStackResult UpdateSpecVersionOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
+                                       uint16_t port, const char* specVer)
 {
-    if (NULL == secVer)
+    if (NULL == specVer)
     {
         return OC_STACK_INVALID_PARAM;
     }
@@ -405,7 +404,7 @@ OCStackResult UpdateSecVersionOfDevice(OCProvisionDev_t **ppDevicesList, const c
         return OC_STACK_ERROR;
     }
 
-    OICStrcpy(ptr->secVer, OIC_SEC_MAX_VER_LEN, secVer);
+    OICStrcpy(ptr->specVer, SPEC_MAX_VER_LEN, specVer);
 
     return OC_STACK_OK;
 }
@@ -463,13 +462,13 @@ OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src)
         VERIFY_NOT_NULL(TAG, newDev->doxm, ERROR);
     }
 
-    if (0 == strlen(src->secVer))
+    if (0 == strlen(src->specVer))
     {
-        OICStrcpy(newDev->secVer, OIC_SEC_MAX_VER_LEN, DEFAULT_SEC_VERSION);
+        OICStrcpy(newDev->specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION);
     }
     else
     {
-        OICStrcpy(newDev->secVer, OIC_SEC_MAX_VER_LEN, src->secVer);
+        OICStrcpy(newDev->specVer, SPEC_MAX_VER_LEN, src->specVer);
     }
 
     newDev->securePort = src->securePort;
@@ -627,8 +626,7 @@ bool OC_CALL PMGenerateQuery(bool isSecure,
  * Since security version discovery does not used anymore, disable security version discovery.
  * Need to discussion to removing all version discovery related codes.
  */
-#if 0
-static OCStackApplicationResult SecurityVersionDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
+static OCStackApplicationResult SpecVersionDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
                                 OCClientResponse *clientResponse)
 {
     if (ctx == NULL)
@@ -651,45 +649,42 @@ static OCStackApplicationResult SecurityVersionDiscoveryHandler(void *ctx, OCDoH
         }
         else
         {
-            if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
+            if (PAYLOAD_TYPE_REPRESENTATION != clientResponse->payload->type)
             {
                 OIC_LOG(INFO, TAG, "Unknown payload type");
                 return OC_STACK_KEEP_TRANSACTION;
             }
+            OCRepPayloadValue* val = ((OCRepPayload*) clientResponse->payload)->values;
 
-            OicSecVer_t *ptrVer = NULL;
-            uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
-            size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
-
-            OCStackResult res = CBORPayloadToVer(payload, size, &ptrVer);
-            if ((NULL == ptrVer) && (OC_STACK_OK != res))
-            {
-                OIC_LOG(INFO, TAG, "Ignoring malformed CBOR");
-                return OC_STACK_KEEP_TRANSACTION;
-            }
-            else
+            char specVer[SPEC_MAX_VER_LEN + 1] = {0};
+            OICStrcpy(specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION);
+            while (val)
             {
-                OIC_LOG(DEBUG, TAG, "Successfully converted ver cbor to bin.");
-
-                //If this is owend device discovery we have to filter out the responses.
-                DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
-                res = UpdateSecVersionOfDevice(pDInfo->ppDevicesList, clientResponse->devAddr.addr,
-                                                         clientResponse->devAddr.port, ptrVer->secv);
-                if (OC_STACK_OK != res)
+                if (val->type == OCREP_PROP_STRING)
                 {
-                    OIC_LOG(ERROR, TAG, "Error while getting security version.");
-                    DeleteVerBinData(ptrVer);
-                    return OC_STACK_KEEP_TRANSACTION;
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s:%s", val->name, val->str);
+                    if (0 == strcmp(val->name, OC_RSRVD_SPEC_VERSION))
+                    {
+                        OICStrcpy(specVer, SPEC_MAX_VER_LEN, val->str);
+                        break;
+                    }
                 }
-
-                OIC_LOG(INFO, TAG, "= Discovered security version =");
-                OIC_LOG_V(DEBUG, TAG, "IP %s", clientResponse->devAddr.addr);
-                OIC_LOG_V(DEBUG, TAG, "PORT %d", clientResponse->devAddr.port);
-                OIC_LOG_V(DEBUG, TAG, "VERSION %s", ptrVer->secv);
-
-                OIC_LOG(INFO, TAG, "Exiting SecVersionDiscoveryHandler.");
-                DeleteVerBinData(ptrVer);
+                val = val -> next;
+            }
+            //If this is owend device discovery we have to filter out the responses.
+            DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
+            OCStackResult res = UpdateSpecVersionOfDevice(pDInfo->ppDevicesList, clientResponse->devAddr.addr,
+                                                     clientResponse->devAddr.port, specVer);
+            if (OC_STACK_OK != res)
+            {
+                OIC_LOG(ERROR, TAG, "Error while getting security version.");
+                return OC_STACK_KEEP_TRANSACTION;
             }
+
+            OIC_LOG(INFO, TAG, "= Discovered security version =");
+            OIC_LOG_V(DEBUG, TAG, "IP %s", clientResponse->devAddr.addr);
+            OIC_LOG_V(DEBUG, TAG, "PORT %d", clientResponse->devAddr.port);
+            OIC_LOG_V(DEBUG, TAG, "VERSION %s", specVer);
         }
     }
     else
@@ -700,7 +695,6 @@ static OCStackApplicationResult SecurityVersionDiscoveryHandler(void *ctx, OCDoH
 
     return  OC_STACK_DELETE_TRANSACTION;
 }
-#endif
 
 static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
                                  OCClientResponse *clientResponse)
@@ -856,18 +850,13 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
                 pDInfo->isFound = true;
             }
 
-/*
- * Since security version discovery does not used anymore, disable security version discovery.
- * Need to discussion to removing all version discovery related codes.
- */
-#if 0
-            res = SecurityVersionDiscovery(pDInfo, clientResponse);
+            res = SpecVersionDiscovery(pDInfo, clientResponse);
             if(OC_STACK_OK != res)
             {
-                OIC_LOG(ERROR, TAG, "Failed to SecurityVersionDiscovery");
+                OIC_LOG(ERROR, TAG, "Failed to SpecVersionDiscovery");
                 return OC_STACK_DELETE_TRANSACTION;
             }
-#endif
+
             OIC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
         }
 
@@ -1731,15 +1720,11 @@ static OCStackResult SecurePortDiscovery(DiscoveryInfo* discoveryInfo,
     return ret;
 }
 
-/*
- * Since security version discovery does not used anymore, disable security version discovery.
- * Need to discussion to removing all version discovery related codes.
- */
-#if 0
-static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
+
+static OCStackResult SpecVersionDiscovery(DiscoveryInfo* discoveryInfo,
                                               const OCClientResponse *clientResponse)
 {
-    OIC_LOG(DEBUG, TAG, "IN SecurityVersionDiscovery");
+    OIC_LOG(DEBUG, TAG, "IN SpecVersionDiscovery");
 
     if(NULL == discoveryInfo || NULL == clientResponse)
     {
@@ -1751,15 +1736,15 @@ static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
     if(!PMGenerateQuery(false,
                         clientResponse->devAddr.addr, clientResponse->devAddr.port,
                         clientResponse->connType,
-                        query, sizeof(query), OIC_RSRC_VER_URI))
+                        query, sizeof(query), OC_RSRVD_DEVICE_URI))
     {
-        OIC_LOG(ERROR, TAG, "SecurityVersionDiscovery : Failed to generate query");
+        OIC_LOG(ERROR, TAG, "SpecVersionDiscovery : Failed to generate query");
         return OC_STACK_ERROR;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
 
     OCCallbackData cbData;
-    cbData.cb = &SecurityVersionDiscoveryHandler;
+    cbData.cb = &SpecVersionDiscoveryHandler;
     cbData.context = (void*)discoveryInfo;
     cbData.cd = NULL;
     OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
@@ -1774,11 +1759,10 @@ static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
         OIC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
     }
 
-    OIC_LOG(DEBUG, TAG, "OUT SecurityVersionDiscovery");
+    OIC_LOG(DEBUG, TAG, "OUT SpecVersionDiscovery");
 
     return ret;
 }
-#endif
 
 /**
  * Function to print OCProvisionDev_t for debug purpose.
index f191914..a86a34f 100644 (file)
@@ -820,6 +820,13 @@ static OCStackResult SetDOS(const Data_t *data, OicSecDeviceOnboardingState_t do
             return OC_STACK_INVALID_PARAM;
         }
     }
+    // Skip posting new DOS state in case of OIC server
+    if (IS_OIC(pTargetDev->specVer))
+    {
+        OCClientResponse clientResponse = {.result = OC_STACK_RESOURCE_CHANGED};
+        resultCallback((void*) data, NULL, &clientResponse);
+        return OC_STACK_OK;
+    }
 
     OCStackResult res = OC_STACK_ERROR;
     OicSecPstat_t *pstat = (OicSecPstat_t *) OICCalloc(1, sizeof(OicSecPstat_t));
index 9b48738..10af591 100644 (file)
@@ -35,7 +35,6 @@
 #include "pconfresource.h"
 #include "dpairingresource.h"
 //#endif // DIRECT_PAIRING
-#include "verresource.h"
 
 #define TAG "OIC_SRM_RM"
 
@@ -126,10 +125,6 @@ OCStackResult InitSecureResources( )
         ret = InitDpairingResource();
     }
 //#endif // DIRECT_PAIRING
-    if(OC_STACK_OK == ret)
-    {
-        ret = InitVerResource();
-    }
     if(OC_STACK_OK != ret)
     {
         //TODO: Update the default behavior if one of the SVR fails
@@ -154,7 +149,6 @@ OCStackResult DestroySecureResources( )
     DeInitPconfResource();
     DeInitDpairingResource();
 //#endif // DIRECT_PAIRING
-    DeInitVerResource();
 
     return OC_STACK_OK;
 }
index d7ebdf6..0429297 100644 (file)
@@ -223,8 +223,8 @@ const char * OIC_SEC_FALSE = "false";
 const char * OIC_SEC_REST_QUERY_SEPARATOR = ";";
 char OIC_SEC_REST_QUERY_DELIMETER = '=';
 
-//Security Version
-const char * DEFAULT_SEC_VERSION = "0.0.0";
+//Spec Version
+const char * DEFAULT_SPEC_VERSION = "core.0.0.0";
 
 //Preconfigured Pin credential identifier
 #ifdef MULTIPLE_OWNER
diff --git a/resource/csdk/security/src/verresource.c b/resource/csdk/security/src/verresource.c
deleted file mode 100644 (file)
index bfc4c9b..0000000
+++ /dev/null
@@ -1,365 +0,0 @@
-/* *****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * *****************************************************************/
-
-#include "iotivity_config.h"
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#include "ocstack.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "logger.h"
-#include "payload_logging.h"
-#include "ocpayload.h"
-#include "ocpayloadcbor.h"
-#include "cainterface.h"
-#include "ocserverrequest.h"
-#include "resourcemanager.h"
-#include "verresource.h"
-#include "doxmresource.h"
-#include "psinterface.h"
-#include "srmresourcestrings.h"
-#include "securevirtualresourcetypes.h"
-#include "srmutility.h"
-
-#define TAG  "OIC_SEC_VER"
-
-/** Default cbor payload size. This value is increased in case of CborErrorOutOfMemory.
- * The value of payload size is increased until reaching belox max cbor size. */
-static const uint8_t CBOR_SIZE = 255;
-
-/** Max cbor size payload. */
-static const uint16_t CBOR_MAX_SIZE = 4400;
-
-/** VER Map size - Number of mandatory items. */
-static const uint8_t VER_MAP_SIZE = 2;
-
-static OCResourceHandle    gVerHandle = NULL;
-
-/** Security version is mapped with iotivity release version */
-const char* SECURITY_VERSION = IOTIVITY_VERSION;
-
-static OicSecVer_t gVer =
-{
-    {0},                  /* char *secv */
-    {.id = {0}},         /* OicUuid_t deviceID */
-};
-
-void DeleteVerBinData(OicSecVer_t* ver)
-{
-    if (ver)
-    {
-        //Clean ver itself
-        OICFree(ver);
-    }
-}
-
-OCStackResult VerToCBORPayload(const OicSecVer_t *ver, uint8_t **payload, size_t *size)
-{
-    if (NULL == ver || NULL == payload || NULL != *payload || NULL == size)
-    {
-        return OC_STACK_INVALID_PARAM;
-    }
-    size_t cborLen = *size;
-    if (0 == cborLen)
-    {
-        cborLen = CBOR_SIZE;
-    }
-    *payload = NULL;
-    *size = 0;
-
-    OCStackResult ret = OC_STACK_ERROR;
-
-    CborEncoder encoder;
-    CborEncoder verMap;
-
-    int64_t cborEncoderResult = CborNoError;
-    uint8_t mapSize = VER_MAP_SIZE;
-    char* strUuid = NULL;
-
-    uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
-
-    cbor_encoder_init(&encoder, outPayload, cborLen, 0);
-
-    cborEncoderResult |= cbor_encoder_create_map(&encoder, &verMap, mapSize);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Ver Map.");
-
-    //SecV -- Mandatory
-    cborEncoderResult |= cbor_encode_text_string(&verMap, OIC_JSON_SEC_V_NAME,
-        strlen(OIC_JSON_SEC_V_NAME));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SecV Tag.");
-    cborEncoderResult |= cbor_encode_text_string(&verMap, ver->secv, strlen(ver->secv));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SecV Value.");
-
-    //DeviceId -- Mandatory
-    cborEncoderResult = cbor_encode_text_string(&verMap, OIC_JSON_DEVICE_ID_NAME,
-        strlen(OIC_JSON_DEVICE_ID_NAME));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Device Id Tag.");
-    ret = ConvertUuidToStr(&ver->deviceID, &strUuid);
-    VERIFY_SUCCESS(TAG, OC_STACK_OK == ret , ERROR);
-    cborEncoderResult = cbor_encode_text_string(&verMap, strUuid, strlen(strUuid));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Device Id Value.");
-    OICFree(strUuid);
-    strUuid = NULL;
-
-
-    // Close ver(first) container
-    cborEncoderResult |= cbor_encoder_close_container(&encoder, &verMap);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing VerMap.");
-
-    if (CborNoError == cborEncoderResult)
-    {
-        *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
-        *payload = outPayload;
-        ret = OC_STACK_OK;
-    }
-exit:
-    if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
-    {
-        OIC_LOG(DEBUG, TAG, "Memory getting reallocated.");
-        // reallocate and try again!
-        OICFree(outPayload);
-        outPayload = NULL;
-        // Since the allocated initial memory failed, double the memory.
-        cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
-        OIC_LOG_V(DEBUG, TAG, "Ver reallocation size : %zd.", cborLen);
-        cborEncoderResult = CborNoError;
-        ret = VerToCBORPayload(ver, payload, &cborLen);
-        *size = cborLen;
-    }
-
-    if ((CborNoError != cborEncoderResult) || (OC_STACK_OK != ret))
-    {
-       OICFree(outPayload);
-       outPayload = NULL;
-       *payload = NULL;
-       *size = 0;
-       ret = OC_STACK_ERROR;
-    }
-
-    return ret;
-}
-
-OCStackResult CBORPayloadToVer(const uint8_t *cborPayload, size_t size,
-                                OicSecVer_t **secVer)
-{
-    if (NULL == cborPayload || NULL == secVer || NULL != *secVer || 0 == size)
-    {
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    OCStackResult ret = OC_STACK_ERROR;
-    *secVer = NULL;
-    char *strUuid = NULL;
-
-    CborParser parser = { .end = NULL};
-    CborError cborFindResult = CborNoError;
-    size_t len = 0;
-    CborValue verCbor = { .parser = NULL };
-    cbor_parser_init(cborPayload, size, 0, &parser, &verCbor);
-    CborValue verMap = { .parser = NULL };
-    OicSecVer_t *ver = (OicSecVer_t *)OICCalloc(1, sizeof(OicSecVer_t));
-    VERIFY_NOT_NULL(TAG, ver, ERROR);
-
-
-    cborFindResult = cbor_value_map_find_value(&verCbor, OIC_JSON_SEC_V_NAME, &verMap);
-    if (CborNoError == cborFindResult && cbor_value_is_text_string(&verMap))
-    {
-        char *version = NULL;
-        cborFindResult = cbor_value_dup_text_string(&verMap, &version, &len, NULL);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Security Version Value.");
-        if (sizeof(ver->secv) < len)
-        {
-            OIC_LOG (ERROR, TAG, "Version length is too long");
-            OICFree(version);
-            OICFree(ver);
-            goto exit;
-        }
-        memcpy(ver->secv, version, len);
-        OICFree(version);
-    }
-
-    cborFindResult = cbor_value_map_find_value(&verCbor, OIC_JSON_DEVICE_ID_NAME, &verMap);
-    if (CborNoError == cborFindResult && cbor_value_is_text_string(&verMap))
-    {
-        cborFindResult = cbor_value_dup_text_string(&verMap, &strUuid , &len, NULL);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Device Id Value.");
-        ret = ConvertStrToUuid(strUuid , &ver->deviceID);
-        VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
-        OICFree(strUuid );
-        strUuid  = NULL;
-    }
-
-    *secVer = ver;
-    ret = OC_STACK_OK;
-
-exit:
-    if (CborNoError != cborFindResult)
-    {
-        OIC_LOG (ERROR, TAG, "CBORPayloadToVer failed!!!");
-        DeleteVerBinData(ver);
-        ret = OC_STACK_ERROR;
-    }
-    return ret;
-}
-
-static OCEntityHandlerResult HandleVerGetRequest (const OCEntityHandlerRequest * ehRequest)
-{
-    OCEntityHandlerResult ehRet = OC_EH_OK;
-
-    OIC_LOG(DEBUG, TAG, "Ver EntityHandle processing GET request");
-
-    /*
-     * For GET request return ver resource CBOR payload.
-     * For non-valid query return NULL json payload.
-     * The version is static built-in information, so VerToCBORPayload will
-     * return valid ver resource json.
-     */
-    uint8_t *payload = NULL;
-    size_t size = 0;
-    if (OC_STACK_OK != VerToCBORPayload(&gVer, &payload, &size))
-    {
-        payload = NULL;
-    }
-
-    // Send response payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleVerGetRequest");
-    }
-
-    OICFree(payload);
-
-    return ehRet;
-}
-
-OCEntityHandlerResult VerEntityHandler(OCEntityHandlerFlag flag,
-                                        OCEntityHandlerRequest * ehRequest,
-                                        void* callbackParam)
-{
-    (void)callbackParam;
-    OCEntityHandlerResult ehRet = OC_EH_ERROR;
-
-    if(NULL == ehRequest)
-    {
-        return ehRet;
-    }
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        OIC_LOG(DEBUG, TAG, "Flag includes OC_REQUEST_FLAG");
-
-        switch (ehRequest->method)
-        {
-            case OC_REST_GET:
-                ehRet = HandleVerGetRequest(ehRequest);
-                break;
-
-            default:
-                ehRet = OC_EH_ERROR;
-                SendSRMResponse(ehRequest, ehRet, NULL, 0);
-                break;
-        }
-    }
-
-    return ehRet;
-}
-
-OCStackResult CreateVerResource()
-{
-    OCStackResult ret = OCCreateResource(&gVerHandle,
-                                         OIC_RSRC_TYPE_SEC_VER,
-                                         OC_RSRVD_INTERFACE_DEFAULT,
-                                         OIC_RSRC_VER_URI,
-                                         VerEntityHandler,
-                                         NULL,
-                                         OC_SECURE);
-
-    if (OC_STACK_OK != ret)
-    {
-        OIC_LOG (FATAL, TAG, "Unable to instantiate Ver resource");
-        DeInitVerResource();
-    }
-    return ret;
-}
-
-/**
- * Get the security version.
- *
- * @return the version string of security.
- */
-const char* GetSecVersion()
-{
-    OIC_LOG(DEBUG, TAG, "GetSecVersion");
-    return gVer.secv;
-}
-
-const OicSecVer_t* GetVerResourceData()
-{
-    return &gVer;
-}
-
-OCStackResult InitVerResource()
-{
-    OCStackResult ret = OC_STACK_ERROR;
-
-    OICStrcpy(gVer.secv, OIC_SEC_MAX_VER_LEN, SECURITY_VERSION);
-
-    //Read device id from doxm
-    OicUuid_t deviceID = {.id={0}};
-    ret = GetDoxmDeviceID(&deviceID);
-    if (OC_STACK_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "Error while retrieving doxm device ID");
-        return ret;
-    }
-    memcpy(&gVer.deviceID, &deviceID, sizeof(OicUuid_t));
-
-    //Instantiate 'oic.sec.ver'
-    ret = CreateVerResource();
-    if (OC_STACK_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "Error while creating VER resource");
-    }
-
-    return ret;
-}
-
-OCStackResult DeInitVerResource()
-{
-    OCStackResult ret = OCDeleteResource(gVerHandle);
-
-    memset(&gVer, 0, sizeof(gVer));
-
-    if (OC_STACK_OK == ret)
-    {
-        return OC_STACK_OK;
-    }
-    else
-    {
-        return OC_STACK_ERROR;
-    }
-}