From: Oleksii Beketov Date: Thu, 29 Nov 2018 12:33:36 +0000 (+0200) Subject: Add OTM select callback X-Git-Tag: submit/tizen_5.0/20181206.000945~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca18ebf6ddca2095e71bc3863bc461776b130fb8;p=platform%2Fupstream%2Fiotivity.git Add OTM select callback https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/334 (cherry picked from commit 532f133abc97e9a165ced0fd94b24d513362237c) Change-Id: Ifa6e264c2a900a5927ff15ec240a45f210ca9b59 Signed-off-by: Oleksii Beketov Signed-off-by: DoHyun Pyun --- diff --git a/resource/csdk/security/include/internal/secureresourcemanager.h b/resource/csdk/security/include/internal/secureresourcemanager.h index cc9c531e6..15bb37d2b 100644 --- a/resource/csdk/security/include/internal/secureresourcemanager.h +++ b/resource/csdk/security/include/internal/secureresourcemanager.h @@ -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. */ diff --git a/resource/csdk/security/provisioning/include/internal/ownershiptransfermanager.h b/resource/csdk/security/provisioning/include/internal/ownershiptransfermanager.h index b8f34c97d..a7f2eb67b 100644 --- a/resource/csdk/security/provisioning/include/internal/ownershiptransfermanager.h +++ b/resource/csdk/security/provisioning/include/internal/ownershiptransfermanager.h @@ -81,6 +81,11 @@ typedef OCStackResult (*OTMCreateSecureSession)(OTMContext_t* otmCtx); typedef OCStackResult (*OTMCreatePayloadCallback)(OTMContext_t* otmCtx, uint8_t **payload, size_t *size); +/* + * Callback for selecting OTM. + */ +typedef OicSecOxm_t (*OTMSelectMethodCallback)(const OicSecOxm_t* otmList, const uint32_t len); + /** * Required callback for performing ownership transfer */ @@ -90,6 +95,7 @@ struct OTMCallbackData OTMCreateSecureSession createSecureSessionCB; OTMCreatePayloadCallback createSelectOxmPayloadCB; OTMCreatePayloadCallback createOwnerTransferPayloadCB; + OTMSelectMethodCallback selectOTMCB; }; /** diff --git a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h index 50c00fb88..24b55dc9d 100644 --- a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h +++ b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h @@ -582,6 +582,11 @@ OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethod */ OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback); +/* + * Callback for selecting OTM. + */ +void SetSelectOTMCB(OTMSelectMethodCallback selectOTMcb); + #endif // __WITH_DTLS__ || __WITH_TLS__ diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index 7e7aefa47..af45c6f91 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -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); diff --git a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c index 326376bce..e0e82ef7d 100644 --- a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c +++ b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c @@ -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) diff --git a/resource/csdk/security/src/pconfresource.c b/resource/csdk/security/src/pconfresource.c index da0b9c0c9..3404a16c3 100644 --- a/resource/csdk/security/src/pconfresource.c +++ b/resource/csdk/security/src/pconfresource.c @@ -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"); diff --git a/resource/csdk/security/src/secureresourcemanager.c b/resource/csdk/security/src/secureresourcemanager.c index a054e73a6..8c1963e80 100644 --- a/resource/csdk/security/src/secureresourcemanager.c +++ b/resource/csdk/security/src/secureresourcemanager.c @@ -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)