From 148302bb08aecb0e25ddbb778d9ef97b0a41929f Mon Sep 17 00:00:00 2001 From: Jongmin Choi Date: Wed, 7 Dec 2016 17:21:37 +0900 Subject: [PATCH] Fix Doxm Handler for Manufacturer Cert OTM Fix error due to confirmable cert OTM Change-Id: Id191ae12e3842e910a44b9d025794caf6aaaf16b Signed-off-by: Jongmin Choi Reviewed-on: https://gerrit.iotivity.org/gerrit/15227 Tested-by: jenkins-iotivity Reviewed-by: Jongsung Lee Reviewed-by: Randeep Singh (cherry picked from commit 50a09e72b62edc9179fdc8b824a0cc6bfbeee88f) Reviewed-on: https://gerrit.iotivity.org/gerrit/15311 --- resource/csdk/security/src/doxmresource.c | 59 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 4f11005..c3256d6 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -1319,45 +1319,42 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe #if defined(__WITH_DTLS__) || defined (__WITH_TLS__) else if (OIC_MANUFACTURER_CERTIFICATE == newDoxm->oxmSel || OIC_CON_MFG_CERT == newDoxm->oxmSel) { - if (memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) == 0) + //Save the owner's UUID to derive owner credential + memcpy(&(gDoxm->owner), &(newDoxm->owner), sizeof(OicUuid_t)); + gDoxm->oxmSel = newDoxm->oxmSel; + //Update new state in persistent storage + if (UpdatePersistentStorage(gDoxm)) { - //Save the owner's UUID to derive owner credential - memcpy(&(gDoxm->owner), &(newDoxm->owner), sizeof(OicUuid_t)); - gDoxm->oxmSel = newDoxm->oxmSel; - //Update new state in persistent storage - if (UpdatePersistentStorage(gDoxm)) - { - ehRet = OC_EH_OK; - } - else - { - OIC_LOG(WARNING, TAG, "Failed to update DOXM in persistent storage"); - ehRet = OC_EH_ERROR; - } - CAResult_t caRes = CAEnableAnonECDHCipherSuite(false); - VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR); - OIC_LOG(INFO, TAG, "ECDH_ANON CipherSuite is DISABLED"); - - VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterPkixInfoHandler(GetManufacturerPkixInfo), ERROR); - VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterGetCredentialTypesHandler(InitManufacturerCipherSuiteList), ERROR); + ehRet = OC_EH_OK; } else { - //In case of Confirm Manufacturer Cert, get user confirmation - if (OIC_CON_MFG_CERT == newDoxm->oxmSel && false == newDoxm->owned && - previousMsgId != ehRequest->messageID) + OIC_LOG(WARNING, TAG, "Failed to update DOXM in persistent storage"); + ehRet = OC_EH_ERROR; + } + CAResult_t caRes = CAEnableAnonECDHCipherSuite(false); + VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR); + OIC_LOG(INFO, TAG, "ECDH_ANON CipherSuite is DISABLED"); + + VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterPkixInfoHandler(GetManufacturerPkixInfo), ERROR); + VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterGetCredentialTypesHandler(InitManufacturerCipherSuiteList), ERROR); + + //In case of Confirm Manufacturer Cert, get user confirmation + if (OIC_CON_MFG_CERT == newDoxm->oxmSel && false == newDoxm->owned && + previousMsgId != ehRequest->messageID && + memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0) + { + if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM)) { - if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM)) - { - ehRet = OC_EH_NOT_ACCEPTABLE; - } - else - { - ehRet = OC_EH_OK; - } + ehRet = OC_EH_NOT_ACCEPTABLE; + } + else + { + ehRet = OC_EH_OK; } } + } #endif // __WITH_DTLS__ or __WITH_TLS__ } -- 2.7.4