Add OTM select callback 15/194515/1
authorOleksii Beketov <ol.beketov@samsung.com>
Thu, 29 Nov 2018 12:33:36 +0000 (14:33 +0200)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 5 Dec 2018 07:34:34 +0000 (16:34 +0900)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/334
(cherry picked from commit 532f133abc97e9a165ced0fd94b24d513362237c)

Change-Id: Ifa6e264c2a900a5927ff15ec240a45f210ca9b59
Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/security/include/internal/secureresourcemanager.h
resource/csdk/security/provisioning/include/internal/ownershiptransfermanager.h
resource/csdk/security/provisioning/include/ocprovisioningmanager.h
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/src/pconfresource.c
resource/csdk/security/src/secureresourcemanager.c

index cc9c531..15bb37d 100644 (file)
@@ -91,7 +91,7 @@ typedef bool (*SPResponseCallback) (const CAEndpoint_t *object,
                                     const CAResponseInfo_t *responseInfo);
 
 /**
- * Function to register provisoning API's response callback.
+ * Function to register provisioning API's response callback.
  *
  * @param respHandler response handler callback.
  */
index b8f34c9..a7f2eb6 100644 (file)
@@ -81,6 +81,11 @@ typedef OCStackResult (*OTMCreateSecureSession)(OTMContext_t* otmCtx);
 typedef OCStackResult (*OTMCreatePayloadCallback)(OTMContext_t* otmCtx, uint8_t **payload,\r
                                                   size_t *size);\r
 \r
+/*\r
+ * Callback for selecting OTM.\r
+ */\r
+typedef OicSecOxm_t (*OTMSelectMethodCallback)(const OicSecOxm_t* otmList, const uint32_t len);\r
+\r
 /**\r
  * Required callback for performing ownership transfer\r
  */\r
@@ -90,6 +95,7 @@ struct OTMCallbackData
     OTMCreateSecureSession createSecureSessionCB;\r
     OTMCreatePayloadCallback createSelectOxmPayloadCB;\r
     OTMCreatePayloadCallback createOwnerTransferPayloadCB;\r
+    OTMSelectMethodCallback selectOTMCB;\r
 };\r
 \r
 /**\r
index 50c00fb..24b55dc 100644 (file)
@@ -582,6 +582,11 @@ OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethod
  */\r
 OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback);\r
 \r
+/*\r
+ * Callback for selecting OTM.\r
+ */\r
+void SetSelectOTMCB(OTMSelectMethodCallback selectOTMcb);\r
+\r
 #endif // __WITH_DTLS__ || __WITH_TLS__\r
 \r
 \r
index 7e7aefa..af45c6f 100644 (file)
@@ -1302,6 +1302,11 @@ OCStackResult notifyInputStateCB(void * ctx)
     return OC_STACK_OK;
 }
 
+OicSecOxm_t selectOTMcb(const OicSecOxm_t* otmList, const uint32_t len)
+{
+    return otmList[len-1];
+}
+
 #ifdef MULTIPLE_OWNER
 static int changeMultipleOwnershipTrnasferMode(void)
 {
@@ -2521,6 +2526,7 @@ int main()
     SetDisplayNumCB(NULL, displayNumCB);
     SetUserConfirmCB(NULL, confirmNumCB);
     SetInputStateCB(NULL, notifyInputStateCB);
+    SetSelectOTMCB(selectOTMcb);
 
     // set callback for checking peer certificate information
     OCSetPeerCertCallback(NULL, peerCertCallback);
index 326376b..e0e82ef 100644 (file)
@@ -104,6 +104,8 @@ static uint8_t g_OxmAllowStatus[OXM_IDX_COUNT] = {ALLOWED_OXM, ALLOWED_OXM, ALLO
                                                   NOT_ALLOWED_OXM};
 #endif
 
+static OTMSelectMethodCallback g_selectOTMCB = NULL;
+
 OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks)
 {
     OCStackResult res = OC_STACK_INVALID_PARAM;
@@ -180,6 +182,12 @@ exit:
     return res;
 }
 
