X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fprovisioning%2Fsrc%2Fcredentialgenerator.c;h=a930e5358900fadb519e6285b0b06a408e2cbbfe;hb=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20171010.063815;hp=8e96518c8c2308832cab67e02cbd06d19dd53ae3;hpb=b029953884356f976a4bdf560a6693bc6bcc115a;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/provisioning/src/credentialgenerator.c b/resource/csdk/security/provisioning/src/credentialgenerator.c index 8e96518..a930e53 100644 --- a/resource/csdk/security/provisioning/src/credentialgenerator.c +++ b/resource/csdk/security/provisioning/src/credentialgenerator.c @@ -18,59 +18,70 @@ * * *****************************************************************/ #include - -#include "provisioningmanager.h" #include "credentialgenerator.h" +#include "base64.h" #include "oic_malloc.h" -#include "logger.h" +#include "oic_string.h" +#include "ocpayload.h" +#include "payload_logging.h" #include "credresource.h" #include "ocrandom.h" -#include "base64.h" -#define TAG "SPProvisionAPI" -#define KEY_LENGTH 16 +#include "srmutility.h" +#include "stdbool.h" +#include "securevirtualresourcetypes.h" -SPResult SPGeneratePairWiseCredentials(OicSecCredType_t type, const OicUuid_t *ptDeviceId, - const OicUuid_t *firstDeviceId, - const OicUuid_t *secondDeviceId, - OicSecCred_t **firstCred, - OicSecCred_t **secondCred) -{ +#define TAG "OIC_SRPAPI_CG" - if (NULL == ptDeviceId || NULL == firstDeviceId || NULL == secondDeviceId) +OCStackResult PMGeneratePairWiseCredentials(OicSecCredType_t type, size_t keySize, + const OicUuid_t *ptDeviceId, const OicUuid_t *firstDeviceId, + const OicUuid_t *secondDeviceId, OicSecCred_t **firstCred, OicSecCred_t **secondCred) +{ + if (NULL == ptDeviceId || NULL == firstDeviceId || NULL == firstCred || NULL != *firstCred || \ + NULL == secondDeviceId || NULL == secondCred || NULL != *secondCred) { - return SP_RESULT_INVALID_PARAM; + OIC_LOG(INFO, TAG, "Invalid params"); + return OC_STACK_INVALID_PARAM; } - uint8_t privData[KEY_LENGTH] = {0,}; - OCFillRandomMem(privData, KEY_LENGTH); - - uint32_t outLen = 0; - char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(privData)) + 1] = {}; - B64Result b64Ret = b64Encode(privData, sizeof(privData), base64Buff, - sizeof(base64Buff), &outLen); - if (B64_OK != b64Ret) + if(!(keySize == OWNER_PSK_LENGTH_128 || keySize == OWNER_PSK_LENGTH_256)) { - OC_LOG(ERROR, TAG, "Error while encoding key"); - return SP_RESULT_INTERNAL_ERROR; + OIC_LOG(INFO, TAG, "Invalid key size"); + return OC_STACK_INVALID_PARAM; } + OCStackResult res = OC_STACK_ERROR; + OicSecCred_t *tempFirstCred = NULL; + OicSecCred_t *tempSecondCred = NULL; + + size_t privDataKeySize = keySize; + + uint8_t *privData = (uint8_t *)OICCalloc(privDataKeySize, sizeof(uint8_t)); + VERIFY_NON_NULL(TAG, privData, ERROR); + OicSecKey_t privKey = {.data=privData, .len=keySize}; + + OCFillRandomMem(privData, privDataKeySize); + + // TODO: currently owner array is 1. only provisioning tool's id. + tempFirstCred = GenerateCredential(secondDeviceId, type, NULL, &privKey, ptDeviceId, NULL); + VERIFY_NON_NULL(TAG, tempFirstCred, ERROR); + + // TODO: currently owner array is 1. only provisioning tool's id. + tempSecondCred = GenerateCredential(firstDeviceId, type, NULL, &privKey, ptDeviceId, NULL); + VERIFY_NON_NULL(TAG, tempSecondCred, ERROR); - // TODO currently owner array is 1. only provisioning tool's id. - OicSecCred_t *tempFirstCred = GenerateCredential(secondDeviceId, type, NULL, base64Buff, 1, - ptDeviceId); - if (NULL == tempFirstCred) - { - OC_LOG(ERROR, TAG, "Error while generating credential."); - return SP_RESULT_INTERNAL_ERROR; - } - // TODO currently owner array is 1. only provisioning tool's id. - OicSecCred_t *tempSecondCred = GenerateCredential(firstDeviceId, type, NULL, base64Buff, 1, - ptDeviceId); - if (NULL == tempSecondCred) - { - DeleteCredList(tempFirstCred); - OC_LOG(ERROR, TAG, "Error while generating credential."); - return SP_RESULT_INTERNAL_ERROR; - } *firstCred = tempFirstCred; *secondCred = tempSecondCred; - return SP_RESULT_SUCCESS; + res = OC_STACK_OK; + +exit: + OICClearMemory(privData, privDataKeySize); + OICFree(privData); + + if(res != OC_STACK_OK) + { + OICFree(tempFirstCred); + OICFree(tempSecondCred); + *firstCred = NULL; + *secondCred = NULL; + } + + return res; }