From: Dmitrii Zhuravlev Date: Tue, 29 Sep 2015 15:55:07 +0000 (+0300) Subject: Synchronize PKIX with provisioning API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e45de70ec8d17402c4d3327e5a5c18d3c74f7cd;p=contrib%2Fiotivity.git Synchronize PKIX with provisioning API Certificate based provisioning does not use sql database now Change-Id: I5dbceea998f24bfd449efbf108640fc80dd02be7 Signed-off-by: Dmitrii Zhuravlev Reviewed-on: https://gerrit.iotivity.org/gerrit/3285 Tested-by: jenkins-iotivity Reviewed-by: Sachin Agrawal --- diff --git a/resource/csdk/security/provisioning/ck_manager/SConscript b/resource/csdk/security/provisioning/ck_manager/SConscript index 0a95b5e..a473e5e 100644 --- a/resource/csdk/security/provisioning/ck_manager/SConscript +++ b/resource/csdk/security/provisioning/ck_manager/SConscript @@ -45,3 +45,6 @@ x509_env.InstallTarget(ckmStaticLib, 'libCKManager') x509_env.AppendUnique(LIBS = ['asn1']) x509_env.AppendUnique(LIBS = ['Base64']) x509_env.AppendUnique(LIBS = ['Json']) + +SConscript('sample/SConscript') +SConscript('unittest/SConscript') diff --git a/resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/Door_sample.cpp b/resource/csdk/security/provisioning/ck_manager/sample/Door_sample.cpp similarity index 98% rename from resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/Door_sample.cpp rename to resource/csdk/security/provisioning/ck_manager/sample/Door_sample.cpp index c4db6bc..2f2bdbd 100755 --- a/resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/Door_sample.cpp +++ b/resource/csdk/security/provisioning/ck_manager/sample/Door_sample.cpp @@ -32,7 +32,6 @@ #include "global.h" #include "cainterface.h" #include "cacommon.h" -#include "ocstackinternal.h" #include "payload_logging.h" #include "ocpayload.h" @@ -363,7 +362,7 @@ OCStackApplicationResult putReqCB(void * ctx, OCDoHandle /*handle*/, OCClientRes { OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result)); OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber); - OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload); + OC_LOG_PAYLOAD(INFO, clientResponse->payload); if ((OCSecurityPayload*)clientResponse->payload) { OC_LOG_V(INFO, TAG, "=============> Put Response", @@ -381,7 +380,7 @@ OCStackApplicationResult getReqCB(void * /*ctx*/, OCDoHandle /*handle*/, OCClien { OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result)); OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber); - OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload); + OC_LOG_PAYLOAD(INFO, clientResponse->payload); if ((OCSecurityPayload*)clientResponse->payload) { OC_LOG(INFO, TAG, PCF("=============> Get Response")); @@ -406,7 +405,7 @@ OCStackApplicationResult discoveryReqCB(void* /*ctx*/, OCDoHandle /*handle*/, if (clientResponse->result == OC_STACK_OK) { - OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload); + OC_LOG_PAYLOAD(INFO, clientResponse->payload); ocConnType = clientResponse->connType; parseClientResponse(clientResponse); } diff --git a/resource/csdk/security/provisioning/ck_manager/sample/Light_Resource/Light_sample.cpp b/resource/csdk/security/provisioning/ck_manager/sample/Light_sample.cpp similarity index 100% rename from resource/csdk/security/provisioning/ck_manager/sample/Light_Resource/Light_sample.cpp rename to resource/csdk/security/provisioning/ck_manager/sample/Light_sample.cpp diff --git a/resource/csdk/security/provisioning/ck_manager/sample/SConscript b/resource/csdk/security/provisioning/ck_manager/sample/SConscript new file mode 100644 index 0000000..f1d251c --- /dev/null +++ b/resource/csdk/security/provisioning/ck_manager/sample/SConscript @@ -0,0 +1,91 @@ +# //****************************************************************** +# // +# // Copyright 2015 Samsung Electronics All Rights Reserved. +# // +# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# // +# // Licensed under the Apache License, Version 2.0 (the "License"); +# // you may not use this file except in compliance with the License. +# // You may obtain a copy of the License at +# // +# // http://www.apache.org/licenses/LICENSE-2.0 +# // +# // Unless required by applicable law or agreed to in writing, software +# // distributed under the License is distributed on an "AS IS" BASIS, +# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# // See the License for the specific language governing permissions and +# // limitations under the License. +# // +# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# + +Import('env') + +provisioning_env = env.Clone() + +###################################################################### +# Build flags +###################################################################### +provisioning_env.AppendUnique(CPPPATH = [ + '../../../../stack/include', + '../../../../ocrandom/include', + '../../../../logger/include', + '../../../../security/include', + '../../../../../oc_logger/include', + '../../include', + '../../include/internal', + '../../../include', + '../../../include/internal', + '../../../../../../extlibs/tinydtls', + '../../../../../../extlibs/cjson', + '../../../../../../extlibs/asn1cert/', + '../../../../../../extlibs/tinydtls/ecc/', + '../../../../../../extlibs/tinydtls/sha2/', + '../../../../connectivity/inc', + '../../../../connectivity/inc/pkix/', + '../../../../connectivity/common/inc', + '../../../../connectivity/lib/libcoap-4.1.1', + '../../../../connectivity/api', + '../../../../../c_common/oic_malloc/include', + '../include', + '../../include/oxm' + ]) + +provisioning_env.AppendUnique(CFLAGS = ['-D__WITH_DTLS__','-std=c99']) +provisioning_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-fpermissive']) +provisioning_env.AppendUnique(RPATH = [env.get('BUILD_DIR')]) +provisioning_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) +provisioning_env.ParseConfig('pkg-config --libs glib-2.0'); + +provisioning_env.PrependUnique(LIBS = ['ocpmapi','oc', 'oc_logger', 'ocsrm','m', 'octbstack', 'connectivity_abstraction', 'coap']) +provisioning_env.AppendUnique(LIBS = ['CKManager']) +provisioning_env.AppendUnique(LIBS = ['asn1']) + +if env.get('SECURED') == '1': + provisioning_env.AppendUnique(LIBS = ['tinydtls']) + +provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG']) + +###################################################################### +# Source files and Targets +###################################################################### +provisioning_client = provisioning_env.Program('provisioningclient', 'provisioningclient.c') +light_server =provisioning_env.Program('light_server', 'Light_sample.cpp') +door_server=provisioning_env.Program('door_server', 'Door_sample.cpp') + +Alias("samples", [provisioning_client, light_server, door_server]) + +provisioning_env.AppendTarget('samples') + +src_dir = provisioning_env.get('SRC_DIR') +sec_provisioning_src_dir = src_dir + '/resource/csdk/security/provisioning/ck_manager/sample/' +sec_provisioning_build_dir = env.get('BUILD_DIR') +'/resource/csdk/security/provisioning/ck_manager/sample/' + +provisioning_env.Alias("install", provisioning_env.Install( sec_provisioning_build_dir, + sec_provisioning_src_dir + 'oic_svr_db_pt.json')) +provisioning_env.Alias("install", provisioning_env.Install( sec_provisioning_build_dir, + sec_provisioning_src_dir + 'oic_svr_db_light.json')) +provisioning_env.Alias("install", provisioning_env.Install( sec_provisioning_build_dir, + sec_provisioning_src_dir + 'oic_svr_db_door.json')) +provisioning_env.Alias("install", provisioning_env.Install( sec_provisioning_build_dir, + sec_provisioning_src_dir + 'README.txt')) diff --git a/resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/oic_svr_db_door.json b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_door.json similarity index 98% rename from resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/oic_svr_db_door.json rename to resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_door.json index 21aa0e7..8bcb39f 100644 --- a/resource/csdk/security/provisioning/ck_manager/sample/Door_Resource/oic_svr_db_door.json +++ b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_door.json @@ -40,6 +40,7 @@ "doxm": { "oxm": [0], "oxmsel": 0, + "sct": 1, "owned": false, "deviceid": "ZG9vckRldmljZVVVSUQwMA==" } diff --git a/resource/csdk/security/provisioning/ck_manager/sample/Light_Resource/oic_svr_db_light.json b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_light.json old mode 100755 new mode 100644 similarity index 98% rename from resource/csdk/security/provisioning/ck_manager/sample/Light_Resource/oic_svr_db_light.json rename to resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_light.json index d10b71e..048384b --- a/resource/csdk/security/provisioning/ck_manager/sample/Light_Resource/oic_svr_db_light.json +++ b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_light.json @@ -40,6 +40,7 @@ "doxm": { "oxm": [0], "oxmsel": 0, + "sct": 1, "owned": false, "deviceid": "bGlnaHREZXZpY2VVVUlEMA==" } diff --git a/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_pt.json b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_pt.json index 49fb2a8..dd5dec4 100644 --- a/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_pt.json +++ b/resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_pt.json @@ -36,6 +36,7 @@ "doxm": { "oxm": [0], "oxmsel": 0, + "sct": 1, "owned": true, "deviceid": "YWRtaW5EZXZpY2VVVUlEMA==", "ownr": "YWRtaW5EZXZpY2VVVUlEMA==" diff --git a/resource/csdk/security/provisioning/ck_manager/sample/provisioningclient.c b/resource/csdk/security/provisioning/ck_manager/sample/provisioningclient.c index 466cfe9..972a373 100644 --- a/resource/csdk/security/provisioning/ck_manager/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/ck_manager/sample/provisioningclient.c @@ -51,6 +51,7 @@ static OicSecAcl_t *gAcl = NULL; static OicSecCrl_t *gCrl = NULL; static char PROV_TOOL_DB_FILE[] = "oic_svr_db_pt.json"; +static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db"; static int gOwnershipState = 0; typedef enum @@ -495,6 +496,11 @@ int main() OC_LOG(ERROR, TAG, "OCStack init error"); goto error; } + if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME)) + { + OC_LOG(ERROR, TAG, "OC_PM init error"); + goto error; + } OCProvisionDev_t* pDeviceList = NULL; res = OCDiscoverUnownedDevices(PREDEFINED_TIMEOUT, &pDeviceList); @@ -671,7 +677,6 @@ int main() PRINT_BYTE_ARRAY("gCrl = \n", gCrl->CrlData); - res = OCProvisionCRL(ctx, pOwnedDevices[Device2], gCrl, &ProvisionCrlCB); if (OC_STACK_OK != res) OC_LOG_V(ERROR, TAG, "Failed to CRL provision Device 2 : %d", res); @@ -694,8 +699,8 @@ int main() error: deleteACL(gAcl); - OCDeleteDiscoveredDevices(&pDeviceList); - OCDeleteDiscoveredDevices(&pOwnedList); + OCDeleteDiscoveredDevices(pDeviceList); + OCDeleteDiscoveredDevices(pOwnedList); return 0; } diff --git a/resource/csdk/security/provisioning/src/secureresourceprovider.c b/resource/csdk/security/provisioning/src/secureresourceprovider.c index a6a9e35..b9761ee 100755 --- a/resource/csdk/security/provisioning/src/secureresourceprovider.c +++ b/resource/csdk/security/provisioning/src/secureresourceprovider.c @@ -633,17 +633,21 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k OC_LOG(INFO, TAG, "In SRPProvisionCredentials"); - bool linkExisits = true; - OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExisits); - if (res != OC_STACK_OK) - { - OC_LOG(ERROR, TAG, "Internal error occured"); - return res; - } - if (linkExisits) + if (SYMMETRIC_PAIR_WISE_KEY == type) { - OC_LOG(ERROR, TAG, "Link already exists"); - return OC_STACK_INVALID_PARAM; + bool linkExisits = true; + OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExisits); + + if (res != OC_STACK_OK) + { + OC_LOG(ERROR, TAG, "Internal error occured"); + return res; + } + if (linkExisits) + { + OC_LOG(ERROR, TAG, "Link already exists"); + return OC_STACK_INVALID_PARAM; + } } OicUuid_t provTooldeviceID = {{0,}};