+void SetSelectOTMCB(OTMSelectMethodCallback selectOTMcb)
+{
+    g_selectOTMCB = selectOTMcb;
+    return;
+}
+
 /**
  * Internal API to convert OxM value to index of oxm allow table.
  */
@@ -237,6 +245,11 @@ OCStackResult OTMSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMetho
     {
         case SUPER_OWNER:
         {
+            if (g_selectOTMCB)
+            {
+                uint32_t methNum = 0;
+                OicSecOxm_t list[10] = {0};
+
             for (size_t i = 0; i < numberOfMethods; i++)
             {
                 selectedOxmIdx = GetOxmAllowTableIdx(supportedMethods[i]);
@@ -245,19 +258,45 @@ OCStackResult OTMSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMetho
                     OIC_LOG(WARNING, TAG, "Invalid oxm index to access OxM allow table");
                     continue;
                 }
-#ifdef MULTIPLE_OWNER
+    #ifdef MULTIPLE_OWNER
+                    if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx] &&
+                       OXM_IDX_PRECONFIG_PIN != selectedOxmIdx)
+    #else
+
+                    if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx])
+    #endif //MULTIPLE_OWNER
+                    {
+                        list[methNum] = supportedMethods[i];
+                        methNum++;
+                    }
+                }
+                *selectedMethod = g_selectOTMCB(list, methNum);
+                isOxmSelected = true;
+            }
+            else
+            {
+                for (size_t i = 0; i < numberOfMethods; i++)
+                {
+                    selectedOxmIdx = GetOxmAllowTableIdx(supportedMethods[i]);
+                    if (OXM_IDX_COUNT <= selectedOxmIdx)
+                    {
+                        OIC_LOG(WARNING, TAG, "Invalid oxm index to access OxM allow table");
+                        continue;
+                    }
+    #ifdef MULTIPLE_OWNER
                 if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx] &&
                    OXM_IDX_PRECONFIG_PIN != selectedOxmIdx)
-#else
+    #else
 
                 if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx])
-#endif //MULTIPLE_OWNER
+    #endif //MULTIPLE_OWNER
                 {
                     *selectedMethod  = supportedMethods[i];
                     isOxmSelected = true;
                 }
             }
         }
+        }
         break;
 #ifdef MULTIPLE_OWNER
         case SUB_OWNER:
@@ -2144,7 +2183,7 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
         SetResult(otmCtx, res);
         return res;
     }
-    OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+    OIC_LOG_V(DEBUG, TAG, "Selected provisioning method = %d", selectedDevice->doxm->oxmSel);
 
     res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
     if(OC_STACK_OK != res)
@@ -2197,7 +2236,7 @@ static OCStackResult StartCustomOwnershipTransfer(void* ctx, OCProvisionDev_t* s
 
     //Select the OxM to performing ownership transfer
     selectedDevice->doxm->oxmSel = method;
-    OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+    OIC_LOG_V(DEBUG, TAG, "Selected provisioning method = %d", selectedDevice->doxm->oxmSel);
 
     res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
     if(OC_STACK_OK != res)
index da0b9c0..3404a16 100644 (file)
@@ -401,7 +401,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     }
 
     //DeviceId -- Mandatory
-    //There may not be devicd id if caller is provisoning tool
+    //There may not be devicd id if caller is provisioning tool
     cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_DEVICE_ID_NAME,
             strlen(OIC_JSON_DEVICE_ID_NAME));
     VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode device id");
index a054e73..8c1963e 100644 (file)
@@ -60,7 +60,7 @@ static SPResponseCallback gSPResponseHandler = NULL;
 PEContext_t g_policyEngineContext;
 
 /**
- * Function to register provisoning API's response callback.
+ * Function to register provisioning API's response callback.
  * @param respHandler response handler callback.
  */
 void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler)