X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fprovisioning%2Fexamples%2Fprovisioningclient.cpp;h=9c20bddeb192fccd118e5d130af83cf9e3e4024d;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=163a769789baaff6061f82b8e6300f1faafb3dc2;hpb=200999544972ec5e66997c142244df84d2725df4;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/provisioning/examples/provisioningclient.cpp b/resource/provisioning/examples/provisioningclient.cpp index 163a769..9c20bdd 100644 --- a/resource/provisioning/examples/provisioningclient.cpp +++ b/resource/provisioning/examples/provisioningclient.cpp @@ -33,13 +33,13 @@ #include "oic_string.h" #include "OCPlatform.h" #include "OCApi.h" -#include "OCProvisioningManager.h" +#include "OCProvisioningManager.hpp" #include "oxmjustworks.h" #include "oxmrandompin.h" #include "aclresource.h" #include "utlist.h" +#include "mbedtls/x509_crt.h" -#define MAX_URI_LENGTH (64) #define MAX_PERMISSION_LENGTH (5) #define ACL_RESRC_ARRAY_SIZE (3) #define CREATE (1) @@ -66,9 +66,10 @@ static const OicSecPrm_t SUPPORTED_PRMS[1] = using namespace OC; -DeviceList_t pUnownedDevList, pOwnedDevList; +DeviceList_t pUnownedDevList, pOwnedDevList, pMOTEnabledDeviceList; static int transferDevIdx, ask = 1; static OicSecPconf_t g_pconf; +static uint16_t g_credId = 0; static FILE* client_open(const char *UNUSED_PARAM, const char *mode) { @@ -91,7 +92,22 @@ void printMenu() std::cout << " 10. Get Linked Devices"<serial.p, cert->serial.len); + OIC_LOG(DEBUG, TAG, "***** Serial number of peer certificate is above *****"); + OIC_LOG_V(DEBUG, TAG, "OUT%s", __func__); + + return OC_STACK_OK; +} + void ownershipTransferCB(PMResultList_t *result, int hasError) { if (hasError) @@ -397,7 +426,7 @@ static int InputACL(OicSecAcl_t *acl) return -1; } printf("-URI of resource\n"); - printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n"); + printf("ex)/oic/sh/temp/0 (Max_URI_Length: %d Byte )\n", MAX_URI_LENGTH); for(size_t i = 0; i < resourcesLen; i++) { OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); @@ -422,17 +451,17 @@ static int InputACL(OicSecAcl_t *acl) OICFree(temp_rsc); char* rsrc_in = NULL; - int arrLen = 0; + size_t arrLen = 0; while(1) { printf(" Enter Number of resource type for [%s]: ", rsrc->href); for(int ret=0; 1!=ret; ) { - ret = scanf("%d", &arrLen); + ret = scanf("%zu", &arrLen); for( ; 0x20<=getchar(); ); // for removing overflow garbages // '0x20<=code' is character region } - if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen) + if(ACL_RESRC_ARRAY_SIZE >= arrLen) { break; } @@ -447,7 +476,7 @@ static int InputACL(OicSecAcl_t *acl) goto error; } - for(int i = 0; i < arrLen; i++) + for(unsigned int i = 0; i < arrLen; i++) { printf(" Enter ResourceType[%d] Name (e.g. core.led): ", i+1); for(int ret=0; 1!=ret; ) @@ -470,11 +499,11 @@ static int InputACL(OicSecAcl_t *acl) printf(" Enter Number of interface name for [%s]: ", rsrc->href); for(int ret=0; 1!=ret; ) { - ret = scanf("%d", &arrLen); + ret = scanf("%zu", &arrLen); for( ; 0x20<=getchar(); ); // for removing overflow garbages // '0x20<=code' is character region } - if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen) + if(ACL_RESRC_ARRAY_SIZE >= arrLen) { break; } @@ -489,7 +518,7 @@ static int InputACL(OicSecAcl_t *acl) goto error; } - for(int i = 0; i < arrLen; i++) + for(unsigned int i = 0; i < arrLen; i++) { printf(" Enter interfnace[%d] Name (e.g. oic.if.baseline): ", i+1); for(int ret=0; 1!=ret; ) @@ -653,7 +682,7 @@ static OicSecPdAcl_t* InputPdACL() return NULL; } printf("-URI of resource\n"); - printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n"); + printf("ex)/oic/sh/temp/0 (Max_URI_Length: %d Byte )\n", MAX_URI_LENGTH); acl->resources = (char **)OICCalloc(acl->resourcesLen, sizeof(char *)); if (NULL == acl->resources) { @@ -796,9 +825,135 @@ PVDP_ERROR: ask = 1; } +OCStackResult displayMutualVerifNumCB(uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN]) +{ + OIC_LOG(INFO, TAG, "IN displayMutualVerifNumCB"); + OIC_LOG(INFO, TAG, "############ mutualVerifNum ############"); + OIC_LOG_BUFFER(INFO, TAG, mutualVerifNum, MUTUAL_VERIF_NUM_LEN); + OIC_LOG(INFO, TAG, "############ mutualVerifNum ############"); + OIC_LOG(INFO, TAG, "OUT displayMutualVerifNumCB"); + return OC_STACK_OK; +} + +OCStackResult confirmMutualVerifNumCB(void) +{ + for (;;) + { + int userConfirm; + + printf(" > Press 1 if the mutual verification numbers are the same\n"); + printf(" > Press 0 if the mutual verification numbers are not the same\n"); + + for (int ret=0; 1!=ret; ) + { + ret = scanf("%d", &userConfirm); + for (; 0x20<=getchar(); ); // for removing overflow garbage + // '0x20<=code' is character region + } + if (1 == userConfirm) + { + break; + } + else if (0 == userConfirm) + { + return OC_STACK_USER_DENIED_REQ; + } + printf(" Entered Wrong Number. Please Enter Again\n"); + } + return OC_STACK_OK; +} + + + + +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) +static int saveTrustCert(void) +{ + + // call |OCSaveTrustCertChainBin| API actually + printf(" Save Trust Cert. Chain into Cred of SVR.\n"); + + ByteArray trustCertChainArray = {0, 0}; + + FILE *fp = fopen("rootca.crt", "rb+"); + + if (fp) + { + int fsize; + if (fseeko(fp, 0, SEEK_END) == 0 && (fsize = ftello(fp)) >= 0) + { + trustCertChainArray.data = (uint8_t*)OICCalloc(1, fsize); + trustCertChainArray.len = fsize; + if (NULL == trustCertChainArray.data) + { + OIC_LOG(ERROR,TAG,"Failed to allocate memory"); + fclose(fp); + return -1; + } + rewind(fp); + fsize = fread(trustCertChainArray.data, 1, fsize, fp); + if(0 == fsize) + { + OIC_LOG(ERROR,TAG,"Read error"); + } + } + fclose(fp); + } + OIC_LOG_BUFFER(DEBUG, TAG, trustCertChainArray.data, trustCertChainArray.len); + + if(OC_STACK_OK != OCSecure::saveTrustCertChain(trustCertChainArray.data, trustCertChainArray.len, + OIC_ENCODING_PEM,&g_credId)) + { + OIC_LOG(ERROR, TAG, "OCSaveTrustCertChainBin API error"); + return -1; + } + printf("CredId of Saved Trust Cert. Chain into Cred of SVR : %d.\n", g_credId); + + return 0; +} + +void certChainCallBack(uint16_t credId, uint8_t *trustCertChain,size_t chainSize) +{ + OIC_LOG_V(INFO, TAG, "trustCertChain Changed for credId %u", credId); + OC_UNUSED(trustCertChain); + OC_UNUSED(chainSize); + return; +} +#endif // __WITH_DTLS__ or __WITH_TLS__ + +#ifdef MULTIPLE_OWNER +void MOTMethodCB(PMResultList_t *result, int hasError) +{ + if (hasError) + { + std::cout << "Error!!! in callback"<removeDeviceWithUuid(DISCOVERY_TIMEOUT, + if (OCSecure::removeDeviceWithUuid(DISCOVERY_TIMEOUT, pOwnedDevList[index]->getDeviceID(), provisionCB) != OC_STACK_OK) @@ -1232,7 +1376,407 @@ int main(void) break; } +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) case 13: + { + std::cout<< "registering cert chain change notifier"<getDeviceID()<< std::endl; + + ask = 0; + + if (pOwnedDevList[index]->provisionTrustCertChain(SIGNED_ASYMMETRIC_KEY, + g_credId,provisionCB ) != OC_STACK_OK) + { + ask = 1; + std::cout <<"provision cert is failed"<< std::endl; + } + break; + } + case 15: + { + if (0==g_credId) + { + std::cout<<"please save cert using option 13."; + } + else + { + uint8_t *trustCertChain = NULL; + size_t chainSize = 0; + if (OC_STACK_OK != OCSecure::readTrustCertChain(g_credId, &trustCertChain,&chainSize)) + { + std::cout <<"issue in read trust chain"<< std::endl; + } + else + { + std::cout<<"size of cert : "<getDeviceID()<<" From IP: "; + std::cout << pMOTEnabledDeviceList[i]->getDevAddr() << std::endl; + } + } + + // select device + unsigned int dev_num = 0; + for( ; ; ) + { + std::cout << "Enter Device Number, to change the mode: "<> dev_num; + if(0 < dev_num && dev_count >= dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Enter Mode of Multiple Ownership Transfer :"<changeMOTMode( + (const OicSecMomType_t)momType,MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + else + { + if(dev_num <= pOwnedDevList.size()) + { + if(OC_STACK_OK != pOwnedDevList[dev_num-1]->changeMOTMode(momType, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + else + { + if(OC_STACK_OK != pMOTEnabledDeviceList[(dev_num - + pOwnedDevList.size() - 1)]->changeMOTMode(momType, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + } + break; + } + case 17: + { + if (!pMOTEnabledDeviceList.size()) + { + std::cout <<"Please discover the MOT device first. Use option 18"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Enter Number of OxM for Multiple Ownership Transfer : "<> oxm; + if(0 == oxm) + { + secOxm = OIC_RANDOM_DEVICE_PIN; + break; + } + if(1 == oxm) + { + secOxm = OIC_PRECONFIG_PIN; + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"<selectMOTMethod((const OicSecOxm_t)secOxm, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "selectMOTMethod API error"); + } + break; + } + case 18: + { + pMOTEnabledDeviceList.clear(); + std::cout << "Started MOT Enabled device discovery..." <> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Input the 8 digit PreconfigPin (e.g. 12341234) :" <provisionPreconfPin(preconfigPin, + preconfPinLength, MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "provisionPreconfPin API error"); + } + break; + } + case 20: + { + if (!pMOTEnabledDeviceList.size()) + { + std::cout <<"Please discover the MOT device first. Use option 16"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Input the 8 digit preconfPIN (e.g. 12341234) :" <addPreconfigPIN(preconfPIN, + preconfPinLength)) + { + OIC_LOG(ERROR, TAG, "addPreconfigPIN API error"); + } + break; + } + case 21: //Remove sub-owner + { + if (!pMOTEnabledDeviceList.size()) + { + std::cout <<"Please discover the MOT device first. Use option 16"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"<getSubOwnerList(subOwenrList); + if (0 == subOwenrList.size()) + { + std::cout << "SubOwner List is empty."<> so_num; + if(0 < so_num && subOwenrList.size() >=so_num) + { + pMOTEnabledDeviceList[dev_num - 1]->removeSubOwner(&subOwenrList[so_num], MOTRemoveSubOwnerCB); + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"<getSubOwnerList(subOwenrList); + if (0 == subOwenrList.size()) + { + std::cout << "SubOwner List is empty."<removeAllSubOwner(MOTRemoveSubOwnerCB); + } + break; + } +#endif //MULTIPLE_OWNER + case 30: + { + OCStackResult result; + result = OCSecure::configSelfOwnership(); + if (OC_STACK_OK != result) + { + std::cout<<"configSelfOwnership API error. Please check SVR DB"<