From be0d881debd2f846f23f4a319b50896ca8dd7859 Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Mon, 5 Dec 2016 18:09:45 -0800 Subject: [PATCH] IOT-1583: Removing /W3 warning from resource/csdk/security. I'm also refactoring some SConscript files in order to enable /W3 and /WX only for specific directories and I'm adding _CRT_NONSTDC_NO_WARNINGS to disable warnings about issues we cannot change anyway, because the code has to build for multiple platforms. Change-Id: Ifef66b6c59540df2ceb40a54af47865d56a302d7 Signed-off-by: Pawel Winogrodzki Reviewed-on: https://gerrit.iotivity.org/gerrit/16329 Tested-by: jenkins-iotivity Reviewed-by: Kevin Kane --- build_common/linux/SConscript | 4 + build_common/thread.scons | 5 +- extlibs/boost/SConscript | 22 +- extlibs/cjson/SConscript | 25 +++ java/jni/JniSecureUtils.cpp | 2 +- resource/SConscript | 3 - resource/c_common/platform_features.h | 1 - resource/c_common/windows/include/memmem.h | 36 +-- resource/csdk/SConscript | 6 +- resource/csdk/logger/include/logger.h | 4 +- resource/csdk/logger/src/logger.c | 6 +- resource/csdk/security/SConscript | 66 +++--- resource/csdk/security/include/base64.h | 4 +- resource/csdk/security/include/pbkdf2.h | 6 +- resource/csdk/security/include/srmutility.h | 18 +- resource/csdk/security/provisioning/SConscript | 53 ++--- .../csdk/security/provisioning/include/pmtypes.h | 2 +- .../csdk/security/provisioning/sample/SConscript | 124 +++++------ .../security/provisioning/sample/cloud/cloudAuth.c | 16 +- .../provisioning/sample/cloud/cloudResource.c | 2 +- .../provisioning/sample/cloud/cloudResource.h | 2 +- .../provisioning/sample/cloud/cloudWrapper.h | 1 - .../provisioning/sample/provisioningclient.c | 53 +++-- .../provisioning/sample/sampleserver_justworks.cpp | 14 +- .../provisioning/sample/sampleserver_mfg.cpp | 10 +- .../sample/sampleserver_mvjustworks.cpp | 12 +- .../sample/sampleserver_preconfpin.cpp | 6 +- .../provisioning/sample/sampleserver_randompin.cpp | 12 +- .../security/provisioning/sample/subownerclient.c | 46 ++-- .../provisioning/src/credentialgenerator.c | 6 +- .../src/multipleownershiptransfermanager.c | 113 ++++++---- .../provisioning/src/ocprovisioningmanager.c | 8 +- .../provisioning/src/ownershiptransfermanager.c | 51 ++--- .../csdk/security/provisioning/src/oxmpreconfpin.c | 3 +- .../csdk/security/provisioning/src/pmutility.c | 8 +- .../provisioning/src/provisioningdatabasemanager.c | 88 ++++++-- .../provisioning/src/secureresourceprovider.c | 125 +++++------ .../unittest/ocprovisioningmanager.cpp | 2 +- .../security/provisioning/unittest/otmunittest.cpp | 30 +-- .../unittest/provisioningdatabasemanager.cpp | 9 +- .../unittest/secureresourceprovider.cpp | 5 +- resource/csdk/security/src/aclresource.c | 186 ++++++++-------- resource/csdk/security/src/amaclresource.c | 10 +- resource/csdk/security/src/amsmgr.c | 14 +- resource/csdk/security/src/base64.c | 16 +- resource/csdk/security/src/credresource.c | 129 +++++++---- resource/csdk/security/src/crlresource.c | 8 +- resource/csdk/security/src/directpairing.c | 10 +- resource/csdk/security/src/doxmresource.c | 34 +-- resource/csdk/security/src/dpairingresource.c | 30 +-- resource/csdk/security/src/iotvticalendar.c | 4 +- resource/csdk/security/src/oxmpincommon.c | 33 +-- resource/csdk/security/src/pbkdf2.c | 25 ++- resource/csdk/security/src/pconfresource.c | 18 +- resource/csdk/security/src/policyengine.c | 6 +- resource/csdk/security/src/psinterface.c | 16 +- resource/csdk/security/src/pstatresource.c | 14 +- resource/csdk/security/src/secureresourcemanager.c | 60 +++-- resource/csdk/security/src/srmutility.c | 2 +- resource/csdk/security/src/svcresource.c | 6 +- resource/csdk/security/src/verresource.c | 4 +- resource/csdk/security/tool/SConscript | 15 +- resource/csdk/security/tool/json2cbor.c | 244 +++++++++++---------- .../csdk/security/unittest/aclresourcetest.cpp | 22 +- resource/csdk/security/unittest/base64tests.cpp | 23 +- .../csdk/security/unittest/credentialresource.cpp | 12 +- .../security/unittest/securityresourcemanager.cpp | 2 +- resource/csdk/security/unittest/srmtestcommon.cpp | 6 +- resource/csdk/security/unittests/SConscript | 33 +++ .../samples/linux/SimpleClientServer/SConscript | 6 +- .../linux/SimpleClientServer/ocserverslow.cpp | 5 + .../samples/linux/secure/occlientdirectpairing.cpp | 4 +- resource/csdk/unittests/SConscript | 3 +- resource/examples/SConscript | 6 +- resource/include/OCProvisioningManager.hpp | 2 +- resource/provisioning/examples/SConscript | 17 +- resource/provisioning/examples/cloudAuth.cpp | 2 +- .../provisioning/src/OCProvisioningManager.cpp | 4 +- resource/src/SConscript | 10 +- service/coap-http-proxy/SConscript | 4 +- service/simulator/ramlparser/SConscript | 23 +- 81 files changed, 1140 insertions(+), 937 deletions(-) create mode 100644 extlibs/cjson/SConscript create mode 100644 resource/csdk/security/unittests/SConscript diff --git a/build_common/linux/SConscript b/build_common/linux/SConscript index 4b9871f..b67c233 100644 --- a/build_common/linux/SConscript +++ b/build_common/linux/SConscript @@ -30,6 +30,10 @@ if env.get('BUILD_JAVA') == True: help_vars.Update(env) Help(help_vars.GenerateHelpText(env)) +# Add the default lib directory +build_dir = env.get('BUILD_DIR') +env.AppendUnique(LIBPATH = [build_dir]) +env.AppendENVPath('LD_LIBRARY_PATH', [build_dir]) # Set release/debug flags if env.get('RELEASE'): diff --git a/build_common/thread.scons b/build_common/thread.scons index fc01aef..8c8c5d8 100644 --- a/build_common/thread.scons +++ b/build_common/thread.scons @@ -1,9 +1,8 @@ # Factorize pthread configurations in single file import os -Import('env') +Import('thread_env') -thread_env = env.Clone() target_os = thread_env.get('TARGET_OS') # Export flags once for all @@ -13,5 +12,3 @@ if 'gcc' in compiler: if target_os not in ['android']: thread_env.AppendUnique(CFLAGS = ['-pthread']) thread_env.AppendUnique(LIBS = ['pthread']) - -Return('thread_env') diff --git a/extlibs/boost/SConscript b/extlibs/boost/SConscript index c54970e..749156b 100644 --- a/extlibs/boost/SConscript +++ b/extlibs/boost/SConscript @@ -40,11 +40,11 @@ elif target_os in ['windows']: boost_zip = boost_zip_file else: print '*** Downloading Boost zip file (> 100MB). Please wait... ***' - boost_zip = env.Download(boost_zip_file, boost_url) + boost_zip = boost_env.Download(boost_zip_file, boost_url) # Unzip boost print '*** Unpacking boost %s zip file ... ***' % boost_version - env.UnpackAll(boost_dir, boost_zip) + boost_env.UnpackAll(boost_dir, boost_zip) # Rename from boost_1_60_0 -> boost os.rename(boost_base_name, 'boost') @@ -70,10 +70,10 @@ elif target_os in ['windows']: Exit(1) elif target_os in ['android']: - env.Tool('URLDownload', toolpath=['../../tools/scons']) - env.Tool('UnpackAll', toolpath=['../../tools/scons']) - env.Tool('BoostBootstrap', toolpath=['../../tools/scons']) - env.Tool('BoostBuild', toolpath=['../../tools/scons']) + boost_env.Tool('URLDownload', toolpath=['../../tools/scons']) + boost_env.Tool('UnpackAll', toolpath=['../../tools/scons']) + boost_env.Tool('BoostBootstrap', toolpath=['../../tools/scons']) + boost_env.Tool('BoostBuild', toolpath=['../../tools/scons']) host_os = sys.platform @@ -84,14 +84,14 @@ elif target_os in ['android']: raise SCons.Errors.EnvironmentError(msg) if not os.path.exists(boost_arch_name) and not os.path.exists(boost_base_name): - boost_arch_name = env.URLDownload(boost_arch_name, boost_url) + boost_arch_name = boost_env.URLDownload(boost_arch_name, boost_url) if not os.path.exists(boost_base_name): - boost_arch_name = env.UnpackAll(boost_bootstrap, boost_arch_name) + boost_arch_name = boost_env.UnpackAll(boost_bootstrap, boost_arch_name) - boost_b2 = env.BoostBootstrap(boost_b2_name, boost_arch_name) + boost_b2 = boost_env.BoostBootstrap(boost_b2_name, boost_arch_name) - dep_sys_root = env['DEP_SYS_ROOT'] + dep_sys_root = boost_env['DEP_SYS_ROOT'] dep_src_dir = dep_sys_root + os.sep + 'include' dep_lib_dir = dep_sys_root + os.sep + 'lib' @@ -108,5 +108,5 @@ elif target_os in ['android']: os.path.join(dep_src_dir, 'libboost_program_options.a') ] - boost_build = env.BoostBuild(boost_targets, boost_b2, PREFIX=dep_sys_root, MODULES=modules) + boost_build = boost_env.BoostBuild(boost_targets, boost_b2, PREFIX=dep_sys_root, MODULES=modules) diff --git a/extlibs/cjson/SConscript b/extlibs/cjson/SConscript new file mode 100644 index 0000000..92126f3 --- /dev/null +++ b/extlibs/cjson/SConscript @@ -0,0 +1,25 @@ +#****************************************************************** +# +# Copyright 2016 Microsoft +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# +# 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') + +libcjson = env.StaticLibrary('cjsonLibrary', ['cJSON.c']) +env.InstallTarget(libcjson, 'libCjson'); + diff --git a/java/jni/JniSecureUtils.cpp b/java/jni/JniSecureUtils.cpp index e18de5b..332a7e6 100644 --- a/java/jni/JniSecureUtils.cpp +++ b/java/jni/JniSecureUtils.cpp @@ -108,7 +108,7 @@ std::string JniSecureUtils::convertUUIDtoStr(OicUuid_t uuid) { std::ostringstream deviceId(""); char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*)0)->id)) + 1] = {0,}; - uint32_t outLen = 0; + size_t outLen = 0; B64Result b64Ret = B64_OK; b64Ret = b64Encode(uuid.id, sizeof(uuid.id), base64Buff, diff --git a/resource/SConscript b/resource/SConscript index 0cce7d5..f79d09e 100644 --- a/resource/SConscript +++ b/resource/SConscript @@ -51,9 +51,6 @@ if env.get('ROUTING') in ['GW', 'EP']: if 'CLIENT' in rd_mode or 'SERVER' in rd_mode: SConscript('csdk/resource-directory/SConscript') -# Build libocsrm -SConscript('csdk/security/SConscript') - # Build liboctbstack SConscript('csdk/SConscript') diff --git a/resource/c_common/platform_features.h b/resource/c_common/platform_features.h index 0615bbc..08cbce4 100644 --- a/resource/c_common/platform_features.h +++ b/resource/c_common/platform_features.h @@ -72,7 +72,6 @@ # include "windows/include/vs12_snprintf.h" # endif # define ssize_t SSIZE_T -# define F_OK 0 # define SHUT_RDWR SD_BOTH # define sleep(SECS) Sleep(1000*(SECS)) # ifdef __cplusplus diff --git a/resource/c_common/windows/include/memmem.h b/resource/c_common/windows/include/memmem.h index 5f6c8a4..484baf7 100644 --- a/resource/c_common/windows/include/memmem.h +++ b/resource/c_common/windows/include/memmem.h @@ -1,25 +1,27 @@ /* ***************************************************************** -* -* Copyright 2017 Microsoft -* -* -* 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. -* -******************************************************************/ + * + * Copyright 2017 Microsoft + * + * + * 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. + * + ******************************************************************/ #ifndef MEMMEM_H__ #define MEMMEM_H__ +#include + // crtdefs.h is required for size_t #include diff --git a/resource/csdk/SConscript b/resource/csdk/SConscript index c4c5482..088f2f5 100644 --- a/resource/csdk/SConscript +++ b/resource/csdk/SConscript @@ -23,9 +23,10 @@ ## Import('env') -lib_env = env.Clone() +# Build libocsrm +SConscript('security/SConscript') -liboctbstack_env = lib_env.Clone() +liboctbstack_env = env.Clone() target_os = env.get('TARGET_OS') rd_mode = env.get('RD_MODE') @@ -137,7 +138,6 @@ if target_os == 'arduino': elif target_os not in ['darwin','ios', 'msys_nt', 'windows']: liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC']) if target_os in ['darwin', 'ios']: - env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE']) liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE']) liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) if target_os not in ['arduino', 'windows']: diff --git a/resource/csdk/logger/include/logger.h b/resource/csdk/logger/include/logger.h index 7ccb51c..75456ac 100644 --- a/resource/csdk/logger/include/logger.h +++ b/resource/csdk/logger/include/logger.h @@ -91,7 +91,7 @@ typedef enum { * @param[in] buffer pointer to buffer of bytes * @param[in] bufferSize max number of byte in buffer */ -void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize); +void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, size_t bufferSize); #define OCLog(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes) #define OCLogv(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, (level),tag,fmt,##args) @@ -147,7 +147,7 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint1 * @param buffer - pointer to buffer of bytes * @param bufferSize - max number of byte in buffer */ - void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize); + void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, size_t bufferSize); #else // For arduino platforms /** * Initialize the serial logger for Arduino diff --git a/resource/csdk/logger/src/logger.c b/resource/csdk/logger/src/logger.c index edeb167..51a4221 100644 --- a/resource/csdk/logger/src/logger.c +++ b/resource/csdk/logger/src/logger.c @@ -123,7 +123,7 @@ static oc_log_level LEVEL_XTABLE[] = {OC_LOG_DEBUG, OC_LOG_INFO, * @param buffer - pointer to buffer of bytes * @param bufferSize - max number of byte in buffer */ -void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize) +void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, size_t bufferSize) { if (!buffer || !tag || (bufferSize == 0)) { @@ -134,8 +134,8 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint1 // that this is a variable-sized object. char lineBuffer[LINE_BUFFER_SIZE]; memset(lineBuffer, 0, sizeof lineBuffer); - int lineIndex = 0; - int i; + size_t lineIndex = 0; + size_t i; for (i = 0; i < bufferSize; i++) { // Format the buffer data into a line diff --git a/resource/csdk/security/SConscript b/resource/csdk/security/SConscript index ebd1cdb..57746f0 100644 --- a/resource/csdk/security/SConscript +++ b/resource/csdk/security/SConscript @@ -24,16 +24,9 @@ Import('env') import os -lib_env = env.Clone() - -libocsrm_env = lib_env.Clone() +libocsrm_env = env.Clone() target_os = libocsrm_env.get('TARGET_OS') -# As in the source code, it includes arduino Time library (C++) -# It requires compile the .c with g++ -if target_os == 'arduino': - libocsrm_env.Replace(CC = libocsrm_env.get('CXX')) - libocsrm_env.Replace(CFLAGS = libocsrm_env.get('CXXFLAGS')) ###################################################################### # Build flags @@ -44,25 +37,41 @@ if with_upstream_libcoap == '1': libocsrm_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include']) else: # For bring up purposes only, the forked version will live here. - libocsrm_env.AppendUnique(CPPPATH = ['../connectivity/lib/libcoap-4.1.1/include']) + libocsrm_env.AppendUnique(CPPPATH = ['#/resource/connectivity/lib/libcoap-4.1.1/include']) libocsrm_env.PrependUnique(CPPPATH = [ - '../../../extlibs/tinydtls/', - '../logger/include', - '../../c_common/ocrandom/include', - '../include', - '../stack/include', - '../stack/include/internal', - '../../oc_logger/include', - '../connectivity/external/inc', - '../connectivity/common/inc', - '../connectivity/inc', - '../connectivity/api', - '../security/include', - '../security/include/internal', - '../security/provisioning/include' + '#/extlibs/tinydtls', + '#/resource/csdk/logger/include', + '#/resource/c_common/ocrandom/include', + '#/resource/csdk/include', + '#/resource/csdk/stack/include', + '#/resource/csdk/stack/include/internal', + '#/resource/oc_logger/include', + '#/resource/csdk/connectivity/external/inc', + '#/resource/csdk/connectivity/common/inc', + '#/resource/csdk/connectivity/inc', + '#/resource/csdk/connectivity/api', + '#/resource/csdk/security/include', + '#/resource/csdk/security/include/internal', + '#/resource/csdk/security/provisioning/include' ]) +if target_os in ['windows', 'msys_nt']: + libocsrm_env.AppendUnique(LIBPATH = [os.path.join(libocsrm_env.get('BUILD_DIR'), 'resource', 'oc_logger')]) + libocsrm_env.AppendUnique(CCFLAGS=['/W3', '/WX']) + +if target_os in ['linux', 'android', 'tizen', 'msys_nt', 'windows'] and libocsrm_env.get('SECURED') == '1': + SConscript('provisioning/SConscript', 'libocsrm_env') + +if target_os in ['linux', 'windows', 'darwin'] and libocsrm_env.get('SECURED') == '1': + SConscript('tool/SConscript', 'libocsrm_env') + +# As in the source code, it includes arduino Time library (C++) +# It requires compile the .c with g++ +if target_os == 'arduino': + libocsrm_env.Replace(CC = libocsrm_env.get('CXX')) + libocsrm_env.Replace(CFLAGS = libocsrm_env.get('CXXFLAGS')) + if target_os not in ['arduino', 'windows']: libocsrm_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_GNU_SOURCE']) libocsrm_env.AppendUnique(CFLAGS = ['-std=c99', '-Wall']) @@ -76,13 +85,8 @@ elif target_os not in ['windows', 'msys_nt']: libocsrm_env.AppendUnique(CFLAGS = ['-fPIC']) libocsrm_env.AppendUnique(LIBS = ['m']) -if target_os in ['windows', 'msys_nt']: - libocsrm_env.AppendUnique(LIBPATH = [os.path.join(libocsrm_env.get('BUILD_DIR'), 'resource', 'oc_logger')]) - if target_os in ['darwin', 'ios']: libocsrm_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE']) - libocsrm_env.AppendUnique(LIBPATH = [libocsrm_env.get('BUILD_DIR')]) - libocsrm_env.AppendUnique(LIBS = ['coap']) if env.get('LOGGING'): libocsrm_env.AppendUnique(CPPDEFINES = ['TB_LOG']) @@ -140,9 +144,3 @@ libocsrm_env = libocsrm_conf.Finish() libocsrm = libocsrm_env.StaticLibrary('ocsrm', libocsrm_src) libocsrm_env.InstallTarget(libocsrm, 'ocsrm') - -if target_os in ['linux', 'android', 'tizen', 'msys_nt', 'windows'] and libocsrm_env.get('SECURED') == '1': - SConscript('provisioning/SConscript') - -if target_os in ['linux', 'windows', 'darwin'] and libocsrm_env.get('SECURED') == '1': - SConscript('tool/SConscript') diff --git a/resource/csdk/security/include/base64.h b/resource/csdk/security/include/base64.h index a983f1e..d2cea9b 100644 --- a/resource/csdk/security/include/base64.h +++ b/resource/csdk/security/include/base64.h @@ -64,7 +64,7 @@ typedef enum * @return ::B64_OK for Success, otherwise some error value. */ B64Result b64Encode(const uint8_t* in, const size_t inLen, - char* outBuf, const size_t outBufSize, uint32_t *outLen); + char* outBuf, const size_t outBufSize, size_t* outLen); /** * Decode the encoded message in base64. @@ -79,7 +79,7 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, * @return ::B64_OK for Success, otherwise some error value. */ B64Result b64Decode(const char* in, const size_t inLen, - uint8_t* outBuf, size_t outBufSize, uint32_t *outLen); + uint8_t* outBuf, size_t outBufSize, size_t* outLen); #ifdef __cplusplus } diff --git a/resource/csdk/security/include/pbkdf2.h b/resource/csdk/security/include/pbkdf2.h index d2408d5..9a05d79 100644 --- a/resource/csdk/security/include/pbkdf2.h +++ b/resource/csdk/security/include/pbkdf2.h @@ -52,9 +52,9 @@ extern "C" * @return 0 on success */ int DeriveCryptoKeyFromPassword(const unsigned char* passwd, size_t pLen, - const uint8_t* salt, const size_t saltLen, - const size_t iterations, - const size_t keyLen, uint8_t* derivedKey); + const uint8_t* salt, size_t saltLen, + size_t iterations, + size_t keyLen, uint8_t* derivedKey); #ifdef __cplusplus } diff --git a/resource/csdk/security/include/srmutility.h b/resource/csdk/security/include/srmutility.h index c2f0466..38c42bd 100644 --- a/resource/csdk/security/include/srmutility.h +++ b/resource/csdk/security/include/srmutility.h @@ -63,14 +63,28 @@ struct OicParseQueryIter {OIC_LOG((logLevel), tag, #op " failed!!"); goto exit; } }while(0) /** + * Macro to verify success of operation. + * eg: VERIFY_SUCCESS_RETURN(TAG, OC_STACK_OK == foo(), ERROR, OC_STACK_ERROR); + */ +#define VERIFY_SUCCESS_RETURN(tag, op, logLevel, retValue) do { if (!(op)) \ + {OIC_LOG((logLevel), tag, #op " failed!!"); return retValue;} } while(0) + +/** * Macro to verify argument is not equal to NULL. - * eg: VERIFY_NON_NULL(TAG, ptrData, ERROR); + * eg: VERIFY_NOT_NULL(TAG, ptrData, ERROR); * @note Invoking function must define "exit:" label for goto functionality to work correctly. */ -#define VERIFY_NON_NULL(tag, arg, logLevel) do{ if (NULL == (arg)) \ +#define VERIFY_NOT_NULL(tag, arg, logLevel) do{ if (NULL == (arg)) \ { OIC_LOG((logLevel), tag, #arg " is NULL"); goto exit; } }while(0) /** + * Macro to verify argument is not equal to NULL. + * eg: VERIFY_NOT_NULL_RETURN(TAG, ptrData, ERROR, OC_STACK_ERROR); + */ +#define VERIFY_NOT_NULL_RETURN(tag, arg, logLevel, retValue) do { if (NULL == (arg)) \ + { OIC_LOG((logLevel), tag, #arg " is NULL"); return retValue; } } while(0) + +/** * This method initializes the @ref OicParseQueryIter_t struct. * * @param query is the REST query, to be parsed. diff --git a/resource/csdk/security/provisioning/SConscript b/resource/csdk/security/provisioning/SConscript index 7c3a43b..68a7a63 100644 --- a/resource/csdk/security/provisioning/SConscript +++ b/resource/csdk/security/provisioning/SConscript @@ -19,47 +19,26 @@ # // # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # +Import('libocsrm_env') -provisioning_env = SConscript('#build_common/thread.scons') +provisioning_env = libocsrm_env.Clone() + +SConscript('#build_common/thread.scons', exports = {'thread_env' : provisioning_env}) target_os = provisioning_env.get('TARGET_OS') -root_dir = './../../../../' ###################################################################### # Build flags ###################################################################### -with_upstream_libcoap = provisioning_env.get('WITH_UPSTREAM_LIBCOAP') -if with_upstream_libcoap == '1': - # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded. - provisioning_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include']) -else: - # For bring up purposes only, the forked version will live here. - provisioning_env.AppendUnique(CPPPATH = ['../../connectivity/lib/libcoap-4.1.1/include']) - provisioning_env.AppendUnique(CPPPATH = [ - '../../include', - '../../stack/include', - '../../stack/include/internal', - '../../../c_common/ocrandom/include', - '../../logger/include', - '../../../oc_logger/include', - '../../../c_common/oic_malloc/include', - 'include', - 'include/internal', - 'include/cloud', - 'include/oxm', - '../../resource/csdk/security/include', - '../../../../extlibs/tinydtls/', - '../../connectivity/inc', - '../../connectivity/inc/pkix', - '../../connectivity/external/inc', - '../../connectivity/common/inc', - '../../connectivity/api', - '../include', - '../include/internal', - '../../../../extlibs/tinydtls/ecc', - '../../../../extlibs/tinydtls/sha2', - '../../../../extlibs/asn1cert', - 'ck_manager/include' + '#/resource/csdk/include', + '#/resource/c_common/oic_malloc/include', + '#/resource/csdk/security/provisioning/include/internal', + '#/resource/csdk/security/provisioning/include/cloud', + '#/resource/csdk/security/provisioning/include/oxm', + '#/resource/csdk/connectivity/inc/pkix', + '#/extlibs/tinydtls/ecc', + '#/extlibs/tinydtls/sha2', + '#/extlibs/asn1cert' ]) provisioning_env.AppendUnique(CPPDEFINES= ['__WITH_DTLS__']) @@ -125,8 +104,8 @@ if provisioning_env.get('WITH_TCP') == True: if target_os in ['linux', 'tizen']: provisioning_env.ParseConfig('pkg-config --cflags --libs sqlite3') else: - provisioning_env.AppendUnique(CPPPATH = ['../../../../extlibs/sqlite3']) - provisioning_src = provisioning_src + [root_dir+'/extlibs/sqlite3/sqlite3.c' ] + provisioning_env.AppendUnique(CPPPATH = ['#/extlibs/sqlite3']) + provisioning_src = provisioning_src + ['#/extlibs/sqlite3/sqlite3.c' ] if target_os in ['windows', 'msys_nt']: # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll. @@ -140,4 +119,4 @@ provisioning_env.InstallTarget(provisioningserver, 'ocpmapi') provisioning_env.UserInstallTargetLib(provisioningserver, 'ocpmapi') if target_os in ['linux', 'msys_nt', 'windows', 'tizen']: - SConscript('sample/SConscript') + SConscript('sample/SConscript', 'provisioning_env') diff --git a/resource/csdk/security/provisioning/include/pmtypes.h b/resource/csdk/security/provisioning/include/pmtypes.h index 6a46dd6..8e39a46 100644 --- a/resource/csdk/security/provisioning/include/pmtypes.h +++ b/resource/csdk/security/provisioning/include/pmtypes.h @@ -134,7 +134,7 @@ typedef enum OxmAllowTableIdx { * @param[OUT} hasError - If there is no error, it's returned with 'false' but if there is a single * or more error is/are occured during operation, it will be 'true'. */ -typedef void (*OCProvisionResultCB)(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError); +typedef void (*OCProvisionResultCB)(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError); /** diff --git a/resource/csdk/security/provisioning/sample/SConscript b/resource/csdk/security/provisioning/sample/SConscript index 5222593..e9b0e08 100644 --- a/resource/csdk/security/provisioning/sample/SConscript +++ b/resource/csdk/security/provisioning/sample/SConscript @@ -19,137 +19,113 @@ # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # -Import('env') +Import('env provisioning_env') import os.path -provisioning_env = env.Clone() -target_os = provisioning_env.get('TARGET_OS') +provisioning_sample_env = provisioning_env.Clone() +target_os = provisioning_sample_env.get('TARGET_OS') ###################################################################### # Build flags ###################################################################### -with_upstream_libcoap = provisioning_env.get('WITH_UPSTREAM_LIBCOAP') -if with_upstream_libcoap == '1': - # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded. - provisioning_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include']) -else: - # For bring up purposes only, the forked version will live here. - provisioning_env.AppendUnique(CPPPATH = ['../../../connectivity/lib/libcoap-4.1.1/include']) - -provisioning_env.AppendUnique(CPPPATH = [ - '../../../include', - '../../../ocrandom/include', - '../../../logger/include', - '../../../stack/include', - '../../../security/include', - '../../../security/include/internal', - '../../../security/provisioning/include/internal', - '../../../../oc_logger/include', - '../include', - '../include/oxm', - '../include/cloud', - '../../include', - '../../../../../extlibs/tinydtls', - '../../../../../extlibs/base64', - '../../../connectivity/inc', - '../../../connectivity/inc/pkix', - '../../../connectivity/common/inc', - '../../../connectivity/api', - 'cloud' +provisioning_sample_env.AppendUnique(CPPPATH = [ + '#/resource/csdk/include', + '#/extlibs/base64', + '#/resource/csdk/security/provisioning/sample/cloud' ]) target_os = env.get('TARGET_OS') -provisioning_env.AppendUnique(RPATH = [env.get('BUILD_DIR')]) -provisioning_env.AppendUnique(CPPDEFINES = ['__WITH_DTLS__']) +provisioning_sample_env.AppendUnique(RPATH = [env.get('BUILD_DIR')]) +provisioning_sample_env.AppendUnique(CPPDEFINES = ['__WITH_DTLS__']) if target_os not in ['windows']: - provisioning_env.AppendUnique(CFLAGS = ['-std=c99']) - provisioning_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-fpermissive']) - provisioning_env.AppendUnique(LIBS = ['pthread']) + provisioning_sample_env.AppendUnique(CFLAGS = ['-std=c99']) + provisioning_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-fpermissive']) + provisioning_sample_env.AppendUnique(LIBS = ['pthread']) if target_os not in ['msys_nt', 'windows']: - provisioning_env.AppendUnique(LIBS = ['dl', 'm']) - provisioning_env.ParseConfig('pkg-config --libs glib-2.0'); - provisioning_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) + provisioning_sample_env.AppendUnique(LIBS = ['dl', 'm']) + provisioning_sample_env.ParseConfig('pkg-config --libs glib-2.0'); + provisioning_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) else: - provisioning_env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk')]) + provisioning_sample_env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk')]) -provisioning_env.PrependUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'connectivity_abstraction', 'coap']) +provisioning_sample_env.PrependUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'connectivity_abstraction', 'coap']) if target_os not in ['msys_nt', 'windows']: # octbstack.dll is exporting ocpmapi and ocsrm APIs on Windows. - provisioning_env.PrependUnique(LIBS = ['ocpmapi', 'ocsrm']) + provisioning_sample_env.PrependUnique(LIBS = ['ocpmapi', 'ocsrm']) if env.get('SECURED') == '1': - provisioning_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto']) + provisioning_sample_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto']) if env.get('MULTIPLE_OWNER') == '1': - provisioning_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER']) + provisioning_sample_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER']) -provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG']) +provisioning_sample_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if target_os == 'tizen': - provisioning_env.AppendUnique(CPPDEFINES = ['__TIZEN__']) + provisioning_sample_env.AppendUnique(CPPDEFINES = ['__TIZEN__']) if target_os in ['linux', 'tizen']: - provisioning_env.ParseConfig('pkg-config --cflags --libs sqlite3') + provisioning_sample_env.ParseConfig('pkg-config --cflags --libs sqlite3') ###################################################################### # Source files and Targets ###################################################################### -provisioningclient = provisioning_env.Program('provisioningclient', 'provisioningclient.c') -sampleserver_justworks = provisioning_env.Program('sampleserver_justworks', 'sampleserver_justworks.cpp') -sampleserver_randompin = provisioning_env.Program('sampleserver_randompin', 'sampleserver_randompin.cpp') -sampleserver_mfg = provisioning_env.Program('sampleserver_mfg', 'sampleserver_mfg.cpp') -sampleserver_mvjustworks = provisioning_env.Program('sampleserver_mvjustworks', 'sampleserver_mvjustworks.cpp') +provisioningclient = provisioning_sample_env.Program('provisioningclient', 'provisioningclient.c') +sampleserver_justworks = provisioning_sample_env.Program('sampleserver_justworks', 'sampleserver_justworks.cpp') +sampleserver_randompin = provisioning_sample_env.Program('sampleserver_randompin', 'sampleserver_randompin.cpp') +sampleserver_mfg = provisioning_sample_env.Program('sampleserver_mfg', 'sampleserver_mfg.cpp') +sampleserver_mvjustworks = provisioning_sample_env.Program('sampleserver_mvjustworks', 'sampleserver_mvjustworks.cpp') -if provisioning_env.get('MULTIPLE_OWNER') == '1': - subownerclient = provisioning_env.Program('subownerclient', 'subownerclient.c') - sampleserver_preconfpin = provisioning_env.Program('sampleserver_preconfpin', 'sampleserver_preconfpin.cpp') +if provisioning_sample_env.get('MULTIPLE_OWNER') == '1': + subownerclient = provisioning_sample_env.Program('subownerclient', 'subownerclient.c') + sampleserver_preconfpin = provisioning_sample_env.Program('sampleserver_preconfpin', 'sampleserver_preconfpin.cpp') -if provisioning_env.get('WITH_TCP') == True: +if provisioning_sample_env.get('WITH_TCP') == True: cloud_src = [ 'cloud/cloudAuth.c', 'cloud/cloudCommon.c', 'cloud/cloudWrapper.c', 'cloud/cloudDiscovery.c'] - cloudClient = provisioning_env.Program('cloudClient', cloud_src + ['cloudClient.c']) - cloudServer = provisioning_env.Program('cloudServer', cloud_src + ['cloudServer.c', 'cloud/cloudResource.c']) + cloudClient = provisioning_sample_env.Program('cloudClient', cloud_src + ['cloudClient.c']) + cloudServer = provisioning_sample_env.Program('cloudServer', cloud_src + ['cloudServer.c', 'cloud/cloudResource.c']) -src_dir = provisioning_env.get('SRC_DIR') +src_dir = provisioning_sample_env.get('SRC_DIR') sec_provisioning_src_dir = src_dir + '/resource/csdk/security/provisioning/sample/' sec_provisioning_build_dir = env.get('BUILD_DIR') +'/resource/csdk/security/provisioning/sample/' -clientdat = provisioning_env.Install(sec_provisioning_build_dir, +clientdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'oic_svr_db_client.dat') -justworksdat = provisioning_env.Install(sec_provisioning_build_dir, +justworksdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'oic_svr_db_server_justworks.dat') -randompindat = provisioning_env.Install(sec_provisioning_build_dir, +randompindat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir+ 'oic_svr_db_server_randompin.dat') -mfgdat = provisioning_env.Install(sec_provisioning_build_dir, +mfgdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir+ 'oic_svr_db_server_mfg.dat') -randompin_with_emptyuuid_dat = provisioning_env.Install(sec_provisioning_build_dir, +randompin_with_emptyuuid_dat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir+ 'oic_svr_db_randompin_with_empty_deviceid.dat') -mvjustworksdat = provisioning_env.Install(sec_provisioning_build_dir, +mvjustworksdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'oic_svr_db_server_mvjustworks.dat') -if provisioning_env.get('MULTIPLE_OWNER') == '1': - subownerclientdat = provisioning_env.Install(sec_provisioning_build_dir, +if provisioning_sample_env.get('MULTIPLE_OWNER') == '1': + subownerclientdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'oic_svr_db_subowner_client.dat') - preconfserverdat = provisioning_env.Install(sec_provisioning_build_dir, + preconfserverdat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'oic_svr_db_server_preconfpin.dat') -if provisioning_env.get('WITH_TCP') == True: - clouddat = provisioning_env.Install(sec_provisioning_build_dir, +if provisioning_sample_env.get('WITH_TCP') == True: + clouddat = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'cloud.dat') - rootcert = provisioning_env.Install(sec_provisioning_build_dir, + rootcert = provisioning_sample_env.Install(sec_provisioning_build_dir, sec_provisioning_src_dir + 'rootca.crt') Alias("cloud", [clouddat, rootcert, cloudClient, cloudServer]) - provisioning_env.AppendTarget("cloud") + provisioning_sample_env.AppendTarget("cloud") -if provisioning_env.get('MULTIPLE_OWNER') == '1': +if provisioning_sample_env.get('MULTIPLE_OWNER') == '1': Alias("samples", [ provisioningclient, subownerclient, sampleserver_justworks, sampleserver_randompin, sampleserver_mfg, @@ -167,4 +143,4 @@ else: mvjustworksdat ]) -provisioning_env.AppendTarget('samples') +provisioning_sample_env.AppendTarget('samples') diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c b/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c index a14a7e5..e44d434 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c +++ b/resource/csdk/security/provisioning/sample/cloud/cloudAuth.c @@ -48,7 +48,7 @@ typedef struct char *accesstoken; char *refreshtoken; char *tokentype; - long expiresin; + int64_t expiresin; char *uid; char *redirecturi; char *certificate; @@ -103,15 +103,10 @@ static OCStackResult SessionParsePayload(OCRepPayload *payload) { OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_TOKEN_TYPE); } - int64_t tmp = 0; - if (!OCRepPayloadGetPropInt(payload, OC_RSRVD_EXPIRES_IN, &tmp)) + if (!OCRepPayloadGetPropInt(payload, OC_RSRVD_EXPIRES_IN, &(sessionObject.expiresin))) { OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN); } - else - { - sessionObject.expiresin = tmp; - } if (!OCRepPayloadGetPropString(payload, OC_RSRVD_USER_UUID, &sessionObject.uid)) { @@ -234,15 +229,10 @@ static OCStackApplicationResult handleCloudSignInResponse(void *ctx, } sessionObject.expiresin = 0; - int64_t tmp = 0; - if (!OCRepPayloadGetPropInt((OCRepPayload*)response->payload, OC_RSRVD_EXPIRES_IN, &tmp)) + if (!OCRepPayloadGetPropInt((OCRepPayload*)response->payload, OC_RSRVD_EXPIRES_IN, &(sessionObject.expiresin))) { OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_EXPIRES_IN); } - else - { - sessionObject.expiresin = tmp; - } OIC_LOG(INFO, TAG, "Sign In OK"); diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudResource.c b/resource/csdk/security/provisioning/sample/cloud/cloudResource.c index 35ec5c2..1481b5c 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudResource.c +++ b/resource/csdk/security/provisioning/sample/cloud/cloudResource.c @@ -131,7 +131,7 @@ static OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *request { // Create new LED instance char uri[15] = "/a/led/"; - int length = strlen(uri); + size_t length = strlen(uri); snprintf (uri + length, sizeof(uri) - length, "%d", gCurrLedInstance); answer = OCRepPayloadCreate(); diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudResource.h b/resource/csdk/security/provisioning/sample/cloud/cloudResource.h index 777c0ca..8126118 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudResource.h +++ b/resource/csdk/security/provisioning/sample/cloud/cloudResource.h @@ -23,7 +23,7 @@ typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; /** diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h index 1df22cb..4862c62 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h +++ b/resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h @@ -101,7 +101,6 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud * @param[in] callback result callback * @return OCStackResult application result */ - OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudResponseCB callback); /** diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index e96c204..f2f1545 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -38,6 +38,13 @@ #include "pmtypes.h" #include "oxmverifycommon.h" +#ifdef _MSC_VER +#include + +#define F_OK 0 +#define access _access_s +#endif + #ifdef __cplusplus extern "C" { @@ -97,7 +104,7 @@ static const OicSecPrm_t SUPPORTED_PRMS[1] = // |g_ctx| means provision manager application context and // the following, includes |un/own_list|, could be variables, which |g_ctx| has, // for accessing all function(s) for these, they are declared on global domain -static const char* g_ctx = "Provision Manager Client Application Context"; +static char* g_ctx = "Provision Manager Client Application Context"; static char* g_svr_fname; static char* g_prvn_fname; static OCProvisionDev_t* g_own_list; @@ -121,14 +128,14 @@ static OicSecPdAcl_t* createPdAcl(const int); static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int); static int printDevList(const OCProvisionDev_t*); static size_t printUuidList(const OCUuidList_t*); -static int printResultList(const OCProvisionResult_t*, const int); +static size_t printResultList(const OCProvisionResult_t*, const size_t); static void printUuid(const OicUuid_t*); static FILE* fopen_prvnMng(const char*, const char*); static int waitCallbackRet(void); static int selectTwoDiffNum(int*, int*, const int, const char*); // callback function(s) for provisioning client using C-level provisioning API -static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void ownershipTransferCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -142,7 +149,7 @@ static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, g_doneCB = true; } -static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionPairwiseCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -156,7 +163,7 @@ static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, g_doneCB = true; } -static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionCredCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -170,7 +177,7 @@ static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, boo g_doneCB = true; } -static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionAclCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -184,7 +191,7 @@ static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } -static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void getCredCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -198,7 +205,7 @@ static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasE g_doneCB = true; } -static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void getAclCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -212,7 +219,7 @@ static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasEr g_doneCB = true; } -static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionDPCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -226,7 +233,7 @@ static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } -static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void unlinkDevicesCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -240,7 +247,7 @@ static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, boo g_doneCB = true; } -static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void removeDeviceCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -254,7 +261,7 @@ static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } -static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void syncDeviceCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -269,7 +276,7 @@ static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool h } #ifdef MULTIPLE_OWNER -static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -311,7 +318,7 @@ static int initProvisionClient(void) .read = fread, .write = fwrite, .close = fclose, - .unlink = unlink + .unlink = remove }; if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr)) { @@ -1879,16 +1886,16 @@ static OicSecPdAcl_t* createPdAcl(const int dev_num) pdAcl->resourcesLen = 1; // resource - int num = pdAcl->resourcesLen; + size_t num = pdAcl->resourcesLen; pdAcl->resources = (char**) OICCalloc(num, sizeof(char*)); if(!pdAcl->resources) { OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return"); goto CRPDACL_ERROR; } - for(int i=0; num>i; ++i) + for (size_t i = 0; num > i; ++i) { - size_t len = strlen(rsrc_in[i])+1; // '1' for null termination + size_t len = strlen(rsrc_in[i]) + 1; // '1' for null termination char* rsrc = (char*) OICCalloc(len, sizeof(char)); if(!rsrc) { @@ -1974,19 +1981,19 @@ static size_t printUuidList(const OCUuidList_t* uid_lst) return lst_cnt; } -static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt) +static size_t printResultList(const OCProvisionResult_t* rslt_lst, const size_t rslt_cnt) { - if(!rslt_lst || 0>=rslt_cnt) + if (!rslt_lst || (0 == rslt_cnt)) { printf(" Device List is Empty..\n\n"); return 0; } - int lst_cnt = 0; - for( ; rslt_cnt>lst_cnt; ++lst_cnt) + size_t lst_cnt = 0; + for (; rslt_cnt > lst_cnt; ++lst_cnt) { - printf(" [%d] ", lst_cnt+1); - printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId); + printf(" [%" PRIuPTR "] ", lst_cnt + 1); + printUuid((const OicUuid_t*)&rslt_lst[lst_cnt].deviceId); printf(" - result: %d\n", rslt_lst[lst_cnt].res); } printf("\n"); diff --git a/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp b/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp index 6b7c9ed..20a0c4a 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp @@ -54,7 +54,7 @@ int gQuitFlag = 0; typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; static LEDResource LED; @@ -74,7 +74,7 @@ static char CRED_FILE[] = "oic_svr_db_server_justworks.dat"; /* Function that creates a new LED resource by calling the * OCCreateResource() method. */ -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower); +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower); /* This method converts the payload to JSON format */ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest); @@ -189,7 +189,7 @@ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest) int64_t pow; if(OCRepPayloadGetPropInt(input, "power", &pow)) { - currLEDResource->power =pow; + currLEDResource->power = pow; } bool state; @@ -265,8 +265,8 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, { // Create new LED instance char newLedUri[15] = "/a/led/"; - int newLedUriLength = strlen(newLedUri); - snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance); + size_t newLedUriLength = strlen(newLedUri); + snprintf(newLedUri + newLedUriLength, sizeof(newLedUri) - newLedUriLength, "%d", gCurrLedInstance); respPLPost_led = OCRepPayloadCreate(); OCRepPayloadSetUri(respPLPost_led, gResourceUri); @@ -424,7 +424,7 @@ int main() OIC_LOG(DEBUG, TAG, "OCServer is starting..."); // Initialize Persistent Storage for SVR database - OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, remove}; OCRegisterPersistentStorageHandler(&ps); @@ -465,7 +465,7 @@ int main() return 0; } -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower) +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower) { if (!uri) { diff --git a/resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp b/resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp index 775deb6..586d237 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp @@ -53,7 +53,7 @@ int gQuitFlag = 0; typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; static LEDResource LED; @@ -72,7 +72,7 @@ static char CRED_FILE[] = "oic_svr_db_server_mfg.dat"; /* Function that creates a new LED resource by calling the * OCCreateResource() method. */ -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower); +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower); /* This method converts the payload to JSON format */ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest); @@ -263,7 +263,7 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, { // Create new LED instance char newLedUri[15] = "/a/led/"; - int newLedUriLength = strlen(newLedUri); + size_t newLedUriLength = strlen(newLedUri); snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance); respPLPost_led = OCRepPayloadCreate(); @@ -422,7 +422,7 @@ int main() OIC_LOG(DEBUG, TAG, "OCServer is starting..."); // Initialize Persistent Storage for SVR database - OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, remove}; OCRegisterPersistentStorageHandler(&ps); @@ -463,7 +463,7 @@ int main() return 0; } -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower) +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower) { if (!uri) { diff --git a/resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp b/resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp index 77233e1..2bdc8fd 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp @@ -55,7 +55,7 @@ int gQuitFlag = 0; typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; static LEDResource LED; @@ -75,7 +75,7 @@ static char CRED_FILE[] = "oic_svr_db_server_mvjustworks.dat"; /* Function that creates a new LED resource by calling the * OCCreateResource() method. */ -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower); +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower); /* This method converts the payload to JSON format */ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest); @@ -190,7 +190,7 @@ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest) int64_t pow; if(OCRepPayloadGetPropInt(input, "power", &pow)) { - currLEDResource->power =pow; + currLEDResource->power = pow; } bool state; @@ -266,7 +266,7 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, { // Create new LED instance char newLedUri[15] = "/a/led/"; - int newLedUriLength = strlen(newLedUri); + size_t newLedUriLength = strlen(newLedUri); snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance); respPLPost_led = OCRepPayloadCreate(); @@ -471,7 +471,7 @@ int main() SetVerifyOption((VerifyOptionBitmask_t)(DISPLAY_NUM | USER_CONFIRM)); // Initialize Persistent Storage for SVR database - OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, remove}; OCRegisterPersistentStorageHandler(&ps); @@ -512,7 +512,7 @@ int main() return 0; } -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower) +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower) { if (!uri) { diff --git a/resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp b/resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp index 8d91882..cb553c5 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp @@ -54,7 +54,7 @@ int gQuitFlag = 0; typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; static LEDResource LED; @@ -265,8 +265,8 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, { // Create new LED instance char newLedUri[15] = "/a/led/"; - int newLedUriLength = strlen(newLedUri); - snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance); + size_t newLedUriLength = strlen(newLedUri); + snprintf(newLedUri + newLedUriLength, sizeof(newLedUri) - newLedUriLength, "%d", gCurrLedInstance); respPLPost_led = OCRepPayloadCreate(); OCRepPayloadSetUri(respPLPost_led, gResourceUri); diff --git a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp index 00f025f..45cc4f4 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp @@ -53,7 +53,7 @@ int gQuitFlag = 0; typedef struct LEDRESOURCE{ OCResourceHandle handle; bool state; - int power; + int64_t power; } LEDResource; static LEDResource LED; @@ -73,7 +73,7 @@ static char CRED_FILE[] = "oic_svr_db_server_randompin.dat"; /* Function that creates a new LED resource by calling the * OCCreateResource() method. */ -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower); +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower); /* This method converts the payload to JSON format */ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest); @@ -225,7 +225,7 @@ OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest) int64_t pow; if(OCRepPayloadGetPropInt(input, "power", &pow)) { - currLEDResource->power =pow; + currLEDResource->power = pow; } bool state; @@ -301,7 +301,7 @@ OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest, { // Create new LED instance char newLedUri[15] = "/a/led/"; - int newLedUriLength = strlen(newLedUri); + size_t newLedUriLength = strlen(newLedUri); snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance); respPLPost_led = OCRepPayloadCreate(); @@ -472,7 +472,7 @@ int main() OIC_LOG(DEBUG, TAG, "OCServer is starting..."); // Initialize Persistent Storage for SVR database - OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink}; + OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, remove}; OCRegisterPersistentStorageHandler(&ps); if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) @@ -553,7 +553,7 @@ int main() return 0; } -int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower) +int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower) { if (!uri) { diff --git a/resource/csdk/security/provisioning/sample/subownerclient.c b/resource/csdk/security/provisioning/sample/subownerclient.c index 8fd6020..3e5803d 100644 --- a/resource/csdk/security/provisioning/sample/subownerclient.c +++ b/resource/csdk/security/provisioning/sample/subownerclient.c @@ -21,6 +21,7 @@ #include #include +#include #ifdef HAVE_UNISTD_H #include #endif @@ -38,6 +39,13 @@ #include "pmtypes.h" #include "pmutility.h" +#ifdef _MSC_VER +#include + +#define F_OK 0 +#define access _access_s +#endif + #ifdef __cplusplus extern "C" { @@ -73,7 +81,7 @@ static const OicSecPrm_t SUPPORTED_PRMS[1] = // |g_ctx| means provision manager application context and // the following, includes |un/own_list|, could be variables, which |g_ctx| has, // for accessing all function(s) for these, they are declared on global domain -static const char* g_ctx = "SubOwner Client Application Context"; +static char* g_ctx = "SubOwner Client Application Context"; static char* g_svr_fname; static char* g_prvn_fname; static OCProvisionDev_t* g_own_list; @@ -90,14 +98,14 @@ static bool g_doneCB; static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int); static int printDevList(const OCProvisionDev_t*); static size_t printUuidList(const OCUuidList_t*); -static int printResultList(const OCProvisionResult_t*, const int); +static size_t printResultList(const OCProvisionResult_t*, const size_t); static void printUuid(const OicUuid_t*); static FILE* fopen_prvnMng(const char*, const char*); static int waitCallbackRet(void); static int selectTwoDiffNum(int*, int*, const int, const char*); // callback function(s) for provisioning client using C-level provisioning API -static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void multipleOwnershipTransferCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -112,7 +120,7 @@ static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult } // callback function(s) for provisioning client using C-level provisioning API -static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void ownershipTransferCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -126,7 +134,7 @@ static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, g_doneCB = true; } -static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -140,7 +148,7 @@ static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, g_doneCB = true; } -static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionCredCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -154,7 +162,7 @@ static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, boo g_doneCB = true; } -static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionAclCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) { @@ -178,7 +186,7 @@ static OCStackApplicationResult LedCB(void *ctx, OCDoHandle UNUSED, OCClientResp printf("Received OC_STACK_OK from server\n"); if(clientResponse->payload) { - printf("Response ===================> %s\n", clientResponse->payload); + printf("Response ===================> %s\n", (char*)clientResponse->payload); } } else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result) @@ -594,7 +602,7 @@ static int provisionAclForLed() for( ; 0x20<=getchar(); ); // for removing overflow garbages // '0x20<=code' is character region } - if(0=dev_num) + if (0 < dev_num && g_mowned_cnt >= dev_num) { break; } @@ -763,7 +771,7 @@ static int printDevList(const OCProvisionDev_t* dev_lst) OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst; int lst_cnt = 0; - for( ; lst; ) + while(lst) { printf(" [%d] ", ++lst_cnt); printUuid((const OicUuid_t*) &lst->doxm->deviceID); @@ -785,9 +793,9 @@ static size_t printUuidList(const OCUuidList_t* uid_lst) OCUuidList_t* lst = (OCUuidList_t*) uid_lst; size_t lst_cnt = 0; - for( ; lst; ) + while(lst) { - printf(" [%zu] ", ++lst_cnt); + printf(" [%" PRIuPTR "] ", ++lst_cnt); printUuid((const OicUuid_t*) &lst->dev); printf("\n"); lst = lst->next; @@ -797,21 +805,21 @@ static size_t printUuidList(const OCUuidList_t* uid_lst) return lst_cnt; } -static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt) +static size_t printResultList(const OCProvisionResult_t* rslt_lst, const size_t rslt_cnt) { - if(!rslt_lst || 0>=rslt_cnt) + if (!rslt_lst || (0 == rslt_cnt)) { printf(" Device List is Empty..\n\n"); return 0; } - int lst_cnt = 0; - for( ; rslt_cnt>lst_cnt; ++lst_cnt) + size_t lst_cnt = 0; + do { - printf(" [%d] ", lst_cnt+1); - printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId); + printf(" [%" PRIuPTR "] ", lst_cnt + 1); + printUuid((const OicUuid_t*)&rslt_lst[lst_cnt].deviceId); printf(" - result: %d\n", rslt_lst[lst_cnt].res); - } + } while (++lst_cnt < rslt_cnt); printf("\n"); return lst_cnt; diff --git a/resource/csdk/security/provisioning/src/credentialgenerator.c b/resource/csdk/security/provisioning/src/credentialgenerator.c index 7b0c41f..a70cf8b 100644 --- a/resource/csdk/security/provisioning/src/credentialgenerator.c +++ b/resource/csdk/security/provisioning/src/credentialgenerator.c @@ -54,7 +54,7 @@ OCStackResult PMGeneratePairWiseCredentials(OicSecCredType_t type, size_t keySiz size_t privDataKeySize = keySize; uint8_t *privData = (uint8_t *)OICCalloc(privDataKeySize, sizeof(uint8_t)); - VERIFY_NON_NULL(TAG, privData, ERROR); + VERIFY_NOT_NULL(TAG, privData, ERROR); OicSecKey_t privKey = {.data=privData, .len=keySize}; if (!OCGetRandomBytes(privData, privDataKeySize)) @@ -66,11 +66,11 @@ OCStackResult PMGeneratePairWiseCredentials(OicSecCredType_t type, size_t keySiz // 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); + VERIFY_NOT_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); + VERIFY_NOT_NULL(TAG, tempSecondCred, ERROR); *firstCred = tempFirstCred; *secondCred = tempSecondCred; diff --git a/resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c b/resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c index 5844252..20dcfad 100644 --- a/resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c +++ b/resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c @@ -80,9 +80,9 @@ static OCStackApplicationResult MOTUpdateSecurityResourceCB(void *ctx, OCDoHandl OIC_LOG_V(INFO, TAG, "Inside MOTUpdateMomCB."); (void)UNUSED; OTMContext_t *motCtx = (OTMContext_t*)ctx; - VERIFY_NON_NULL(TAG, motCtx, ERROR); - VERIFY_NON_NULL(TAG, motCtx->ctxResultCallback, ERROR); - VERIFY_NON_NULL(TAG, motCtx->ctxResultArray, ERROR); + VERIFY_NOT_NULL(TAG, motCtx, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->ctxResultCallback, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR); if(clientResponse) { @@ -130,13 +130,14 @@ static OCStackResult MOTSendPostDoxm(void *ctx, OCStackResult postMomRes = OC_STACK_ERROR; OCSecurityPayload* secPayload = NULL; OTMContext_t *motCtx = NULL; + OCProvisionDev_t *localTargetDeviceInfo = NULL; bool freeFlag = true; OIC_LOG(DEBUG, TAG, "IN MOTSendPostDoxm"); //Generate the security payload using updated doxm secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload)); - VERIFY_NON_NULL(TAG, secPayload, ERROR); + VERIFY_NOT_NULL(TAG, secPayload, ERROR); secPayload->base.type = PAYLOAD_TYPE_SECURITY; postMomRes = DoxmToCBORPayload(doxm, &secPayload->securityData, &secPayload->payloadSize, true); @@ -154,16 +155,19 @@ static OCStackResult MOTSendPostDoxm(void *ctx, VERIFY_SUCCESS(TAG, (true == queryGenRes), ERROR); OIC_LOG_V(DEBUG, TAG, "Query=%s", query); + localTargetDeviceInfo = PMCloneOCProvisionDev(targetDeviceInfo); + VERIFY_NOT_NULL(TAG, localTargetDeviceInfo, ERROR); + //Create the MOT Context to handle the response message motCtx = (OTMContext_t*)OICCalloc(1, sizeof(OTMContext_t)); - VERIFY_NON_NULL(TAG, motCtx, ERROR); - motCtx->selectedDeviceInfo = targetDeviceInfo; + VERIFY_NOT_NULL(TAG, motCtx, ERROR); + motCtx->selectedDeviceInfo = localTargetDeviceInfo; motCtx->ctxResultCallback = resultCallback; motCtx->ctxResultArraySize = 1; motCtx->ctxHasError = false; motCtx->userCtx = ctx; motCtx->ctxResultArray= (OCProvisionResult_t*)OICCalloc(1, sizeof(OCProvisionResult_t)); - VERIFY_NON_NULL(TAG, motCtx->ctxResultArray, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR); //Send POST request OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL}; @@ -187,6 +191,11 @@ exit: OICFree(motCtx); } + if (localTargetDeviceInfo) + { + PMDeleteDeviceList(localTargetDeviceInfo); + } + return postMomRes; } @@ -210,9 +219,9 @@ OCStackResult MOTChangeMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo, OIC_LOG(DEBUG, TAG, "IN MOTChangeMode"); VERIFY_SUCCESS(TAG, (OIC_NUMBER_OF_MOM_TYPE > momType), ERROR); - VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR); + VERIFY_NOT_NULL(TAG, targetDeviceInfo, ERROR); postMomRes = OC_STACK_INVALID_CALLBACK; - VERIFY_NON_NULL(TAG, resultCallback, ERROR); + VERIFY_NOT_NULL(TAG, resultCallback, ERROR); //Dulpicate doxm resource to update the 'mom' property postMomRes = DoxmToCBORPayload(targetDeviceInfo->doxm, &doxmPayload, &doxmPayloadLen, false); @@ -220,13 +229,13 @@ OCStackResult MOTChangeMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo, postMomRes = CBORPayloadToDoxm(doxmPayload, doxmPayloadLen, &doxm); VERIFY_SUCCESS(TAG, (OC_STACK_OK == postMomRes), ERROR); - VERIFY_NON_NULL(TAG, doxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm, ERROR); if(NULL == doxm->mom) { postMomRes = OC_STACK_NO_MEMORY; doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t)); - VERIFY_NON_NULL(TAG, (doxm->mom), ERROR); + VERIFY_NOT_NULL(TAG, (doxm->mom), ERROR); } doxm->mom->mode = momType; @@ -262,9 +271,9 @@ OCStackResult MOTAddMOTMethod(void *ctx, OCProvisionDev_t *targetDeviceInfo, OIC_LOG(DEBUG, TAG, "IN MOTAddMOTMethod"); VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > newOxm || OIC_PRECONFIG_PIN == newOxm), ERROR); - VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR); + VERIFY_NOT_NULL(TAG, targetDeviceInfo, ERROR); postOxmRes = OC_STACK_INVALID_CALLBACK; - VERIFY_NON_NULL(TAG, resultCallback, ERROR); + VERIFY_NOT_NULL(TAG, resultCallback, ERROR); postOxmRes = OC_STACK_NO_MEMORY; for(size_t i = 0; i < targetDeviceInfo->doxm->oxmLen; i++) @@ -273,7 +282,7 @@ OCStackResult MOTAddMOTMethod(void *ctx, OCProvisionDev_t *targetDeviceInfo, { OIC_LOG_V(INFO, TAG, "[%d] OxM already supported", (int)newOxm); OCProvisionResult_t* resArr = (OCProvisionResult_t*)OICCalloc(1, sizeof(OCProvisionResult_t)); - VERIFY_NON_NULL(TAG, resArr, ERROR); + VERIFY_NOT_NULL(TAG, resArr, ERROR); resArr->res = OC_STACK_OK; memcpy(resArr->deviceId.id, targetDeviceInfo->doxm->deviceID.id, sizeof(resArr->deviceId.id)); resultCallback(ctx, 1, resArr, false); @@ -282,7 +291,7 @@ OCStackResult MOTAddMOTMethod(void *ctx, OCProvisionDev_t *targetDeviceInfo, } newOxms = (OicSecOxm_t*)OICMalloc(sizeof(OicSecOxm_t) * (targetDeviceInfo->doxm->oxmLen + 1)); - VERIFY_NON_NULL(TAG, newOxms , ERROR); + VERIFY_NOT_NULL(TAG, newOxms , ERROR); for(size_t i = 0; i < targetDeviceInfo->doxm->oxmLen; i++) { @@ -323,9 +332,9 @@ OCStackResult MOTSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDevice OIC_LOG(DEBUG, TAG, "IN MOTSelectOTMethod"); - VERIFY_NON_NULL(TAG, resultCallback, ERROR); + VERIFY_NOT_NULL(TAG, resultCallback, ERROR); postMomRes = OC_STACK_INVALID_PARAM; - VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR); + VERIFY_NOT_NULL(TAG, targetDeviceInfo, ERROR); bool isValidOxmsel = false; for(size_t i = 0; i < targetDeviceInfo->doxm->oxmLen; i++) @@ -344,7 +353,7 @@ OCStackResult MOTSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDevice postMomRes = CBORPayloadToDoxm(doxmPayload, doxmPayloadLen, &doxm); VERIFY_SUCCESS(TAG, (OC_STACK_OK == postMomRes), ERROR); - VERIFY_NON_NULL(TAG, doxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm, ERROR); doxm->oxmSel = oxmSelValue; @@ -378,23 +387,24 @@ OCStackResult MOTProvisionPreconfigPIN(void *ctx, const OCProvisionDev_t *target OCSecurityPayload* secPayload = NULL; OTMContext_t *motCtx = NULL; OicSecCred_t* pinCred = NULL; + OCProvisionDev_t* localTargetDeviceInfo = NULL; OIC_LOG(DEBUG, TAG, "IN MOTProvisionPreconfigPIN"); - VERIFY_NON_NULL(TAG, resultCallback, ERROR); + VERIFY_NOT_NULL(TAG, resultCallback, ERROR); postCredRes = OC_STACK_INVALID_PARAM; - VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR); - VERIFY_NON_NULL(TAG, preconfPIN, ERROR); + VERIFY_NOT_NULL(TAG, targetDeviceInfo, ERROR); + VERIFY_NOT_NULL(TAG, preconfPIN, ERROR); VERIFY_SUCCESS(TAG, (0 != preconfPINLen), ERROR); VERIFY_SUCCESS(TAG, (0 != preconfPINLen && OXM_PRECONFIG_PIN_MAX_SIZE >= preconfPINLen), ERROR); postCredRes = OC_STACK_NO_MEMORY; //Generate PIN based credential pinCred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t)); - VERIFY_NON_NULL(TAG, pinCred, ERROR); + VERIFY_NOT_NULL(TAG, pinCred, ERROR); pinCred->privateData.data = (uint8_t*)OICMalloc(preconfPINLen + 1); - VERIFY_NON_NULL(TAG, pinCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, pinCred->privateData.data, ERROR); memcpy(pinCred->privateData.data, preconfPIN, preconfPINLen); pinCred->privateData.data[preconfPINLen] = '\0'; @@ -405,7 +415,7 @@ OCStackResult MOTProvisionPreconfigPIN(void *ctx, const OCProvisionDev_t *target //Generate the security payload using updated doxm secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload)); - VERIFY_NON_NULL(TAG, secPayload, ERROR); + VERIFY_NOT_NULL(TAG, secPayload, ERROR); secPayload->base.type = PAYLOAD_TYPE_SECURITY; postCredRes = CredToCBORPayload(pinCred, &secPayload->securityData, &secPayload->payloadSize, false); @@ -423,16 +433,19 @@ OCStackResult MOTProvisionPreconfigPIN(void *ctx, const OCProvisionDev_t *target VERIFY_SUCCESS(TAG, (true == queryGenRes), ERROR); OIC_LOG_V(DEBUG, TAG, "Query=%s", query); + localTargetDeviceInfo = PMCloneOCProvisionDev(targetDeviceInfo); + VERIFY_NOT_NULL(TAG, localTargetDeviceInfo, ERROR); + //Create the MOT Context to handle the response message motCtx = (OTMContext_t*)OICCalloc(1, sizeof(OTMContext_t)); - VERIFY_NON_NULL(TAG, motCtx, ERROR); - motCtx->selectedDeviceInfo= targetDeviceInfo; + VERIFY_NOT_NULL(TAG, motCtx, ERROR); + motCtx->selectedDeviceInfo= localTargetDeviceInfo; motCtx->ctxResultCallback = resultCallback; motCtx->ctxResultArraySize =1; motCtx->ctxHasError = false; motCtx->userCtx = ctx; motCtx->ctxResultArray = (OCProvisionResult_t*)OICCalloc(1, sizeof(OCProvisionResult_t)); - VERIFY_NON_NULL(TAG, motCtx->ctxResultArray, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR); //Send POST request OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL}; @@ -462,6 +475,12 @@ exit: OICFree(pinCred->privateData.data); OICFree(pinCred); } + + if (localTargetDeviceInfo) + { + PMDeleteDeviceList(localTargetDeviceInfo); + } + return postCredRes; } @@ -497,7 +516,7 @@ static bool IsComplete(OTMContext_t* otmCtx) static void SetMOTResult(OTMContext_t* motCtx, const OCStackResult res) { OIC_LOG_V(DEBUG, TAG, "IN SetMOTResult : %d ", res); - VERIFY_NON_NULL(TAG, motCtx, ERROR); + VERIFY_NOT_NULL(TAG, motCtx, ERROR); if(motCtx->selectedDeviceInfo) { @@ -590,8 +609,8 @@ OCStackResult MOTAddPreconfigPIN(const OCProvisionDev_t *targetDeviceInfo, OIC_LOG(DEBUG, TAG, "IN MOTAddPreconfigPIN"); - VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR); - VERIFY_NON_NULL(TAG, preconfPIN, ERROR); + VERIFY_NOT_NULL(TAG, targetDeviceInfo, ERROR); + VERIFY_NOT_NULL(TAG, preconfPIN, ERROR); VERIFY_SUCCESS(TAG, (0 != preconfPINLen), ERROR); VERIFY_SUCCESS(TAG, (0 != preconfPINLen && OXM_PRECONFIG_PIN_MAX_SIZE >= preconfPINLen), ERROR); @@ -605,10 +624,10 @@ OCStackResult MOTAddPreconfigPIN(const OCProvisionDev_t *targetDeviceInfo, addCredRes = OC_STACK_NO_MEMORY; //Generate PIN based credential pinCred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t)); - VERIFY_NON_NULL(TAG, pinCred, ERROR); + VERIFY_NOT_NULL(TAG, pinCred, ERROR); pinCred->privateData.data = (uint8_t*)OICMalloc(preconfPINLen + 1); - VERIFY_NON_NULL(TAG, pinCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, pinCred->privateData.data, ERROR); memcpy(pinCred->privateData.data, preconfPIN, preconfPINLen); pinCred->privateData.data[preconfPINLen] = '\0'; @@ -678,17 +697,17 @@ static OCStackResult SaveSubOwnerPSK(OCProvisionDev_t *selectedDeviceInfo) OicSecCred_t *cred = GenerateCredential(&selectedDeviceInfo->doxm->deviceID, SYMMETRIC_PAIR_WISE_KEY, NULL, &ownerKey, &ownerDeviceID, &ownerDeviceID); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); - uint32_t outSize = 0; + size_t outSize = 0; size_t b64BufSize = B64ENCODE_OUT_SAFESIZE((OWNER_PSK_LENGTH_128 + 1)); char* b64Buf = (uint8_t *)OICCalloc(1, b64BufSize); - VERIFY_NON_NULL(TAG, b64Buf, ERROR); + VERIFY_NOT_NULL(TAG, b64Buf, ERROR); b64Encode(cred->privateData.data, cred->privateData.len, b64Buf, b64BufSize, &outSize); OICFree( cred->privateData.data ); cred->privateData.data = (uint8_t *)OICCalloc(1, outSize + 1); - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); strncpy(cred->privateData.data, b64Buf, outSize); cred->privateData.data[outSize] = '\0'; @@ -727,8 +746,8 @@ exit: static OCStackApplicationResult SubOwnerCredentialHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OIC_LOG(DEBUG, TAG, "IN SubOwnerCredentialHandler"); (void)UNUSED; @@ -986,9 +1005,9 @@ static OCStackResult StartMultipleOwnershipTransfer(OTMContext_t* motCtx, OCStackResult res = OC_STACK_INVALID_PARAM; OicUuid_t myUuid = {.id={0}}; - VERIFY_NON_NULL(TAG, motCtx, ERROR); - VERIFY_NON_NULL(TAG, selectedDevice, ERROR); - VERIFY_NON_NULL(TAG, selectedDevice->doxm, ERROR); + VERIFY_NOT_NULL(TAG, motCtx, ERROR); + VERIFY_NOT_NULL(TAG, selectedDevice, ERROR); + VERIFY_NOT_NULL(TAG, selectedDevice->doxm, ERROR); motCtx->selectedDeviceInfo = selectedDevice; res = GetDoxmDeviceID(&myUuid); @@ -1082,8 +1101,8 @@ static OCStackResult StartMultipleOwnershipTransfer(OTMContext_t* motCtx, return res; } //Only two functions required for MOT - VERIFY_NON_NULL(TAG, motCtx->otmCallback.loadSecretCB, ERROR); - VERIFY_NON_NULL(TAG, motCtx->otmCallback.createSecureSessionCB, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->otmCallback.loadSecretCB, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->otmCallback.createSecureSessionCB, ERROR); if(OIC_RANDOM_DEVICE_PIN == oxmSel) { @@ -1118,12 +1137,12 @@ OCStackResult MOTDoOwnershipTransfer(void* ctx, OTMContext_t* motCtx = NULL; OCProvisionDev_t* pCurDev = NULL; - VERIFY_NON_NULL(TAG, selectedDevicelist, ERROR); - VERIFY_NON_NULL(TAG, resultCallback, ERROR); + VERIFY_NOT_NULL(TAG, selectedDevicelist, ERROR); + VERIFY_NOT_NULL(TAG, resultCallback, ERROR); res = OC_STACK_NO_MEMORY; motCtx = (OTMContext_t*)OICCalloc(1,sizeof(OTMContext_t)); - VERIFY_NON_NULL(TAG, motCtx, ERROR); + VERIFY_NOT_NULL(TAG, motCtx, ERROR); motCtx->ctxResultCallback = resultCallback; motCtx->ctxHasError = false; @@ -1136,7 +1155,7 @@ OCStackResult MOTDoOwnershipTransfer(void* ctx, motCtx->ctxResultArray = (OCProvisionResult_t*)OICCalloc(motCtx->ctxResultArraySize, sizeof(OCProvisionResult_t)); - VERIFY_NON_NULL(TAG, motCtx->ctxResultArray, ERROR); + VERIFY_NOT_NULL(TAG, motCtx->ctxResultArray, ERROR); //Fill the device UUID for result array. size_t devIdx = 0; diff --git a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c index fd5d4a3..2531a76 100644 --- a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c +++ b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c @@ -435,7 +435,7 @@ OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *select } #ifdef MULTIPLE_OWNER -static void AddPreconfPinOxMCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) +static void AddPreconfPinOxMCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError) { ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)ctx; if(provCtx) @@ -925,7 +925,7 @@ static void UpdateLinkResults(Linkdata_t *link, int device, OCStackResult stackr /** * Callback to handle ACL provisioning for device 2. */ -static void AclProv2CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) +static void AclProv2CB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError) { if (NULL == ctx) @@ -961,7 +961,7 @@ static void AclProv2CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool has /** * Callback to handle ACL provisioning for device 1 */ -static void AclProv1CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) +static void AclProv1CB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError) { if (NULL == ctx) @@ -1012,7 +1012,7 @@ static void AclProv1CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool has /** * Callback to handle credential provisioning. */ -static void ProvisionCredsCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) +static void ProvisionCredsCB(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError) { if (NULL == ctx) { diff --git a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c index 24618ef..3b841ec 100644 --- a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c +++ b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c @@ -57,6 +57,7 @@ #include "credresource.h" #include "aclresource.h" #include "ownershiptransfermanager.h" +#include "secureresourceprovider.h" #include "securevirtualresourcetypes.h" #include "oxmjustworks.h" #include "oxmrandompin.h" @@ -100,7 +101,7 @@ OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks) OIC_LOG(INFO, TAG, "IN OTMSetOTCallback"); - VERIFY_NON_NULL(TAG, callbacks, ERROR); + VERIFY_NOT_NULL(TAG, callbacks, ERROR); #ifdef MULTIPLE_OWNER VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > oxm || OIC_PRECONFIG_PIN == oxm || OIC_MV_JUST_WORKS == oxm @@ -757,17 +758,17 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo) SYMMETRIC_PAIR_WISE_KEY, NULL, &ownerKey, &ownerDeviceID, NULL); OICClearMemory(ownerPSK, sizeof(ownerPSK)); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); - uint32_t outSize = 0; + size_t outSize = 0; size_t b64BufSize = B64ENCODE_OUT_SAFESIZE((OWNER_PSK_LENGTH_128 + 1)); char* b64Buf = (char *)OICCalloc(1, b64BufSize); - VERIFY_NON_NULL(TAG, b64Buf, ERROR); + VERIFY_NOT_NULL(TAG, b64Buf, ERROR); b64Encode(cred->privateData.data, cred->privateData.len, b64Buf, b64BufSize, &outSize); OICFree( cred->privateData.data ); cred->privateData.data = (uint8_t *)OICCalloc(1, outSize + 1); - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); strncpy((char*)(cred->privateData.data), b64Buf, outSize); cred->privateData.data[outSize] = '\0'; @@ -841,8 +842,8 @@ static OCStackApplicationResult OwnerTransferModeHandler(void *ctx, OCDoHandle U { OIC_LOG(DEBUG, TAG, "IN OwnerTransferModeHandler"); - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OTMContext_t* otmCtx = (OTMContext_t*)ctx; otmCtx->ocDoHandle = NULL; @@ -885,8 +886,8 @@ static OCStackApplicationResult ListMethodsHandler(void *ctx, OCDoHandle UNUSED, { OIC_LOG(DEBUG, TAG, "IN ListMethodsHandler"); - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OTMContext_t* otmCtx = (OTMContext_t*)ctx; otmCtx->ocDoHandle = NULL; @@ -960,8 +961,8 @@ exit: static OCStackApplicationResult OwnerUuidUpdateHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OIC_LOG(DEBUG, TAG, "IN OwnerUuidUpdateHandler"); (void)UNUSED; @@ -1032,8 +1033,8 @@ static OCStackApplicationResult OperationModeUpdateHandler(void *ctx, OCDoHandle { OIC_LOG(DEBUG, TAG, "IN OperationModeUpdateHandler"); - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OTMContext_t* otmCtx = (OTMContext_t*)ctx; otmCtx->ocDoHandle = NULL; @@ -1101,8 +1102,8 @@ exit: static OCStackApplicationResult OwnerCredentialHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OIC_LOG(DEBUG, TAG, "IN OwnerCredentialHandler"); (void)UNUSED; @@ -1195,8 +1196,8 @@ exit: static OCStackApplicationResult OwnerAclHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OIC_LOG(DEBUG, TAG, "IN OwnerAclHandler"); (void)UNUSED; @@ -1243,8 +1244,8 @@ exit: static OCStackApplicationResult OwnershipInformationHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL(TAG, clientResponse, WARNING); - VERIFY_NON_NULL(TAG, ctx, WARNING); + VERIFY_NOT_NULL(TAG, clientResponse, WARNING); + VERIFY_NOT_NULL(TAG, ctx, WARNING); OIC_LOG(DEBUG, TAG, "IN OwnershipInformationHandler"); (void)UNUSED; @@ -1294,8 +1295,8 @@ static OCStackApplicationResult ProvisioningStatusHandler(void *ctx, OCDoHandle { OIC_LOG_V(INFO, TAG, "IN ProvisioningStatusHandler."); - VERIFY_NON_NULL(TAG, clientResponse, ERROR); - VERIFY_NON_NULL(TAG, ctx, ERROR); + VERIFY_NOT_NULL(TAG, clientResponse, ERROR); + VERIFY_NOT_NULL(TAG, ctx, ERROR); OTMContext_t* otmCtx = (OTMContext_t*) ctx; otmCtx->ocDoHandle = NULL; @@ -1342,8 +1343,8 @@ static OCStackApplicationResult ReadyForNomalStatusHandler(void *ctx, OCDoHandle { OIC_LOG_V(INFO, TAG, "IN ReadyForNomalStatusHandler."); - VERIFY_NON_NULL(TAG, clientResponse, ERROR); - VERIFY_NON_NULL(TAG, ctx, ERROR); + VERIFY_NOT_NULL(TAG, clientResponse, ERROR); + VERIFY_NOT_NULL(TAG, ctx, ERROR); OTMContext_t* otmCtx = (OTMContext_t*) ctx; otmCtx->ocDoHandle = NULL; @@ -1898,8 +1899,8 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte OIC_LOG(INFO, TAG, "IN StartOwnershipTransfer"); OCStackResult res = OC_STACK_INVALID_PARAM; - VERIFY_NON_NULL(TAG, selectedDevice, ERROR); - VERIFY_NON_NULL(TAG, selectedDevice->doxm, ERROR); + VERIFY_NOT_NULL(TAG, selectedDevice, ERROR); + VERIFY_NOT_NULL(TAG, selectedDevice->doxm, ERROR); OTMContext_t* otmCtx = (OTMContext_t*)ctx; otmCtx->selectedDeviceInfo = selectedDevice; diff --git a/resource/csdk/security/provisioning/src/oxmpreconfpin.c b/resource/csdk/security/provisioning/src/oxmpreconfpin.c index 723c5e9..05b8064 100644 --- a/resource/csdk/security/provisioning/src/oxmpreconfpin.c +++ b/resource/csdk/security/provisioning/src/oxmpreconfpin.c @@ -28,6 +28,7 @@ #include "cainterface.h" #include "ocrandom.h" #include "oic_malloc.h" +#include "oic_string.h" #include "logger.h" #include "pbkdf2.h" #include "global.h" @@ -102,7 +103,7 @@ OCStackResult LoadPreconfigPinCodeCallback(OTMContext_t *otmCtx) OIC_LOG(ERROR, TAG, "Failed to memory allocation."); return OC_STACK_NO_MEMORY; } - uint32_t pinLen = 0; + size_t pinLen = 0; if(B64_OK != b64Decode(cred->privateData.data, cred->privateData.len, pinBuffer, pinBufLen, &pinLen)) { OIC_LOG(ERROR, TAG, "Failed to base64 deconding for preconfig PIN"); diff --git a/resource/csdk/security/provisioning/src/pmutility.c b/resource/csdk/security/provisioning/src/pmutility.c index e310ba1..1cdd369 100644 --- a/resource/csdk/security/provisioning/src/pmutility.c +++ b/resource/csdk/security/provisioning/src/pmutility.c @@ -48,7 +48,7 @@ #include "srmutility.h" -static const uint64_t USECS_PER_MSEC = 1000; +static const unsigned int USECS_PER_MSEC = 1000; #define TAG ("OIC_PM_UTILITY") @@ -334,14 +334,14 @@ OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src) // TODO: Consider use VERIFY_NON_NULL instead of if ( null check ) { goto exit; } OCProvisionDev_t* newDev = (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t)); - VERIFY_NON_NULL(TAG, newDev, ERROR); + VERIFY_NOT_NULL(TAG, newDev, ERROR); memcpy(&newDev->endpoint, &src->endpoint, sizeof(OCDevAddr)); if (src->pstat) { newDev->pstat= (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t)); - VERIFY_NON_NULL(TAG, newDev->pstat, ERROR); + VERIFY_NOT_NULL(TAG, newDev->pstat, ERROR); memcpy(newDev->pstat, src->pstat, sizeof(OicSecPstat_t)); // We have to assign NULL for not necessary information to prevent memory corruption. @@ -351,7 +351,7 @@ OCProvisionDev_t* PMCloneOCProvisionDev(const OCProvisionDev_t* src) if (src->doxm) { newDev->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t)); - VERIFY_NON_NULL(TAG, newDev->doxm, ERROR); + VERIFY_NOT_NULL(TAG, newDev->doxm, ERROR); memcpy(newDev->doxm, src->doxm, sizeof(OicSecDoxm_t)); // We have to assign NULL for not necessary information to prevent memory corruption. diff --git a/resource/csdk/security/provisioning/src/provisioningdatabasemanager.c b/resource/csdk/security/provisioning/src/provisioningdatabasemanager.c index 68c8ece..51e0b4d 100644 --- a/resource/csdk/security/provisioning/src/provisioningdatabasemanager.c +++ b/resource/csdk/security/provisioning/src/provisioningdatabasemanager.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "sqlite3.h" #include "logger.h" @@ -59,24 +60,76 @@ #define PDM_SQLITE_TRANSACTION_BEGIN "BEGIN TRANSACTION;" #define PDM_SQLITE_TRANSACTION_COMMIT "COMMIT;" #define PDM_SQLITE_TRANSACTION_ROLLBACK "ROLLBACK;" + +#ifdef __GNUC__ +#if ((__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)) +#define static_assert(value, message) _Static_assert((value) ? 1 : 0, message) +#else +#define static_assert(value, message) +#endif +#endif +#define PDM_VERIFY_STATEMENT_SIZE(stmt) \ + static_assert(sizeof(stmt) < INT_MAX, #stmt " must be shorter than INT_MAX.") + #define PDM_SQLITE_GET_STALE_INFO "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE STATE = ?" +#define PDM_SQLITE_GET_STALE_INFO_SIZE (int)sizeof(PDM_SQLITE_GET_STALE_INFO) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_STALE_INFO); + #define PDM_SQLITE_INSERT_T_DEVICE_LIST "INSERT INTO T_DEVICE_LIST VALUES(?,?,?)" +#define PDM_SQLITE_INSERT_T_DEVICE_LIST_SIZE (int)sizeof(PDM_SQLITE_INSERT_T_DEVICE_LIST) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_INSERT_T_DEVICE_LIST); + #define PDM_SQLITE_GET_ID "SELECT ID FROM T_DEVICE_LIST WHERE UUID like ?" +#define PDM_SQLITE_GET_ID_SIZE (int)sizeof(PDM_SQLITE_GET_ID) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_ID); + #define PDM_SQLITE_INSERT_LINK_DATA "INSERT INTO T_DEVICE_LINK_STATE VALUES(?,?,?)" +#define PDM_SQLITE_INSERT_LINK_DATA_SIZE (int)sizeof(PDM_SQLITE_INSERT_LINK_DATA) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_INSERT_LINK_DATA); + #define PDM_SQLITE_DELETE_LINK "DELETE FROM T_DEVICE_LINK_STATE WHERE ID = ? and ID2 = ?" -#define PDM_SQLITE_DELETE_DEVICE_LINK "DELETE FROM T_DEVICE_LINK_STATE WHERE ID = ? or ID2 = ?" +#define PDM_SQLITE_DELETE_LINK_SIZE (int)sizeof(PDM_SQLITE_DELETE_LINK) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_DELETE_LINK); + #define PDM_SQLITE_DELETE_DEVICE "DELETE FROM T_DEVICE_LIST WHERE ID = ?" +#define PDM_SQLITE_DELETE_DEVICE_SIZE (int)sizeof(PDM_SQLITE_DELETE_DEVICE) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_DELETE_DEVICE); + #define PDM_SQLITE_UPDATE_LINK "UPDATE T_DEVICE_LINK_STATE SET STATE = ? WHERE ID = ? and ID2 = ?" +#define PDM_SQLITE_UPDATE_LINK_SIZE (int)sizeof(PDM_SQLITE_UPDATE_LINK) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_UPDATE_LINK); + #define PDM_SQLITE_LIST_ALL_UUID "SELECT UUID FROM T_DEVICE_LIST WHERE STATE = 0" +#define PDM_SQLITE_LIST_ALL_UUID_SIZE (int)sizeof(PDM_SQLITE_LIST_ALL_UUID) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_LIST_ALL_UUID); + #define PDM_SQLITE_GET_UUID "SELECT UUID,STATE FROM T_DEVICE_LIST WHERE ID = ?" +#define PDM_SQLITE_GET_UUID_SIZE (int)sizeof(PDM_SQLITE_GET_UUID) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_UUID); + #define PDM_SQLITE_GET_LINKED_DEVICES "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE \ (ID = ? or ID2 = ?) and state = 0" +#define PDM_SQLITE_GET_LINKED_DEVICES_SIZE (int)sizeof(PDM_SQLITE_GET_LINKED_DEVICES) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_LINKED_DEVICES); + #define PDM_SQLITE_GET_DEVICE_LINKS "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE \ ID = ? and ID2 = ? and state = 0" +#define PDM_SQLITE_GET_DEVICE_LINKS_SIZE (int)sizeof(PDM_SQLITE_GET_DEVICE_LINKS) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_DEVICE_LINKS); + #define PDM_SQLITE_UPDATE_DEVICE "UPDATE T_DEVICE_LIST SET STATE = ? WHERE UUID like ?" +#define PDM_SQLITE_UPDATE_DEVICE_SIZE (int)sizeof(PDM_SQLITE_UPDATE_DEVICE) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_UPDATE_DEVICE); + #define PDM_SQLITE_GET_DEVICE_STATUS "SELECT STATE FROM T_DEVICE_LIST WHERE UUID like ?" +#define PDM_SQLITE_GET_DEVICE_STATUS_SIZE (int)sizeof(PDM_SQLITE_GET_DEVICE_STATUS) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_GET_DEVICE_STATUS); + #define PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE "UPDATE T_DEVICE_LINK_STATE SET STATE = 1\ WHERE ID = ? or ID2 = ?" +#define PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE_SIZE (int)sizeof(PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE) +PDM_VERIFY_STATEMENT_SIZE(PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE); + #define ASCENDING_ORDER(id1, id2) do{if( (id1) > (id2) )\ { int temp; temp = id1; id1 = id2; id2 = temp; }}while(0) @@ -194,7 +247,7 @@ OCStackResult PDMAddDevice(const OicUuid_t *UUID) sqlite3_stmt *stmt = 0; int res =0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_INSERT_T_DEVICE_LIST, - strlen(PDM_SQLITE_INSERT_T_DEVICE_LIST) + 1, &stmt, NULL); + PDM_SQLITE_INSERT_T_DEVICE_LIST_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_SECOND, UUID, UUID_LENGTH, SQLITE_STATIC); @@ -228,7 +281,8 @@ static OCStackResult getIdForUUID(const OicUuid_t *UUID , int *id) { sqlite3_stmt *stmt = 0; int res = 0; - res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, strlen(PDM_SQLITE_GET_ID) + 1, &stmt, NULL); + res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, PDM_SQLITE_GET_ID_SIZE, + &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_FIRST, UUID, UUID_LENGTH, SQLITE_STATIC); @@ -261,7 +315,8 @@ OCStackResult PDMIsDuplicateDevice(const OicUuid_t* UUID, bool *result) } sqlite3_stmt *stmt = 0; int res = 0; - res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, strlen(PDM_SQLITE_GET_ID) + 1, &stmt, NULL); + res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, PDM_SQLITE_GET_ID_SIZE, + &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_FIRST, UUID, UUID_LENGTH, SQLITE_STATIC); @@ -288,7 +343,7 @@ static OCStackResult addlink(int id1, int id2) sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_INSERT_LINK_DATA, - strlen(PDM_SQLITE_INSERT_LINK_DATA) + 1, &stmt, NULL); + PDM_SQLITE_INSERT_LINK_DATA_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1); @@ -367,7 +422,8 @@ static OCStackResult removeLink(int id1, int id2) { int res = 0; sqlite3_stmt *stmt = 0; - res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_LINK, strlen(PDM_SQLITE_DELETE_LINK) + 1, &stmt, NULL); + res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_LINK, + PDM_SQLITE_DELETE_LINK_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1); @@ -417,7 +473,7 @@ static OCStackResult removeFromDeviceList(int id) sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_DEVICE, - strlen(PDM_SQLITE_DELETE_DEVICE) + 1, &stmt, NULL); + PDM_SQLITE_DELETE_DEVICE_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id); @@ -463,7 +519,7 @@ static OCStackResult updateLinkState(int id1, int id2, int state) sqlite3_stmt *stmt = 0; int res = 0 ; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_UPDATE_LINK, - strlen(PDM_SQLITE_UPDATE_LINK) + 1, &stmt, NULL); + PDM_SQLITE_UPDATE_LINK_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, state); @@ -522,7 +578,7 @@ OCStackResult PDMGetOwnedDevices(OCUuidList_t **uuidList, size_t *numOfDevices) sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_LIST_ALL_UUID, - strlen(PDM_SQLITE_LIST_ALL_UUID) + 1, &stmt, NULL); + PDM_SQLITE_LIST_ALL_UUID_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); size_t counter = 0; @@ -551,7 +607,7 @@ static OCStackResult getUUIDforId(int id, OicUuid_t *uid, bool *result) sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_UUID, - strlen(PDM_SQLITE_GET_UUID) + 1, &stmt, NULL); + PDM_SQLITE_GET_UUID_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id); @@ -619,7 +675,7 @@ OCStackResult PDMGetLinkedDevices(const OicUuid_t *UUID, OCUuidList_t **UUIDLIST sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_LINKED_DEVICES, - strlen(PDM_SQLITE_GET_LINKED_DEVICES) + 1, &stmt, NULL); + PDM_SQLITE_GET_LINKED_DEVICES_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id); @@ -672,7 +728,7 @@ OCStackResult PDMGetToBeUnlinkedDevices(OCPairList_t **staleDevList, size_t *num sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_STALE_INFO, - strlen(PDM_SQLITE_GET_STALE_INFO) + 1, &stmt, NULL); + PDM_SQLITE_GET_STALE_INFO_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, PDM_DEVICE_STALE); @@ -791,7 +847,7 @@ OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* u sqlite3_stmt *stmt = 0; int res = 0; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_DEVICE_LINKS, - strlen(PDM_SQLITE_GET_DEVICE_LINKS) + 1, &stmt, NULL); + PDM_SQLITE_GET_DEVICE_LINKS_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1); @@ -816,7 +872,7 @@ static OCStackResult updateDeviceState(const OicUuid_t *uuid, PdmDeviceState_t s sqlite3_stmt *stmt = 0; int res = 0 ; res = sqlite3_prepare_v2(g_db, PDM_SQLITE_UPDATE_DEVICE, - strlen(PDM_SQLITE_UPDATE_DEVICE) + 1, &stmt, NULL); + PDM_SQLITE_UPDATE_DEVICE_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, state); @@ -848,7 +904,7 @@ static OCStackResult updateLinkForStaleDevice(const OicUuid_t *devUuid) } res = sqlite3_prepare_v2(g_db, PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE, - strlen(PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE) + 1, + PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); @@ -912,7 +968,7 @@ OCStackResult PDMGetDeviceState(const OicUuid_t *uuid, PdmDeviceState_t* result) sqlite3_stmt *stmt = 0; int res = 0; - res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_DEVICE_STATUS, strlen(PDM_SQLITE_GET_DEVICE_STATUS) + 1, + res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_DEVICE_STATUS, PDM_SQLITE_GET_DEVICE_STATUS_SIZE, &stmt, NULL); PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR); diff --git a/resource/csdk/security/provisioning/src/secureresourceprovider.c b/resource/csdk/security/provisioning/src/secureresourceprovider.c index 5476179..8c6f3f3 100644 --- a/resource/csdk/security/provisioning/src/secureresourceprovider.c +++ b/resource/csdk/security/provisioning/src/secureresourceprovider.c @@ -37,6 +37,7 @@ #include "pconfresource.h" #include "credentialgenerator.h" #include "cainterface.h" +#include "oic_string.h" #include "pmtypes.h" #include "pmutility.h" #include "srmutility.h" @@ -44,6 +45,7 @@ #include "base64.h" #include "utlist.h" #include "ocpayload.h" +#include "srmutility.h" #ifdef __WITH_DTLS__ #include "crlresource.h" @@ -51,21 +53,6 @@ #define TAG "OIC_SRPAPI" -/** - * Macro to verify argument is not equal to NULL. - * eg: VERIFY_NON_NULL_RET(TAG, ptrData, ERROR,OC_STACK_ERROR); - */ -#define VERIFY_NON_NULL_RET(tag, arg, logLevel, retValue) { if (NULL == (arg)) \ - { OIC_LOG((logLevel), tag, #arg " is NULL"); return retValue; } } - -/** - * Macro to verify success of operation. - * eg: VERIFY_SUCCESS_RET(TAG, OC_STACK_OK == foo(), ERROR, OC_STACK_ERROR); - */ -#define VERIFY_SUCCESS_RET(tag, op, logLevel, retValue) { if (!(op)) \ - {OIC_LOG((logLevel), tag, #op " failed!!"); return retValue;} } - - trustCertChainContext_t g_trustCertChainNotifier; /** @@ -161,7 +148,6 @@ static OCStackResult provisionCredentials(const OicSecCred_t *cred, const OCProvisionDev_t *deviceInfo, CredentialData_t *credData, OCClientResponseHandler responseHandler); - /** * Internal function to update result in result array. */ @@ -196,7 +182,7 @@ static void registerResultForCredProvisioning(CredentialData_t *credData, static OCStackApplicationResult provisionCredentialCB2(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); CredentialData_t *credData = (CredentialData_t *) ctx; (void)UNUSED; @@ -247,7 +233,7 @@ static OCStackApplicationResult provisionCredentialCB2(void *ctx, OCDoHandle UNU static OCStackApplicationResult provisionCredentialCB1(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); (void)UNUSED; CredentialData_t* credData = (CredentialData_t*) ctx; OICFree(credData->credInfoFirst); @@ -301,7 +287,6 @@ static OCStackApplicationResult provisionCredentialCB1(void *ctx, OCDoHandle UNU } - /** * Internal function for handling credential generation and sending credential to resource server. * @@ -425,7 +410,7 @@ void SRPRemoveTrustCertChainNotifier() static OCStackApplicationResult provisionCertCB(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); CertData_t *certData = (CertData_t *) ctx; (void)UNUSED; @@ -459,8 +444,8 @@ OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint1 const OCProvisionDev_t *selectedDeviceInfo, OCProvisionResultCB resultCallback) { OIC_LOG(INFO, TAG, "In SRPProvisionTrustCertChain"); - VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); + VERIFY_NOT_NULL_RETURN(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); if (SIGNED_ASYMMETRIC_KEY != type) { OIC_LOG(INFO, TAG, "Invalid key type"); @@ -545,7 +530,7 @@ OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint1 OICFree(certData); } - VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); return OC_STACK_OK; } @@ -553,18 +538,18 @@ OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, OicEncodingType_t encodingType, uint16_t *credId) { OIC_LOG(DEBUG, TAG, "IN SRPSaveTrustCertChain"); - VERIFY_NON_NULL_RET(TAG, trustCertChain, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, credId, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, trustCertChain, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, credId, ERROR, OC_STACK_INVALID_PARAM); OCStackResult res = OC_STACK_ERROR; OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred)); - VERIFY_NON_NULL_RET(TAG, cred, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred, ERROR, OC_STACK_NO_MEMORY); memcpy(cred->subject.id, &WILDCARD_SUBJECT_ID, WILDCARD_SUBJECT_ID_LEN); cred->credUsage= (char *)OICCalloc(1, strlen(TRUST_CA)+1 ); - VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY); OICStrcpy(cred->credUsage, strlen(TRUST_CA) + 1, TRUST_CA); cred->credType = SIGNED_ASYMMETRIC_KEY; @@ -572,13 +557,13 @@ OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, if (encodingType == OIC_ENCODING_PEM) { cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize + 1); - VERIFY_NON_NULL_RET(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY); cred->optionalData.len = chainSize + 1; } else { cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize); - VERIFY_NON_NULL_RET(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY); cred->optionalData.len = chainSize; } memcpy(cred->optionalData.data, trustCertChain, chainSize); @@ -596,7 +581,7 @@ OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, if (g_trustCertChainNotifier.callback) { uint8_t *certChain = (uint8_t*)OICCalloc(1, sizeof(uint8_t) * chainSize); - VERIFY_NON_NULL_RET(TAG, certChain, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, certChain, ERROR, OC_STACK_NO_MEMORY); memcpy(certChain, trustCertChain, chainSize); g_trustCertChainNotifier.callback(g_trustCertChainNotifier.context, *credId, certChain, chainSize); @@ -608,20 +593,19 @@ OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize, return res; } - OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_t *credId) { OIC_LOG_V(DEBUG, TAG, "In %s", __func__); - VERIFY_NON_NULL_RET(TAG, cert, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, cert->data, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, key, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, key->data, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, credId, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, cert, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, cert->data, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, key, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, key->data, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, credId, ERROR, OC_STACK_INVALID_PARAM); OCStackResult res = OC_STACK_ERROR; OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred)); - VERIFY_NON_NULL_RET(TAG, cred, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred, ERROR, OC_STACK_NO_MEMORY); OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__); @@ -631,21 +615,21 @@ OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_ } cred->credUsage= (char *)OICCalloc(1, strlen(PRIMARY_CERT)+1 ); - VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY); OICStrcpy(cred->credUsage, strlen(PRIMARY_CERT) + 1, PRIMARY_CERT) ; cred->credType = SIGNED_ASYMMETRIC_KEY; OicSecKey_t *publicData = &cred->publicData; publicData->data = (uint8_t *)OICCalloc(1, cert->len); - VERIFY_NON_NULL_RET(TAG, publicData->data, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, publicData->data, ERROR, OC_STACK_NO_MEMORY); memcpy(publicData->data, cert->data, cert->len); publicData->len = cert->len; publicData->encoding = cert->encoding; OicSecKey_t *privateData = &cred->privateData; privateData->data = (uint8_t *)OICCalloc(1, key->len); - VERIFY_NON_NULL_RET(TAG, privateData->data, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, privateData->data, ERROR, OC_STACK_NO_MEMORY); memcpy(privateData->data, key->data, key->len); privateData->len = key->len; privateData->encoding = key->encoding; @@ -669,10 +653,10 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k const OCProvisionDev_t *pDev2, OCProvisionResultCB resultCallback) { - VERIFY_NON_NULL_RET(TAG, pDev1, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, pDev1, ERROR, OC_STACK_INVALID_PARAM); if (SYMMETRIC_PAIR_WISE_KEY == type) { - VERIFY_NON_NULL_RET(TAG, pDev2, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, pDev2, ERROR, OC_STACK_INVALID_PARAM); } if (!resultCallback) { @@ -731,7 +715,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k OCStackResult res = PMGeneratePairWiseCredentials(type, keySize, &provTooldeviceID, &firstDevice->doxm->deviceID, &secondDevice->doxm->deviceID, &firstCred, &secondCred); - VERIFY_SUCCESS_RET(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR); OIC_LOG(INFO, TAG, "Credentials generated successfully"); CredentialData_t *credData = (CredentialData_t *) OICCalloc(1, sizeof(CredentialData_t)); @@ -771,7 +755,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k OICFree(credData); } OIC_LOG_V(INFO, TAG, "provisionCredentials returned: %d",res); - VERIFY_SUCCESS_RET(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR); return res; } default: @@ -811,7 +795,7 @@ static OCStackApplicationResult SRPProvisionACLCB(void *ctx, OCDoHandle UNUSED, { OIC_LOG_V(INFO, TAG, "Inside SRPProvisionACLCB."); (void)UNUSED; - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); ACLData_t *aclData = (ACLData_t*)ctx; OCProvisionResultCB resultCallback = aclData->resultCallback; @@ -841,9 +825,9 @@ static OCStackApplicationResult SRPProvisionACLCB(void *ctx, OCDoHandle UNUSED, OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl, OCProvisionResultCB resultCallback) { - VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, acl, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); + VERIFY_NOT_NULL_RETURN(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, acl, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); // if rowneruuid is empty, set it to device ID OicUuid_t emptyOwner = {.id = {0} }; @@ -928,14 +912,14 @@ OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceI OICFree(aclData->resArr); OICFree(aclData); } - VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); return OC_STACK_OK; } OCStackResult SRPSaveACL(const OicSecAcl_t *acl) { OIC_LOG(DEBUG, TAG, "IN SRPSaveACL"); - VERIFY_NON_NULL_RET(TAG, acl, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, acl, ERROR, OC_STACK_INVALID_PARAM); OCStackResult res = InstallACL(acl); @@ -971,7 +955,7 @@ static OCStackApplicationResult SRPProvisionDirectPairingCB(void *ctx, OCDoHandl { OIC_LOG_V(INFO, TAG, "Inside SRPProvisionDirectPairingCB."); (void)UNUSED; - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); PconfData_t *pconfData = (PconfData_t*)ctx; OCProvisionResultCB resultCallback = pconfData->resultCallback; @@ -1001,9 +985,9 @@ static OCStackApplicationResult SRPProvisionDirectPairingCB(void *ctx, OCDoHandl OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf, OCProvisionResultCB resultCallback) { - VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, pconf, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); + VERIFY_NOT_NULL_RETURN(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, pconf, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); // check direct-pairing capability if (true != selectedDeviceInfo->doxm->dpc) @@ -1038,7 +1022,6 @@ OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selec OIC_LOG(DEBUG, TAG, "Created payload for pconf set"); OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize); - char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0}; if(!PMGenerateQuery(true, selectedDeviceInfo->endpoint.addr, @@ -1087,7 +1070,7 @@ OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selec OICFree(pconfData->resArr); OICFree(pconfData); } - VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); return OC_STACK_OK; } @@ -1233,7 +1216,6 @@ static OCStackResult SendDeleteACLRequest(void* ctx, return OC_STACK_ERROR; } - char reqBuf[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0}; int snRet = 0; //coaps://0.0.0.0:5684/oic/sec/acl?subjectuuid=(Canonical ENCODED UUID) @@ -1286,7 +1268,7 @@ static OCStackApplicationResult SRPUnlinkDevice2CB(void *unlinkCtx, OCDoHandle h { (void) handle; OIC_LOG(DEBUG, TAG, "IN SRPUnlinkDevice2CB"); - VERIFY_NON_NULL_RET(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION); UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx; if (clientResponse) @@ -1349,7 +1331,7 @@ static OCStackApplicationResult SRPUnlinkDevice1CB(void *unlinkCtx, OCDoHandle h OCClientResponse *clientResponse) { OIC_LOG_V(INFO, TAG, "Inside SRPUnlinkDevice1CB "); - VERIFY_NON_NULL_RET(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION); UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx; (void) handle; @@ -1455,7 +1437,7 @@ OCStackResult SRPUnlinkDevices(void* ctx, } UnlinkData_t* unlinkData = (UnlinkData_t*)OICCalloc(1, sizeof(UnlinkData_t)); - VERIFY_NON_NULL_RET(TAG, unlinkData, ERROR, OC_STACK_NO_MEMORY); + VERIFY_NOT_NULL_RETURN(TAG, unlinkData, ERROR, OC_STACK_NO_MEMORY); //Initialize unlink data unlinkData->ctx = ctx; @@ -1589,7 +1571,7 @@ static OCStackApplicationResult SRPRemoveDeviceCB(void *delDevCtx, OCDoHandle ha //Save the deleted status in delDevCtx (void)handle; OIC_LOG_V(INFO, TAG, "Inside SRPRemoveDeviceCB."); - VERIFY_NON_NULL_RET(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION); OCStackResult res = OC_STACK_ERROR; RemoveData_t* removeData = (RemoveData_t*)delDevCtx; @@ -1648,7 +1630,6 @@ static OCStackApplicationResult SRPRemoveDeviceCB(void *delDevCtx, OCDoHandle ha OIC_LOG(ERROR, TAG, "SRPRemoveDevices received Null clientResponse"); } - return OC_STACK_DELETE_TRANSACTION; } @@ -1668,7 +1649,7 @@ static OCStackApplicationResult SRPSyncDeviceCredCB(void *delDevCtx, OCDoHandle //Save the deleted status in delDevCtx (void)handle; OIC_LOG_V(INFO, TAG, "Inside SRPSyncDeviceCredCB."); - VERIFY_NON_NULL_RET(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION); OCStackResult res = OC_STACK_ERROR; RemoveData_t* removeData = (RemoveData_t*)delDevCtx; @@ -2459,7 +2440,7 @@ static OCStackApplicationResult SRPGetCredResourceCB(void *ctx, OCDoHandle UNUSE { OIC_LOG_V(INFO, TAG, "Inside SRPGetCredResourceCB."); (void)UNUSED; - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); GetSecData_t *GetSecData = (GetSecData_t*)ctx; OCProvisionResultCB resultCallback = GetSecData->resultCallback; @@ -2495,12 +2476,11 @@ static OCStackApplicationResult SRPGetCredResourceCB(void *ctx, OCDoHandle UNUSE return OC_STACK_DELETE_TRANSACTION; } - OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OCProvisionResultCB resultCallback) { - VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); + VERIFY_NOT_NULL_RETURN(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0}; if(!PMGenerateQuery(true, @@ -2548,7 +2528,7 @@ OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDevi OICFree(GetSecData->resArr); OICFree(GetSecData); } - VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); OIC_LOG(DEBUG, TAG, "OUT SRPGetCredResource"); return OC_STACK_OK; @@ -2582,7 +2562,7 @@ static OCStackApplicationResult SRPGetACLResourceCB(void *ctx, OCDoHandle UNUSED { OIC_LOG_V(INFO, TAG, "Inside SRPGetACLResourceCB."); (void)UNUSED; - VERIFY_NON_NULL_RET(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); + VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION); GetSecData_t *GetSecData = (GetSecData_t*)ctx; OCProvisionResultCB resultCallback = GetSecData->resultCallback; @@ -2618,12 +2598,11 @@ static OCStackApplicationResult SRPGetACLResourceCB(void *ctx, OCDoHandle UNUSED return OC_STACK_DELETE_TRANSACTION; } - OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OCProvisionResultCB resultCallback) { - VERIFY_NON_NULL_RET(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); - VERIFY_NON_NULL_RET(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); + VERIFY_NOT_NULL_RETURN(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM); + VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK); char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0}; if(!PMGenerateQuery(true, @@ -2671,7 +2650,7 @@ OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDevic OICFree(GetSecData->resArr); OICFree(GetSecData); } - VERIFY_SUCCESS_RET(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); + VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR); OIC_LOG(DEBUG, TAG, "OUT SRPGetACLResource"); return OC_STACK_OK; diff --git a/resource/csdk/security/provisioning/unittest/ocprovisioningmanager.cpp b/resource/csdk/security/provisioning/unittest/ocprovisioningmanager.cpp index 9d971c9..e87fad0 100644 --- a/resource/csdk/security/provisioning/unittest/ocprovisioningmanager.cpp +++ b/resource/csdk/security/provisioning/unittest/ocprovisioningmanager.cpp @@ -55,7 +55,7 @@ static OicSecDoxm_t defaultDoxm2 = {{0}}, /* OicUuid_t owner */ }; -static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4) +static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4) { //dummy callback (void) UNUSED1; diff --git a/resource/csdk/security/provisioning/unittest/otmunittest.cpp b/resource/csdk/security/provisioning/unittest/otmunittest.cpp index 83a4d6a..ceff880 100644 --- a/resource/csdk/security/provisioning/unittest/otmunittest.cpp +++ b/resource/csdk/security/provisioning/unittest/otmunittest.cpp @@ -290,11 +290,11 @@ static FILE* fopen_prvnMng(const char* path, const char* mode) } // callback function(s) for provisioning client using C-level provisioning API -static void ownershipTransferCB(void* ctx, int UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError) +static void ownershipTransferCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError) { - (void)UNUSED1; - (void)UNUSED2; - (void)ctx; + OC_UNUSED(UNUSED1); + OC_UNUSED(UNUSED2); + OC_UNUSED(ctx); if(!hasError) { @@ -309,8 +309,10 @@ static void ownershipTransferCB(void* ctx, int UNUSED1, OCProvisionResult_t* UNU } #ifdef MULTIPLE_OWNER -static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { + OC_UNUSED(nOfRes); + if(!hasError) { OIC_LOG_V(INFO, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx); @@ -323,8 +325,10 @@ static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, g_doneCB = true; } -static void provisionPreconfiguredPinCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void provisionPreconfiguredPinCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError) { + OC_UNUSED(nOfRes); + if(!hasError) { OIC_LOG_V(INFO, TAG, "Provision Preconfigured-PIN SUCCEEDED - ctx: %s", (char*) ctx); @@ -339,11 +343,11 @@ static void provisionPreconfiguredPinCB(void* ctx, int nOfRes, OCProvisionResult #endif //MULTIPLE_OWNER // callback function(s) for provisioning client using C-level provisioning API -static void removeDeviceCB(void* ctx, int UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError) +static void removeDeviceCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError) { - (void)UNUSED1; - (void)UNUSED2; - (void)ctx; + OC_UNUSED(UNUSED1); + OC_UNUSED(UNUSED2); + OC_UNUSED(ctx); if(!hasError) { @@ -455,13 +459,13 @@ TEST(InitForOTM, NullParam) { snprintf(server1_path, sizeof(server1_path), "%ssample_server1", cwd); status1 = system(server1_path); - (void)status1; + OC_UNUSED(status1); } if(0 == (g_myPID2 = fork())) { snprintf(server2_path, sizeof(server2_path), "%ssample_server2", cwd); - status2= system(server2_path); - (void)status2; + status2 = system(server2_path); + OC_UNUSED(status2); } //Waiting for sample server initialization. diff --git a/resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp b/resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp index 5bbf811..b457c6d 100644 --- a/resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp +++ b/resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp @@ -21,6 +21,13 @@ #include "gtest/gtest.h" #include "provisioningdatabasemanager.h" +#ifdef _MSC_VER +#include + +#define F_OK 0 +#define access _access_s +#endif + #define DB_FILE "PDM.db" const char ID_1 [] = "1111111111111111"; const char ID_2 [] = "2111111111111111"; @@ -41,7 +48,7 @@ TEST(CallPDMAPIbeforeInit, BeforeInit) { if (0 == access(DB_FILE, F_OK)) { - EXPECT_EQ(0, unlink(DB_FILE)); + EXPECT_EQ(0, remove(DB_FILE)); } EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMAddDevice(NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsDuplicateDevice(NULL,NULL)); diff --git a/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp b/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp index 5a0ef46..045387d 100644 --- a/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp +++ b/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp @@ -57,7 +57,7 @@ static OicSecDoxm_t defaultDoxm2 = {{0}}, /* OicUuid_t owner */ }; -static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4) +static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4) { //dummy callback (void) UNUSED1; @@ -194,7 +194,7 @@ void SetPersistentHandler(OCPersistentStorage *ps) ps->read = fread; ps->write = fwrite; ps->close = fclose; - ps->unlink = unlink; + ps->unlink = remove; } } @@ -298,7 +298,6 @@ TEST_F(SRPTest, SRPSaveTrustCertChainNullCertData) TEST_F(SRPTest, SRPSaveTrustCertChainNullCredId) { int result; - uint16_t credId; result = SRPSaveTrustCertChain(certData, sizeof(certData), OIC_ENCODING_DER, NULL); diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index 7d3ac32..777d706 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -165,7 +165,7 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) if(ace) { newAce = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, newAce, ERROR); + VERIFY_NOT_NULL(TAG, newAce, ERROR); //Subject uuid memcpy(&newAce->subjectuuid, &ace->subjectuuid, sizeof(OicUuid_t)); @@ -174,21 +174,21 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) LL_FOREACH(ace->resources, rsrc) { OicSecRsrc_t* newRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, newRsrc, ERROR); + VERIFY_NOT_NULL(TAG, newRsrc, ERROR); LL_APPEND(newAce->resources, newRsrc); //href is mandatory - VERIFY_NON_NULL(TAG, rsrc->href, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->href, ERROR); allocateSize = strlen(rsrc->href) + 1; newRsrc->href = (char*)OICMalloc(sizeof(char) * allocateSize); - VERIFY_NON_NULL(TAG, newRsrc->href, ERROR); + VERIFY_NOT_NULL(TAG, newRsrc->href, ERROR); OICStrcpy(newRsrc->href, allocateSize, rsrc->href); if(rsrc->rel) { allocateSize = strlen(rsrc->rel) + 1; newRsrc->rel = (char*)OICMalloc(sizeof(char) * allocateSize); - VERIFY_NON_NULL(TAG, newRsrc->rel, ERROR); + VERIFY_NOT_NULL(TAG, newRsrc->rel, ERROR); OICStrcpy(newRsrc->rel, allocateSize, rsrc->rel); } @@ -196,11 +196,11 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) { newRsrc->typeLen = rsrc->typeLen; newRsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, (newRsrc->types), ERROR); + VERIFY_NOT_NULL(TAG, (newRsrc->types), ERROR); for(size_t i = 0; i < rsrc->typeLen; i++) { newRsrc->types[i] = OICStrdup(rsrc->types[i]); - VERIFY_NON_NULL(TAG, (newRsrc->types[i]), ERROR); + VERIFY_NOT_NULL(TAG, (newRsrc->types[i]), ERROR); } } @@ -208,11 +208,11 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) { newRsrc->interfaceLen = rsrc->interfaceLen; newRsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, (newRsrc->interfaces), ERROR); + VERIFY_NOT_NULL(TAG, (newRsrc->interfaces), ERROR); for(size_t i = 0; i < rsrc->interfaceLen; i++) { newRsrc->interfaces[i] = OICStrdup(rsrc->interfaces[i]); - VERIFY_NON_NULL(TAG, (newRsrc->interfaces[i]), ERROR); + VERIFY_NOT_NULL(TAG, (newRsrc->interfaces[i]), ERROR); } } } @@ -227,14 +227,14 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) LL_FOREACH(ace->validities, validity) { OicSecValidity_t* newValidity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - VERIFY_NON_NULL(TAG, newValidity, ERROR); + VERIFY_NOT_NULL(TAG, newValidity, ERROR); LL_APPEND(newAce->validities, newValidity); if(validity->period) { allocateSize = strlen(validity->period) + 1; newValidity->period = (char*)OICMalloc(sizeof(char) * allocateSize); - VERIFY_NON_NULL(TAG, newValidity->period, ERROR); + VERIFY_NOT_NULL(TAG, newValidity->period, ERROR); OICStrcpy(newValidity->period, allocateSize, validity->period); } @@ -243,13 +243,13 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) newValidity->recurrenceLen = validity->recurrenceLen; newValidity->recurrences = (char**)OICMalloc(sizeof(char*) * validity->recurrenceLen); - VERIFY_NON_NULL(TAG, newValidity->recurrences, ERROR); + VERIFY_NOT_NULL(TAG, newValidity->recurrences, ERROR); for(size_t i = 0; i < validity->recurrenceLen; i++) { allocateSize = strlen(validity->recurrences[i]) + 1; newValidity->recurrences[i] = (char*)OICMalloc(sizeof(char) * allocateSize); - VERIFY_NON_NULL(TAG, (newValidity->recurrences[i]), ERROR); + VERIFY_NOT_NULL(TAG, (newValidity->recurrences[i]), ERROR); OICStrcpy(newValidity->recurrences[i], allocateSize, validity->recurrences[i]); } } @@ -262,7 +262,7 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) if (NULL == newAce->eownerID) { newAce->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, (newAce->eownerID), ERROR); + VERIFY_NOT_NULL(TAG, (newAce->eownerID), ERROR); } memcpy(newAce->eownerID->id, ace->eownerID->id, sizeof(ace->eownerID->id)); } @@ -320,7 +320,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz } outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); // Create ACL Map (aclist, rownerid) @@ -428,7 +428,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Map."); //href -- Mandatory - VERIFY_NON_NULL(TAG, rsrc->href, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->href, ERROR); cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_HREF_NAME, strlen(OIC_JSON_HREF_NAME)); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Name Tag."); @@ -724,10 +724,10 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) OicSecAce_t *ace = NULL; ace = (OicSecAce_t *) OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); LL_APPEND(acl->aces, ace); - VERIFY_NON_NULL(TAG, acl, ERROR); + VERIFY_NOT_NULL(TAG, acl, ERROR); while (cbor_value_is_valid(&aceMap)) { @@ -777,7 +777,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map"); OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, rsrc, ERROR); + VERIFY_NOT_NULL(TAG, rsrc, ERROR); LL_APPEND(ace->resources, rsrc); while(cbor_value_is_valid(&rMap)) @@ -804,7 +804,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) VERIFY_SUCCESS(TAG, (0 != rsrc->typeLen), ERROR); rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->types, ERROR); CborValue resourceTypes; cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes); @@ -828,7 +828,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) VERIFY_SUCCESS(TAG, (0 != rsrc->interfaceLen), ERROR); rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->interfaces, ERROR); CborValue interfaces; cborFindResult = cbor_value_enter_container(&rMap, &interfaces); @@ -892,7 +892,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) while(cbor_value_is_valid(&validitiesMap)) { OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - VERIFY_NON_NULL(TAG, validity, ERROR); + VERIFY_NOT_NULL(TAG, validity, ERROR); LL_APPEND(ace->validities, validity); CborValue validityMap = {.parser = NULL}; @@ -913,7 +913,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size) VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Adding Recurrence Array."); validity->recurrences = (char**)OICCalloc(validity->recurrenceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, validity->recurrences, ERROR); + VERIFY_NOT_NULL(TAG, validity->recurrences, ERROR); for(size_t i = 0; cbor_value_is_text_string(&recurrenceMap) && i < validity->recurrenceLen; i++) { @@ -995,7 +995,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) cbor_parser_init(cborPayload, size, 0, &parser, &aclCbor); OicSecAcl_t *acl = (OicSecAcl_t *) OICCalloc(1, sizeof(OicSecAcl_t)); - VERIFY_NON_NULL(TAG, acl, ERROR); + VERIFY_NOT_NULL(TAG, acl, ERROR); // Enter ACL Map cborFindResult = cbor_value_enter_container(&aclCbor, &aclMap); @@ -1054,7 +1054,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) OicSecAce_t *ace = NULL; ace = (OicSecAce_t *) OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); LL_APPEND(acl->aces, ace); while (cbor_value_is_valid(&aceMap)) @@ -1104,7 +1104,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map"); OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, rsrc, ERROR); + VERIFY_NOT_NULL(TAG, rsrc, ERROR); LL_APPEND(ace->resources, rsrc); while(cbor_value_is_valid(&rMap)) @@ -1131,7 +1131,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) VERIFY_SUCCESS(TAG, (0 != rsrc->typeLen), ERROR); rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->types, ERROR); CborValue resourceTypes; cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes); @@ -1154,7 +1154,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) VERIFY_SUCCESS(TAG, (0 != rsrc->interfaceLen), ERROR); rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->interfaces, ERROR); CborValue interfaces; cborFindResult = cbor_value_enter_container(&rMap, &interfaces); @@ -1217,7 +1217,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) while(cbor_value_is_valid(&validitiesMap)) { OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - VERIFY_NON_NULL(TAG, validity, ERROR); + VERIFY_NOT_NULL(TAG, validity, ERROR); LL_APPEND(ace->validities, validity); CborValue validityMap = {.parser = NULL}; @@ -1238,7 +1238,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Adding Recurrence Array."); validity->recurrences = (char**)OICCalloc(validity->recurrenceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, validity->recurrences, ERROR); + VERIFY_NOT_NULL(TAG, validity->recurrences, ERROR); for(size_t i = 0; cbor_value_is_text_string(&recurrenceMap) && i < validity->recurrenceLen; i++) { @@ -1264,7 +1264,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) if(NULL == ace->eownerID) { ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, ace->eownerID, ERROR); + VERIFY_NOT_NULL(TAG, ace->eownerID, ERROR); } ret = ConvertStrToUuid(eowner, ace->eownerID); OICFree(eowner); @@ -1339,12 +1339,12 @@ bool IsValidAclAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPaylo bool retValue = false; OicSecAcl_t* acl = NULL; - VERIFY_NON_NULL(TAG, uuid, ERROR); - VERIFY_NON_NULL(TAG, cborPayload, ERROR); + VERIFY_NOT_NULL(TAG, uuid, ERROR); + VERIFY_NOT_NULL(TAG, cborPayload, ERROR); VERIFY_SUCCESS(TAG, 0 != size, ERROR); acl = CBORPayloadToAcl(cborPayload, size); - VERIFY_NON_NULL(TAG, acl, ERROR); + VERIFY_NOT_NULL(TAG, acl, ERROR); OicSecAce_t* ace = NULL; OicSecAce_t* tempAce = NULL; @@ -1353,7 +1353,7 @@ bool IsValidAclAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPaylo OicSecRsrc_t* rsrc = NULL; OicSecRsrc_t* tempRsrc = NULL; - VERIFY_NON_NULL(TAG, ace->eownerID, ERROR); + VERIFY_NOT_NULL(TAG, ace->eownerID, ERROR); VERIFY_SUCCESS(TAG, memcmp(ace->eownerID->id, uuid->id, sizeof(uuid->id)) == 0, ERROR); LL_FOREACH_SAFE(ace->resources, rsrc, tempRsrc) @@ -2021,7 +2021,7 @@ static OCEntityHandlerResult HandleACLDeleteRequest(const OCEntityHandlerRequest OicUuid_t subject = { .id= { 0 } }; char resource[MAX_URI_LENGTH] = { 0 }; - VERIFY_NON_NULL(TAG, ehRequest->query, ERROR); + VERIFY_NOT_NULL(TAG, ehRequest->query, ERROR); // If 'Subject' field exist, processing a querystring in REST request. if(GetSubjectFromQueryString(ehRequest->query, &subject)) @@ -2148,11 +2148,11 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl) } acl = (OicSecAcl_t *) OICCalloc(1, sizeof(OicSecAcl_t)); - VERIFY_NON_NULL(TAG, acl, ERROR); + VERIFY_NOT_NULL(TAG, acl, ERROR); // Default ACE allowing read-only access, for discovery readOnlyAce = (OicSecAce_t *) OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, readOnlyAce, ERROR); + VERIFY_NOT_NULL(TAG, readOnlyAce, ERROR); // Subject -- Mandatory memcpy(readOnlyAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t)); @@ -2160,60 +2160,60 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl) // Resources -- Mandatory // /oic/res resRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, resRsrc, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc, ERROR); LL_APPEND(readOnlyAce->resources, resRsrc); resRsrc->href = OICStrdup(OC_RSRVD_WELL_KNOWN_URI); - VERIFY_NON_NULL(TAG, (resRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (resRsrc->href), ERROR); resRsrc->typeLen = 1; resRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, resRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->types, ERROR); resRsrc->types[0] = OICStrdup(OC_RSRVD_RESOURCE_TYPE_RES); - VERIFY_NON_NULL(TAG, resRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->types[0], ERROR); resRsrc->interfaceLen = 2; resRsrc->interfaces = (char**)OICCalloc(resRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, resRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces, ERROR); resRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, resRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces[0], ERROR); resRsrc->interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ); - VERIFY_NON_NULL(TAG, resRsrc->interfaces[1], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces[1], ERROR); // /oic/d deviceRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, deviceRsrc, ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc, ERROR); LL_APPEND(readOnlyAce->resources, deviceRsrc); deviceRsrc->href = OICStrdup(OC_RSRVD_DEVICE_URI); - VERIFY_NON_NULL(TAG, (deviceRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (deviceRsrc->href), ERROR); deviceRsrc->typeLen = 1; deviceRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, deviceRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc->types, ERROR); deviceRsrc->types[0] = OICStrdup(OC_RSRVD_RESOURCE_TYPE_DEVICE); - VERIFY_NON_NULL(TAG, deviceRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc->types[0], ERROR); deviceRsrc->interfaceLen = 2; deviceRsrc->interfaces = (char**)OICCalloc(deviceRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, deviceRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc->interfaces, ERROR); deviceRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, deviceRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc->interfaces[0], ERROR); deviceRsrc->interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ); - VERIFY_NON_NULL(TAG, deviceRsrc->interfaces[1], ERROR); + VERIFY_NOT_NULL(TAG, deviceRsrc->interfaces[1], ERROR); // /oic/p platformRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, platformRsrc, ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc, ERROR); LL_APPEND(readOnlyAce->resources, platformRsrc); platformRsrc->href = OICStrdup(OC_RSRVD_PLATFORM_URI); - VERIFY_NON_NULL(TAG, (platformRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (platformRsrc->href), ERROR); platformRsrc->typeLen = 1; platformRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, platformRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc->types, ERROR); platformRsrc->types[0] = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM); - VERIFY_NON_NULL(TAG, platformRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc->types[0], ERROR); platformRsrc->interfaceLen = 2; platformRsrc->interfaces = (char**)OICCalloc(platformRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, platformRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc->interfaces, ERROR); platformRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, platformRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc->interfaces[0], ERROR); platformRsrc->interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ); - VERIFY_NON_NULL(TAG, platformRsrc->interfaces[1], ERROR); + VERIFY_NOT_NULL(TAG, platformRsrc->interfaces[1], ERROR); readOnlyAce->permission = PERMISSION_READ; readOnlyAce->validities = NULL; @@ -2224,7 +2224,7 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl) // Default ACE allowing read + write access, for ownership transfer readWriteAce = (OicSecAce_t *) OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, readWriteAce, ERROR); + VERIFY_NOT_NULL(TAG, readWriteAce, ERROR); // Subject -- Mandatory memcpy(readWriteAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t)); @@ -2232,56 +2232,56 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl) // Resources -- Mandatory // /oic/sec/doxm doxmRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, doxmRsrc, ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc, ERROR); LL_APPEND(readWriteAce->resources, doxmRsrc); doxmRsrc->href = OICStrdup(OIC_RSRC_DOXM_URI); - VERIFY_NON_NULL(TAG, (doxmRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->href), ERROR); doxmRsrc->typeLen = 1; doxmRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, doxmRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc->types, ERROR); doxmRsrc->types[0] = OICStrdup(OIC_RSRC_TYPE_SEC_DOXM); - VERIFY_NON_NULL(TAG, doxmRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc->types[0], ERROR); doxmRsrc->interfaceLen = 1; doxmRsrc->interfaces = (char**)OICCalloc(doxmRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, doxmRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc->interfaces, ERROR); doxmRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, doxmRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc->interfaces[0], ERROR); // /oic/sec/pstat pstatRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, pstatRsrc, ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc, ERROR); LL_APPEND(readWriteAce->resources, pstatRsrc); pstatRsrc->href = OICStrdup(OIC_RSRC_PSTAT_URI); - VERIFY_NON_NULL(TAG, (pstatRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->href), ERROR); pstatRsrc->typeLen = 1; pstatRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, pstatRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc->types, ERROR); pstatRsrc->types[0] = OICStrdup(OIC_RSRC_TYPE_SEC_PSTAT); - VERIFY_NON_NULL(TAG, pstatRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc->types[0], ERROR); pstatRsrc->interfaceLen = 1; pstatRsrc->interfaces = (char**)OICCalloc(pstatRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, pstatRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc->interfaces, ERROR); pstatRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, pstatRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc->interfaces[0], ERROR); // /oic/sec/cred resRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, resRsrc, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc, ERROR); LL_APPEND(readWriteAce->resources, resRsrc); resRsrc->href = OICStrdup(OIC_RSRC_CRED_URI); - VERIFY_NON_NULL(TAG, (resRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (resRsrc->href), ERROR); resRsrc->typeLen = 1; resRsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, resRsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->types, ERROR); resRsrc->types[0] = OICStrdup(OIC_RSRC_TYPE_SEC_CRED); - VERIFY_NON_NULL(TAG, resRsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->types[0], ERROR); resRsrc->interfaceLen = 2; resRsrc->interfaces = (char**)OICCalloc(resRsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, resRsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces, ERROR); resRsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, resRsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces[0], ERROR); resRsrc->interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ); - VERIFY_NON_NULL(TAG, resRsrc->interfaces[1], ERROR); + VERIFY_NOT_NULL(TAG, resRsrc->interfaces[1], ERROR); readWriteAce->permission = PERMISSION_READ | PERMISSION_WRITE; readWriteAce->validities = NULL; @@ -2358,7 +2358,7 @@ OCStackResult InitACLResource() } // TODO Needs to update persistent storage } - VERIFY_NON_NULL(TAG, gAcl, FATAL); + VERIFY_NOT_NULL(TAG, gAcl, FATAL); // Instantiate 'oic.sec.acl' ret = CreateACLResource(); @@ -2652,7 +2652,7 @@ static OicSecAce_t* GetSecDefaultACE() //Generate default ACE OicSecAce_t* newAce = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, newAce, ERROR); + VERIFY_NOT_NULL(TAG, newAce, ERROR); // Subject -- Mandatory memcpy(newAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, WILDCARD_SUBJECT_ID_LEN); @@ -2660,54 +2660,54 @@ static OicSecAce_t* GetSecDefaultACE() //Resources -- Mandatory //Add doxm doxmRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, doxmRsrc, ERROR); + VERIFY_NOT_NULL(TAG, doxmRsrc, ERROR); LL_APPEND(newAce->resources, doxmRsrc); // pstat-href doxmRsrc->href = OICStrdup(OIC_RSRC_DOXM_URI); - VERIFY_NON_NULL(TAG, (doxmRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->href), ERROR); // pstat-rt doxmRsrc->typeLen = NUM_OF_DOXM_RT; doxmRsrc->types = (char**)OICCalloc(NUM_OF_DOXM_RT, sizeof(char*)); - VERIFY_NON_NULL(TAG, (doxmRsrc->types), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->types), ERROR); for(int i = 0; i < NUM_OF_DOXM_RT; i++) { doxmRsrc->types[i] = OICStrdup(doxmRt[i]); - VERIFY_NON_NULL(TAG, (doxmRsrc->types[i]), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->types[i]), ERROR); } // pstat-if doxmRsrc->interfaceLen = NUM_OF_DOXM_IF; doxmRsrc->interfaces = (char**)OICCalloc(NUM_OF_DOXM_IF, sizeof(char*)); - VERIFY_NON_NULL(TAG, (doxmRsrc->interfaces), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->interfaces), ERROR); for(int i = 0; i < NUM_OF_DOXM_IF; i++) { doxmRsrc->interfaces[i] = OICStrdup(doxmIf[i]); - VERIFY_NON_NULL(TAG, (doxmRsrc->interfaces[i]), ERROR); + VERIFY_NOT_NULL(TAG, (doxmRsrc->interfaces[i]), ERROR); } //Add pstat pstatRsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, pstatRsrc, ERROR); + VERIFY_NOT_NULL(TAG, pstatRsrc, ERROR); LL_APPEND(newAce->resources, pstatRsrc); //pstat-href pstatRsrc->href = OICStrdup(OIC_RSRC_PSTAT_URI); - VERIFY_NON_NULL(TAG, (pstatRsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->href), ERROR); //pstat-rt pstatRsrc->typeLen = NUM_OF_PSTAT_RT; pstatRsrc->types = (char**)OICCalloc(NUM_OF_PSTAT_RT, sizeof(char*)); - VERIFY_NON_NULL(TAG, (pstatRsrc->types), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->types), ERROR); for(int i = 0; i < NUM_OF_PSTAT_RT; i++) { pstatRsrc->types[i] = OICStrdup(pstatRt[i]); - VERIFY_NON_NULL(TAG, (pstatRsrc->types[i]), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->types[i]), ERROR); } // pstat-if pstatRsrc->interfaceLen = NUM_OF_PSTAT_IF; pstatRsrc->interfaces = (char**)OICCalloc(NUM_OF_PSTAT_IF, sizeof(char*)); - VERIFY_NON_NULL(TAG, (pstatRsrc->interfaces), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->interfaces), ERROR); for(int i = 0; i < NUM_OF_PSTAT_IF; i++) { pstatRsrc->interfaces[i] = OICStrdup(pstatIf[i]); - VERIFY_NON_NULL(TAG, (pstatRsrc->interfaces[i]), ERROR); + VERIFY_NOT_NULL(TAG, (pstatRsrc->interfaces[i]), ERROR); } // Permissions -- Mandatory diff --git a/resource/csdk/security/src/amaclresource.c b/resource/csdk/security/src/amaclresource.c index ca0be5c..6eac57c 100644 --- a/resource/csdk/security/src/amaclresource.c +++ b/resource/csdk/security/src/amaclresource.c @@ -101,7 +101,7 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl const OicSecAmacl_t *amacl = amaclS; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); // Create AMACL Map @@ -305,7 +305,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size, // TODO : Need to check data structure of OicSecAmacl_t based on RAML spec. headAmacl->resources = (char **) OICCalloc(headAmacl->resourcesLen, sizeof(*headAmacl->resources)); - VERIFY_NON_NULL(TAG, headAmacl->resources, ERROR); + VERIFY_NOT_NULL(TAG, headAmacl->resources, ERROR); while (cbor_value_is_valid(&rsrcArray)) { @@ -388,7 +388,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size, cborFindResult = cbor_value_enter_container(&amaclMap, &amsArray); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering AMS Array Container."); headAmacl->amss = (OicUuid_t *)OICCalloc(headAmacl->amssLen, sizeof(*headAmacl->amss)); - VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR); + VERIFY_NOT_NULL(TAG, headAmacl->amss, ERROR); while (cbor_value_is_valid(&amsArray) && cbor_value_is_text_string(&amsArray)) { char *amssId = NULL; @@ -601,8 +601,8 @@ OCStackResult AmaclGetAmsDeviceId(const char *resource, OicUuid_t *amsDeviceId) { OicSecAmacl_t *amacl = NULL; - VERIFY_NON_NULL(TAG, resource, ERROR); - VERIFY_NON_NULL(TAG, amsDeviceId, ERROR); + VERIFY_NOT_NULL(TAG, resource, ERROR); + VERIFY_NOT_NULL(TAG, amsDeviceId, ERROR); LL_FOREACH(gAmacl, amacl) { diff --git a/resource/csdk/security/src/amsmgr.c b/resource/csdk/security/src/amsmgr.c index c6b21b8..02d9788 100644 --- a/resource/csdk/security/src/amsmgr.c +++ b/resource/csdk/security/src/amsmgr.c @@ -59,7 +59,7 @@ OCStackResult DiscoverAmsService(PEContext_t *context) char uri[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0}; OCCallbackData cbData = {.context=NULL}; - VERIFY_NON_NULL(TAG, context, ERROR); + VERIFY_NOT_NULL(TAG, context, ERROR); snprintf(uri, sizeof(uri), DOXM_DEVICEID_QUERY_FMT, OIC_RSRC_DOXM_URI, OIC_JSON_DEVICE_ID_NAME, context->amsMgrContext->amsDeviceId.id); @@ -231,8 +231,8 @@ OCStackResult SendAclReq(PEContext_t *context, OCDevAddr *devAddr, OCConnectivit OCDevAddr destAddr = {.adapter = OC_ADAPTER_IP}; char *subID = NULL; - VERIFY_NON_NULL(TAG, context, ERROR); - VERIFY_NON_NULL(TAG, devAddr, ERROR); + VERIFY_NOT_NULL(TAG, context, ERROR); + VERIFY_NOT_NULL(TAG, devAddr, ERROR); ret = ConvertUuidToStr(&context->subject, &subID); if(OC_STACK_OK != ret) @@ -323,7 +323,7 @@ OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endp const CARequestInfo_t *requestInfo) { OCStackResult ret = OC_STACK_INVALID_PARAM; - VERIFY_NON_NULL(TAG, context->amsMgrContext, ERROR); + VERIFY_NOT_NULL(TAG, context->amsMgrContext, ERROR); ret = OC_STACK_ERROR; //The AmsMgr context endpoint and requestInfo will be free from , @@ -334,7 +334,7 @@ OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endp context->amsMgrContext->endpoint = NULL; } context->amsMgrContext->endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof(CAEndpoint_t )); - VERIFY_NON_NULL(TAG, context->amsMgrContext->endpoint, ERROR); + VERIFY_NOT_NULL(TAG, context->amsMgrContext->endpoint, ERROR); *context->amsMgrContext->endpoint = *endpoint; if (context->amsMgrContext->requestInfo) @@ -343,7 +343,7 @@ OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endp context->amsMgrContext->requestInfo = NULL; } context->amsMgrContext->requestInfo = CACloneRequestInfo(requestInfo); - VERIFY_NON_NULL(TAG, context->amsMgrContext->requestInfo, ERROR); + VERIFY_NOT_NULL(TAG, context->amsMgrContext->requestInfo, ERROR); ret = OC_STACK_OK; exit: return ret; @@ -371,7 +371,7 @@ bool FoundAmaclForRequest(PEContext_t *context) OIC_LOG_V(INFO, TAG, "%s:no ACL found. Searching for AMACL",__func__); bool ret = false; - VERIFY_NON_NULL(TAG, context, ERROR); + VERIFY_NOT_NULL(TAG, context, ERROR); memset(&context->amsMgrContext->amsDeviceId, 0, sizeof(context->amsMgrContext->amsDeviceId)); //Call amacl resource function to get the AMS service deviceID for the resource diff --git a/resource/csdk/security/src/base64.c b/resource/csdk/security/src/base64.c index 4c396f1..8cd202a 100644 --- a/resource/csdk/security/src/base64.c +++ b/resource/csdk/security/src/base64.c @@ -34,7 +34,7 @@ static const char g_b64TransTbl[] = * * @return ::B64_OK for Success, otherwise some error value. */ -static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) +static B64Result b64EncodeBlk(const uint8_t* in, char* out, size_t len) { if (NULL == in || NULL == out || 0 == len ) { @@ -78,7 +78,7 @@ static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) } B64Result b64Encode(const uint8_t* in, const size_t inLen, - char* outBuf, const size_t outBufSize, uint32_t* outLen) + char* outBuf, const size_t outBufSize, size_t* outLen) { if (NULL == in || 0 == inLen || NULL == outBuf || NULL == outLen ) { @@ -88,13 +88,13 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, *outLen = ((inLen / 3) * 3 == inLen) ? ((inLen / 3) * 4) : (((inLen / 3) + 1) * 4); - uint32_t minBufSize = (*outLen + 1); + size_t minBufSize = (*outLen + 1); if (outBufSize < minBufSize) { return B64_OUTPUT_BUFFER_TOO_SMALL; } - uint32_t i; + size_t i; for (i = 0; i < inLen / 3; i++) { if(B64_OK != b64EncodeBlk(in + i * 3, outBuf + i * 4, 3)) @@ -103,7 +103,7 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, } } - if (((size_t)i * 3) != inLen) + if ((i * 3) != inLen) { if (B64_OK != b64EncodeBlk(in + i * 3, outBuf + i * 4, inLen - i * 3)) { @@ -186,7 +186,7 @@ static B64Result b64DecodeBlk(const char* in, uint8_t* out) } B64Result b64Decode(const char* in, const size_t inLen, - uint8_t* outBuf, size_t outBufSize, uint32_t* outLen) + uint8_t* outBuf, size_t outBufSize, size_t* outLen) { if (NULL == in || 0 == inLen || 0 != (inLen & 0x03) || NULL == outBuf || NULL == outLen) { @@ -194,7 +194,7 @@ B64Result b64Decode(const char* in, const size_t inLen, } *outLen = (inLen / 4) * 3; - uint32_t minBufSize = (inLen / 4) * 3; + size_t minBufSize = (inLen / 4) * 3; if ('=' == in[inLen - 1]) { minBufSize--; @@ -210,7 +210,7 @@ B64Result b64Decode(const char* in, const size_t inLen, return B64_OUTPUT_BUFFER_TOO_SMALL; } - for (uint32_t i = 0; i < inLen / 4; i++) + for (size_t i = 0; i < inLen / 4; i++) { if(B64_OK != b64DecodeBlk(in + i * 4, outBuf + i * 3)) { diff --git a/resource/csdk/security/src/credresource.c b/resource/csdk/security/src/credresource.c index 97c5fde..fbfedc0 100644 --- a/resource/csdk/security/src/credresource.c +++ b/resource/csdk/security/src/credresource.c @@ -69,6 +69,7 @@ #ifdef HAVE_WINDOWS_H #include +#include #endif @@ -92,6 +93,17 @@ typedef enum CredCompareResult{ CRED_CMP_ERROR = 2 }CredCompareResult_t; +static bool ValueWithinBounds(uint64_t value, uint64_t maxValue) +{ + if (value > maxValue) + { + OIC_LOG_V(ERROR, TAG, "The value (%ull) is greater than allowed maximum of %ull.", value, maxValue); + return false; + } + + return true; +} + /** * Internal function to check credential */ @@ -102,7 +114,7 @@ static bool IsValidCredential(const OicSecCred_t* cred) OIC_LOG(DEBUG, TAG, "IN IsValidCredential"); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); VERIFY_SUCCESS(TAG, 0 != cred->credId, ERROR); OIC_LOG_V(DEBUG, TAG, "Cred ID = %d", cred->credId); @@ -115,7 +127,7 @@ static bool IsValidCredential(const OicSecCred_t* cred) case SYMMETRIC_GROUP_KEY: case PIN_PASSWORD: { - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); VERIFY_SUCCESS(TAG, 0 != cred->privateData.len, ERROR); VERIFY_SUCCESS(TAG, \ (OIC_ENCODING_RAW == cred->privateData.encoding || \ @@ -125,7 +137,7 @@ static bool IsValidCredential(const OicSecCred_t* cred) } case ASYMMETRIC_KEY: { - VERIFY_NON_NULL(TAG, cred->publicData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->publicData.data, ERROR); VERIFY_SUCCESS(TAG, 0 != cred->publicData.len, ERROR); VERIFY_SUCCESS(TAG, \ (OIC_ENCODING_UNKNOW < cred->publicData.encoding && \ @@ -149,7 +161,7 @@ static bool IsValidCredential(const OicSecCred_t* cred) } case ASYMMETRIC_ENCRYPTION_KEY: { - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); VERIFY_SUCCESS(TAG, 0 != cred->privateData.len, ERROR); VERIFY_SUCCESS(TAG, \ (OIC_ENCODING_UNKNOW < cred->privateData.encoding && \ @@ -565,7 +577,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload } outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); // Create CRED Root Map (creds, rownerid) @@ -883,7 +895,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size, temp->next = cred; } - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); while(cbor_value_is_valid(&credMap) && cbor_value_is_text_string(&credMap)) { @@ -982,7 +994,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size, if(NULL == cred->eownerID) { cred->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, cred->eownerID, ERROR); + VERIFY_NOT_NULL(TAG, cred->eownerID, ERROR); } ret = ConvertStrToUuid(eowner, cred->eownerID); OICFree(eowner); @@ -1054,12 +1066,12 @@ bool IsValidCredentialAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cb OIC_LOG_BUFFER(DEBUG, TAG, cborPayload, size); - VERIFY_NON_NULL(TAG, uuid, ERROR); - VERIFY_NON_NULL(TAG, cborPayload, ERROR); + VERIFY_NOT_NULL(TAG, uuid, ERROR); + VERIFY_NOT_NULL(TAG, cborPayload, ERROR); VERIFY_SUCCESS(TAG, 0 != size, ERROR); VERIFY_SUCCESS(TAG, OC_STACK_OK == CBORPayloadToCred(cborPayload, size, &cred), ERROR); - VERIFY_NON_NULL(TAG, cred, ERROR); - VERIFY_NON_NULL(TAG, cred->eownerID, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred->eownerID, ERROR); VERIFY_SUCCESS(TAG, (memcmp(cred->eownerID->id, uuid->id, sizeof(uuid->id)) == 0), ERROR); isValidCred = true; @@ -1082,13 +1094,13 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr OCStackResult ret = OC_STACK_ERROR; OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred)); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); //CredId is assigned before appending new cred to the existing //credential list and updating svr database in AddCredential(). cred->credId = 0; - VERIFY_NON_NULL(TAG, subject, ERROR); + VERIFY_NOT_NULL(TAG, subject, ERROR); memcpy(cred->subject.id, subject->id , sizeof(cred->subject.id)); VERIFY_SUCCESS(TAG, credType < (NO_SECURITY_MODE | SYMMETRIC_PAIR_WISE_KEY | @@ -1099,7 +1111,7 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr if (publicData && publicData->data) { cred->publicData.data = (uint8_t *)OICCalloc(1, publicData->len); - VERIFY_NON_NULL(TAG, cred->publicData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->publicData.data, ERROR); memcpy(cred->publicData.data, publicData->data, publicData->len); cred->publicData.len = publicData->len; } @@ -1108,20 +1120,20 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr if (privateData && privateData->data) { cred->privateData.data = (uint8_t *)OICCalloc(1, privateData->len); - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); memcpy(cred->privateData.data, privateData->data, privateData->len); cred->privateData.len = privateData->len; cred->privateData.encoding = OIC_ENCODING_RAW; } - VERIFY_NON_NULL(TAG, rownerID, ERROR); + VERIFY_NOT_NULL(TAG, rownerID, ERROR); memcpy(&cred->rownerID, rownerID, sizeof(OicUuid_t)); #ifdef MULTIPLE_OWNER if(eownerID) { cred->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, cred->eownerID, ERROR); + VERIFY_NOT_NULL(TAG, cred->eownerID, ERROR); memcpy(cred->eownerID->id, eownerID->id, sizeof(eownerID->id)); } #else @@ -1225,9 +1237,18 @@ static bool UpdatePersistentStorage(const OicSecCred_t *cred) /* On Windows, keep the credential resource encrypted on disk to protect symmetric and private keys. Only the * current user on this system will be able to decrypt it later, to help prevent credential theft. */ + DWORD dwordSize; + + if (FAILED(SizeTToDWord(size, &dwordSize))) + { + OIC_LOG(DEBUG, TAG, "Cred size too large."); + res = OC_STACK_ERROR; + ret = false; + } + if ((OC_STACK_OK == res) && payload) { - DATA_BLOB decryptedPayload = { .cbData = size, .pbData = payload }; + DATA_BLOB decryptedPayload = { .cbData = dwordSize, .pbData = payload }; DATA_BLOB encryptedPayload = { .cbData = 0, .pbData = NULL }; if (CryptProtectData( @@ -1355,8 +1376,8 @@ static OicSecCred_t* GetCredDefault() static bool IsSameSecOpt(const OicSecOpt_t* sk1, const OicSecOpt_t* sk2) { - VERIFY_NON_NULL(TAG, sk1, WARNING); - VERIFY_NON_NULL(TAG, sk2, WARNING); + VERIFY_NOT_NULL(TAG, sk1, WARNING); + VERIFY_NOT_NULL(TAG, sk2, WARNING); VERIFY_SUCCESS(TAG, (sk1->len == sk2->len), INFO); VERIFY_SUCCESS(TAG, (sk1->encoding == sk2->encoding), INFO); @@ -1368,8 +1389,8 @@ exit: static bool IsSameSecKey(const OicSecKey_t* sk1, const OicSecKey_t* sk2) { - VERIFY_NON_NULL(TAG, sk1, WARNING); - VERIFY_NON_NULL(TAG, sk2, WARNING); + VERIFY_NOT_NULL(TAG, sk1, WARNING); + VERIFY_NOT_NULL(TAG, sk2, WARNING); VERIFY_SUCCESS(TAG, (sk1->len == sk2->len), INFO); VERIFY_SUCCESS(TAG, (sk1->encoding == sk2->encoding), INFO); @@ -1393,8 +1414,8 @@ static CredCompareResult_t CompareCredential(const OicSecCred_t * l, const OicSe bool isCompared = false; OIC_LOG(DEBUG, TAG, "IN CompareCredetial"); - VERIFY_NON_NULL(TAG, l, ERROR); - VERIFY_NON_NULL(TAG, r, ERROR); + VERIFY_NOT_NULL(TAG, l, ERROR); + VERIFY_NOT_NULL(TAG, r, ERROR); cmpResult = CRED_CMP_NOT_EQUAL; @@ -1654,7 +1675,7 @@ static bool FillPrivateDataOfOwnerPSK(OicSecCred_t* receviedCred, const CAEndpoi const char* oxmLabel = GetOxmString(doxm->oxmSel); char* b64Buf = NULL; size_t b64BufSize = 0; - VERIFY_NON_NULL(TAG, oxmLabel, ERROR); + VERIFY_NOT_NULL(TAG, oxmLabel, ERROR); uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {0}; CAResult_t pskRet = CAGenerateOwnerPSK(ownerAddr, @@ -1673,23 +1694,23 @@ static bool FillPrivateDataOfOwnerPSK(OicSecCred_t* receviedCred, const CAEndpoi if(OIC_ENCODING_RAW == receviedCred->privateData.encoding) { receviedCred->privateData.data = (uint8_t *)OICCalloc(1, OWNER_PSK_LENGTH_128); - VERIFY_NON_NULL(TAG, receviedCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, receviedCred->privateData.data, ERROR); receviedCred->privateData.len = OWNER_PSK_LENGTH_128; memcpy(receviedCred->privateData.data, ownerPSK, OWNER_PSK_LENGTH_128); } else if(OIC_ENCODING_BASE64 == receviedCred->privateData.encoding) { B64Result b64res = B64_OK; - uint32_t b64OutSize = 0; + size_t b64OutSize = 0; b64BufSize = B64ENCODE_OUT_SAFESIZE((OWNER_PSK_LENGTH_128 + 1)); b64Buf = OICCalloc(1, b64BufSize); - VERIFY_NON_NULL(TAG, b64Buf, ERROR); + VERIFY_NOT_NULL(TAG, b64Buf, ERROR); b64res = b64Encode(ownerPSK, OWNER_PSK_LENGTH_128, b64Buf, b64BufSize, &b64OutSize); VERIFY_SUCCESS(TAG, B64_OK == b64res, ERROR); receviedCred->privateData.data = (uint8_t *)OICCalloc(1, b64OutSize + 1); - VERIFY_NON_NULL(TAG, receviedCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, receviedCred->privateData.data, ERROR); receviedCred->privateData.len = b64OutSize; strncpy((char*)receviedCred->privateData.data, b64Buf, b64OutSize); receviedCred->privateData.data[b64OutSize] = '\0'; @@ -1736,7 +1757,7 @@ static bool FillPrivateDataOfSubOwnerPSK(OicSecCred_t* receivedCred, const CAEnd char* b64Buf = NULL; //Derive OwnerPSK locally const char* oxmLabel = GetOxmString(doxm->oxmSel); - VERIFY_NON_NULL(TAG, oxmLabel, ERROR); + VERIFY_NOT_NULL(TAG, oxmLabel, ERROR); uint8_t subOwnerPSK[OWNER_PSK_LENGTH_128] = {0}; CAResult_t pskRet = CAGenerateOwnerPSK(ownerAddr, @@ -1754,23 +1775,23 @@ static bool FillPrivateDataOfSubOwnerPSK(OicSecCred_t* receivedCred, const CAEnd if(OIC_ENCODING_RAW == receivedCred->privateData.encoding) { receivedCred->privateData.data = (uint8_t *)OICCalloc(1, OWNER_PSK_LENGTH_128); - VERIFY_NON_NULL(TAG, receivedCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, receivedCred->privateData.data, ERROR); receivedCred->privateData.len = OWNER_PSK_LENGTH_128; memcpy(receivedCred->privateData.data, subOwnerPSK, OWNER_PSK_LENGTH_128); } else if(OIC_ENCODING_BASE64 == receivedCred->privateData.encoding) { - uint32_t b64OutSize = 0; + size_t b64OutSize = 0; size_t b64BufSize = B64ENCODE_OUT_SAFESIZE((OWNER_PSK_LENGTH_128 + 1)); b64Buf = OICCalloc(1, b64BufSize); - VERIFY_NON_NULL(TAG, b64Buf, ERROR); + VERIFY_NOT_NULL(TAG, b64Buf, ERROR); VERIFY_SUCCESS(TAG, \ B64_OK == b64Encode(subOwnerPSK, OWNER_PSK_LENGTH_128, b64Buf, b64BufSize, &b64OutSize), \ ERROR); receivedCred->privateData.data = (uint8_t *)OICCalloc(1, b64OutSize + 1); - VERIFY_NON_NULL(TAG, receivedCred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, receivedCred->privateData.data, ERROR); receivedCred->privateData.len = b64OutSize; strncpy((char*)receivedCred->privateData.data, b64Buf, b64OutSize); receivedCred->privateData.data[b64OutSize] = '\0'; @@ -2192,9 +2213,17 @@ OCStackResult InitCredResource() #ifdef HAVE_WINDOWS_H /* On Windows, if the credential payload isn't cleartext CBOR, it is encrypted. Decrypt and retry. */ + DWORD dwordSize; + + if (FAILED(SizeTToDWord(size, &dwordSize))) + { + OIC_LOG(DEBUG, TAG, "Cred size too large."); + ret = OC_STACK_ERROR; + } + if (ret != OC_STACK_OK) { - DATA_BLOB encryptedPayload = { .cbData = size, .pbData = data }; + DATA_BLOB encryptedPayload = { .cbData = dwordSize, .pbData = data }; DATA_BLOB decryptedPayload = { .cbData = 0, .pbData = NULL }; if (CryptUnprotectData( @@ -2300,7 +2329,7 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId) if(tmpCred->credId == credId) { cred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t)); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); // common cred->next = NULL; @@ -2317,7 +2346,7 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId) if (tmpCred->privateData.data) { cred->privateData.data = (uint8_t *)OICCalloc(1, tmpCred->privateData.len); - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); memcpy(cred->privateData.data, tmpCred->privateData.data, tmpCred->privateData.len); cred->privateData.len = tmpCred->privateData.len; @@ -2327,7 +2356,7 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId) else if (tmpCred->publicData.data) { cred->publicData.data = (uint8_t *)OICCalloc(1, tmpCred->publicData.len); - VERIFY_NON_NULL(TAG, cred->publicData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->publicData.data, ERROR); memcpy(cred->publicData.data, tmpCred->publicData.data, tmpCred->publicData.len); cred->publicData.len = tmpCred->publicData.len; @@ -2335,7 +2364,7 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId) else if (tmpCred->optionalData.data) { cred->optionalData.data = (uint8_t *)OICCalloc(1, tmpCred->optionalData.len); - VERIFY_NON_NULL(TAG, cred->optionalData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->optionalData.data, ERROR); memcpy(cred->optionalData.data, tmpCred->optionalData.data, tmpCred->optionalData.len); cred->optionalData.len = tmpCred->optionalData.len; @@ -2423,14 +2452,17 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type, // TODO: Added as workaround. Will be replaced soon. if(OIC_ENCODING_RAW == cred->privateData.encoding) { - ret = cred->privateData.len; - memcpy(result, cred->privateData.data, ret); + if (ValueWithinBounds(cred->privateData.len, INT32_MAX)) + { + ret = (int32_t)cred->privateData.len; + memcpy(result, cred->privateData.data, ret); + } } else if(OIC_ENCODING_BASE64 == cred->privateData.encoding) { size_t outBufSize = B64DECODE_OUT_SAFESIZE((cred->privateData.len + 1)); uint8_t* outKey = OICCalloc(1, outBufSize); - uint32_t outKeySize; + size_t outKeySize; if(NULL == outKey) { OIC_LOG (ERROR, TAG, "Failed to allocate memory."); @@ -2439,12 +2471,15 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type, if(B64_OK == b64Decode((char*)cred->privateData.data, cred->privateData.len, outKey, outBufSize, &outKeySize)) { - memcpy(result, outKey, outKeySize); - ret = outKeySize; + if (ValueWithinBounds(outKeySize, INT32_MAX)) + { + memcpy(result, outKey, outKeySize); + ret = (int32_t)outKeySize; + } } else { - OIC_LOG (ERROR, TAG, "Failed to base64 decoding."); + OIC_LOG (ERROR, TAG, "Failed base64 decoding."); } OICFree(outKey); @@ -2470,7 +2505,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type, { //Read PIN/PW char* pinBuffer = NULL; - uint32_t pinLength = 0; + size_t pinLength = 0; if(OIC_ENCODING_RAW == wildCardCred->privateData.encoding) { pinBuffer = OICCalloc(1, wildCardCred->privateData.len + 1); @@ -2684,7 +2719,7 @@ void GetDerCaCert(ByteArray_t * crt, const char * usage) OIC_LOG(ERROR, TAG, "Failed to allocate memory"); return; } - uint32_t outSize; + size_t outSize; if(B64_OK != b64Decode((char*)(temp->optionalData.data), temp->optionalData.len, buf, bufSize, &outSize)) { diff --git a/resource/csdk/security/src/crlresource.c b/resource/csdk/security/src/crlresource.c index 72c86e7..f541b93 100644 --- a/resource/csdk/security/src/crlresource.c +++ b/resource/csdk/security/src/crlresource.c @@ -319,7 +319,7 @@ OCStackResult CrlToCBORPayload(const OicSecCrl_t *crl, uint8_t **payload, size_t CborError cborEncoderResult = CborNoError; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); cborEncoderResult = cbor_encoder_create_map(&encoder, &crlMap, mapSize); @@ -405,7 +405,7 @@ OCStackResult CBORPayloadToCrl(const uint8_t *cborPayload, const size_t size, VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter Crl map"); crl = (OicSecCrl_t *)OICCalloc(1, sizeof(OicSecCrl_t)); - VERIFY_NON_NULL(TAG, crl, ERROR); + VERIFY_NOT_NULL(TAG, crl, ERROR); cborFindResult = cbor_value_map_find_value(&crlCbor, OC_RSRVD_CRL_ID, &crlMap); if (CborNoError == cborFindResult && cbor_value_is_integer(&crlMap)) @@ -510,7 +510,7 @@ static OCEntityHandlerResult HandleCRLPostRequest(const OCEntityHandlerRequest * { OIC_LOG(INFO, TAG, "Update SVR DB..."); CBORPayloadToCrl(payload, size, &crl); - VERIFY_NON_NULL(TAG, crl, ERROR); + VERIFY_NOT_NULL(TAG, crl, ERROR); if (OC_STACK_OK == UpdateCRLResource(crl)) { @@ -794,7 +794,7 @@ void GetDerCrl(ByteArray_t* out) OIC_LOG(ERROR, TAG, "Can't allocate memory for base64 str"); return; } - uint32_t len = 0; + size_t len = 0; if(B64_OK == b64Decode((char*)crl->data, crl->len, out, outSize, &len)) { diff --git a/resource/csdk/security/src/directpairing.c b/resource/csdk/security/src/directpairing.c index 3952bc9..eb2021d 100644 --- a/resource/csdk/security/src/directpairing.c +++ b/resource/csdk/security/src/directpairing.c @@ -647,7 +647,7 @@ static OCStackApplicationResult DirectPairingHandler(void *ctx, OCDoHandle UNUSE // initiate dtls CAEndpoint_t *endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t)); - VERIFY_NON_NULL(TAG, endpoint, FATAL); + VERIFY_NOT_NULL(TAG, endpoint, FATAL); memcpy(endpoint,&dpairData->peer->endpoint,sizeof(CAEndpoint_t)); endpoint->port = dpairData->peer->securePort; OIC_LOG_V(INFO, TAG, "Initiate DTLS handshake to %s(%d)", endpoint->addr, @@ -1005,7 +1005,7 @@ OCStackResult DPDeviceDiscovery(unsigned short waittime) int clock_res = -1; #if defined(_MSC_VER) - time_t startTime = NULL; + time_t startTime = 0; clock_res = (time(&startTime) == -1); #else struct timespec startTime = {.tv_sec=0, .tv_nsec=0}; @@ -1026,7 +1026,7 @@ OCStackResult DPDeviceDiscovery(unsigned short waittime) while (1) { #if defined(_MSC_VER) - time_t currTime = NULL; + time_t currTime = 0; clock_res = (time(&currTime) == -1); #else struct timespec currTime = {.tv_sec=0, .tv_nsec=0}; @@ -1041,9 +1041,9 @@ OCStackResult DPDeviceDiscovery(unsigned short waittime) break; } #if defined(_MSC_VER) - long elapsed = currTime - startTime; + time_t elapsed = currTime - startTime; #else - long elapsed = (currTime.tv_sec - startTime.tv_sec); + time_t elapsed = (currTime.tv_sec - startTime.tv_sec); #endif if (elapsed > waittime) { diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 3cb4196..24218a9 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -170,7 +170,7 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz int64_t cborEncoderResult = CborNoError; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); cborEncoderResult = cbor_encoder_create_map(&encoder, &doxmMap, CborIndefiniteLength); @@ -411,7 +411,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz cbor_parser_init(cborPayload, size, 0, &parser, &doxmCbor); CborValue doxmMap; OicSecDoxm_t *doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(*doxm)); - VERIFY_NON_NULL(TAG, doxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm, ERROR); cborFindResult = cbor_value_map_find_value(&doxmCbor, OIC_JSON_OXM_TYPE_NAME, &doxmMap); //OxmType -- not Mandatory @@ -424,7 +424,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz VERIFY_SUCCESS(TAG, doxm->oxmTypeLen != 0, ERROR); doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(*doxm->oxmType)); - VERIFY_NON_NULL(TAG, doxm->oxmType, ERROR); + VERIFY_NOT_NULL(TAG, doxm->oxmType, ERROR); cborFindResult = cbor_value_enter_container(&doxmMap, &oxmType); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering oxmType Array.") @@ -451,7 +451,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz VERIFY_SUCCESS(TAG, doxm->oxmLen != 0, ERROR); doxm->oxm = (OicSecOxm_t *)OICCalloc(doxm->oxmLen, sizeof(*doxm->oxm)); - VERIFY_NON_NULL(TAG, doxm->oxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm->oxm, ERROR); cborFindResult = cbor_value_enter_container(&doxmMap, &oxm); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering oxmName Array.") @@ -475,9 +475,9 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); doxm->oxm = (OicSecOxm_t *) OICCalloc(gDoxm->oxmLen, sizeof(*doxm->oxm)); - VERIFY_NON_NULL(TAG, doxm->oxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm->oxm, ERROR); doxm->oxmLen = gDoxm->oxmLen; for (size_t i = 0; i < gDoxm->oxmLen; i++) { @@ -496,7 +496,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else // PUT/POST JSON may not have oxmsel so set it to the gDoxm->oxmSel { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); doxm->oxmSel = gDoxm->oxmSel; } @@ -516,7 +516,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else // PUT/POST JSON may not have sct so set it to the gDoxm->sct { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); doxm->sct = gDoxm->sct; } @@ -528,7 +528,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else // PUT/POST JSON may not have owned so set it to the gDomx->owned { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); doxm->owned = gDoxm->owned; } @@ -544,7 +544,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); memcpy(doxm->deviceID.id, &gDoxm->deviceID.id, sizeof(doxm->deviceID.id)); } @@ -560,7 +560,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); memcpy(doxm->owner.id, gDoxm->owner.id, sizeof(doxm->owner.id)); } @@ -574,7 +574,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz if(NULL == doxm->mom) { doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t)); - VERIFY_NON_NULL(TAG, doxm->mom, ERROR); + VERIFY_NOT_NULL(TAG, doxm->mom, ERROR); } doxm->mom->mode = (OicSecMomType_t)mode; } @@ -584,7 +584,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz if(NULL == doxm->mom) { doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t)); - VERIFY_NON_NULL(TAG, doxm->mom, ERROR); + VERIFY_NOT_NULL(TAG, doxm->mom, ERROR); } doxm->mom->mode = gDoxm->mom->mode; } @@ -612,7 +612,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding SubOwnerId Value"); subOwner = (OicSecSubOwner_t*)OICCalloc(1, sizeof(OicSecSubOwner_t)); - VERIFY_NON_NULL(TAG, subOwner, ERROR); + VERIFY_NOT_NULL(TAG, subOwner, ERROR); convertRes = ConvertStrToUuid(strUuid, &subOwner->uuid); VERIFY_SUCCESS(TAG, OC_STACK_OK == convertRes, ERROR); @@ -630,7 +630,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz LL_FOREACH(gDoxm->subOwners, subOwnerItor) { OicSecSubOwner_t* subOwnerId = (OicSecSubOwner_t*)OICCalloc(1, sizeof(OicSecSubOwner_t)); - VERIFY_NON_NULL(TAG, subOwnerId, ERROR); + VERIFY_NOT_NULL(TAG, subOwnerId, ERROR); memcpy(&subOwnerId->uuid, &subOwnerItor->uuid, sizeof(OicUuid_t)); subOwnerId->status = MOT_STATUS_DONE; @@ -652,7 +652,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz } else { - VERIFY_NON_NULL(TAG, gDoxm, ERROR); + VERIFY_NOT_NULL(TAG, gDoxm, ERROR); memcpy(doxm->rownerID.id, gDoxm->rownerID.id, sizeof(doxm->rownerID.id)); } @@ -1661,7 +1661,7 @@ const OicSecDoxm_t* GetDoxmResourceData() static void PrepareMOT(const OicSecDoxm_t* doxm) { OIC_LOG(INFO, TAG, "IN PrepareMOT"); - VERIFY_NON_NULL(TAG, doxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm, ERROR); if(true == doxm->owned && NULL != doxm->mom && OIC_MULTIPLE_OWNER_DISABLE != doxm->mom->mode) { diff --git a/resource/csdk/security/src/dpairingresource.c b/resource/csdk/security/src/dpairingresource.c index 538bad8..f21d4b4 100644 --- a/resource/csdk/security/src/dpairingresource.c +++ b/resource/csdk/security/src/dpairingresource.c @@ -154,7 +154,7 @@ OCStackResult SavePairingPSK(OCDevAddr *endpoint, SYMMETRIC_PAIR_WISE_KEY, NULL, &pairingKey, owner, NULL); OICClearMemory(pairingPSK, sizeof(pairingPSK)); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); res = AddCredential(cred); if(res != OC_STACK_OK) @@ -199,7 +199,7 @@ OCStackResult DpairingToCBORPayload(const OicSecDpairing_t *dpair, uint8_t **pay uint8_t mapSize = DPAIR_MAP_SIZE; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); cborEncoderResult = cbor_encoder_create_map(&encoder, &dpairMap, mapSize); @@ -294,7 +294,7 @@ OCStackResult CBORPayloadToDpair(const uint8_t *cborPayload, size_t size, VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering DPairing Map"); dpair = (OicSecDpairing_t *)OICCalloc(1, sizeof(*dpair)); - VERIFY_NON_NULL(TAG, dpair, ERROR); + VERIFY_NOT_NULL(TAG, dpair, ERROR); while (cbor_value_is_valid(&dpairMap) && cbor_value_is_text_string(&dpairMap)) { @@ -543,7 +543,7 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ VERIFY_SUCCESS(TAG, PRM_NOT_ALLOWED == newDpair->spm, ERROR); const OicSecPconf_t *pconf = GetPconfResourceData(); - VERIFY_NON_NULL(TAG, pconf, ERROR); + VERIFY_NOT_NULL(TAG, pconf, ERROR); #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) OCServerRequest * request = (OCServerRequest *)ehRequest->requestHandle; @@ -562,10 +562,10 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ LL_FOREACH(pconf->pdacls, pdAcl) { OicSecAcl_t* acl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t)); - VERIFY_NON_NULL(TAG, acl, ERROR); + VERIFY_NOT_NULL(TAG, acl, ERROR); OicSecAce_t* ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); LL_APPEND(acl->aces, ace); @@ -574,7 +574,7 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ for(size_t i = 0; i < pdAcl->resourcesLen; i++) { OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, rsrc, ERROR); + VERIFY_NOT_NULL(TAG, rsrc, ERROR); LL_APPEND(ace->resources, rsrc); //href @@ -584,16 +584,16 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ // if rsrc->interfaceLen = 1; rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char)); - VERIFY_NON_NULL(TAG, (rsrc->interfaces), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->interfaces), ERROR); rsrc->interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT); - VERIFY_NON_NULL(TAG, (rsrc->interfaces[0]), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->interfaces[0]), ERROR); //rt rsrc->typeLen = 1; rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char)); - VERIFY_NON_NULL(TAG, (rsrc->types), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->types), ERROR); rsrc->types[0] = OICStrdup("oic.core"); - VERIFY_NON_NULL(TAG, (rsrc->types[0]), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->types[0]), ERROR); } ace->permission = pdAcl->permission; @@ -602,13 +602,13 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ if(pdAcl->periods || pdAcl->recurrences) { OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - VERIFY_NON_NULL(TAG, validity, ERROR); + VERIFY_NOT_NULL(TAG, validity, ERROR); if(pdAcl->periods && pdAcl->periods[0]) { size_t periodLen = strlen(pdAcl->periods[0]) + 1; validity->period = (char*)OICMalloc(periodLen * sizeof(char)); - VERIFY_NON_NULL(TAG, (validity->period), ERROR); + VERIFY_NOT_NULL(TAG, (validity->period), ERROR); OICStrcpy(validity->period, periodLen, pdAcl->periods[0]); } @@ -616,13 +616,13 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ { validity->recurrenceLen = pdAcl->prdRecrLen; validity->recurrences = (char**)OICMalloc(sizeof(char*) * pdAcl->prdRecrLen); - VERIFY_NON_NULL(TAG, (validity->recurrences), ERROR); + VERIFY_NOT_NULL(TAG, (validity->recurrences), ERROR); for(size_t i = 0; i < pdAcl->prdRecrLen; i++) { size_t recurrenceLen = strlen(pdAcl->recurrences[i]) + 1; validity->recurrences[i] = (char*)OICMalloc(recurrenceLen * sizeof(char)); - VERIFY_NON_NULL(TAG, (validity->recurrences[i]), ERROR); + VERIFY_NOT_NULL(TAG, (validity->recurrences[i]), ERROR); OICStrcpy(validity->recurrences[i], recurrenceLen, pdAcl->recurrences[i]); } diff --git a/resource/csdk/security/src/iotvticalendar.c b/resource/csdk/security/src/iotvticalendar.c index 73663ce..cde76ce 100644 --- a/resource/csdk/security/src/iotvticalendar.c +++ b/resource/csdk/security/src/iotvticalendar.c @@ -56,8 +56,8 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) char *endDTPos; char *fmt = ""; - int startDTLen; - int endDTLen; + size_t startDTLen; + size_t endDTLen; //Finding length of startDateTime and endDateTime in period //startDateTime and endDateTime can have form YYYYmmdd or YYYYmmddTHHMMSS diff --git a/resource/csdk/security/src/oxmpincommon.c b/resource/csdk/security/src/oxmpincommon.c index 0a38ae7..5a1d70c 100644 --- a/resource/csdk/security/src/oxmpincommon.c +++ b/resource/csdk/security/src/oxmpincommon.c @@ -21,6 +21,8 @@ #include #include "ocstack.h" +#include "oic_malloc.h" +#include "oic_string.h" #include "ocrandom.h" #include "logger.h" #include "pinoxmcommon.h" @@ -214,7 +216,7 @@ static char GenerateRandomPinElement(OicSecPinType_t pinType) { const char defaultRetValue = '0'; char allowedCharacters[NUMBER_OF_PINNUM + NUMBER_OF_ALPHABET * 2]; - size_t curIndex = 0; + uint32_t curIndex = 0; if(NUM_PIN & pinType) { @@ -404,7 +406,9 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, (void)UNUSED1; (void)UNUSED2; - if (NULL == result || result_length < OWNER_PSK_LENGTH_128) + if ((NULL == result) + || (result_length < OWNER_PSK_LENGTH_128) + || (result_length > INT32_MAX)) { return ret; } @@ -423,10 +427,9 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, if (!OCGetRandomBytes(result, result_length)) { OIC_LOG(ERROR, TAG, "Failed to generate random PSK hint"); - ret = -1; break; } - ret = result_length; + ret = (int32_t)result_length; OIC_LOG(DEBUG, TAG, "PSK HINT : "); OIC_LOG_BUFFER(DEBUG, TAG, result, result_length); @@ -442,7 +445,6 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, else { OIC_LOG_V(ERROR, TAG, "Failed to derive crypto key from PIN"); - ret = -1; } } break; @@ -450,7 +452,6 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, default: { OIC_LOG (ERROR, TAG, "Wrong value passed for CADtlsPskCredType_t."); - ret = -1; } break; } @@ -522,7 +523,9 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type, (void)UNUSED1; (void)UNUSED2; - if (NULL == result || result_length < OWNER_PSK_LENGTH_128) + if ((NULL == result) + || (result_length < OWNER_PSK_LENGTH_128) + || (result_length > INT_MAX)) { return ret; } @@ -547,7 +550,7 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type, ret = -1; break; } - ret = result_length; + ret = (int32_t)result_length; OIC_LOG(DEBUG, TAG, "PSK HINT : "); OIC_LOG_BUFFER(DEBUG, TAG, result, result_length); @@ -565,10 +568,10 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type, if(cred) { char* pinBuffer = NULL; - uint32_t pinLength = 0; + size_t pinLength = 0; if(OIC_ENCODING_RAW == cred->privateData.encoding) { - pinBuffer = OICCalloc(1, cred->privateData.len + 1); + pinBuffer = (char*)OICCalloc(1, cred->privateData.len + 1); if(NULL == pinBuffer) { OIC_LOG (ERROR, TAG, "Failed to allocate memory"); @@ -580,7 +583,7 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type, else if(OIC_ENCODING_BASE64 == cred->privateData.encoding) { size_t pinBufSize = B64DECODE_OUT_SAFESIZE((cred->privateData.len + 1)); - pinBuffer = OICCalloc(1, pinBufSize); + pinBuffer = (char*)OICCalloc(1, pinBufSize); if(NULL == pinBuffer) { OIC_LOG (ERROR, TAG, "Failed to allocate memory"); @@ -590,6 +593,7 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type, if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength)) { OIC_LOG (ERROR, TAG, "Failed to base64 decoding."); + OICFree(pinBuffer); return ret; } } @@ -665,10 +669,10 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type, if(cred) { char* pinBuffer = NULL; - uint32_t pinLength = 0; + size_t pinLength = 0; if(OIC_ENCODING_RAW == cred->privateData.encoding) { - pinBuffer = OICCalloc(1, cred->privateData.len + 1); + pinBuffer = (char*)OICCalloc(1, cred->privateData.len + 1); if(NULL == pinBuffer) { OIC_LOG (ERROR, TAG, "Failed to allocate memory"); @@ -680,7 +684,7 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type, else if(OIC_ENCODING_BASE64 == cred->privateData.encoding) { size_t pinBufSize = B64DECODE_OUT_SAFESIZE((cred->privateData.len + 1)); - pinBuffer = OICCalloc(1, pinBufSize); + pinBuffer = (char*)OICCalloc(1, pinBufSize); if(NULL == pinBuffer) { OIC_LOG (ERROR, TAG, "Failed to allocate memory"); @@ -690,6 +694,7 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type, if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength)) { OIC_LOG (ERROR, TAG, "Failed to base64 decoding."); + OICFree(pinBuffer); return ret; } } diff --git a/resource/csdk/security/src/pbkdf2.c b/resource/csdk/security/src/pbkdf2.c index 0f3da99..66a224a 100644 --- a/resource/csdk/security/src/pbkdf2.c +++ b/resource/csdk/security/src/pbkdf2.c @@ -21,18 +21,31 @@ #include "logger.h" #include "mbedtls/pkcs5.h" #include "mbedtls/md.h" +#include #define TAG "OIC_SEC_PBDKF2" int DeriveCryptoKeyFromPassword(const unsigned char *passwd, size_t pLen, - const uint8_t *salt, const size_t saltLen, - const size_t iterations, - const size_t keyLen, uint8_t *derivedKey) + const uint8_t *salt, size_t saltLen, + size_t iterations, + size_t keyLen, uint8_t *derivedKey) { mbedtls_md_context_t sha_ctx; const mbedtls_md_info_t *info_sha; int ret = -1; + if (iterations > UINT_MAX) + { + OIC_LOG_V(ERROR, TAG, "Number of iterations over maximum %u", UINT_MAX); + return ret; + } + + if (keyLen > UINT32_MAX) + { + OIC_LOG_V(ERROR, TAG, "Key length over maximum %u", UINT32_MAX); + return ret; + } + /* Setup the hash/HMAC function, for the PBKDF2 function. */ mbedtls_md_init(&sha_ctx); @@ -50,7 +63,11 @@ int DeriveCryptoKeyFromPassword(const unsigned char *passwd, size_t pLen, return ret; } - ret = mbedtls_pkcs5_pbkdf2_hmac(&sha_ctx, passwd, pLen, salt, saltLen, iterations, keyLen, derivedKey); + ret = mbedtls_pkcs5_pbkdf2_hmac(&sha_ctx, + passwd, pLen, + salt, saltLen, + (unsigned int)iterations, + (uint32_t)keyLen, derivedKey); if (ret != 0) { OIC_LOG(ERROR, TAG, "Call to mbedtls PBKDF2 function failed"); diff --git a/resource/csdk/security/src/pconfresource.c b/resource/csdk/security/src/pconfresource.c index 77bdc04..f30c84f 100644 --- a/resource/csdk/security/src/pconfresource.c +++ b/resource/csdk/security/src/pconfresource.c @@ -186,7 +186,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si } uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); cborEncoderResult = cbor_encoder_create_map(&encoder, &pconfMap, mapSize); @@ -468,7 +468,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec cborFindResult = cbor_value_enter_container(&pconfCbor, &pconfMap); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter map"); pconf = (OicSecPconf_t *)OICCalloc(1, sizeof(*pconf)); - VERIFY_NON_NULL(TAG, pconf, ERROR); + VERIFY_NOT_NULL(TAG, pconf, ERROR); while (cbor_value_is_valid(&pconfMap)) { char *name = NULL; @@ -499,7 +499,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec VERIFY_SUCCESS(TAG, pconf->prmLen != 0, ERROR); pconf->prm = (OicSecPrm_t *)OICCalloc(pconf->prmLen, sizeof(OicSecPrm_t)); - VERIFY_NON_NULL(TAG, pconf->prm, ERROR); + VERIFY_NOT_NULL(TAG, pconf->prm, ERROR); cborFindResult = cbor_value_enter_container(&pconfMap, &prm); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to eneter array"); @@ -537,7 +537,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec { CborValue pdAclMap = { .parser = NULL}; OicSecPdAcl_t *pdacl = (OicSecPdAcl_t *) OICCalloc(1, sizeof(OicSecPdAcl_t)); - VERIFY_NON_NULL(TAG, pdacl, ERROR); + VERIFY_NOT_NULL(TAG, pdacl, ERROR); cborFindResult = cbor_value_enter_container(&pdAclArray, &pdAclMap); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter"); @@ -569,7 +569,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter"); pdacl->resources = (char **) OICCalloc(pdacl->resourcesLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, pdacl->resources, ERROR); + VERIFY_NOT_NULL(TAG, pdacl->resources, ERROR); while (cbor_value_is_valid(&resources)) { @@ -660,7 +660,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec cborFindResult = cbor_value_enter_container(&pdAclMap, &period); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter"); pdacl->periods = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, pdacl->periods, ERROR); + VERIFY_NOT_NULL(TAG, pdacl->periods, ERROR); while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period)) { @@ -683,7 +683,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec cborFindResult = cbor_value_enter_container(&pdAclMap, &recurrences); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter"); pdacl->recurrences = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, pdacl->recurrences, ERROR); + VERIFY_NOT_NULL(TAG, pdacl->recurrences, ERROR); while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences)) { @@ -737,7 +737,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to enter"); pconf->pddevs = (OicUuid_t *)OICMalloc(pconf->pddevLen * sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, pconf->pddevs, ERROR); + VERIFY_NOT_NULL(TAG, pconf->pddevs, ERROR); while (cbor_value_is_valid(&pddevs) && cbor_value_is_text_string(&pddevs)) { char *pddev = NULL; @@ -1080,7 +1080,7 @@ OCStackResult InitPconfResource() VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR); memcpy(&gPconf->deviceID, &deviceId, sizeof(OicUuid_t)); } - VERIFY_NON_NULL(TAG, gPconf, ERROR); + VERIFY_NOT_NULL(TAG, gPconf, ERROR); // Instantiate 'oic.sec.pconf' ret = CreatePconfResource(); diff --git a/resource/csdk/security/src/policyengine.c b/resource/csdk/security/src/policyengine.c index 779688c..534faf3 100644 --- a/resource/csdk/security/src/policyengine.c +++ b/resource/csdk/security/src/policyengine.c @@ -554,9 +554,9 @@ SRMAccessResponse_t CheckPermission(PEContext_t *context, { SRMAccessResponse_t retVal = ACCESS_DENIED_POLICY_ENGINE_ERROR; - VERIFY_NON_NULL(TAG, context, ERROR); - VERIFY_NON_NULL(TAG, subjectId, ERROR); - VERIFY_NON_NULL(TAG, resource, ERROR); + VERIFY_NOT_NULL(TAG, context, ERROR); + VERIFY_NOT_NULL(TAG, subjectId, ERROR); + VERIFY_NOT_NULL(TAG, resource, ERROR); // Each state machine context can only be processing one request at a time. // Therefore if the context is not in AWAITING_REQUEST or AWAITING_AMS_RESPONSE diff --git a/resource/csdk/security/src/psinterface.c b/resource/csdk/security/src/psinterface.c index 5d219bd..3a8518e 100644 --- a/resource/csdk/security/src/psinterface.c +++ b/resource/csdk/security/src/psinterface.c @@ -101,17 +101,17 @@ OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **dat OCStackResult ret = OC_STACK_ERROR; OCPersistentStorage *ps = SRMGetPersistentStorageHandler(); - VERIFY_NON_NULL(TAG, ps, ERROR); + VERIFY_NOT_NULL(TAG, ps, ERROR); fileSize = GetSVRDatabaseSize(ps); OIC_LOG_V(DEBUG, TAG, "File Read Size: %zu", fileSize); if (fileSize) { fsData = (uint8_t *) OICCalloc(1, fileSize); - VERIFY_NON_NULL(TAG, fsData, ERROR); + VERIFY_NOT_NULL(TAG, fsData, ERROR); fp = ps->open(SVR_DB_DAT_FILE_NAME, "rb"); - VERIFY_NON_NULL(TAG, fp, ERROR); + VERIFY_NOT_NULL(TAG, fp, ERROR); if (ps->read(fsData, 1, fileSize, fp) == fileSize) { if (rsrcName) @@ -134,7 +134,7 @@ OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **dat { *size = fileSize; *data = (uint8_t *) OICCalloc(1, fileSize); - VERIFY_NON_NULL(TAG, *data, ERROR); + VERIFY_NOT_NULL(TAG, *data, ERROR); memcpy(*data, fsData, fileSize); ret = OC_STACK_OK; } @@ -280,7 +280,7 @@ OCStackResult UpdateSecureResourceInPS(const char *rsrcName, const uint8_t *psPa // This added '255' is arbitrary value that is added to cover the name of the resource, map addition and ending outPayload = (uint8_t *) OICCalloc(1, size); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); CborEncoder encoder; // will be initialized in |cbor_parser_init| cbor_encoder_init(&encoder, outPayload, size, 0); CborEncoder secRsrc; // will be initialized in |cbor_encoder_create_map| @@ -369,7 +369,7 @@ OCStackResult UpdateSecureResourceInPS(const char *rsrcName, const uint8_t *psPa // This added '255' is arbitrary value that is added to cover the name of the resource, map addition and ending outPayload = (uint8_t *) OICCalloc(1, size); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); CborEncoder encoder; // will be initialized in |cbor_parser_init| cbor_encoder_init(&encoder, outPayload, size, 0); CborEncoder secRsrc; // will be initialized in |cbor_encoder_create_map| @@ -517,7 +517,7 @@ OCStackResult ResetSecureResourceInPS(void) // This added '255' is arbitrary value added to cover the name of the resource, map addition, and ending outPayload = (uint8_t *) OICCalloc(1, size); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); CborEncoder encoder; cbor_encoder_init(&encoder, outPayload, size, 0); CborEncoder secRsrc; @@ -668,7 +668,7 @@ OCStackResult CreateResetProfile(void) { size_t size = aclCborLen + credCborLen + pstatCborLen + doxmCborLen + 255; resetPfCbor = (uint8_t *) OICCalloc(1, size); - VERIFY_NON_NULL(TAG, resetPfCbor, ERROR); + VERIFY_NOT_NULL(TAG, resetPfCbor, ERROR); CborEncoder encoder; // will be initialized in |cbor_parser_init| cbor_encoder_init(&encoder, resetPfCbor, size, 0); CborEncoder secRsrc; // will be initialized in |cbor_encoder_create_map| diff --git a/resource/csdk/security/src/pstatresource.c b/resource/csdk/security/src/pstatresource.c index dee9fd8..ae7f8f0 100644 --- a/resource/csdk/security/src/pstatresource.c +++ b/resource/csdk/security/src/pstatresource.c @@ -112,7 +112,7 @@ OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat, uint8_t **payload, int64_t cborEncoderResult = CborNoError; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); if (false == writableOnly) @@ -275,7 +275,7 @@ static OCStackResult CBORPayloadToPstatBin(const uint8_t *cborPayload, const siz VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Map."); pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t)); - VERIFY_NON_NULL(TAG, pstat, ERROR); + VERIFY_NOT_NULL(TAG, pstat, ERROR); cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_ISOP_NAME, &pstatMap); if (CborNoError == cborFindResult && cbor_value_is_boolean(&pstatMap)) @@ -369,7 +369,7 @@ static OCStackResult CBORPayloadToPstatBin(const uint8_t *cborPayload, const siz } else { - VERIFY_NON_NULL(TAG, gPstat, ERROR); + VERIFY_NOT_NULL(TAG, gPstat, ERROR); pstat->smLen = gPstat->smLen; pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t)); *pstat->sm = *gPstat->sm; @@ -388,7 +388,7 @@ static OCStackResult CBORPayloadToPstatBin(const uint8_t *cborPayload, const siz } else { - VERIFY_NON_NULL(TAG, gPstat, ERROR); + VERIFY_NOT_NULL(TAG, gPstat, ERROR); memcpy(pstat->rownerID.id, gPstat->rownerID.id, sizeof(gPstat->rownerID.id)); cborFindResult = CborNoError; } @@ -521,11 +521,11 @@ static OCEntityHandlerResult HandlePstatPostRequest(OCEntityHandlerRequest *ehRe { uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData; size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize; - VERIFY_NON_NULL(TAG, payload, ERROR); + VERIFY_NOT_NULL(TAG, payload, ERROR); bool roParsed = false; OCStackResult ret = CBORPayloadToPstatBin(payload, size, &pstat, &roParsed); - VERIFY_NON_NULL(TAG, pstat, ERROR); + VERIFY_NOT_NULL(TAG, pstat, ERROR); if (OC_STACK_OK == ret) { bool validReq = false; @@ -771,7 +771,7 @@ OCStackResult InitPstatResource() { gPstat = GetPstatDefault(); } - VERIFY_NON_NULL(TAG, gPstat, FATAL); + VERIFY_NOT_NULL(TAG, gPstat, FATAL); //In case of Pstat's device id is empty, fill the device id as doxm's device id. if(0 == memcmp(&gPstat->deviceID, &emptyUuid, sizeof(OicUuid_t))) diff --git a/resource/csdk/security/src/secureresourcemanager.c b/resource/csdk/security/src/secureresourcemanager.c index a8cd632..83614c2 100644 --- a/resource/csdk/security/src/secureresourcemanager.c +++ b/resource/csdk/security/src/secureresourcemanager.c @@ -54,6 +54,35 @@ static SPResponseCallback gSPResponseHandler = NULL; */ PEContext_t g_policyEngineContext; + +/** + * Function to retrieve the length of the resource URI address part. + * + * @param resourceUri A null-terminated string representing the resource URI. + * + * @return Length of the resource URI address or -1, if failed. + */ +static int GetResourceUriAddressLength(CAURI_t resourceUri) +{ + if (!resourceUri) + { + OIC_LOG(ERROR, TAG, "Missing resource URI"); + return -1; + } + + size_t resourceUriLength = strlen(resourceUri); + if (resourceUriLength > MAX_URI_LENGTH) + { + OIC_LOG(ERROR, TAG, "Invalid resource URI length"); + return -1; + } + + //Check the URI has the query and skip it before checking the permission + char *uri = strstr(resourceUri, "?"); + + return uri ? (int)(uri - resourceUri) : (int)resourceUriLength; +} + /** * Function to register provisoning API's response callback. * @param respHandler response handler callback. @@ -149,32 +178,17 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ isRequestOverSecureChannel = true; } - //Check the URI has the query and skip it before checking the permission - if (NULL == requestInfo->info.resourceUri) - { - OIC_LOG(ERROR, TAG, "Invalid resourceUri"); - return; - } + CAURI_t resourceUri = requestInfo->info.resourceUri; + int resourceUriAddressLength = GetResourceUriAddressLength(resourceUri); - char *uri = strstr(requestInfo->info.resourceUri, "?"); - int position = 0; - if (uri) + if (resourceUriAddressLength < 0) { - //Skip query and pass the resource uri - position = uri - requestInfo->info.resourceUri; - } - else - { - position = strlen(requestInfo->info.resourceUri); - } - if (MAX_URI_LENGTH < position || 0 > position) - { - OIC_LOG(ERROR, TAG, "Incorrect URI length"); return; } + SRMAccessResponse_t response = ACCESS_DENIED; char newUri[MAX_URI_LENGTH + 1]; - OICStrcpyPartial(newUri, MAX_URI_LENGTH + 1, requestInfo->info.resourceUri, position); + OICStrcpyPartial(newUri, MAX_URI_LENGTH + 1, resourceUri, resourceUriAddressLength); SetResourceRequestType(&g_policyEngineContext, newUri); @@ -221,14 +235,14 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ if (AWAITING_REQUEST == g_policyEngineContext.state) { OIC_LOG_V(DEBUG, TAG, "Processing request with uri, %s for method, %d", - requestInfo->info.resourceUri, requestInfo->method); + resourceUri, requestInfo->method); response = CheckPermission(&g_policyEngineContext, &subjectId, newUri, GetPermissionFromCAMethod_t(requestInfo->method)); } else { OIC_LOG_V(INFO, TAG, "PE state %d. Ignoring request with uri, %s for method, %d", - g_policyEngineContext.state, requestInfo->info.resourceUri, requestInfo->method); + g_policyEngineContext.state, resourceUri, requestInfo->method); } if (IsAccessGranted(response) && gRequestHandler) @@ -237,7 +251,7 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ return; } - VERIFY_NON_NULL(TAG, gRequestHandler, ERROR); + VERIFY_NOT_NULL(TAG, gRequestHandler, ERROR); if (ACCESS_WAITING_FOR_AMS == response) { diff --git a/resource/csdk/security/src/srmutility.c b/resource/csdk/security/src/srmutility.c index 0080407..cac74fd 100644 --- a/resource/csdk/security/src/srmutility.c +++ b/resource/csdk/security/src/srmutility.c @@ -118,7 +118,7 @@ OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid) size_t urnIdx = 0; const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1; char* convertedUrn = (char*)OICCalloc(urnBufSize, sizeof(char)); - VERIFY_NON_NULL(TAG, convertedUrn, ERROR); + VERIFY_NOT_NULL(TAG, convertedUrn, ERROR); for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize; uuidIdx++, urnIdx+=2) { diff --git a/resource/csdk/security/src/svcresource.c b/resource/csdk/security/src/svcresource.c index 6020d71..77398c5 100644 --- a/resource/csdk/security/src/svcresource.c +++ b/resource/csdk/security/src/svcresource.c @@ -99,7 +99,7 @@ OCStackResult SVCToCBORPayload(const OicSecSvc_t *svc, uint8_t **cborPayload, CborEncoder svcArray; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); @@ -214,7 +214,7 @@ OCStackResult CBORPayloadToSVC(const uint8_t *cborPayload, size_t size, { CborValue svcMap = { .parser = NULL }; OicSecSvc_t *svc = (OicSecSvc_t *) OICCalloc(1, sizeof(OicSecSvc_t)); - VERIFY_NON_NULL(TAG, svc, ERROR); + VERIFY_NOT_NULL(TAG, svc, ERROR); cborFindResult = cbor_value_enter_container(&svcArray, &svcMap); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to Enter SVC Map."); @@ -260,7 +260,7 @@ OCStackResult CBORPayloadToSVC(const uint8_t *cborPayload, size_t size, cborFindResult = cbor_value_enter_container(&svcMap, &owners); VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to Enter Owner Array."); svc->owners = (OicUuid_t *)OICCalloc(svc->ownersLen, sizeof(*svc->owners)); - VERIFY_NON_NULL(TAG, svc->owners, ERROR); + VERIFY_NOT_NULL(TAG, svc->owners, ERROR); while (cbor_value_is_valid(&owners) && cbor_value_is_byte_string(&owners)) { diff --git a/resource/csdk/security/src/verresource.c b/resource/csdk/security/src/verresource.c index e2363ad..4a61953 100644 --- a/resource/csdk/security/src/verresource.c +++ b/resource/csdk/security/src/verresource.c @@ -99,7 +99,7 @@ OCStackResult VerToCBORPayload(const OicSecVer_t *ver, uint8_t **payload, size_t char* strUuid = NULL; uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborLen, 0); cborEncoderResult |= cbor_encoder_create_map(&encoder, &verMap, mapSize); @@ -179,7 +179,7 @@ OCStackResult CBORPayloadToVer(const uint8_t *cborPayload, size_t size, cbor_parser_init(cborPayload, size, 0, &parser, &verCbor); CborValue verMap = { .parser = NULL }; OicSecVer_t *ver = (OicSecVer_t *)OICCalloc(1, sizeof(OicSecVer_t)); - VERIFY_NON_NULL(TAG, ver, ERROR); + VERIFY_NOT_NULL(TAG, ver, ERROR); cborFindResult = cbor_value_map_find_value(&verCbor, OIC_JSON_SEC_V_NAME, &verMap); diff --git a/resource/csdk/security/tool/SConscript b/resource/csdk/security/tool/SConscript index 15c2181..baeedfe 100644 --- a/resource/csdk/security/tool/SConscript +++ b/resource/csdk/security/tool/SConscript @@ -18,9 +18,9 @@ # // # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # -Import('env') +Import('libocsrm_env') -tools_env = env.Clone() +tools_env = libocsrm_env.Clone() src_dir = tools_env.get('SRC_DIR') target_os = tools_env.get('TARGET_OS') @@ -50,6 +50,8 @@ tools_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra', '-std=c++0x' tools_env.AppendUnique(LIBPATH = [tools_env.get('BUILD_DIR')]) tools_env.AppendUnique(RPATH = [tools_env.get('BUILD_DIR')]) +tools_env.PrepareLib('cjson') + if target_os in ['msys_nt', 'windows']: # octbstack.dll doesn't export all the functions called by this app, so use static LIBs instead. tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto', @@ -58,13 +60,14 @@ elif target_os in ['darwin']: tools_env.AppendUnique(LIBS = ['coap', 'tinydtls', 'mbedtls', 'mbedx509', 'mbedcrypto', 'octbstack', 'ocsrm', 'connectivity_abstraction']) else: - tools_env.PrependUnique(LIBS = ['octbstack', 'm']) + tools_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'm']) + +tools_env.PrependUnique(LIBS = ['cjsonLibrary']) ###################################################################### # Source files and Targets ###################################################################### -json2cbor_src = ['../../../../extlibs/cjson/cJSON.c', - 'json2cbor.c',] +json2cbor_src = ['json2cbor.c'] json2cbor = tools_env.Program('json2cbor', json2cbor_src) Alias("json2cbor", [json2cbor]) -env.AppendTarget('json2cbor') +tools_env.AppendTarget('json2cbor') diff --git a/resource/csdk/security/tool/json2cbor.c b/resource/csdk/security/tool/json2cbor.c index 762845c..22fa723 100644 --- a/resource/csdk/security/tool/json2cbor.c +++ b/resource/csdk/security/tool/json2cbor.c @@ -42,7 +42,7 @@ #include "security_internals.h" #define TAG "OIC_JSON2CBOR" -#define MAX_RANGE ((size_t)-1) +#define MAX_RANGE SIZE_MAX //SVR database buffer block size #define DB_FILE_SIZE_BLOCK 1023 @@ -98,7 +98,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName } jsonStr = (char *)OICMalloc(size + 1); - VERIFY_NON_NULL(TAG, jsonStr, FATAL); + VERIFY_NOT_NULL(TAG, jsonStr, FATAL); fp = fopen(jsonFileName, "r"); if (fp) @@ -124,7 +124,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecAcl_t *acl = JSONToAclBin(jsonStr); - VERIFY_NON_NULL(TAG, acl, FATAL); + VERIFY_NOT_NULL(TAG, acl, FATAL); ret = AclToCBORPayload(acl, &aclCbor, &aclCborSize); if(OC_STACK_OK != ret) { @@ -141,7 +141,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecPstat_t *pstat = JSONToPstatBin(jsonStr); - VERIFY_NON_NULL(TAG, pstat, FATAL); + VERIFY_NOT_NULL(TAG, pstat, FATAL); ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize, false); if(OC_STACK_OK != ret) { @@ -157,7 +157,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecDoxm_t *doxm = JSONToDoxmBin(jsonStr); - VERIFY_NON_NULL(TAG, doxm, FATAL); + VERIFY_NOT_NULL(TAG, doxm, FATAL); ret = DoxmToCBORPayload(doxm, &doxmCbor, &doxmCborSize, false); if(OC_STACK_OK != ret) { @@ -173,7 +173,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecAmacl_t *amacl = JSONToAmaclBin(jsonStr); - VERIFY_NON_NULL(TAG, amacl, FATAL); + VERIFY_NOT_NULL(TAG, amacl, FATAL); ret = AmaclToCBORPayload(amacl, &amaclCbor, &amaclCborSize); if(OC_STACK_OK != ret) { @@ -189,7 +189,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecSvc_t *svc = JSONToSvcBin(jsonStr); - VERIFY_NON_NULL(TAG, svc, FATAL); + VERIFY_NOT_NULL(TAG, svc, FATAL); ret = SVCToCBORPayload(svc, &svcCbor, &svcCborSize); if(OC_STACK_OK != ret) { @@ -207,7 +207,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName if (NULL != value) { OicSecCred_t *cred = JSONToCredBin(jsonStr); - VERIFY_NON_NULL(TAG, cred, FATAL); + VERIFY_NOT_NULL(TAG, cred, FATAL); ret = CredToCBORPayload(cred, &credCbor, &credCborSize, secureFlag); if(OC_STACK_OK != ret) { @@ -225,7 +225,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName printf("Total Cbor Size : %zd\n", cborSize); cborSize += 255; // buffer margin for adding map and byte string uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborSize); - VERIFY_NON_NULL(TAG, outPayload, ERROR); + VERIFY_NOT_NULL(TAG, outPayload, ERROR); cbor_encoder_init(&encoder, outPayload, cborSize, 0); CborEncoder map; CborError cborEncoderResult = cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength); @@ -314,24 +314,24 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t)); cJSON *jsonRoot = NULL; - VERIFY_NON_NULL(TAG, jsonStr, ERROR); + VERIFY_NOT_NULL(TAG, jsonStr, ERROR); jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); + VERIFY_NOT_NULL(TAG, jsonRoot, ERROR); cJSON *jsonAclMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME); - VERIFY_NON_NULL(TAG, jsonAclMap, ERROR); + VERIFY_NOT_NULL(TAG, jsonAclMap, ERROR); cJSON *jsonAclObj = NULL; // aclist jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ACLIST_NAME); - VERIFY_NON_NULL(TAG, jsonAclObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonAclObj, ERROR); // aclist-aces cJSON *jsonAclArray = NULL; jsonAclArray = cJSON_GetObjectItem(jsonAclObj, OIC_JSON_ACES_NAME); - VERIFY_NON_NULL(TAG, jsonAclArray, ERROR); + VERIFY_NOT_NULL(TAG, jsonAclArray, ERROR); if (cJSON_Array == jsonAclArray->type) { @@ -343,16 +343,16 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) do { cJSON *jsonAcl = cJSON_GetArrayItem(jsonAclArray, idx); - VERIFY_NON_NULL(TAG, jsonAcl, ERROR); + VERIFY_NOT_NULL(TAG, jsonAcl, ERROR); OicSecAce_t *ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); LL_APPEND(headAcl->aces, ace); size_t jsonObjLen = 0; cJSON *jsonObj = NULL; jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_SUBJECTID_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0) { @@ -365,29 +365,31 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) } // Resources -- Mandatory jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_RESOURCES_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR); - size_t resourcesLen = (size_t)cJSON_GetArraySize(jsonObj); + size_t resourcesLen = cJSON_GetArraySize(jsonObj); VERIFY_SUCCESS(TAG, resourcesLen > 0, ERROR); for(size_t idxx = 0; idxx < resourcesLen; idxx++) { OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, rsrc, ERROR); + VERIFY_NOT_NULL(TAG, rsrc, ERROR); +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonRsrc = cJSON_GetArrayItem(jsonObj, idxx); - VERIFY_NON_NULL(TAG, jsonRsrc, ERROR); + VERIFY_NOT_NULL(TAG, jsonRsrc, ERROR); //href size_t jsonRsrcObjLen = 0; cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME); - VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonRsrcObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR); jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1; rsrc->href = (char*)OICMalloc(jsonRsrcObjLen); - VERIFY_NON_NULL(TAG, (rsrc->href), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->href), ERROR); OICStrcpy(rsrc->href, jsonRsrcObjLen, jsonRsrcObj->valuestring); //rel @@ -396,7 +398,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) { jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1; rsrc->rel = (char*)OICMalloc(jsonRsrcObjLen); - VERIFY_NON_NULL(TAG, (rsrc->rel), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->rel), ERROR); OICStrcpy(rsrc->rel, jsonRsrcObjLen, jsonRsrcObj->valuestring); } @@ -404,16 +406,18 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_RT_NAME); if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type) { - rsrc->typeLen = (size_t)cJSON_GetArraySize(jsonRsrcObj); + rsrc->typeLen = cJSON_GetArraySize(jsonRsrcObj); VERIFY_SUCCESS(TAG, (0 < rsrc->typeLen), ERROR); rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, (rsrc->types), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->types), ERROR); for(size_t i = 0; i < rsrc->typeLen; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonRsrcType = cJSON_GetArrayItem(jsonRsrcObj, i); - VERIFY_NON_NULL(TAG, jsonRsrcType, ERROR); + VERIFY_NOT_NULL(TAG, jsonRsrcType, ERROR); rsrc->types[i] = OICStrdup(jsonRsrcType->valuestring); - VERIFY_NON_NULL(TAG, (rsrc->types[i]), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->types[i]), ERROR); } } @@ -421,16 +425,18 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_IF_NAME); if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type) { - rsrc->interfaceLen = (size_t)cJSON_GetArraySize(jsonRsrcObj); + rsrc->interfaceLen = cJSON_GetArraySize(jsonRsrcObj); VERIFY_SUCCESS(TAG, (0 < rsrc->interfaceLen), ERROR); rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, (rsrc->interfaces), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->interfaces), ERROR); for(size_t i = 0; i < rsrc->interfaceLen; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonInterface = cJSON_GetArrayItem(jsonRsrcObj, i); - VERIFY_NON_NULL(TAG, jsonInterface, ERROR); + VERIFY_NOT_NULL(TAG, jsonInterface, ERROR); rsrc->interfaces[i] = OICStrdup(jsonInterface->valuestring); - VERIFY_NON_NULL(TAG, (rsrc->interfaces[i]), ERROR); + VERIFY_NOT_NULL(TAG, (rsrc->interfaces[i]), ERROR); } } @@ -439,7 +445,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) // Permissions -- Mandatory jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_PERMISSION_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); ace->permission = jsonObj->valueint; @@ -448,18 +454,20 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) if(jsonValidityObj) { VERIFY_SUCCESS(TAG, cJSON_Array == jsonValidityObj->type, ERROR); - size_t validityLen = (size_t) cJSON_GetArraySize(jsonValidityObj); + size_t validityLen = cJSON_GetArraySize(jsonValidityObj); VERIFY_SUCCESS(TAG, (0 < validityLen), ERROR); cJSON *jsonValidity = NULL; for(size_t i = 0; i < validityLen; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) jsonValidity = cJSON_GetArrayItem(jsonValidityObj, i); - VERIFY_NON_NULL(TAG, jsonValidity, ERROR); + VERIFY_NOT_NULL(TAG, jsonValidity, ERROR); VERIFY_SUCCESS(TAG, (jsonValidity->type == cJSON_Array), ERROR); OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - VERIFY_NON_NULL(TAG, validity, ERROR); + VERIFY_NOT_NULL(TAG, validity, ERROR); LL_APPEND(ace->validities, validity); //Period @@ -470,7 +478,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) jsonObjLen = strlen(jsonPeriod->valuestring) + 1; validity->period = (char*)OICMalloc(jsonObjLen); - VERIFY_NON_NULL(TAG, validity->period, ERROR); + VERIFY_NOT_NULL(TAG, validity->period, ERROR); OICStrcpy(validity->period, jsonObjLen, jsonPeriod->valuestring); } @@ -479,20 +487,22 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) if(jsonRecurObj) { VERIFY_SUCCESS(TAG, (cJSON_Array == jsonRecurObj->type), ERROR); - validity->recurrenceLen = (size_t) cJSON_GetArraySize(jsonRecurObj); + validity->recurrenceLen = cJSON_GetArraySize(jsonRecurObj); VERIFY_SUCCESS(TAG, (0 < validity->recurrenceLen), ERROR); validity->recurrences = (char**)OICCalloc(validity->recurrenceLen, sizeof(char*)); - VERIFY_NON_NULL(TAG, validity->recurrences, ERROR); + VERIFY_NOT_NULL(TAG, validity->recurrences, ERROR); cJSON *jsonRecur = NULL; for(size_t i = 0; i < validity->recurrenceLen; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i); - VERIFY_NON_NULL(TAG, jsonRecur, ERROR); + VERIFY_NOT_NULL(TAG, jsonRecur, ERROR); jsonObjLen = strlen(jsonRecur->valuestring) + 1; validity->recurrences[i] = (char*)OICMalloc(jsonObjLen); - VERIFY_NON_NULL(TAG, validity->recurrences[i], ERROR); + VERIFY_NOT_NULL(TAG, validity->recurrences[i], ERROR); OICStrcpy(validity->recurrences[i], jsonObjLen, jsonRecur->valuestring); } } @@ -504,7 +514,7 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr) // rownerid jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ROWNERID_NAME); - VERIFY_NON_NULL(TAG, jsonAclObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonAclObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonAclObj->type, ERROR); ret = ConvertStrToUuid(jsonAclObj->valuestring, &headAcl->rownerID); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR); @@ -537,32 +547,34 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) size_t jsonObjLen = 0; cJSON *jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); + VERIFY_NOT_NULL(TAG, jsonRoot, ERROR); jsonDoxm = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME); - VERIFY_NON_NULL(TAG, jsonDoxm, ERROR); + VERIFY_NOT_NULL(TAG, jsonDoxm, ERROR); doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t)); - VERIFY_NON_NULL(TAG, doxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm, ERROR); //OxmType -- not Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_TYPE_NAME); if ((jsonObj) && (cJSON_Array == jsonObj->type)) { - doxm->oxmTypeLen = (size_t)cJSON_GetArraySize(jsonObj); + doxm->oxmTypeLen = cJSON_GetArraySize(jsonObj); VERIFY_SUCCESS(TAG, doxm->oxmTypeLen > 0, ERROR); doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *)); - VERIFY_NON_NULL(TAG, (doxm->oxmType), ERROR); + VERIFY_NOT_NULL(TAG, (doxm->oxmType), ERROR); for (size_t i = 0; i < doxm->oxmTypeLen ; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonOxmTy = cJSON_GetArrayItem(jsonObj, i); - VERIFY_NON_NULL(TAG, jsonOxmTy, ERROR); + VERIFY_NOT_NULL(TAG, jsonOxmTy, ERROR); jsonObjLen = strlen(jsonOxmTy->valuestring) + 1; doxm->oxmType[i] = (char*)OICMalloc(jsonObjLen); - VERIFY_NON_NULL(TAG, doxm->oxmType[i], ERROR); + VERIFY_NOT_NULL(TAG, doxm->oxmType[i], ERROR); strncpy((char *)doxm->oxmType[i], (char *)jsonOxmTy->valuestring, jsonObjLen); } } @@ -571,21 +583,25 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXMS_NAME); if (jsonObj && cJSON_Array == jsonObj->type) { - doxm->oxmLen = (size_t)cJSON_GetArraySize(jsonObj); + doxm->oxmLen = cJSON_GetArraySize(jsonObj); VERIFY_SUCCESS(TAG, doxm->oxmLen > 0, ERROR); doxm->oxm = (OicSecOxm_t*)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t)); - VERIFY_NON_NULL(TAG, doxm->oxm, ERROR); + VERIFY_NOT_NULL(TAG, doxm->oxm, ERROR); for (size_t i = 0; i < doxm->oxmLen ; i++) { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonOxm = cJSON_GetArrayItem(jsonObj, i); - VERIFY_NON_NULL(TAG, jsonOxm, ERROR); + VERIFY_NOT_NULL(TAG, jsonOxm, ERROR); doxm->oxm[i] = (OicSecOxm_t)jsonOxm->valueint; } } //OxmSel -- Mandatory +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_SEL_NAME); if (jsonObj) { @@ -616,7 +632,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) { VERIFY_SUCCESS(TAG, (cJSON_Number == jsonObj->type), ERROR); doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t)); - VERIFY_NON_NULL(TAG, doxm->mom, ERROR); + VERIFY_NOT_NULL(TAG, doxm->mom, ERROR); doxm->mom->mode = (OicSecMomType_t)jsonObj->valueint; } #endif //MULTIPLE_OWNER @@ -641,7 +657,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_ROWNERID_NAME); if (true == doxm->owned) { - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); } if (jsonObj) { @@ -653,7 +669,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVOWNERID_NAME); if (true == doxm->owned) { - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); } if (jsonObj) { @@ -688,47 +704,47 @@ OicSecPstat_t* JSONToPstatBin(const char * jsonStr) cJSON *jsonObj = NULL; cJSON *jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, INFO); + VERIFY_NOT_NULL(TAG, jsonRoot, INFO); jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME); - VERIFY_NON_NULL(TAG, jsonPstat, INFO); + VERIFY_NOT_NULL(TAG, jsonPstat, INFO); pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t)); - VERIFY_NON_NULL(TAG, pstat, INFO); + VERIFY_NOT_NULL(TAG, pstat, INFO); jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ISOP_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type) , ERROR); pstat->isOp = jsonObj->valueint; jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_DEVICE_ID_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->deviceID); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR); jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ROWNERID_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->rownerID); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR); jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_CM_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); pstat->cm = (OicSecDpm_t)jsonObj->valueint; jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_TM_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); pstat->tm = (OicSecDpm_t)jsonObj->valueint; jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); pstat->om = (OicSecDpom_t)jsonObj->valueint; jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_SM_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); pstat->smLen = 1; pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t)); @@ -781,18 +797,18 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) OicSecCred_t *headCred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t)); OCStackResult ret = OC_STACK_ERROR; cJSON *jsonRoot = NULL; - VERIFY_NON_NULL(TAG, headCred, ERROR); + VERIFY_NOT_NULL(TAG, headCred, ERROR); jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); + VERIFY_NOT_NULL(TAG, jsonRoot, ERROR); cJSON *jsonCredMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME); - VERIFY_NON_NULL(TAG, jsonCredMap, ERROR); + VERIFY_NOT_NULL(TAG, jsonCredMap, ERROR); // creds cJSON *jsonCredArray = NULL; jsonCredArray = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_CREDS_NAME); - VERIFY_NON_NULL(TAG, jsonCredArray, ERROR); + VERIFY_NOT_NULL(TAG, jsonCredArray, ERROR); if (cJSON_Array == jsonCredArray->type) { @@ -802,7 +818,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) do { cJSON *jsonCred = cJSON_GetArrayItem(jsonCredArray, idx); - VERIFY_NON_NULL(TAG, jsonCred, ERROR); + VERIFY_NOT_NULL(TAG, jsonCred, ERROR); OicSecCred_t *cred = NULL; if(idx == 0) @@ -819,7 +835,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) } temp->next = cred; } - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); size_t jsonObjLen = 0; cJSON *jsonObj = NULL; @@ -834,7 +850,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) //subject -- Mandatory jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_SUBJECTID_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0) { @@ -848,7 +864,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) //CredType -- Mandatory jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDTYPE_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); cred->credType = (OicSecCredType_t)jsonObj->valueint; //PrivateData is mandatory for some of the credential types listed below. @@ -857,15 +873,15 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) if (NULL != jsonObj) { cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); - VERIFY_NON_NULL(TAG, jsonPriv, ERROR); + VERIFY_NOT_NULL(TAG, jsonPriv, ERROR); jsonObjLen = strlen(jsonPriv->valuestring); cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen); - VERIFY_NON_NULL(TAG, (cred->privateData.data), ERROR); + VERIFY_NOT_NULL(TAG, (cred->privateData.data), ERROR); memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen); cred->privateData.len = jsonObjLen; cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME); - VERIFY_NON_NULL(TAG, jsonEncoding, ERROR); + VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR); cred->privateData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring); } #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) @@ -875,10 +891,10 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) if (NULL != jsonObj) { cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); - VERIFY_NON_NULL(TAG, jsonPub, ERROR); + VERIFY_NOT_NULL(TAG, jsonPub, ERROR); jsonObjLen = strlen(jsonPub->valuestring); cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen); - VERIFY_NON_NULL(TAG, (cred->publicData.data), ERROR); + VERIFY_NOT_NULL(TAG, (cred->publicData.data), ERROR); memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen); cred->publicData.len = jsonObjLen; } @@ -888,19 +904,19 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) if (NULL != jsonObj) { cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); - VERIFY_NON_NULL(TAG, jsonOpt, ERROR); + VERIFY_NOT_NULL(TAG, jsonOpt, ERROR); jsonObjLen = strlen(jsonOpt->valuestring); cred->optionalData.data = (uint8_t *)OICCalloc(1, jsonObjLen); - VERIFY_NON_NULL(TAG, (cred->optionalData.data), ERROR); + VERIFY_NOT_NULL(TAG, (cred->optionalData.data), ERROR); memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen); cred->optionalData.len = jsonObjLen; cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME); - VERIFY_NON_NULL(TAG, jsonEncoding, ERROR); + VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR); cred->optionalData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring); cJSON *jsonRevstat = cJSON_GetObjectItem(jsonObj, OIC_JSON_REVOCATION_STATUS_NAME); - VERIFY_NON_NULL(TAG, jsonRevstat, ERROR); + VERIFY_NOT_NULL(TAG, jsonRevstat, ERROR); cred->optionalData.revstat = jsonObj->valueint; } @@ -910,7 +926,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) { jsonObjLen = strlen(jsonObj->valuestring); cred->credUsage = OICStrdup(jsonObj->valuestring); - VERIFY_NON_NULL(TAG, (cred->credUsage), ERROR); + VERIFY_NOT_NULL(TAG, (cred->credUsage), ERROR); } #endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__) @@ -921,7 +937,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) { jsonObjLen = strlen(jsonObj->valuestring) + 1; cred->period = (char *)OICMalloc(jsonObjLen); - VERIFY_NON_NULL(TAG, cred->period, ERROR); + VERIFY_NOT_NULL(TAG, cred->period, ERROR); strncpy(cred->period, jsonObj->valuestring, jsonObjLen); } cred->next = NULL; @@ -930,7 +946,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) // rownerid cJSON *jsonCredObj = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_ROWNERID_NAME); - VERIFY_NON_NULL(TAG, jsonCredObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonCredObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonCredObj->type, ERROR); ret = ConvertStrToUuid(jsonCredObj->valuestring, &headCred->rownerID); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR); @@ -954,13 +970,13 @@ static OicSecSvc_t* JSONToSvcBin(const char * jsonStr) cJSON *jsonRoot = NULL; cJSON *jsonSvcArray = NULL; - VERIFY_NON_NULL(TAG, jsonStr, ERROR); + VERIFY_NOT_NULL(TAG, jsonStr, ERROR); jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); + VERIFY_NOT_NULL(TAG, jsonRoot, ERROR); jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME); - VERIFY_NON_NULL(TAG, jsonSvcArray, INFO); + VERIFY_NOT_NULL(TAG, jsonSvcArray, INFO); if (cJSON_Array == jsonSvcArray->type) { @@ -971,10 +987,10 @@ static OicSecSvc_t* JSONToSvcBin(const char * jsonStr) do { cJSON *jsonSvc = cJSON_GetArrayItem(jsonSvcArray, idx); - VERIFY_NON_NULL(TAG, jsonSvc, ERROR); + VERIFY_NOT_NULL(TAG, jsonSvc, ERROR); OicSecSvc_t *svc = (OicSecSvc_t*)OICCalloc(1, sizeof(OicSecSvc_t)); - VERIFY_NON_NULL(TAG, svc, ERROR); + VERIFY_NOT_NULL(TAG, svc, ERROR); headSvc = (headSvc) ? headSvc : svc; if (prevSvc) @@ -984,12 +1000,12 @@ static OicSecSvc_t* JSONToSvcBin(const char * jsonStr) cJSON *jsonObj = NULL; unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {0}; - uint32_t outLen = 0; + size_t outLen = 0; B64Result b64Ret = B64_OK; // Service Device Identity jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_DEVICE_ID); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); outLen = 0; b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff, @@ -999,25 +1015,27 @@ static OicSecSvc_t* JSONToSvcBin(const char * jsonStr) // Service Type jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_TYPE); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); svc->svct = (OicSecSvcType_t)jsonObj->valueint; // Resource Owners jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_OWNERS_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR); - svc->ownersLen = (size_t)cJSON_GetArraySize(jsonObj); + svc->ownersLen = cJSON_GetArraySize(jsonObj); VERIFY_SUCCESS(TAG, svc->ownersLen > 0, ERROR); svc->owners = (OicUuid_t*)OICCalloc(svc->ownersLen, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, (svc->owners), ERROR); + VERIFY_NOT_NULL(TAG, (svc->owners), ERROR); size_t idxx = 0; do { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonOwnr = cJSON_GetArrayItem(jsonObj, idxx); - VERIFY_NON_NULL(TAG, jsonOwnr, ERROR); + VERIFY_NOT_NULL(TAG, jsonOwnr, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonOwnr->type, ERROR); outLen = 0; b64Ret = b64Decode(jsonOwnr->valuestring, strlen(jsonOwnr->valuestring), base64Buff, @@ -1052,60 +1070,64 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr) cJSON *jsonRoot = NULL; cJSON *jsonAmacl = NULL; - VERIFY_NON_NULL(TAG, jsonStr, ERROR); + VERIFY_NOT_NULL(TAG, jsonStr, ERROR); jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); + VERIFY_NOT_NULL(TAG, jsonRoot, ERROR); jsonAmacl = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME); - VERIFY_NON_NULL(TAG, jsonAmacl, INFO); + VERIFY_NOT_NULL(TAG, jsonAmacl, INFO); cJSON *jsonObj = NULL; // Resources -- Mandatory jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_RESOURCES_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); // Rlist cJSON *jsonRlistArray = cJSON_GetObjectItem(jsonObj, OIC_JSON_RLIST_NAME); - VERIFY_NON_NULL(TAG, jsonRlistArray, ERROR); + VERIFY_NOT_NULL(TAG, jsonRlistArray, ERROR); VERIFY_SUCCESS(TAG, cJSON_Array == jsonRlistArray->type, ERROR); - headAmacl->resourcesLen = (size_t)cJSON_GetArraySize(jsonRlistArray); + headAmacl->resourcesLen = cJSON_GetArraySize(jsonRlistArray); headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*)); size_t idxx = 0; do { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonRsrc = cJSON_GetArrayItem(jsonRlistArray, idxx); - VERIFY_NON_NULL(TAG, jsonRsrc, ERROR); + VERIFY_NOT_NULL(TAG, jsonRsrc, ERROR); cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME); - VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonRsrcObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR); size_t jsonRsrcObjLen = 0; jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1; headAmacl->resources[idxx] = (char*)OICMalloc(jsonRsrcObjLen); - VERIFY_NON_NULL(TAG, (headAmacl->resources[idxx]), ERROR); + VERIFY_NOT_NULL(TAG, (headAmacl->resources[idxx]), ERROR); OICStrcpy(headAmacl->resources[idxx], jsonRsrcObjLen, jsonRsrcObj->valuestring); } while ( ++idxx < headAmacl->resourcesLen); // Ams -- Mandatory jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_AMS_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR); - headAmacl->amssLen = (size_t)cJSON_GetArraySize(jsonObj); + headAmacl->amssLen = cJSON_GetArraySize(jsonObj); VERIFY_SUCCESS(TAG, headAmacl->amssLen > 0, ERROR); headAmacl->amss = (OicUuid_t*)OICCalloc(headAmacl->amssLen, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR); + VERIFY_NOT_NULL(TAG, headAmacl->amss, ERROR); idxx = 0; do { +// Needs to be removed once IOT-1746 is resolved. +#pragma warning(suppress : 4267) cJSON *jsonAms = cJSON_GetArrayItem(jsonObj, idxx); - VERIFY_NON_NULL(TAG, jsonAms, ERROR); + VERIFY_NOT_NULL(TAG, jsonAms, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonAms->type, ERROR); memcpy(headAmacl->amss[idxx].id, (OicUuid_t *)jsonAms->valuestring, strlen(jsonAms->valuestring)); @@ -1115,7 +1137,7 @@ static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr) // Rowner -- Mandatory jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_ROWNERID_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); + VERIFY_NOT_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); ret = ConvertStrToUuid(jsonObj->valuestring, &headAmacl->rownerID); diff --git a/resource/csdk/security/unittest/aclresourcetest.cpp b/resource/csdk/security/unittest/aclresourcetest.cpp index 3657ee5..5566e94 100644 --- a/resource/csdk/security/unittest/aclresourcetest.cpp +++ b/resource/csdk/security/unittest/aclresourcetest.cpp @@ -55,27 +55,27 @@ static bool AddResourceToACE(OicSecAce_t* ace, const char* rsrcName, { OicSecRsrc_t* rsrc = NULL; - VERIFY_NON_NULL(TAG, ace, ERROR); - VERIFY_NON_NULL(TAG, rsrcName, ERROR); - VERIFY_NON_NULL(TAG, interfaceName, ERROR); - VERIFY_NON_NULL(TAG, typeName, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, rsrcName, ERROR); + VERIFY_NOT_NULL(TAG, interfaceName, ERROR); + VERIFY_NOT_NULL(TAG, typeName, ERROR); rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - VERIFY_NON_NULL(TAG, rsrc, ERROR); + VERIFY_NOT_NULL(TAG, rsrc, ERROR); rsrc->href = OICStrdup(rsrcName); - VERIFY_NON_NULL(TAG, rsrc->href, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->href, ERROR); rsrc->typeLen = 1; rsrc->types = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->types, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->types, ERROR); rsrc->types[0] = OICStrdup(typeName); - VERIFY_NON_NULL(TAG, rsrc->types[0], ERROR); + VERIFY_NOT_NULL(TAG, rsrc->types[0], ERROR); rsrc->interfaceLen = 1; rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*)); - VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR); + VERIFY_NOT_NULL(TAG, rsrc->interfaces, ERROR); rsrc->interfaces[0] = OICStrdup(interfaceName); - VERIFY_NON_NULL(TAG, rsrc->interfaces[0], ERROR); + VERIFY_NOT_NULL(TAG, rsrc->interfaces[0], ERROR); LL_APPEND(ace->resources, rsrc); return true; @@ -380,7 +380,7 @@ static OCStackResult populateAcl(OicSecAcl_t *acl, int numRsrc) { OCStackResult ret = OC_STACK_ERROR; OicSecAce_t* ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t)); - VERIFY_NON_NULL(TAG, ace, ERROR); + VERIFY_NOT_NULL(TAG, ace, ERROR); memcpy(ace->subjectuuid.id, "2222222222222222", sizeof(ace->subjectuuid.id)); EXPECT_EQ(true, AddResourceToACE(ace, "/a/led", "oic.core", "oic.if.r")); diff --git a/resource/csdk/security/unittest/base64tests.cpp b/resource/csdk/security/unittest/base64tests.cpp index 68e30e2..046c33c 100644 --- a/resource/csdk/security/unittest/base64tests.cpp +++ b/resource/csdk/security/unittest/base64tests.cpp @@ -27,9 +27,8 @@ TEST(B64EncodeTest, ValidInputForEncoding) { char buf[128]; - uint32_t outputLength; - uint32_t expectedLength; - uint32_t i=0; + size_t outputLength = 0; + size_t i = 0; B64Result res = B64_OK; const char* input = "IoTivity base64~!@#$%^&*()-=0123456789<>?;:'[]{},.\"\\|"; @@ -92,11 +91,11 @@ TEST(B64EncodeTest, ValidInputForEncoding) "SW9UaXZpdHkgYmFzZTY0fiFAIyQlXiYqKCktPTAxMjM0NTY3ODk8Pj87OidbXXt9LC4iXHw=" }; - for(i=0; i< strlen(input); i++) + for (i = 0; i < strlen(input); i++) { memset(buf, 0, sizeof(buf)); - expectedLength = strlen(expectedOutput[i]); + size_t expectedLength = strlen(expectedOutput[i]); res = b64Encode((uint8_t*)input, i + 1, buf, 128, &outputLength); @@ -110,8 +109,8 @@ TEST(B64EncodeTest, ValidInputForEncoding) TEST(B64DeodeTest, ValidInputForDecoding) { uint8_t buf[128]; - uint32_t outputLength; - uint32_t i=0; + size_t outputLength = 0; + size_t i = 0; B64Result res = B64_OK; const char* input[53] = { @@ -171,7 +170,7 @@ TEST(B64DeodeTest, ValidInputForDecoding) }; const char* expectedOutput = "IoTivity base64~!@#$%^&*()-=0123456789<>?;:'[]{},.\"\\|"; - for(i=0; i< (sizeof(input)/sizeof(char*)); i++) + for (i = 0; i < (sizeof(input) / sizeof(char*)); i++) { memset(buf, 0, sizeof(buf)); @@ -187,8 +186,8 @@ TEST(B64DeodeTest, ValidInputForDecoding) TEST(B64DeodeTest, InvalidInputForDecoding) { uint8_t buf[128] = {0,}; - uint32_t outputLength; - uint32_t i=0; + size_t outputLength = 0; + size_t i = 0; const char* input[53] = { "SQ=", @@ -247,11 +246,11 @@ TEST(B64DeodeTest, InvalidInputForDecoding) }; const char* expectedOutput = "IoTivity base64~!@#$%^&*()-=0123456789<>?;:'[]{},.\"\\|"; - for(i=0; i< (sizeof(input)/sizeof(char*)); i++) + for (i = 0; i < (sizeof(input) / sizeof(char*)); i++) { memset(buf, 0, sizeof(buf)); - if( B64_OK == b64Decode(input[i], strlen(input[i]), buf, 128, &outputLength) ) + if (B64_OK == b64Decode(input[i], strlen(input[i]), buf, 128, &outputLength)) { EXPECT_NE(0, memcmp(expectedOutput, buf, i + 1)); } diff --git a/resource/csdk/security/unittest/credentialresource.cpp b/resource/csdk/security/unittest/credentialresource.cpp index 3dd6fd4..9c247fa 100644 --- a/resource/csdk/security/unittest/credentialresource.cpp +++ b/resource/csdk/security/unittest/credentialresource.cpp @@ -38,7 +38,7 @@ OicSecCred_t * getCredList() { size_t sz = 0; OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred)); - VERIFY_NON_NULL(TAG, cred, ERROR); + VERIFY_NOT_NULL(TAG, cred, ERROR); cred->credId = 1234; // use |memcpy| for copying full-lengthed UUID without null termination memcpy(cred->subject.id, "1111111111111111", sizeof(cred->subject.id)); @@ -46,7 +46,7 @@ OicSecCred_t * getCredList() #if 0 cred->roleIdsLen = 2; cred->roleIds = (OicSecRole_t *)OICCalloc(cred->roleIdsLen, sizeof(OicSecRole_t)); - VERIFY_NON_NULL(TAG, cred->roleIds, ERROR); + VERIFY_NOT_NULL(TAG, cred->roleIds, ERROR); OICStrcpy((char *)cred->roleIds[0].id, sizeof(cred->roleIds[0].id), "role11"); OICStrcpy((char *)cred->roleIds[1].id, sizeof(cred->roleIds[1].id), "role12"); #endif @@ -55,12 +55,12 @@ OicSecCred_t * getCredList() cred->privateData.encoding = OIC_ENCODING_RAW; cred->privateData.data = (uint8_t *)OICCalloc(1, strlen("My private Key11") + 1); cred->privateData.len = strlen("My private Key11"); - VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->privateData.data, ERROR); OICStrcpy((char *)cred->privateData.data, strlen("My private Key11")+1,"My private Key11"); // use |memcpy| for copying full-lengthed UUID without null termination memcpy(cred->rownerID.id, "aaaaaaaaaaaaaaaa", sizeof(cred->rownerID.id)); cred->next = (OicSecCred_t*)OICCalloc(1, sizeof(*cred->next)); - VERIFY_NON_NULL(TAG, cred->next, ERROR); + VERIFY_NOT_NULL(TAG, cred->next, ERROR); cred->next->credId = 5678; // use |memcpy| for copying full-lengthed UUID without null termination memcpy(cred->next->subject.id, "2222222222222222", sizeof(cred->next->subject.id)); @@ -72,12 +72,12 @@ OicSecCred_t * getCredList() cred->next->privateData.len = strlen("My private Key21"); sz = cred->next->privateData.len + 1; cred->next->privateData.data = (uint8_t *)OICCalloc(1, sz); - VERIFY_NON_NULL(TAG, cred->next->privateData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->next->privateData.data, ERROR); OICStrcpy((char *)cred->next->privateData.data, sz, "My private Key21"); #if 0 sz = strlen("My Public Key123") + 1; cred->next->publicData.data = (char *)OICCalloc(1, sz); - VERIFY_NON_NULL(TAG, cred->next->publicData.data, ERROR); + VERIFY_NOT_NULL(TAG, cred->next->publicData.data, ERROR); OICStrcpy(cred->next->publicData.data, sz,"My Public Key123"); #endif // use |memcpy| for copying full-lengthed UUID without null termination diff --git a/resource/csdk/security/unittest/securityresourcemanager.cpp b/resource/csdk/security/unittest/securityresourcemanager.cpp index 9a38f48..2fa77f4 100644 --- a/resource/csdk/security/unittest/securityresourcemanager.cpp +++ b/resource/csdk/security/unittest/securityresourcemanager.cpp @@ -80,7 +80,7 @@ int utclose(FILE *fp) int utunlink(const char *path) { EXPECT_TRUE((path != NULL)) << "utunlink\n"; - return unlink(path); + return remove(path); } static OCPersistentStorage gpsi; diff --git a/resource/csdk/security/unittest/srmtestcommon.cpp b/resource/csdk/security/unittest/srmtestcommon.cpp index 5bfe64e..eea01e4 100644 --- a/resource/csdk/security/unittest/srmtestcommon.cpp +++ b/resource/csdk/security/unittest/srmtestcommon.cpp @@ -71,7 +71,7 @@ bool ReadCBORFile(const char* filename, const char* rsrcname, uint8_t **payload, uint8_t *data = NULL; size_t size = 0; - int len = strlen(STRINGIZE(SECURITY_BUILD_UNITTEST_DIR)) + strlen(filename) + 1; + size_t len = strlen(STRINGIZE(SECURITY_BUILD_UNITTEST_DIR)) + strlen(filename) + 1; char *filepath = (char *)OICCalloc(1, len); if (!filepath) { @@ -81,7 +81,7 @@ bool ReadCBORFile(const char* filename, const char* rsrcname, uint8_t **payload, int ret = snprintf(filepath, len, "%s%s", STRINGIZE(SECURITY_BUILD_UNITTEST_DIR), filename); printf("Root build path: %s \n", filepath); - if (ret == len-1) + if (ret == (len - 1)) { FILE *fp = fopen(filepath, "rb"); if (fp) @@ -151,7 +151,7 @@ void SetPersistentHandler(OCPersistentStorage *ps, bool set) ps->read = fread; ps->write = fwrite; ps->close = fclose; - ps->unlink = unlink; + ps->unlink = remove; } else { diff --git a/resource/csdk/security/unittests/SConscript b/resource/csdk/security/unittests/SConscript new file mode 100644 index 0000000..76632c8 --- /dev/null +++ b/resource/csdk/security/unittests/SConscript @@ -0,0 +1,33 @@ +#****************************************************************** +# +# Copyright 2016 Microsoft +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# +# 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. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +## +# Script for building unit tests and libs. +## + +Import('test_env') + +security_test_env = test_env.Clone() + +if security_test_env.get('TARGET_OS') in ['windows', 'msys_nt']: + security_test_env.AppendUnique(CCFLAGS=['/W3', '/WX']) + +SConscript('../unittest/SConscript', exports = { 'test_env' : security_test_env }) +SConscript('../provisioning/unittest/SConscript', exports = { 'test_env' : security_test_env }) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript b/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript index 8a9699d..2ce662c 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript @@ -17,9 +17,11 @@ # limitations under the License. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Import('env') + +samples_env = env.Clone() +SConscript('#build_common/thread.scons', exports = {'thread_env' : samples_env}) -thread_env = SConscript('#build_common/thread.scons') -samples_env = thread_env.Clone() target_os = samples_env.get('TARGET_OS') with_ra = samples_env.get ('WITH_RA') diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp index 5ac7357..1abf2f9 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserverslow.cpp @@ -201,6 +201,9 @@ OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest void AlarmHandler(int sig); int WINAPI AlarmThread(void *seconds) { +// Explicit casts didn't remove this warning and we're guaranteed to be within +// bounds expected by sleep(). +#pragma warning( suppress : 4311 ) sleep((unsigned int)seconds); AlarmHandler(0); return 0; @@ -208,6 +211,8 @@ int WINAPI AlarmThread(void *seconds) void alarm(unsigned int seconds) { +// Explicit casts didn't remove this warning. +#pragma warning( suppress : 4312 ) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AlarmThread, (void*)seconds, 0, NULL); } #endif diff --git a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp index d5f3928..776a695 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp @@ -234,9 +234,9 @@ bool printPairingMethod(const OCDPDev_t* pDev) } bool bAvailable = true; - for(size_t i=0; iprmLen; i++) + for (size_t i = 0; i < pDev->prmLen; i++) { - printf(" [%ld] ", i+1); + printf(" [%" PRIuPTR "] ", i + 1); switch (pDev->prm[i]) { case DP_PRE_CONFIGURED: diff --git a/resource/csdk/unittests/SConscript b/resource/csdk/unittests/SConscript index 55b76bb..a3ee3a4 100644 --- a/resource/csdk/unittests/SConscript +++ b/resource/csdk/unittests/SConscript @@ -31,5 +31,4 @@ SConscript('../connectivity/test/SConscript', 'test_env') # Build Security Resource Manager and Provisioning API unit test if (target_os in ['linux', 'windows']) and (test_env.get('SECURED') == '1'): - SConscript('../security/unittest/SConscript', 'test_env') - SConscript('../security/provisioning/unittest/SConscript', 'test_env') + SConscript('../security/unittests/SConscript', 'test_env') diff --git a/resource/examples/SConscript b/resource/examples/SConscript index 59d9564..5bc0128 100644 --- a/resource/examples/SConscript +++ b/resource/examples/SConscript @@ -18,11 +18,13 @@ # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Import('env') + ## # Examples build script ## -thread_env = SConscript('#build_common/thread.scons') -lib_env = thread_env.Clone() +lib_env = env.Clone() +SConscript('#build_common/thread.scons', exports = {'thread_env' : lib_env}) # Add third party libraries SConscript('#resource/third_party_libs.scons', 'lib_env') diff --git a/resource/include/OCProvisioningManager.hpp b/resource/include/OCProvisioningManager.hpp index 8c87009..f38ce50 100644 --- a/resource/include/OCProvisioningManager.hpp +++ b/resource/include/OCProvisioningManager.hpp @@ -703,7 +703,7 @@ namespace OC /** * Common callback wrapper, which will be called from OC-APIs. */ - static void callbackWrapper(void* ctx, int nOfRes, + static void callbackWrapper(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError); #ifdef MULTIPLE_OWNER diff --git a/resource/provisioning/examples/SConscript b/resource/provisioning/examples/SConscript index c153316..f374c60 100644 --- a/resource/provisioning/examples/SConscript +++ b/resource/provisioning/examples/SConscript @@ -18,20 +18,21 @@ # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Import('env') + ## # Examples build script ## -thread_env = SConscript('#build_common/thread.scons') -lib_env = thread_env.Clone() -target_os = lib_env.get('TARGET_OS') +examples_env = env.Clone() +SConscript('#build_common/thread.scons', exports = {'thread_env' : examples_env}) -# Add third party libraries -SConscript('#resource/third_party_libs.scons', 'lib_env') +target_os = examples_env.get('TARGET_OS') -with_ra = lib_env.get('WITH_RA') -with_ra_ibb = lib_env.get('WITH_RA_IBB') +# Add third party libraries +SConscript('#resource/third_party_libs.scons', exports = {'lib_env' : examples_env}) -examples_env = lib_env.Clone() +with_ra = examples_env.get('WITH_RA') +with_ra_ibb = examples_env.get('WITH_RA_IBB') ###################################################################### # Build flags diff --git a/resource/provisioning/examples/cloudAuth.cpp b/resource/provisioning/examples/cloudAuth.cpp index f68e7df..813448d 100644 --- a/resource/provisioning/examples/cloudAuth.cpp +++ b/resource/provisioning/examples/cloudAuth.cpp @@ -104,7 +104,7 @@ OCStackResult SessionParsePayload(OCRepPayload *payload) { OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__); - VERIFY_NON_NULL(TAG, payload, ERROR); + VERIFY_NOT_NULL(TAG, payload, ERROR); SessionInit(); diff --git a/resource/provisioning/src/OCProvisioningManager.cpp b/resource/provisioning/src/OCProvisioningManager.cpp index 9bc698d..d329f65 100644 --- a/resource/provisioning/src/OCProvisioningManager.cpp +++ b/resource/provisioning/src/OCProvisioningManager.cpp @@ -990,7 +990,7 @@ namespace OC } #endif // __WITH_DTLS__ || __WITH_TLS__ - void OCSecureResource::callbackWrapper(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) + void OCSecureResource::callbackWrapper(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError) { PMResultList_t *results = nullptr; ProvisionContext* context = static_cast(ctx); @@ -1005,7 +1005,7 @@ namespace OC return; } - for (int i = 0; i < nOfRes; i++) + for (size_t i = 0; i < nOfRes; i++) { results->push_back(arr[i]); } diff --git a/resource/src/SConscript b/resource/src/SConscript index 0883838..3781026 100644 --- a/resource/src/SConscript +++ b/resource/src/SConscript @@ -22,13 +22,15 @@ # OCLib (share library) build script ## import os -thread_env = SConscript('#build_common/thread.scons') -lib_env = thread_env.Clone() + +Import('env') + +oclib_env = env.Clone() +SConscript('#build_common/thread.scons', exports = {'thread_env' : oclib_env}) # Add third party libraries -SConscript('#resource/third_party_libs.scons', 'lib_env') +SConscript('#resource/third_party_libs.scons', exports = {'lib_env' : oclib_env}) -oclib_env = lib_env.Clone() secured = oclib_env.get('SECURED') target_os = oclib_env.get('TARGET_OS') with_cloud = oclib_env.get('WITH_CLOUD') diff --git a/service/coap-http-proxy/SConscript b/service/coap-http-proxy/SConscript index 194c6de..3434b85 100644 --- a/service/coap-http-proxy/SConscript +++ b/service/coap-http-proxy/SConscript @@ -54,8 +54,9 @@ if with_upstream_libcoap == '1': env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include']) else: env.AppendUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include']) +local_env.PrepareLib('cjson') -local_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap']) +local_env.PrependUnique(LIBS = ['cjsonLibrary', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap']) if target_os not in ['windows']: local_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra']) @@ -73,7 +74,6 @@ if target_os == 'android': ###################################################################### proxy_src = [ - '../../extlibs/cjson/cJSON.c', './src/CoapHttpHandler.c', './src/CoapHttpMap.c', './src/CoapHttpParser.c', diff --git a/service/simulator/ramlparser/SConscript b/service/simulator/ramlparser/SConscript index b7575e3..5eb8f16 100755 --- a/service/simulator/ramlparser/SConscript +++ b/service/simulator/ramlparser/SConscript @@ -24,28 +24,31 @@ lib_env = env.Clone() SConscript('#service/third_party_libs.scons', 'lib_env') raml_env = lib_env.Clone() +raml_env.PrepareLib('cjson') +raml_env.PrepareLib('yaml') ###################################################################### # Build flags ###################################################################### -raml_env.AppendUnique(CPPPATH = ['../../../extlibs/timer']) -raml_env.AppendUnique(CPPPATH = ['raml/model','raml/jsonSchemaParser','raml', '../../../extlibs/yaml/yaml/src' , '../../../extlibs/yaml/yaml/include']) -raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread']) +raml_env.AppendUnique(CPPPATH = ['#/extlibs/timer', + '#/extlibs/cjson', + '#/extlibs/yaml/yaml/src' , + '#/extlibs/yaml/yaml/include', + 'raml/model', + 'raml/jsonSchemaParser', + 'raml']) +raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-O2', '-g', '-Wall', '-fmessage-length=0']) raml_env.AppendUnique(CPPDEFINES = ['LINUX']) - raml_env.Append( RPATH = env.Literal('\\$$ORIGIN')) -raml_env.AppendUnique(CPPPATH = ['../../../extlibs/cjson/']) raml_env.PrependUnique(LIBS = ['octbstack', 'YamlParser']) -raml_env.AppendUnique(LIBS = ['pthread', 'm']) - -raml_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x']) +raml_env.AppendUnique(LIBS = ['pthread', 'm', 'cjsonLibrary']) ###################################################################### # Source files and Targets ###################################################################### -raml_src = ['#extlibs/cjson/cJSON.c', env.Glob('raml/model/*.cpp'), env.Glob('raml/jsonSchemaParser/*.cpp'), env.Glob('raml/*.cpp')] +raml_src = [env.Glob('raml/model/*.cpp'), env.Glob('raml/jsonSchemaParser/*.cpp'), env.Glob('raml/*.cpp')] + ramlsdk = raml_env.SharedLibrary('RamlParser', raml_src) raml_env.InstallTarget(ramlsdk, 'libRaml') -SConscript('../../../extlibs/yaml/SConscript') -- 2.7.4