From 4d7d7d3bf745e9c42d1620de158820bd4ec9ae76 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Tue, 16 Feb 2016 16:07:11 +0000 Subject: [PATCH] Security code comments which are doxygen compliant Some file using comments similar to doxygen changed. Comments has been updated to used return instead of retval. Comments having in/out tags has been updated. Some functions missing space after keyword has been updated. Change-Id: I0e9b75d2f75576f992d0ff4bafeaf5ba16917cc6 Signed-off-by: Habib Virji Reviewed-on: https://gerrit.iotivity.org/gerrit/5027 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz Reviewed-on: https://gerrit.iotivity.org/gerrit/5757 --- resource/csdk/security/include/base64.h | 74 ++++----- .../csdk/security/include/internal/amaclresource.h | 14 +- resource/csdk/security/include/internal/amsmgr.h | 95 ++++++------ .../csdk/security/include/internal/credresource.h | 9 -- .../csdk/security/include/internal/crlresource.h | 43 +++--- .../csdk/security/include/internal/doxmresource.h | 31 ++-- .../csdk/security/include/internal/policyengine.h | 35 +++-- .../csdk/security/include/internal/pstatresource.h | 4 +- .../include/internal/secureresourcemanager.h | 68 ++++----- .../csdk/security/include/internal/svcresource.h | 4 +- resource/csdk/security/include/iotvticalendar.h | 70 ++++----- resource/csdk/security/include/pbkdf2.h | 52 +++---- resource/csdk/security/include/pinoxmcommon.h | 66 +++++---- .../security/include/securevirtualresourcetypes.h | 45 +++--- resource/csdk/security/include/srmutility.h | 47 +++--- resource/csdk/security/src/amaclresource.c | 24 +-- resource/csdk/security/src/amsmgr.c | 26 ++-- resource/csdk/security/src/base64.c | 122 ++++++--------- resource/csdk/security/src/credresource.c | 104 +++++-------- resource/csdk/security/src/crlresource.c | 31 ++-- resource/csdk/security/src/doxmresource.c | 141 +++++++----------- resource/csdk/security/src/iotvticalendar.c | 165 ++++++++------------- resource/csdk/security/src/oxmpincommon.c | 43 +++--- resource/csdk/security/src/pbkdf2.c | 47 +++--- resource/csdk/security/src/policyengine.c | 143 ++++++++---------- resource/csdk/security/src/psinterface.c | 2 +- resource/csdk/security/src/pstatresource.c | 17 +-- resource/csdk/security/src/resourcemanager.c | 2 +- resource/csdk/security/src/secureresourcemanager.c | 88 ++--------- resource/csdk/security/src/srmutility.c | 50 +++---- resource/csdk/security/src/svcresource.c | 43 +++--- 31 files changed, 709 insertions(+), 996 deletions(-) diff --git a/resource/csdk/security/include/base64.h b/resource/csdk/security/include/base64.h index 4d5837d..a983f1e 100644 --- a/resource/csdk/security/include/base64.h +++ b/resource/csdk/security/include/base64.h @@ -1,22 +1,22 @@ - /****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #ifndef _IOTVT_B64_H_ #define _IOTVT_B64_H_ @@ -41,27 +41,27 @@ extern "C" { #define B64DECODE_OUT_SAFESIZE(x) (((x)*3)/4) /** - * Result code of base64 functions + * Result code of base64 functions. */ -typedef enum { +typedef enum +{ B64_OK = 0, B64_INVALID_PARAM, B64_OUTPUT_BUFFER_TOO_SMALL, B64_ERROR -}B64Result; +} B64Result; /** * Encode the plain message in base64. * - * @param[in] in Plain message - * @param[in] inLen Byte length of 'in' - * @param[in,out] outBuf Output buffer - * Base64 encoded message will be written into 'outBuf' - * NOTE : This method adds a NULL to the string configuration - * @param[in] outBufSize Size of output buffer - * @param[out] outLen Byte length of encoded message + * @param in is the plain message to be converted. + * @param inLen is the byte length of plain message. + * @param outBuf is the output buffer containing Base64 encoded message. + * @note outBuf adds a NULL to the string configuration. + * @param outBufSize is the size of output buffer. + * @param outLen is the byte length of encoded message. * - * @return B64_OK for Success, otherwise some error value + * @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); @@ -69,14 +69,14 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, /** * Decode the encoded message in base64. * - * @param[in] in Base64 encoded message - * @param[in] inLen Byte lenth of 'in' - * @param[in, out] outBuf Output buffer - * Base64 decoded message will be written into 'outBuf' - * @param[in] outBufSize Size of output buffer - * @param[out] outLen Byte length of decoded message + * @param in is the Base64 encoded message to be converted. + * @param inLen is the byte length of the encoded message. + * @param outBuf is the output buffer containing decoded message. + * @note outBuf adds a NULL to the string configuration. + * @param outBufSize is the size of output buffer. + * @param outLen is the byte length of decoded message. * - * @return B64_OK for Success, otherwise some error value + * @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); diff --git a/resource/csdk/security/include/internal/amaclresource.h b/resource/csdk/security/include/internal/amaclresource.h index f724402..e3dc1fa 100755 --- a/resource/csdk/security/include/internal/amaclresource.h +++ b/resource/csdk/security/include/internal/amaclresource.h @@ -36,14 +36,12 @@ extern "C" { /** * Initialize Amacl resource by loading data from persistent storage. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitAmaclResource(); /** * Perform cleanup for Amacl resources. - * - * @retval none */ void DeInitAmaclResource(); @@ -52,13 +50,11 @@ void DeInitAmaclResource(); * If the Amacl is found for the given resource then populate the parameter * amsId with Amacl resource amss id. * - * @param resource resource for which AMS service is required. - * @param amsId ID of the ams service for the given resource - * - * @retval - * OC_STACK_OK If Amacl found for the resource - * OC_STACK_ERROR If no Amacl found for the resource + * @param resource for which AMS service is required. + * @param amsId of the ams service for the given resource. * + * @return ::OC_STACK_OK, if Amacl is found for the resource, else ::OC_STACK_ERROR, + * if no Amacl found for the resource. */ OCStackResult AmaclGetAmsDeviceId(const char *resource, OicUuid_t *amsId); diff --git a/resource/csdk/security/include/internal/amsmgr.h b/resource/csdk/security/include/internal/amsmgr.h index d9d74b5..e07b442 100644 --- a/resource/csdk/security/include/internal/amsmgr.h +++ b/resource/csdk/security/include/internal/amsmgr.h @@ -21,17 +21,18 @@ #ifndef IOTVT_SRM_AMSMGR_H #define IOTVT_SRM_AMSMGR_H +#include +#include + #include "ocstack.h" #include "logger.h" #include "policyengine.h" #include "securevirtualresourcetypes.h" #include "cainterface.h" -#include -#include typedef struct PEContext PEContext_t; /** - * @brief The AMS context.. + * The AMS context. */ typedef struct AmsMgrContext { @@ -40,103 +41,95 @@ typedef struct AmsMgrContext CARequestInfo_t *requestInfo; } AmsMgrContext_t; - /** - * @brief This method updates AmsMgr context's endpoint & requestInfo + * This method updates AmsMgr context's endpoint & requestInfo. * - * @param context Policy engine context. - * @param endpoint CA Endpoint info of the requester - * @param requestInfo CA RequestInfo of the requester + * @param context is the policy engine context. + * @param endpoint is the CA Endpoint info of the requester. + * @param requestInfo is the CA RequestInfo of the requester. + * + * @return ::OC_STACK_OK if successful, else other value in case of error. */ -OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endpoint, - const CARequestInfo_t *requestInfo); +OCStackResult UpdateAmsMgrContext(PEContext_t *context, + const CAEndpoint_t *endpoint, + const CARequestInfo_t *requestInfo); /** - * * This method is called by PolicyEngine to Discover AMS service. * It sends muticast discovery request such as * /oic/sec/doxm?deviceid="AMSSrvcDeviceID" to discover AMS service - * with deviceId="AMSSrvcDeviceID" - * - * @param context Policy engine context. + * with deviceId="AMSSrvcDeviceID". * - * @retval - * OC_STACK_OK If able to successfully send multicast discovery request. - * OC_STACK_ERROR If unable to successfully send multicast discovery request due to error. + * @param context is the policy engine context. * + * @return ::OC_STACK_OK,If able to successfully send multicast discovery request. + * else ::OC_STACK_ERROR, If unable to successfully send multicast discovery request + * due to error. */ OCStackResult DiscoverAmsService(PEContext_t *context); - /** - * * This method sends unicast request to retrieve the secured port info of the * discovered AMS service. It sends unicast discovery request such as - * /oic/res?rt="oic.sec.doxm" to the discovered AMS service + * /oic/res?rt="oic.sec.doxm" to the discovered AMS service. * - * @param context Policy engine context. - * - * @retval - * OC_STACK_OK If able to successfully send unicast discovery request - * OC_STACK_ERROR If unable to successfully send unicast discovery request due to error + * @param context is the policy engine context. * + * @return ::OC_STACK_OK,If able to successfully send unicast discovery request. + * else ::OC_STACK_ERROR, If unable to successfully send unicast discovery request + * due to error. */ -OCStackResult SendUnicastSecurePortDiscovery(PEContext_t *context,OCDevAddr *devAddr, - OCConnectivityType connType); - +OCStackResult SendUnicastSecurePortDiscovery(PEContext_t *context, + OCDevAddr *devAddr, + OCConnectivityType connType); /** - * * This method sends unicast request to AMS service to get ACL for * the Subject and/or Resource. It sends unicast request such as * /oic/sec/acl?sub="subjectId";rsrc="/a/led" to get the ACL for - * the subject & resource + * the subject & resource. * - * @param context Policy engine context. + * @param context is the policy engine context. * - * @retval - * OC_STACK_OK If able to successfully send unicast ACL request - * OC_STACK_ERROR If unable to successfully send unicast ACL request due to error + * @return ::OC_STACK_OK, If able to successfully send unicast ACL request. + * ::OC_STACK_ERROR, If unable to successfully send unicast ACL request due to error. * */ -OCStackResult SendAclReq(PEContext_t *context, OCDevAddr *devAddr, OCConnectivityType connType, - uint16_t securedPort); - +OCStackResult SendAclReq(PEContext_t *context, + OCDevAddr *devAddr, + OCConnectivityType connType, + uint16_t securedPort); /* - * Cleanup CARequestInfo_t object - * @param requestInfo pointer to RequestInfo_t object + * Cleanup CARequestInfo_t object. + * + * @param requestInfo is the pointer to @ref CARequestInfo_t. */ void FreeCARequestInfo(CARequestInfo_t *requestInfo); - /* * This method is used by Policy engine to checks Amacl resource. * If Amacl is found then it fills up context->amsMgrContext->amsDeviceId * with amsID of the Amacl else leaves it empty. * - * @param context Policy engine context. + * @param context is the policy engine context. * - * @return true if AMacl for the resource is found - * false if AMacl for the resource is not found + * @return true, if Amacl for the resource is found. false, if Amacl for the + * resource is not found */ bool FoundAmaclForRequest(PEContext_t *context); - /* - * This method is used by Policy engine to process AMS request - * - * @param context Policy engine context. + * This method is used by Policy engine to process AMS request. * + * @param context is the policy engine context. */ void ProcessAMSRequest(PEContext_t *context); - /* - * This method is used by Policy engine to free AMS context requestInfo - * - * @param requestInfo pointer to CARequestInfo_t. + * This method is used by Policy engine to free AMS context requestInfo/ * + * @param requestInfo is the pointer to @ref CARequestInfo_t. */ void FreeCARequestInfo(CARequestInfo_t *requestInfo); diff --git a/resource/csdk/security/include/internal/credresource.h b/resource/csdk/security/include/internal/credresource.h index ae36c57..a7cad66 100644 --- a/resource/csdk/security/include/internal/credresource.h +++ b/resource/csdk/security/include/internal/credresource.h @@ -105,15 +105,6 @@ OCStackResult AddCredential(OicSecCred_t * cred); */ OCStackResult RemoveCredential(const OicUuid_t *credId); -/** - * Remove all credential data on credential resource and persistent storage - * - * @retval - * OC_STACK_OK - no errors - * OC_STACK_ERROR - stack process error - */ -OCStackResult RemoveAllCredentials(void); - #if defined(__WITH_DTLS__) /** * This internal callback is used by lower stack (i.e. CA layer) to diff --git a/resource/csdk/security/include/internal/crlresource.h b/resource/csdk/security/include/internal/crlresource.h index 75178d8..c31143d 100644 --- a/resource/csdk/security/include/internal/crlresource.h +++ b/resource/csdk/security/include/internal/crlresource.h @@ -29,43 +29,46 @@ extern "C" { #endif /** - * This function stores CRL in SRM - * @param crl - CRL + * This function stores CRL in SRM. * - * @returns OC_STACK_OK for Success, otherwise some error value + * @param crl to be stored in SRM. + * + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult UpdateCRLResource(const OicSecCrl_t *crl); /** - * This function get encoded with base64 CRL from SRM + * This function get encoded with base64 CRL from SRM. + * + * @note Caller responsible for resulting string memory (use OICFree to remove it). * - * @returns encoded CRL with base64 format. NULL if error occured (e.g. CRL did not set) - * @note Caller responsible for resulting string memory (use OICFree to remove it) + * @return encoded CRL with base64 format. NULL if error occured (e.g. CRL did not set). */ char* GetBase64CRL(); /** - * This function get encoded with DER CRL from SRM + * This function get encoded with DER CRL from SRM. * - * @returns encoded CRL with DER format. array len is 0 if error occured (e.g. CRL did not set) + * @return encoded CRL with DER format. array len is 0 if error occured (e.g. CRL did not set). */ void GetDerCrl(ByteArray crlArray); /** - * This function get CRL from SRM + * This function get CRL from SRM. * - * @param crl [out] - pointer to buffer that contains crl. Shoul be not NULL. Buffer + * @param crl is a pointer to buffer that contains crl. Shoul be not NULL. Buffer * will be allocated by the function and content of *crl will be ignored. - * @param outlen [out] - pointer to length of the CRL buffer. Shoul be not NULL. + * @param outlen is a pointer to length of the CRL buffer. Should be not NULL. * - * @returns OC_STACK_OK if success and errorcode otherwise. - * @note Caller responsible for crl buffer memory (use OICFree to free it) + * @note Caller responsible for crl buffer memory (use OICFree to free it). + * + * @return ::OC_STACK_OK if success, otherwise some error value. */ OicSecCrl_t * JSONToCrlBin(const char * jsonStr); /** - * Initialize CLR resource by loading data from persistent storage. + * Initialize CRL resource by loading data from persistent storage. * - * @returns OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitCRLResource(); @@ -74,15 +77,15 @@ OCStackResult InitCRLResource(); */ void DeInitCRLResource(); +/** + * Get an instance of CRL resource. + * + * @return reference to the @ref OicSecCrl_t, holding reference to CRL resource. + */ OicSecCrl_t *GetCRLResource(); -OCEntityHandlerResult CRLEntityHandler(OCEntityHandlerFlag flag, - OCEntityHandlerRequest * ehRequest, - void* callbackParameter); #ifdef __cplusplus } #endif #endif //IOTVT_SRM_CRLR_H - - diff --git a/resource/csdk/security/include/internal/doxmresource.h b/resource/csdk/security/include/internal/doxmresource.h index 237da64..1bd8868 100644 --- a/resource/csdk/security/include/internal/doxmresource.h +++ b/resource/csdk/security/include/internal/doxmresource.h @@ -30,21 +30,21 @@ extern "C" { /** * Initialize DOXM resource by loading data from persistent storage. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitDoxmResource(); /** * Perform cleanup for DOXM resources. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult DeInitDoxmResource(); /** * This method is used by SRM to retrieve DOXM resource data.. * - * @retval reference to @ref OicSecDoxm_t, binary format of Doxm resource data + * @return reference to @ref OicSecDoxm_t, binary format of Doxm resource data. */ const OicSecDoxm_t* GetDoxmResourceData(); @@ -53,44 +53,43 @@ const OicSecDoxm_t* GetDoxmResourceData(); * The JSON DOXM can be from persistent database or * or received as PUT/POST request. * - * @param[in] jsonStr doxm data in json string. - * @return pointer to OicSecDoxm_t. + * @param jsonStr is a doxm data in json string. * - * @note Caller needs to invoke OCFree after done - * using the return pointer + * @note Caller needs to invoke OCFree after done using the return pointer. + * + * @return pointer to @ref OicSecDoxm_t. */ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr); /** * This method converts DOXM data into JSON format. * Caller needs to invoke 'free' when finished done using - * return string + * return string. * * @param[in] doxm Pointer to OicSecDoxm_t. - * @return pointer to json string. + * @note Caller needs to invoke OCFree after done using the return pointer. * - * @note Caller needs to invoke OCFree after done - * using the return pointer + * @return pointer to the json string. */ char * BinToDoxmJSON(const OicSecDoxm_t * doxm); /** * This method returns the SRM device ID for this device. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID); /** - * @brief Gets the OicUuid_t value for the owner of this device. + * Gets the OicUuid_t value for the owner of this device. * - * @return OC_STACK_OK if devOwner is a valid UUID, otherwise OC_STACK_ERROR. + * @return ::OC_STACK_OK if devOwner is a valid UUID, otherwise ::OC_STACK_ERROR. */ OCStackResult GetDoxmDevOwnerId(OicUuid_t *devOwner); /** This function deallocates the memory for OicSecDoxm_t . * - * @param[in] doxm Pointer to OicSecDoxm_t. + * @param doxm is the pointer to @ref OicSecDoxm_t. */ void DeleteDoxmBinData(OicSecDoxm_t* doxm); @@ -105,5 +104,3 @@ void RestoreDoxmToInitState(); #endif #endif //IOTVT_SRM_DOXMR_H - - diff --git a/resource/csdk/security/include/internal/policyengine.h b/resource/csdk/security/include/internal/policyengine.h index ba40d68..72aa01c 100644 --- a/resource/csdk/security/include/internal/policyengine.h +++ b/resource/csdk/security/include/internal/policyengine.h @@ -31,7 +31,6 @@ typedef struct AmsMgrContext AmsMgrContext_t; - typedef enum PEState { STOPPED = 0, //Policy engine state machine is not running @@ -40,7 +39,6 @@ typedef enum PEState BUSY //Can't process new request as processing other requests } PEState_t; - typedef struct PEContext { PEState_t state; @@ -56,13 +54,12 @@ typedef struct PEContext /** * Check whether a request should be allowed. * - * @param context Pointer to Policy Engine context to use. - * @param subjectId Pointer to Id of the requesting entity. - * @param resource Pointer to URI of Resource being requested. - * @param permission Requested permission. + * @param context is the pointer to Policy Engine context to use. + * @param subjectId is the pointer to Id of the requesting entity. + * @param resource is the pointer to URI of Resource being requested. + * @param permission is the requested permission. * - * @return ACCESS_GRANTED if request should go through, - * otherwise some flavor of ACCESS_DENIED + * @return ::ACCESS_GRANTED if request should go through, otherwise some flavor of ACCESS_DENIED. */ SRMAccessResponse_t CheckPermission( PEContext_t *context, @@ -74,33 +71,35 @@ SRMAccessResponse_t CheckPermission( * Initialize the Policy Engine. Call this before calling CheckPermission(). * TODO Eventually this and DeInit() need to be called from a new * "SRMInit(SRMContext_t *)" function, TBD after BeachHead. - * @param context Pointer to Policy Engine context to initialize. - * @return OC_STACK_OK for Success, otherwise some error value + * @param context is the pointer to Policy Engine context to initialize. + * + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitPolicyEngine(PEContext_t *context); /** * De-Initialize the Policy Engine. Call this before exiting to allow Policy * Engine to do cleanup on context. - * @param context Pointer to Policy Engine context to de-initialize. - * @return none + * + * @param context is the pointer to Policy Engine context to de-initialize. */ void DeInitPolicyEngine(PEContext_t *context); /** - * Return the uint16_t CRUDN permission corresponding to passed CAMethod_t. + * Get CRUDN permission for a method. + * + * @param method is CRUDN permission being seeked. + * + * @return the uint16_t CRUDN permission . */ uint16_t GetPermissionFromCAMethod_t(const CAMethod_t method); - /* * This method reset Policy Engine context to default state and update * it's state to @param state. * - * @param context Policy engine context. - * @param state Set Policy engine state to this. - * - * @return none + * @param context is the policy engine context. + * @param state set Policy engine state to this. */ void SetPolicyEngineState(PEContext_t *context, const PEState_t state); diff --git a/resource/csdk/security/include/internal/pstatresource.h b/resource/csdk/security/include/internal/pstatresource.h index 7331484..facab4e 100644 --- a/resource/csdk/security/include/internal/pstatresource.h +++ b/resource/csdk/security/include/internal/pstatresource.h @@ -28,14 +28,14 @@ extern "C" { /** * Initialize Pstat resource by loading data from persistent storage. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitPstatResource(); /** * Perform cleanup for Pstat resources. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult DeInitPstatResource(); diff --git a/resource/csdk/security/include/internal/secureresourcemanager.h b/resource/csdk/security/include/internal/secureresourcemanager.h index eb2643b..51f6a3f 100644 --- a/resource/csdk/security/include/internal/secureresourcemanager.h +++ b/resource/csdk/security/include/internal/secureresourcemanager.h @@ -28,85 +28,85 @@ extern "C" { #endif /** - * @brief Register Persistent storage callback. - * @param persistentStorageHandler [IN] Pointers to open, read, write, close & unlink handlers. - * @return - * OC_STACK_OK - No errors; Success - * OC_STACK_INVALID_PARAM - Invalid parameter + * Register Persistent storage callback. + * + * @param persistentStorageHandler [IN] Pointers to open, read, write, close & unlink handlers. + * + * @return ::OC_STACK_OK is no errors and successful. ::OC_STACK_INVALID_PARAM for invalid parameter. */ OCStackResult SRMRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler); /** - * @brief Get Persistent storage handler pointer. - * @return - * The pointer to Persistent Storage callback handler + * Get Persistent storage handler pointer. + * + * @return The pointer to Persistent Storage callback handler. */ OCPersistentStorage* SRMGetPersistentStorageHandler(); /** - * @brief Register request and response callbacks. - * Requests and responses are delivered in these callbacks. - * @param reqHandler [IN] Request handler callback ( for GET,PUT ..etc) - * @param respHandler [IN] Response handler callback. - * @param errHandler [IN] Error handler callback. - * @return - * OC_STACK_OK - No errors; Success - * OC_STACK_INVALID_PARAM - Invalid parameter + * Register request and response callbacks. Requests and responses are delivered in these callbacks. + * + * @param reqHandler Request handler callback ( for GET,PUT ..etc) + * @param respHandler Response handler callback. + * @param errHandler Error handler callback. + * + * @return ::OC_STACK_OK is no errors and successful. ::OC_STACK_INVALID_PARAM for invalid parameter. */ OCStackResult SRMRegisterHandler(CARequestCallback reqHandler, CAResponseCallback respHandler, CAErrorCallback errHandler); /** - * @brief Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). - * @return OC_STACK_OK for Success, otherwise some error value + * Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult SRMInitSecureResources(); /** - * @brief Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). - * @return none + * Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). */ void SRMDeInitSecureResources(); /** - * @brief Initialize Policy Engine context. - * @return OC_STACK_OK for Success, otherwise some error value. + * Initialize Policy Engine context. + * + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult SRMInitPolicyEngine(); /** - * @brief Cleanup Policy Engine context. - * @return none + * Cleanup Policy Engine context. */ void SRMDeInitPolicyEngine(); /** - * @brief Provisioning API response callback. - * @param object[IN] endpoint instance. - * @param responseInfo[IN] instance of CAResponseInfo_t structure. + * Provisioning API response callback. + * + * @param object endpoint instance. + * @param responseInfo instance of CAResponseInfo_t structure. + * * @return true if received response is for provisioning API false otherwise. */ typedef bool (*SPResponseCallback) (const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo); /** - * @brief function to register provisoning API's response callback. + * Function to register provisoning API's response callback. + * * @param respHandler response handler callback. */ void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler); /** - * @brief Check the security resource URI. - * @param uri [IN] Pointers to security resource URI. - * @return true if the URI is one of security resources, otherwise false. + * Check the security resource URI. + * @param uri Pointers to security resource URI. + * @return true if the URI is one of security resources, otherwise false. */ bool SRMIsSecurityResourceURI(const char* uri); /** - * @brief Sends Response - * @param resposeVal SRMAccessResponse_t value - * @return NONE + * Sends Response + * @param resposeVal Response @ref SRMAccessResponse_t value. */ void SRMSendResponse(SRMAccessResponse_t responseVal); diff --git a/resource/csdk/security/include/internal/svcresource.h b/resource/csdk/security/include/internal/svcresource.h index e77329d..ce759f8 100644 --- a/resource/csdk/security/include/internal/svcresource.h +++ b/resource/csdk/security/include/internal/svcresource.h @@ -28,14 +28,12 @@ extern "C" { /** * Initialize SVC resource by loading data from persistent storage. * - * @retval OC_STACK_OK for Success, otherwise some error value + * @return ::OC_STACK_OK for Success, otherwise some error value. */ OCStackResult InitSVCResource(); /** * Perform cleanup for SVC resources. - * - * @retval none */ void DeInitSVCResource(); diff --git a/resource/csdk/security/include/iotvticalendar.h b/resource/csdk/security/include/iotvticalendar.h index 2d77be0..1fec23e 100644 --- a/resource/csdk/security/include/iotvticalendar.h +++ b/resource/csdk/security/include/iotvticalendar.h @@ -43,8 +43,8 @@ extern "C" typedef struct IotvtICalRecur IotvtICalRecur_t; typedef struct IotvtICalPeriod IotvtICalPeriod_t; -/* - * date-time = date "T" time +/** + * date-time = date "T" time. * * date = date-value * date-value = date-fullyear date-month date-mday @@ -65,8 +65,8 @@ typedef struct IotvtICalPeriod IotvtICalPeriod_t; */ typedef struct tm IotvtICalDateTime_t; //c-lang tm date-time struct -/* - * Bit mask for weekdays +/** + * Bit mask for weekdays. */ typedef enum { @@ -78,24 +78,24 @@ typedef enum THURSDAY = (0x1 << 4), FRIDAY = (0x1 << 5), SATURDAY = (0x1 << 6) -}IotvtICalWeekdayBM_t; +} IotvtICalWeekdayBM_t; -/* - * Result code for IotvtICalendar +/** + * Result code for IotvtICalendar. */ typedef enum { - IOTVTICAL_SUCCESS = 0, //successfully completed operation - IOTVTICAL_VALID_ACCESS, //access is within allowable time - IOTVTICAL_INVALID_ACCESS, //access is not within allowable time - IOTVTICAL_INVALID_PARAMETER, //invalid method parameter - IOTVTICAL_INVALID_RRULE, //rrule is not well form, missing FREQ - IOTVTICAL_INVALID_PERIOD, //period is not well form, start-datetime is after end-datetime - IOTVTICAL_ERROR //encounter error -}IotvtICalResult_t; + IOTVTICAL_SUCCESS = 0, /**< successfully completed operation. */ + IOTVTICAL_VALID_ACCESS, /**< access is within allowable time. */ + IOTVTICAL_INVALID_ACCESS, /**< access is not within allowable time. */ + IOTVTICAL_INVALID_PARAMETER, /**< invalid method parameter. */ + IOTVTICAL_INVALID_RRULE, /**< rrule is not well form, missing FREQ. */ + IOTVTICAL_INVALID_PERIOD, /**< period is not well form, start-datetime is after end-datetime. */ + IOTVTICAL_ERROR /**< encounter error. */ +} IotvtICalResult_t; -/* - * Grammar for iCalendar data type PERIOD +/** + * Grammar for iCalendar data type PERIOD. * * period = date-time "/" date-time ; start-time / end-time. * ;The start-time MUST be before the end-time. @@ -108,7 +108,7 @@ struct IotvtICalPeriod }; /* - * Grammar for iCalendar data type RECUR + * Grammar for iCalendar data type RECUR. * * recur = "FREQ"=freq *( * ( ";" "UNTIL" "=" enddate ) / @@ -143,11 +143,11 @@ struct IotvtICalRecur * @param period string representing period. * @param recur string representing recurrence rule * - * @return IOTVTICAL_VALID_ACCESS -- if the request is within valid time period - * IOTVTICAL_INVALID_ACCESS -- if the request is not within valid time period - * IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_RRULE -- if rrule string has invalid format + * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period + * ::IOTVTICAL_INVALID_ACCESS, if the request is not within valid time period + * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid + * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format + * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format. * *Eg: if(IOTVTICAL_VALID_ACCESS == IsRequestWithinValidTime(period, recur)) * { @@ -158,29 +158,31 @@ struct IotvtICalRecur * //Access is not within allowable time. * } */ -IotvtICalResult_t IsRequestWithinValidTime(char *period, char *recur); +IotvtICalResult_t IsRequestWithinValidTime(const char *period, const char *recur); /** - * Parses periodStr and populate struct IotvtICalPeriod_t + * Parses periodStr and populate struct IotvtICalPeriod_t. * * @param periodStr string to be parsed. - * @param period IotvtICalPeriod_t struct to be populated. + * @param period IotvtICalPeriod_t struct to be populated. * - * @return IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_SUCCESS -- if no error while parsing + * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period + * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid + * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format + * ::IOTVTICAL_INVALID_SUCCESS, if no error while parsing. */ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period); /** - * Parses recurStr and populate struct IotvtICalRecur_t + * Parses recurStr and populate struct IotvtICalRecur_t. * * @param recurStr string to be parsed. - * @param recur IotvtICalPeriod_t struct to be populated. + * @param recur is the IotvtICalPeriod_t struct to be populated. * - * @return IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_RRULE -- if rrule string has invalid format + * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period + * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid + * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format + * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format. */ IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur); diff --git a/resource/csdk/security/include/pbkdf2.h b/resource/csdk/security/include/pbkdf2.h index ff2e3e5..2957db8 100644 --- a/resource/csdk/security/include/pbkdf2.h +++ b/resource/csdk/security/include/pbkdf2.h @@ -1,22 +1,22 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *****************************************************************/ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #ifndef _PBKDF2_H #define _PBKDF2_H @@ -39,14 +39,14 @@ extern "C" * Function to derive cryptographic key from the password. (RFC 2898) * In this implementation, HMAC with SHA2 is considered as a pseudorandom function * - * @param[in] passwd is the master password from which a derived key is generated. - * @param[in] pLen is the byte size of the passwd. - * @param[in] salt is a cryptographic salt. - * @param[in] saltlen is the byte size of the salt. - * @param[in] iteration is the number of iterations desired. - * @param[in] keyLen is the desired byte size of the derived key. (should be the same as + * @param passwd is the master password from which a derived key is generated. + * @param pLen is the byte size of the passwd. + * @param salt is a cryptographic salt. + * @param saltlen is the byte size of the salt. + * @param iteration is the number of iterations desired. + * @param keyLen is the desired byte size of the derived key. (should be the same as * derivedKey size) - * @param[out] derivedKey is the generated derived key + * @param derivedKey is the generated derived key * * @return 0 on success */ diff --git a/resource/csdk/security/include/pinoxmcommon.h b/resource/csdk/security/include/pinoxmcommon.h index de15015..67f07ac 100644 --- a/resource/csdk/security/include/pinoxmcommon.h +++ b/resource/csdk/security/include/pinoxmcommon.h @@ -1,22 +1,22 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *****************************************************************/ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #ifndef PIN_CALLBACK_DEF_H_ #define PIN_CALLBACK_DEF_H_ @@ -31,26 +31,26 @@ #define OXM_RANDOM_PIN_SIZE 8 /** - * Function pointer to print pin code + * Function pointer to print pin code. */ typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize); /** - * Function pointer to input pin code + * Function pointer to input pin code. */ typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize); /** - * Function to setting generate PIN callback from user + * Function to setting generate PIN callback from user. * - * @param[in] pinCB implementation of generate PIN callback + * @param pinCB implementation of generate PIN callback. */ void SetGeneratePinCB(GeneratePinCallback pinCB); /** - * Function to setting input PIN callback from user + * Function to setting input PIN callback from user. * - * @param[in] pinCB implementation of input PIN callback + * @param pinCB implementation of input PIN callback. */ void SetInputPinCB(InputPinCallback pinCB); @@ -58,18 +58,20 @@ void SetInputPinCB(InputPinCallback pinCB); * Function to generate random PIN. * This function will send generated PIN to user via callback. * - * @param[in,out] pinBuffer Buffer to store the generated PIN data. - * @param[in] bufferSize Size of buffer - * @return OC_STACK_SUCCESS in case of success and other value otherwise. + * @param pinBuffer is the reference to the buffer to store the generated PIN data. + * @param bufferSize is the size of buffer. + * + * @return ::OC_STACK_SUCCESS in case of success or other value in case of error. */ OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize); /** - * Function to input PIN callback via input callback + * Function to input PIN callback via input callback. + * + * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data. + * @param[in] bufferSize is the size of buffer. * - * @param[in,out] pinBuffer Buffer to store the inputed PIN data. - * @param[in] bufferSize Size of buffer - * @return OC_STACK_SUCCESS in case of success and other value otherwise. + * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error. */ OCStackResult InputPin(char* pinBuffer, size_t bufferSize); diff --git a/resource/csdk/security/include/securevirtualresourcetypes.h b/resource/csdk/security/include/securevirtualresourcetypes.h index d7597e1..2357604 100644 --- a/resource/csdk/security/include/securevirtualresourcetypes.h +++ b/resource/csdk/security/include/securevirtualresourcetypes.h @@ -52,8 +52,8 @@ extern "C" { #endif /** - * @brief Values used to create bit-maskable enums for single-value - * response with embedded code. + * Values used to create bit-maskable enums for single-value response with + * embedded code. */ #define ACCESS_GRANTED_DEF (1 << 0) #define ACCESS_DENIED_DEF (1 << 1) @@ -189,8 +189,8 @@ typedef enum OSCTBitmask } OSCTBitmask_t; /** - * @brief /oic/sec/credtype (Credential Type) data type. - * Derived from OIC Security Spec /oic/sec/cred; see Spec for details. + * /oic/sec/credtype (Credential Type) data type. + * Derived from OIC Security Spec /oic/sec/cred; see Spec for details. * 0: no security mode * 1: symmetric pair-wise key * 2: symmetric group key @@ -265,7 +265,7 @@ typedef struct OicSecCrl OicSecCrl_t; #endif /* __WITH_X509__ */ /** - * @brief /oic/uuid (Universal Unique Identifier) data type. + * /oic/uuid (Universal Unique Identifier) data type. */ #define UUID_LENGTH 128/8 // 128-bit GUID length //TODO: Confirm the length and type of ROLEID. @@ -281,8 +281,8 @@ struct OicUuid }; /** - * @brief /oic/sec/jwk (JSON Web Key) data type. - * See JSON Web Key (JWK) draft-ietf-jose-json-web-key-41 + * /oic/sec/jwk (JSON Web Key) data type. + * See JSON Web Key (JWK) draft-ietf-jose-json-web-key-41 */ #define JWK_LENGTH 256/8 // 256 bit key length struct OicSecJwk @@ -292,8 +292,8 @@ struct OicSecJwk }; /** - * @brief /oic/sec/acl (Access Control List) data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/acl (Access Control List) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecAcl { @@ -317,9 +317,8 @@ struct OicSecAcl }; /** - * @brief /oic/sec/amacl (Access Manager Service Accesss Control List) - * data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/amacl (Access Manager Service Accesss Control List) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecAmacl { @@ -338,8 +337,8 @@ struct OicSecAmacl }; /** - * @brief /oic/sec/cred (Credential) data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/cred (Credential) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecCred { @@ -364,8 +363,8 @@ struct OicSecCred }; /** - * @brief /oic/sec/doxm (Device Owner Transfer Methods) data type - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/doxm (Device Owner Transfer Methods) data type + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecDoxm { @@ -390,7 +389,7 @@ struct OicSecDoxm }; /** - * @brief /oic/sec/pstat (Provisioning Status) data type. + * /oic/sec/pstat (Provisioning Status) data type. * NOTE: this struct is ahead of Spec v0.95 in definition to include Sm. * TODO: change comment when reconciled to Spec v0.96. */ @@ -410,8 +409,8 @@ struct OicSecPstat }; /** - * @brief /oic/sec/role (Role) data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/role (Role) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecRole { @@ -421,8 +420,8 @@ struct OicSecRole }; /** - * @brief /oic/sec/sacl (Signed Access Control List) data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/sacl (Signed Access Control List) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecSacl { @@ -431,8 +430,8 @@ struct OicSecSacl }; /** - * @brief /oic/sec/svc (Service requiring a secure connection) data type. - * Derived from OIC Security Spec; see Spec for details. + * /oic/sec/svc (Service requiring a secure connection) data type. + * Derived from OIC Security Spec; see Spec for details. */ struct OicSecSvc { diff --git a/resource/csdk/security/include/srmutility.h b/resource/csdk/security/include/srmutility.h index 4cc9355..029a41b 100644 --- a/resource/csdk/security/include/srmutility.h +++ b/resource/csdk/security/include/srmutility.h @@ -37,7 +37,6 @@ extern "C" extern "C" { #endif // __cplusplus - typedef struct OicParseQueryIter OicParseQueryIter_t; /** @@ -49,63 +48,61 @@ typedef struct OicParseQueryIter OicParseQueryIter_t; */ struct OicParseQueryIter { - unsigned char * attrPos; /** #include #include "oic_malloc.h" @@ -426,13 +425,13 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques return ehRet; } -/* +/** * This internal method is the entity handler for Amacl resources and * will handle REST request (GET/PUT/POST/DEL) for them. */ -OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag, - OCEntityHandlerRequest * ehRequest, - void* callbackParameter) +static OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag, + OCEntityHandlerRequest * ehRequest, + void* callbackParameter) { (void) callbackParameter; OCEntityHandlerResult ehRet = OC_EH_ERROR; @@ -464,10 +463,10 @@ OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag, return ehRet; } -/* +/** * This internal method is used to create '/oic/sec/amacl' resource. */ -OCStackResult CreateAmaclResource() +static OCStackResult CreateAmaclResource() { OCStackResult ret = OCCreateResource(&gAmaclHandle, OIC_RSRC_TYPE_SEC_AMACL, @@ -485,11 +484,6 @@ OCStackResult CreateAmaclResource() return ret; } -/** - * Initialize Amacl resource by loading data from persistent storage. - * - * @retval OC_STACK_OK for Success, otherwise some error value - */ OCStackResult InitAmaclResource() { OCStackResult ret = OC_STACK_ERROR; @@ -520,11 +514,6 @@ OCStackResult InitAmaclResource() return ret; } -/** - * Perform cleanup for Amacl resources. - * - * @retval none - */ void DeInitAmaclResource() { OCDeleteResource(gAmaclHandle); @@ -534,7 +523,6 @@ void DeInitAmaclResource() gAmacl = NULL; } - OCStackResult AmaclGetAmsDeviceId(const char *resource, OicUuid_t *amsDeviceId) { OicSecAmacl_t *amacl = NULL; diff --git a/resource/csdk/security/src/amsmgr.c b/resource/csdk/security/src/amsmgr.c index 464e06a..9db18c4 100644 --- a/resource/csdk/security/src/amsmgr.c +++ b/resource/csdk/security/src/amsmgr.c @@ -18,6 +18,7 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include #include "oic_malloc.h" #include "amsmgr.h" #include "resourcemanager.h" @@ -34,11 +35,9 @@ #include "policyengine.h" #include "oic_string.h" #include "caremotehandler.h" -#include #define TAG "SRM-AMSMGR" - //Callback for AMS service multicast discovery request. static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle handle, OCClientResponse * clientResponse); @@ -51,7 +50,6 @@ static OCStackApplicationResult SecurePortDiscoveryCallback(void *ctx, OCDoHandl static OCStackApplicationResult AmsMgrAclReqCallback(void *ctx, OCDoHandle handle, OCClientResponse * clientResponse); - OCStackResult DiscoverAmsService(PEContext_t *context) { OIC_LOG(INFO, TAG, "IN DiscoverAmsService"); @@ -89,7 +87,6 @@ exit: return ret; } - static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle handle, OCClientResponse * clientResponse) { @@ -120,7 +117,7 @@ static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle ha //As doxm is NULL amsmgr can't test if response from trusted AMS service //so keep the transaction. - if(NULL == doxm) + if (NULL == doxm) { OIC_LOG_V(ERROR, TAG, "%s : Unable to convert JSON to Binary",__func__); return OC_STACK_KEEP_TRANSACTION; @@ -138,7 +135,7 @@ static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle ha { OIC_LOG(INFO, TAG, "AMS Manager Sending unicast discovery to get secured port info"); //Sending Unicast discovery to get secure port information - if(OC_STACK_OK == SendUnicastSecurePortDiscovery(context, &clientResponse->devAddr, + if (OC_STACK_OK == SendUnicastSecurePortDiscovery(context, &clientResponse->devAddr, clientResponse->connType)) { context->retVal = ACCESS_WAITING_FOR_AMS; @@ -150,7 +147,6 @@ static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle ha return OC_STACK_DELETE_TRANSACTION; } - OCStackResult SendUnicastSecurePortDiscovery(PEContext_t *context,OCDevAddr *devAddr, OCConnectivityType connType) { @@ -198,7 +194,7 @@ static OCStackApplicationResult SecurePortDiscoveryCallback(void *ctx, OCDoHandl return OC_STACK_DELETE_TRANSACTION; } - OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources; + OCResourcePayload *resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources; //Verifying if the ID of the sender is an AMS service that this device trusts. if(resPayload && @@ -228,7 +224,6 @@ static OCStackApplicationResult SecurePortDiscoveryCallback(void *ctx, OCDoHandl return OC_STACK_DELETE_TRANSACTION; } - OCStackResult SendAclReq(PEContext_t *context, OCDevAddr *devAddr, OCConnectivityType connType, uint16_t securedPort) { @@ -269,7 +264,6 @@ exit: return ret; } - static OCStackApplicationResult AmsMgrAclReqCallback(void *ctx, OCDoHandle handle, OCClientResponse * clientResponse) { @@ -326,7 +320,6 @@ exit: return OC_STACK_DELETE_TRANSACTION; } - OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endpoint, const CARequestInfo_t *requestInfo) { @@ -334,7 +327,7 @@ OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endp //The AmsMgr context endpoint and requestInfo will be free from , //AmsMgrAclReqCallback function - if(context->amsMgrContext->endpoint) + if (context->amsMgrContext->endpoint) { OICFree(context->amsMgrContext->endpoint); context->amsMgrContext->endpoint = NULL; @@ -343,7 +336,7 @@ OCStackResult UpdateAmsMgrContext(PEContext_t *context, const CAEndpoint_t *endp VERIFY_NON_NULL(TAG, context->amsMgrContext->endpoint, ERROR); *context->amsMgrContext->endpoint = *endpoint; - if(context->amsMgrContext->requestInfo) + if (context->amsMgrContext->requestInfo) { FreeCARequestInfo(context->amsMgrContext->requestInfo); context->amsMgrContext->requestInfo = NULL; @@ -357,7 +350,7 @@ exit: void FreeCARequestInfo(CARequestInfo_t *requestInfo) { - if(NULL == requestInfo) + if (NULL == requestInfo) { OIC_LOG_V(ERROR, TAG, "%s: Can't free memory. Received NULL requestInfo", __func__); return; @@ -381,7 +374,7 @@ bool FoundAmaclForRequest(PEContext_t *context) memset(&context->amsMgrContext->amsDeviceId, 0, sizeof(context->amsMgrContext->amsDeviceId)); //Call amacl resource function to get the AMS service deviceID for the resource - if(OC_STACK_OK == AmaclGetAmsDeviceId(context->resource, &context->amsMgrContext->amsDeviceId)) + if (OC_STACK_OK == AmaclGetAmsDeviceId(context->resource, &context->amsMgrContext->amsDeviceId)) { OIC_LOG_V(INFO, TAG, "%s:AMACL found for the requested resource %s", __func__, context->resource); @@ -398,12 +391,11 @@ bool FoundAmaclForRequest(PEContext_t *context) return ret; } - void ProcessAMSRequest(PEContext_t *context) { OicUuid_t emptyUuid = {.id={}}; OIC_LOG_V(INFO, TAG, "Entering %s", __func__); - if(NULL != context) + if (NULL != context) { if((false == context->matchingAclFound) && (false == context->amsProcessing)) { diff --git a/resource/csdk/security/src/base64.c b/resource/csdk/security/src/base64.c index 2a1ac98..b77c4e5 100644 --- a/resource/csdk/security/src/base64.c +++ b/resource/csdk/security/src/base64.c @@ -1,38 +1,38 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "base64.h" -/**< base character of Base64 */ +/** base character of Base64. */ static const char g_b64TransTbl[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"\ "ghijklmnopqrstuvwxyz0123456789+/"; /** - * base64 block encode function + * base64 block encode function. * - * @param[in] in octet stream, max 3 byte - * @param[out] out base64 encoded stream, 4 byte - * @param[in] len byte-length of in + * @param in is the octet stream, max 3 byte. + * @param out is the Base64 encoded stream, 4 byte. + * @param len is the byte-length of octet stream. * - * @return B64_OK for Success, otherwise some error value + * @return ::B64_OK for Success, otherwise some error value. */ static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) { @@ -43,7 +43,7 @@ static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) out[0] = g_b64TransTbl[in[0] >> 2]; - if(1 == len) + if (1 == len) { out[1] = g_b64TransTbl[((in[0] & 0x03) << 4)]; } @@ -52,7 +52,7 @@ static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) out[1] = g_b64TransTbl[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)]; } - if(2 == len) + if (2 == len) { out[2] = g_b64TransTbl[((in[1] & 0x0f) << 2)]; } @@ -77,25 +77,9 @@ static B64Result b64EncodeBlk(const uint8_t* in, char* out, uint32_t len) return B64_OK; } -/** - * Encode the plain message in base64. - * - * @param[in] in Plain message - * @param[in] inLen Byte length of 'in' - * @param[in,out] outBuf Output buffer - * Base64 encoded message will be written into 'out' - * NOTE : This method adds a NULL to the string configuration - * @param[in] outBufSize Size of output buffer - * @param[out] outLen Byte length of encoded message - * - * @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) { - size_t i; - size_t minBufSize; - if (NULL == in || 0 == inLen || NULL == outBuf || NULL == outLen ) { return B64_INVALID_PARAM; @@ -104,12 +88,13 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, *outLen = ((inLen / 3) * 3 == inLen) ? ((inLen / 3) * 4) : (((inLen / 3) + 1) * 4); - minBufSize = (*outLen + 1); - if(outBufSize < minBufSize) + uint32_t minBufSize = (*outLen + 1); + if (outBufSize < minBufSize) { return B64_OUTPUT_BUFFER_TOO_SMALL; } + uint32_t i; for (i = 0; i < inLen / 3; i++) { if(B64_OK != b64EncodeBlk(in + i * 3, outBuf + i * 4, 3)) @@ -120,7 +105,7 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, if (i * 3 != inLen) { - if(B64_OK != b64EncodeBlk(in + i * 3, outBuf + i * 4, inLen - i * 3)) + if (B64_OK != b64EncodeBlk(in + i * 3, outBuf + i * 4, inLen - i * 3)) { return B64_INVALID_PARAM; } @@ -132,11 +117,11 @@ B64Result b64Encode(const uint8_t* in, const size_t inLen, } /** - * Get decoded value + * Get decoded value. * - * @param[in] c Base64 encoded charactor + * @param c is the Base64 encoded character. * - * @return decoded value, 6-bit + * @return decoded value, 6-bit. */ static uint32_t b64GetVal(char c) { @@ -169,23 +154,21 @@ static uint32_t b64GetVal(char c) } /** - * base64 block decode function + * Base64 block decode function. * - * @param[in] in Base64 encoded stream, 4 bytes - * @param[out] out Octet stream, 3 bytes + * @param in is the Base64 encoded stream, 4 bytes. + * @param out is the Octet stream, 3 bytes. * - * @return B64_OK for Success, otherwise some error value + * @return ::B64_OK for Success, otherwise some error value. */ static B64Result b64DecodeBlk(const char* in, uint8_t* out) { - uint32_t val; - - if(NULL == in || NULL == out) + if (NULL == in || NULL == out) { return B64_INVALID_PARAM; } - val = (b64GetVal(in[0]) << 18) | (b64GetVal(in[1]) << 12) | + uint32_t val = (b64GetVal(in[0]) << 18) | (b64GetVal(in[1]) << 12) | (b64GetVal(in[2]) << 6) | (b64GetVal(in[3])); out[0] = (val >> 16) & 0xff; @@ -202,47 +185,32 @@ static B64Result b64DecodeBlk(const char* in, uint8_t* out) return B64_OK; } -/** - * Decode the encoded message in base64. - * - * @param[in] in Base64 encoded message - * @param[in] inLen Byte lenth of 'in' - * @param[in, out] outBuf Output buffer - * Base64 decoded message will be written into 'out' - * @param[in] outBufSize Size of output buffer - * @param[out] outLen Byte length of decoded message - * - * @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) { - uint32_t i; - uint32_t minBufSize; - if (NULL == in || 0 == inLen || 0 != (inLen & 0x03) || NULL == outBuf || NULL == outLen) { return B64_INVALID_PARAM; } *outLen = (inLen / 4) * 3; - minBufSize = (inLen / 4) * 3; - if('=' == in[inLen - 1]) + uint32_t minBufSize = (inLen / 4) * 3; + if ('=' == in[inLen - 1]) { minBufSize--; (*outLen)--; } - if('=' == in[inLen - 2]) + if ('=' == in[inLen - 2]) { minBufSize--; (*outLen)--; } - if(outBufSize < minBufSize) + if (outBufSize < minBufSize) { return B64_OUTPUT_BUFFER_TOO_SMALL; } - for (i = 0; i < inLen / 4; i++) + for (uint32_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 b30eeae..70fb2b4 100644 --- a/resource/csdk/security/src/credresource.c +++ b/resource/csdk/security/src/credresource.c @@ -469,21 +469,6 @@ exit: return ret; } -/** - * This function generates the bin credential data. - * - * @param subject pointer to subject of this credential. - * @param credType credential type. - * @param publicData public data such as public key. - * @param privateData private data such as private key. - * The privateData is expected in base64 encoded format. - * @param ownersLen length of owners array - * @param owners array of owners. - * - * @retval - * pointer to instance of OicSecCred_t - success - * NULL - error - */ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t credType, const uint8_t * publicData, const uint8_t* privateData, size_t ownersLen, const OicUuid_t * owners) @@ -506,7 +491,7 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr cred->credType = credType; #ifdef __WITH_X509__ - if(publicData) + if (publicData) { cred->publicData.data = (uint8_t *)OICCalloc(1, PUBLIC_KEY_SIZE); VERIFY_NON_NULL(TAG, cred->publicData.data, ERROR); @@ -514,7 +499,7 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr } #endif // __WITH_X509__ - if(privateData) + if (privateData) { #ifdef __WITH_X509__ cred->privateData.data = (uint8_t *)OICCalloc(1, PRIVATE_KEY_SIZE); @@ -528,7 +513,7 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr cred->owners = (OicUuid_t *)OICCalloc(cred->ownersLen, sizeof(*cred->owners)); VERIFY_NON_NULL(TAG, cred->owners, ERROR); - for(size_t i = 0; i < cred->ownersLen; i++) + for (size_t i = 0; i < cred->ownersLen; i++) { memcpy(cred->owners[i].id, owners[i].id, sizeof(cred->owners[i].id)); } @@ -570,15 +555,14 @@ static bool UpdatePersistentStorage(const OicSecCred_t *cred) } /** - * Compare function used LL_SORT for sorting credentials + * Compare function used LL_SORT for sorting credentials. * - * @param first pointer to OicSecCred_t struct - * @param second pointer to OicSecCred_t struct + * @param first pointer to OicSecCred_t struct. + * @param second pointer to OicSecCred_t struct. * - *@retval - * -1 if credId of first is less than credId of second - * 0 if credId of first is equal to credId of second - * 1 if credId of first is greater than credId of second + *@return -1, if credId of first is less than credId of second. + * 0, if credId of first is equal to credId of second. + * 1, if credId of first is greater than credId of second. */ static int CmpCredId(const OicSecCred_t * first, const OicSecCred_t *second) { @@ -600,23 +584,19 @@ static int CmpCredId(const OicSecCred_t * first, const OicSecCred_t *second) * available due deletion of OicSecCred_t object or one more than * credId of last credential in the list. * - * @retval - * next available credId - success - * 0 - error + * @return next available credId if successful, else 0 for error. */ - static uint16_t GetCredId() { //Sorts credential list in incremental order of credId LL_SORT(gCred, CmpCredId); - OicSecCred_t *currentCred = NULL, *credTmp = NULL; uint16_t nextCredId = 1; LL_FOREACH_SAFE(gCred, currentCred, credTmp) { - if(currentCred->credId == nextCredId) + if (currentCred->credId == nextCredId) { nextCredId += 1; } @@ -634,23 +614,16 @@ exit: } /** - * Get the default value - * @retval NULL for now. Update it when we finalize the default info. + * Get the default value. + * + * @return NULL for now. */ static OicSecCred_t* GetCredDefault() { + // TODO:Update it when we finalize the default info. return NULL; } -/** - * This function adds the new cred to the credential list. - * - * @param cred pointer to new credential. - * - * @retval - * OC_STACK_OK - cred not NULL and persistent storage gets updated - * OC_STACK_ERROR - cred is NULL or fails to update persistent storage - */ OCStackResult AddCredential(OicSecCred_t * newCred) { OCStackResult ret = OC_STACK_ERROR; @@ -662,6 +635,7 @@ OCStackResult AddCredential(OicSecCred_t * newCred) //Append the new Cred to existing list LL_APPEND(gCred, newCred); + if (UpdatePersistentStorage(gCred)) { ret = OC_STACK_OK; @@ -680,7 +654,7 @@ OCStackResult RemoveCredential(const OicUuid_t *subject) LL_FOREACH_SAFE(gCred, cred, tempCred) { - if(memcmp(cred->subject.id, subject->id, sizeof(subject->id)) == 0) + if (memcmp(cred->subject.id, subject->id, sizeof(subject->id)) == 0) { LL_DELETE(gCred, cred); FreeCred(cred); @@ -688,9 +662,9 @@ OCStackResult RemoveCredential(const OicUuid_t *subject) } } - if(deleteFlag) + if (deleteFlag) { - if(UpdatePersistentStorage(gCred)) + if (UpdatePersistentStorage(gCred)) { ret = OC_STACK_RESOURCE_DELETED; } @@ -711,7 +685,7 @@ OCStackResult RemoveAllCredentials(void) DeleteCredList(gCred); gCred = GetCredDefault(); - if(!UpdatePersistentStorage(gCred)) + if (!UpdatePersistentStorage(gCred)) { return OC_STACK_ERROR; } @@ -726,7 +700,7 @@ OCStackResult RemoveAllCredentials(void) * @param ownerAdd address of OBT(PT) * @param doxm current device's doxm resource * - * @retval + * @return * true successfully done and valid ower psk information * false Invalid owner psk information or failed to owner psk generation */ @@ -752,6 +726,7 @@ static bool FillPrivateDataOfOwnerPSK(OicSecCred_t* receviedCred, const CAEndpoi receviedCred->privateData.data = (uint8_t *)OICCalloc(1, OWNER_PSK_LENGTH_128); VERIFY_NON_NULL(TAG, receviedCred->privateData.data, ERROR); memcpy(receviedCred->privateData.data, ownerPSK, OWNER_PSK_LENGTH_128); + OIC_LOG(INFO, TAG, "PrivateData of OwnerPSK was calculated successfully"); //Verify OwnerPSK information @@ -899,7 +874,7 @@ static OCEntityHandlerResult HandlePutRequest(const OCEntityHandlerRequest * ehR #endif//__WITH_DTLS__ } - if(OC_EH_RESOURCE_CREATED != ret) + if (OC_EH_RESOURCE_CREATED != ret) { if(OC_STACK_OK != RemoveCredential(&cred->subject)) { @@ -937,7 +912,7 @@ static OCEntityHandlerResult HandleDeleteRequest(const OCEntityHandlerRequest *e OCEntityHandlerResult ehRet = OC_EH_ERROR; - if(NULL == ehRequest->query) + if (NULL == ehRequest->query) { return ehRet; } @@ -947,16 +922,16 @@ static OCEntityHandlerResult HandleDeleteRequest(const OCEntityHandlerRequest *e //Parsing REST query to get the subject ParseQueryIterInit((unsigned char *)ehRequest->query, &parseIter); - while(GetNextQuery(&parseIter)) + while (GetNextQuery(&parseIter)) { - if(strncasecmp((char *)parseIter.attrPos, OIC_JSON_SUBJECT_NAME, + if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_SUBJECT_NAME, parseIter.attrLen) == 0) { memcpy(subject.id, parseIter.valPos, parseIter.valLen); } } - if(OC_STACK_RESOURCE_DELETED == RemoveCredential(&subject)) + if (OC_STACK_RESOURCE_DELETED == RemoveCredential(&subject)) { ehRet = OC_EH_RESOURCE_DELETED; } @@ -971,7 +946,7 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag, (void)callbackParameter; OCEntityHandlerResult ret = OC_EH_ERROR; - if(!ehRequest) + if (!ehRequest) { return OC_EH_ERROR; } @@ -979,7 +954,7 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag, { OIC_LOG (DEBUG, TAG, "Flag includes OC_REQUEST_FLAG"); //TODO : Handle PUT/DEL methods - switch(ehRequest->method) + switch (ehRequest->method) { case OC_REST_GET: ret = OC_EH_FORBIDDEN; @@ -1008,15 +983,13 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag, OCStackResult CreateCredResource() { - OCStackResult ret; - - ret = OCCreateResource(&gCredHandle, - OIC_RSRC_TYPE_SEC_CRED, - OIC_MI_DEF, - OIC_RSRC_CRED_URI, - CredEntityHandler, - NULL, - OC_RES_PROP_NONE); + OCStackResult ret = OCCreateResource(&gCredHandle, + OIC_RSRC_TYPE_SEC_CRED, + OIC_MI_DEF, + OIC_RSRC_CRED_URI, + CredEntityHandler, + NULL, + OC_RES_PROP_NONE); if (OC_STACK_OK != ret) { @@ -1231,7 +1204,6 @@ exit: #define CERTIFICATE ("x5c") #define PRIVATE_KEY ("d") - static void WriteCertPrefix(uint8_t *prefix, uint32_t certLen) { for (size_t i = 0; i < CERT_LEN_PREFIX; ++i) @@ -1243,7 +1215,7 @@ static void WriteCertPrefix(uint8_t *prefix, uint32_t certLen) static uint32_t ParseCertPrefix(uint8_t *prefix) { uint32_t res = 0; - if(NULL != prefix) + if (NULL != prefix) { for (int i = 0; i < CERT_LEN_PREFIX; ++i) { @@ -1271,7 +1243,7 @@ static OCStackResult GetCAPublicKeyData(CADtlsX509Creds_t *credInfo) { OCStackResult ret = OC_STACK_ERROR; uint8_t *ccPtr = credInfo->certificateChain; - for(uint8_t i = 0; i < credInfo->chainLen - 1; ++i) + for (uint8_t i = 0; i < credInfo->chainLen - 1; ++i) { ccPtr += CERT_LEN_PREFIX + ParseCertPrefix(ccPtr); } diff --git a/resource/csdk/security/src/crlresource.c b/resource/csdk/security/src/crlresource.c index 9255508..e30c07d 100644 --- a/resource/csdk/security/src/crlresource.c +++ b/resource/csdk/security/src/crlresource.c @@ -314,13 +314,13 @@ static OCEntityHandlerResult HandleCRLPostRequest(const OCEntityHandlerRequest * } -/* +/** * This internal method is the entity handler for CRL resource and * will handle REST request (GET/PUT/POST/DEL) for them. */ -OCEntityHandlerResult CRLEntityHandler(OCEntityHandlerFlag flag, - OCEntityHandlerRequest *ehRequest, - void *callbackParameter) +static OCEntityHandlerResult CRLEntityHandler(OCEntityHandlerFlag flag, + OCEntityHandlerRequest *ehRequest, + void *callbackParameter) { OCEntityHandlerResult ehRet = OC_EH_ERROR; (void)callbackParameter; @@ -356,19 +356,18 @@ OCEntityHandlerResult CRLEntityHandler(OCEntityHandlerFlag flag, return ehRet; } -/* +/** * This internal method is used to create '/oic/sec/crl' resource. */ -OCStackResult CreateCRLResource() +static OCStackResult CreateCRLResource() { - OCStackResult ret; - ret = OCCreateResource(&gCrlHandle, - OIC_RSRC_TYPE_SEC_CRL, - OIC_MI_DEF, - OIC_RSRC_CRL_URI, - CRLEntityHandler, - NULL, - OC_OBSERVABLE); + OCStackResult ret = OCCreateResource(&gCrlHandle, + OIC_RSRC_TYPE_SEC_CRL, + OIC_MI_DEF, + OIC_RSRC_CRL_URI, + CRLEntityHandler, + NULL, + OC_OBSERVABLE); if (OC_STACK_OK != ret) { @@ -379,8 +378,8 @@ OCStackResult CreateCRLResource() } /** - * Get the default value - * @retval NULL for now. Update it when we finalize the default info. + * Get the default value. + * @return defaultCrl for now. */ static OicSecCrl_t *GetCrlDefault() { diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 860a78d..b1a372a 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -17,6 +17,16 @@ // limitations under the License. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include +#include + +#if HAVE_STRINGS_H +#include +#endif + +#ifdef __WITH_DTLS__ +#include "global.h" +#endif #include "ocstack.h" #include "logger.h" @@ -38,17 +48,6 @@ #include "srmutility.h" #include "pinoxmcommon.h" -#ifdef __WITH_DTLS__ -#include "global.h" -#endif - -#include -#include - -#if HAVE_STRINGS_H -#include -#endif - #define TAG "SRM-DOXM" static OicSecDoxm_t *gDoxm = NULL; @@ -109,7 +108,7 @@ char * BinToDoxmJSON(const OicSecDoxm_t * doxm) cJSON_AddItemToObject(jsonRoot, OIC_JSON_DOXM_NAME, jsonDoxm ); //OxmType -- Not Mandatory - if(doxm->oxmTypeLen > 0) + if (doxm->oxmTypeLen > 0) { cJSON *jsonOxmTyArray = cJSON_CreateArray(); VERIFY_NON_NULL(TAG, jsonOxmTyArray, ERROR); @@ -121,7 +120,7 @@ char * BinToDoxmJSON(const OicSecDoxm_t * doxm) } //Oxm -- Not Mandatory - if(doxm->oxmLen > 0) + if (doxm->oxmLen > 0) { cJSON *jsonOxmArray = cJSON_CreateArray(); VERIFY_NON_NULL(TAG, jsonOxmArray, ERROR); @@ -176,7 +175,6 @@ exit: OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) { - if (NULL == jsonStr) { return NULL; @@ -243,7 +241,7 @@ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) //OxmSel -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_SEL_NAME); - if(jsonObj) + if (jsonObj) { VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); doxm->oxmSel = (OicSecOxm_t)jsonObj->valueint; @@ -256,7 +254,7 @@ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) //sct -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_SUPPORTED_CRED_TYPE_NAME); - if(jsonObj) + if (jsonObj) { VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); doxm->sct = (OicSecCredType_t)jsonObj->valueint; @@ -269,7 +267,7 @@ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) //Owned -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OWNED_NAME); - if(jsonObj) + if (jsonObj) { VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type), ERROR); doxm->owned = jsonObj->valueint; @@ -282,10 +280,10 @@ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) //DeviceId -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVICE_ID_NAME); - if(jsonObj) + if (jsonObj) { VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); - if(cJSON_String == jsonObj->type) + if (cJSON_String == jsonObj->type) { //Check for empty string, in case DeviceId field has not been set yet if (jsonObj->valuestring[0]) @@ -326,11 +324,11 @@ OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr) //Owner -- will be empty when device status is unowned. jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OWNER_NAME); - if(true == doxm->owned) + if (true == doxm->owned) { VERIFY_NON_NULL(TAG, jsonObj, ERROR); } - if(jsonObj) + if (jsonObj) { VERIFY_SUCCESS(TAG, (cJSON_String == jsonObj->type), ERROR); outLen = 0; @@ -407,24 +405,24 @@ static bool ValidateQuery(const char * query) ParseQueryIterInit((unsigned char*)query, &parseIter); - while(GetNextQuery(&parseIter)) + while (GetNextQuery(&parseIter)) { - if(strncasecmp((char *)parseIter.attrPos, OIC_JSON_OWNED_NAME, parseIter.attrLen) == 0) + if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_OWNED_NAME, parseIter.attrLen) == 0) { bOwnedQry = true; - if((strncasecmp((char *)parseIter.valPos, OIC_SEC_TRUE, parseIter.valLen) == 0) && + if ((strncasecmp((char *)parseIter.valPos, OIC_SEC_TRUE, parseIter.valLen) == 0) && (gDoxm->owned)) { bOwnedMatch = true; } - else if((strncasecmp((char *)parseIter.valPos, OIC_SEC_FALSE, parseIter.valLen) == 0) + else if ((strncasecmp((char *)parseIter.valPos, OIC_SEC_FALSE, parseIter.valLen) == 0) && (!gDoxm->owned)) { bOwnedMatch = true; } } - if(strncasecmp((char *)parseIter.attrPos, OIC_JSON_DEVICE_ID_NAME, parseIter.attrLen) == 0) + if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_DEVICE_ID_NAME, parseIter.attrLen) == 0) { bDeviceIDQry = true; OicUuid_t subject = {.id={0}}; @@ -437,7 +435,7 @@ static bool ValidateQuery(const char * query) VERIFY_SUCCESS(TAG, (B64_OK == b64Ret && outLen <= sizeof(subject.id)), ERROR); memcpy(subject.id, base64Buff, outLen); - if(0 == memcmp(&gDoxm->deviceID.id, &subject.id, sizeof(gDoxm->deviceID.id))) + if (0 == memcmp(&gDoxm->deviceID.id, &subject.id, sizeof(gDoxm->deviceID.id))) { bDeviceIDMatch = true; } @@ -453,13 +451,13 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest char* jsonStr = NULL; OCEntityHandlerResult ehRet = OC_EH_OK; - OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing GET request"); + OIC_LOG(DEBUG, TAG, "Doxm EntityHandle processing GET request"); //Checking if Get request is a query. - if(ehRequest->query) + if (ehRequest->query) { - OIC_LOG (DEBUG, TAG, "HandleDoxmGetRequest processing query"); - if(!ValidateQuery(ehRequest->query)) + OIC_LOG(DEBUG, TAG, "HandleDoxmGetRequest processing query"); + if (!ValidateQuery(ehRequest->query)) { ehRet = OC_EH_ERROR; } @@ -475,9 +473,9 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest jsonStr = (ehRet == OC_EH_OK) ? BinToDoxmJSON(gDoxm) : NULL; // Send response payload to request originator - if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, jsonStr)) + if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, jsonStr)) { - OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandleDoxmGetRequest"); + OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleDoxmGetRequest"); } OICFree(jsonStr); @@ -559,7 +557,7 @@ static OCEntityHandlerResult HandleDoxmPutRequest (const OCEntityHandlerRequest } } } - else if(OIC_RANDOM_DEVICE_PIN == newDoxm->oxmSel) + else if (OIC_RANDOM_DEVICE_PIN == newDoxm->oxmSel) { if ((false == gDoxm->owned) && (false == newDoxm->owned)) { @@ -572,7 +570,7 @@ static OCEntityHandlerResult HandleDoxmPutRequest (const OCEntityHandlerRequest { gDoxm->oxmSel = newDoxm->oxmSel; //Update new state in persistent storage - if((UpdatePersistentStorage(gDoxm) == true)) + if ((UpdatePersistentStorage(gDoxm) == true)) { ehRet = OC_EH_OK; } @@ -681,19 +679,19 @@ exit: } //Send payload to request originator - if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL)) + if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL)) { - OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandlePstatPostRequest"); + OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandlePstatPostRequest"); } DeleteDoxmBinData(newDoxm); return ehRet; } -/* +/** * This internal method is the entity handler for DOXM resources. */ -OCEntityHandlerResult DoxmEntityHandler (OCEntityHandlerFlag flag, +OCEntityHandlerResult DoxmEntityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * ehRequest, void* callbackParam) { @@ -705,7 +703,6 @@ OCEntityHandlerResult DoxmEntityHandler (OCEntityHandlerFlag flag, return ehRet; } - if (flag & OC_REQUEST_FLAG) { OIC_LOG (DEBUG, TAG, "Flag includes OC_REQUEST_FLAG"); @@ -729,20 +726,19 @@ OCEntityHandlerResult DoxmEntityHandler (OCEntityHandlerFlag flag, return ehRet; } -/* +/** * This internal method is used to create '/oic/sec/doxm' resource. */ OCStackResult CreateDoxmResource() { - OCStackResult ret; - - ret = OCCreateResource(&gDoxmHandle, - OIC_RSRC_TYPE_SEC_DOXM, - OIC_MI_DEF, - OIC_RSRC_DOXM_URI, - DoxmEntityHandler, - NULL, - OC_OBSERVABLE | OC_SECURE | OC_EXPLICIT_DISCOVERABLE); + OCStackResult ret = OCCreateResource(&gDoxmHandle, + OIC_RSRC_TYPE_SEC_DOXM, + OIC_MI_DEF, + OIC_RSRC_DOXM_URI, + DoxmEntityHandler, + NULL, + OC_OBSERVABLE | OC_SECURE | + OC_EXPLICIT_DISCOVERABLE); if (OC_STACK_OK != ret) { @@ -756,7 +752,6 @@ OCStackResult CreateDoxmResource() * Checks if DeviceID is generated during provisioning for the new device. * If DeviceID is NULL then generates the new DeviceID. * Once DeviceID is assigned to the device it does not change for the lifetime of the device. - * */ static OCStackResult CheckDeviceID() { @@ -795,36 +790,27 @@ static OCStackResult CheckDeviceID() /** * Get the default value. - * @retval the gDefaultDoxm pointer; + * + * @return the default value of doxm, @ref OicSecDoxm_t. */ static OicSecDoxm_t* GetDoxmDefault() { - OIC_LOG (DEBUG, TAG, "GetDoxmToDefault"); + OIC_LOG(DEBUG, TAG, "GetDoxmToDefault"); return &gDefaultDoxm; } -/** - * This method is used by SRM to retrieve DOXM resource data. - * - * @retval reference to @ref OicSecDoxm_t, binary format of Doxm resource data - */ const OicSecDoxm_t* GetDoxmResourceData() { return gDoxm; } -/** - * Initialize DOXM resource by loading data from persistent storage. - * - * @retval OC_STACK_OK for Success, otherwise some error value - */ OCStackResult InitDoxmResource() { OCStackResult ret = OC_STACK_ERROR; //Read DOXM resource from PS char* jsonSVRDatabase = GetSVRDatabase(); - if(jsonSVRDatabase) + if (jsonSVRDatabase) { //Convert JSON DOXM into binary format gDoxm = JSONToDoxmBin(jsonSVRDatabase); @@ -834,7 +820,7 @@ OCStackResult InitDoxmResource() * is not available for some reason, a default doxm is created * which allows user to initiate doxm provisioning again. */ - if(!jsonSVRDatabase || !gDoxm) + if (!jsonSVRDatabase || !gDoxm) { gDoxm = GetDoxmDefault(); } @@ -860,24 +846,16 @@ OCStackResult InitDoxmResource() return ret; } -/** - * Perform cleanup for DOXM resources. - * - * @return - * OC_STACK_OK - no error - * OC_STACK_ERROR - stack process error - * - */ OCStackResult DeInitDoxmResource() { OCStackResult ret = OCDeleteResource(gDoxmHandle); - if(gDoxm != &gDefaultDoxm) + if (gDoxm != &gDefaultDoxm) { DeleteDoxmBinData(gDoxm); } gDoxm = NULL; - if(OC_STACK_OK == ret) + if (OC_STACK_OK == ret) { return OC_STACK_OK; } @@ -887,15 +865,9 @@ OCStackResult DeInitDoxmResource() } } - -/** - * This method returns the SRM device ID for this device. - * - * @retval OC_STACK_OK for Success, otherwise some error value - */ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID) { - if(deviceID && gDoxm) + if (deviceID && gDoxm) { *deviceID = gDoxm->deviceID; return OC_STACK_OK; @@ -903,11 +875,6 @@ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID) return OC_STACK_ERROR; } -/** - * @brief Gets the OicUuid_t value for the owner of this device. - * - * @return OC_STACK_OK if devOwner is a valid UUID, otherwise OC_STACK_ERROR. - */ OCStackResult GetDoxmDevOwnerId(OicUuid_t *devOwner) { OCStackResult retVal = OC_STACK_ERROR; diff --git a/resource/csdk/security/src/iotvticalendar.c b/resource/csdk/security/src/iotvticalendar.c index 0692cd9..d3b6cb1 100644 --- a/resource/csdk/security/src/iotvticalendar.c +++ b/resource/csdk/security/src/iotvticalendar.c @@ -34,20 +34,9 @@ static const char UNTIL[] = "UNTIL"; static const char BYDAY[] = "BYDAY"; static const char DAILY[] = "DAILY"; - -/** - * Parses periodStr and populate struct IotvtICalPeriod_t - * - * @param periodStr string to be parsed. - * @param period IotvtICalPeriod_t struct to be populated. - * - * @return IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_SUCCESS -- if no error while parsing - */ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) { - if((NULL == periodStr) || (NULL == period)) + if ((NULL == periodStr) || (NULL == period)) { return IOTVTICAL_INVALID_PARAMETER; } @@ -62,7 +51,7 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) //startDateTime and endDateTime must be same form //Eg: periodStr = "20150629T153050/20150630T203055" // periodStr = "20150629/20150630" - if(NULL == (endDTPos = strchr(periodStr, '/'))) + if (NULL == (endDTPos = strchr(periodStr, '/'))) { return IOTVTICAL_INVALID_PERIOD; } @@ -71,13 +60,13 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) endDTLen = strlen(endDTPos); //Checking if both startDateTime and endDateTime are of same form - if(startDTLen == endDTLen) + if (startDTLen == endDTLen) { - if(8 == startDTLen) //YYYYmmdd + if (8 == startDTLen) //YYYYmmdd { fmt = dFormat; } - else if(15 == startDTLen) //YYYYmmddTHHMMSS + else if (15 == startDTLen) //YYYYmmddTHHMMSS { fmt = dtFormat; } @@ -92,10 +81,10 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) } //Checking if startDateTime has right format - if(NULL != strptime(periodStr, fmt, &period->startDateTime)) + if (NULL != strptime(periodStr, fmt, &period->startDateTime)) { //Checking if endDateTime has right format - if(NULL != strptime(endDTPos, fmt, &period->endDateTime)) + if (NULL != strptime(endDTPos, fmt, &period->endDateTime)) { //Checking if endDateTime is after startDateTime if ((period->startDateTime.tm_year > period->endDateTime.tm_year) @@ -131,29 +120,29 @@ IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period) return IOTVTICAL_INVALID_PERIOD; } - /** - * Parses untilRule and populate "until" field of struct IotvtICalRecur_t + * Parses untilRule and populate "until" field of struct IotvtICalRecur_t. * - * @param untilRule string to be parsed. - * @param recur IotvtICalRecur_t struct to be populated. + * @param untilRule is a string to be parsed. + * @param recur is the reference to the @ref IotvtICalRecur_t to be populated. * - * @return IOTVTICAL_ERRRO -- if untilRule has invalid format - * IOTVTICAL_INVALID_SUCCESS -- if no error while parsing + * @return ::IOTVTICAL_SUCCESS is succesful, else in case of error + * ::IOTVTICAL_ERROR, if untilRule has invalid format or ::IOTVTICAL_INVALID_SUCCESS, + * if no error while parsing. */ static IotvtICalResult_t ParseDate(char *untilRule, IotvtICalRecur_t *recur) { char *date = strchr(untilRule, '='); - if(NULL == date) + if (NULL == date) { return IOTVTICAL_ERROR; } date += 1; - if(strlen(date) == 8) //YYYYmmdd + if (strlen(date) == 8) //YYYYmmdd { - if(NULL != strptime(date, dFormat, &recur->until)) + if (NULL != strptime(date, dFormat, &recur->until)) { return IOTVTICAL_SUCCESS; } @@ -161,49 +150,48 @@ static IotvtICalResult_t ParseDate(char *untilRule, IotvtICalRecur_t *recur) return IOTVTICAL_ERROR; } - /** - * Parses bydayRule and populate "byDay" field of struct IotvtICalRecur_t + * Parses bydayRule and populate "byDay" field of struct @ref IotvtICalRecur_t. * - * @param bydayRule string to be parsed. - * @param recur IotvtICalRecur_t struct to be populated. + * @param bydayRule is a string to be parsed. + * @param recur is a reference to @ref IotvtICalRecur_t struct to be populated. * - * @return IOTVTICAL_ERRRO -- if bydayRule has empty weekday list or invalid weekdays - * IOTVTICAL_INVALID_SUCCESS -- if no error while parsing + * @return ::IOTVTICAL_SUCCESS is succesful, else in case of error ::IOTVTICAL_ERROR, + * if bydayRule has empty weekday list or invalid weekdays. */ static IotvtICalResult_t ParseByday(char *bydayRule, IotvtICalRecur_t *recur) { - if(strstr(bydayRule, "SU")) + if (strstr(bydayRule, "SU")) { recur->byDay = recur->byDay | SUNDAY; } - if(strstr(bydayRule, "MO")) + if (strstr(bydayRule, "MO")) { recur->byDay = recur->byDay | MONDAY; } - if(strstr(bydayRule, "TU")) + if (strstr(bydayRule, "TU")) { recur->byDay = recur->byDay | TUESDAY; } - if(strstr(bydayRule, "WE")) + if (strstr(bydayRule, "WE")) { recur->byDay = recur->byDay | WEDNESDAY; } - if(strstr(bydayRule, "TH")) + if (strstr(bydayRule, "TH")) { recur->byDay = recur->byDay | THURSDAY; } - if(strstr(bydayRule, "FR")) + if (strstr(bydayRule, "FR")) { recur->byDay = recur->byDay | FRIDAY; } - if(strstr(bydayRule, "SA")) + if (strstr(bydayRule, "SA")) { recur->byDay = recur->byDay | SATURDAY; } //Checking if byDay list is empty or has inValid weekdays - if(recur->byDay == NO_WEEKDAY) + if (recur->byDay == NO_WEEKDAY) { return IOTVTICAL_ERROR; } @@ -211,21 +199,9 @@ static IotvtICalResult_t ParseByday(char *bydayRule, IotvtICalRecur_t *recur) return IOTVTICAL_SUCCESS; } - -/** - * Parses recurStr and populate struct IotvtICalRecur_t - * - * @param recurStr string to be parsed. - * @param recur IotvtICalPeriod_t struct to be populated. - * - * @return IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_RRULE -- if rrule string has invalid format - */ IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur) { - - if((NULL == recurStr) || (NULL == recur)) + if ((NULL == recurStr) || (NULL == recur)) { return IOTVTICAL_INVALID_PARAMETER; } @@ -239,17 +215,17 @@ IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur) startPos = recurStr; //Iterates though recurrence rule //Eg, RRULE: FREQ=DAILY; UNTIL=20150703; BYDAY=MO, WE, FR - while('\0' != startPos) + while ('\0' != startPos) { endPos = strchr(startPos, ';'); - if(endPos) + if (endPos) { endPos += 1; } OICStrcpy(buf, (endPos - startPos), startPos); - if(NULL != strstr(buf, FREQ)) + if (NULL != strstr(buf, FREQ)) { - if(NULL != strstr(buf, DAILY)) + if (NULL != strstr(buf, DAILY)) { recur->freq = FREQ_DAILY; freqFlag = 1; @@ -259,16 +235,16 @@ IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur) return IOTVTICAL_INVALID_RRULE; } } - else if(NULL != strstr(buf, UNTIL)) + else if (NULL != strstr(buf, UNTIL)) { - if(IOTVTICAL_SUCCESS != ParseDate(buf, recur)) + if (IOTVTICAL_SUCCESS != ParseDate(buf, recur)) { return IOTVTICAL_INVALID_RRULE; } } - else if(NULL != strstr(buf, BYDAY)) + else if (NULL != strstr(buf, BYDAY)) { - if(IOTVTICAL_SUCCESS != ParseByday(buf, recur)) + if (IOTVTICAL_SUCCESS != ParseByday(buf, recur)) { return IOTVTICAL_INVALID_RRULE; }; @@ -276,7 +252,7 @@ IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur) startPos = endPos; } - if(1 != freqFlag) + if (1 != freqFlag) { return IOTVTICAL_INVALID_RRULE; } @@ -297,12 +273,12 @@ static int DiffDays(IotvtICalDateTime_t *date1, IotvtICalDateTime_t *date2) int days; int leapDays=0; - if(date2->tm_year > date1->tm_year) + if (date2->tm_year > date1->tm_year) { - for(int y = date1->tm_year; y < date2->tm_year; y++) + for (int y = date1->tm_year; y < date2->tm_year; y++) { y += TM_YEAR_OFFSET; - if(y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) + if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { leapDays += 1; } @@ -315,7 +291,6 @@ static int DiffDays(IotvtICalDateTime_t *date1, IotvtICalDateTime_t *date2) return days; } - /** * Computes number of seconds between two time. * @@ -331,18 +306,18 @@ static int DiffSecs(IotvtICalDateTime_t *time1, IotvtICalDateTime_t *time2) } /** - * Validates if the @param currentTime is with in allowable period + * Validates if the @param currentTime is with in allowable period. * - * @param period -- allowable period - * @param currentTime -- the time that need to be validated against allowable time + * @param period allowable period. + * @param currentTime the time that need to be validated against allowable time. * - * @return IOTVTICAL_VALID_ACCESS -- if the request is within valid time period - * IOTVTICAL_INVALID_ACCESS -- if the request is not within valid time period - * IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid + * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period. + * ::IOTVTICAL_INVALID_ACCESS, if the request is not within valid time period. + * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid. */ static IotvtICalResult_t ValidatePeriod(IotvtICalPeriod_t *period, IotvtICalDateTime_t *currentTime) { - if(NULL == period || NULL == currentTime) + if (NULL == period || NULL == currentTime) { return IOTVTICAL_INVALID_PARAMETER; } @@ -355,26 +330,26 @@ static IotvtICalResult_t ValidatePeriod(IotvtICalPeriod_t *period, IotvtICalDate //If today is the start day of the allowable period then check //currentTime > allowable period startTime - if(todayIsStartDay) + if (todayIsStartDay) { validStartTime = (0 <= DiffSecs(&period->startDateTime, currentTime)) ? true : false; } //If today is the end day of allowable period then check //currentTime < allowable period endTime - if(todayIsEndDay) + if (todayIsEndDay) { validEndTime = (0 <= DiffSecs(currentTime, &period->endDateTime)) ? true :false; } //Check if today is valid day between startDate and EndDate inclusive - if((0 <= DiffDays(&period->startDateTime, currentTime)) && + if ((0 <= DiffDays(&period->startDateTime, currentTime)) && (0 <= DiffDays(currentTime, &period->endDateTime))) { validDay = true; } - if(validDay && validStartTime && validEndTime) + if (validDay && validStartTime && validEndTime) { return IOTVTICAL_VALID_ACCESS; } @@ -384,26 +359,12 @@ static IotvtICalResult_t ValidatePeriod(IotvtICalPeriod_t *period, IotvtICalDate } } -/** - * This API is used by policy engine to checks if the - * request to access resource is within valid time. - * - * @param period string representing period. - * @param recur string representing recurrence rule - * - * @return IOTVTICAL_VALID_ACCESS -- if the request is within valid time period - * IOTVTICAL_INVALID_ACCESS -- if the request is not within valid time period - * IOTVTICAL_INVALID_PARAMETER -- if parameter are invalid - * IOTVTICAL_INVALID_PERIOD -- if period string has invalid format - * IOTVTICAL_INVALID_RRULE -- if rrule string has invalid format - */ - -IotvtICalResult_t IsRequestWithinValidTime(char *periodStr, char *recurStr) +IotvtICalResult_t IsRequestWithinValidTime(const char *periodStr, const char *recurStr) { //NULL recur rule means no recurring patter exist. //Period can't be null. Period is used with or without //recur rule to compute allowable access time. - if(NULL == periodStr) + if (NULL == periodStr) { return IOTVTICAL_INVALID_PARAMETER; } @@ -416,13 +377,13 @@ IotvtICalResult_t IsRequestWithinValidTime(char *periodStr, char *recurStr) IotvtICalDateTime_t *currentTime = localtime(&rawTime); ret = ParsePeriod(periodStr, &period); - if(ret != IOTVTICAL_SUCCESS) + if (ret != IOTVTICAL_SUCCESS) { return ret; } //If recur is NULL then the access time is between period's startDateTime and endDateTime - if(NULL == recurStr) + if (NULL == recurStr) { ret = ValidatePeriod(&period, currentTime); } @@ -432,15 +393,15 @@ IotvtICalResult_t IsRequestWithinValidTime(char *periodStr, char *recurStr) //is computed from period's startDate and the last instance is computed from //"UNTIL". If "UNTIL" is not specified then the recurrence goes for forever. //Eg, RRULE: FREQ=DAILY; UNTIL=20150703; BYDAY=MO, WE, FR - if(NULL != recurStr) + if (NULL != recurStr) { ret = ParseRecur(recurStr, &recur); - if(ret != IOTVTICAL_SUCCESS) + if (ret != IOTVTICAL_SUCCESS) { return ret; } - if((0 <= DiffSecs(&period.startDateTime, currentTime))&& + if ((0 <= DiffSecs(&period.startDateTime, currentTime))&& (0 <= DiffSecs(currentTime, &period.endDateTime)) && (0 <= DiffDays(&period.startDateTime, currentTime))) { @@ -448,7 +409,7 @@ IotvtICalResult_t IsRequestWithinValidTime(char *periodStr, char *recurStr) ret = IOTVTICAL_VALID_ACCESS; //"UNTIL" is an optional parameter of RRULE, checking if until present in recur - if(0 != memcmp(&recur.until, &emptyDT, sizeof(IotvtICalDateTime_t))) + if (0 != memcmp(&recur.until, &emptyDT, sizeof(IotvtICalDateTime_t))) { if(0 > DiffDays(currentTime, &recur.until)) { @@ -457,11 +418,11 @@ IotvtICalResult_t IsRequestWithinValidTime(char *periodStr, char *recurStr) } //"BYDAY" is an optional parameter of RRULE, checking if byday present in recur - if(NO_WEEKDAY != recur.byDay) + if (NO_WEEKDAY != recur.byDay) { int isValidWD = (0x1 << currentTime->tm_wday) & recur.byDay; //Valid weekdays - if(!isValidWD) + if (!isValidWD) { ret = IOTVTICAL_INVALID_ACCESS; } diff --git a/resource/csdk/security/src/oxmpincommon.c b/resource/csdk/security/src/oxmpincommon.c index 5652236..f1354aa 100644 --- a/resource/csdk/security/src/oxmpincommon.c +++ b/resource/csdk/security/src/oxmpincommon.c @@ -1,24 +1,24 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *****************************************************************/ - - #include +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include #include "ocstack.h" #include "ocrandom.h" @@ -204,4 +204,3 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, return ret; } #endif //__WITH_DTLS__ - diff --git a/resource/csdk/security/src/pbkdf2.c b/resource/csdk/security/src/pbkdf2.c index ca614ec..02c984a 100644 --- a/resource/csdk/security/src/pbkdf2.c +++ b/resource/csdk/security/src/pbkdf2.c @@ -1,22 +1,23 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *****************************************************************/ +//****************************************************************** +// +// Copyright 2015 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + #include #include #include "pbkdf2.h" @@ -26,14 +27,14 @@ #define TAG "PBDKF2" #define XOR_BUF(in, out, bufSize)\ -do{\ +do \ +{\ size_t i=0;\ - for(i=0; i< (bufSize); i++)\ + for (i=0; i< (bufSize); i++)\ {\ (out)[i] = (in)[i] ^ (out)[i];\ }\ -}while(0)\ - +} while(0)\ static int isLittle() { diff --git a/resource/csdk/security/src/policyengine.c b/resource/csdk/security/src/policyengine.c index 088496a..d0cddc1 100644 --- a/resource/csdk/security/src/policyengine.c +++ b/resource/csdk/security/src/policyengine.c @@ -17,6 +17,7 @@ // limitations under the License. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include #include "oic_malloc.h" #include "policyengine.h" @@ -29,17 +30,13 @@ #include "srmutility.h" #include "doxmresource.h" #include "iotvticalendar.h" -#include #define TAG "SRM-PE" -/** - * Return the uint16_t CRUDN permission corresponding to passed CAMethod_t. - */ uint16_t GetPermissionFromCAMethod_t(const CAMethod_t method) { uint16_t perm = 0; - switch(method) + switch (method) { case CA_GET: perm = (uint16_t)PERMISSION_READ; @@ -59,10 +56,11 @@ uint16_t GetPermissionFromCAMethod_t(const CAMethod_t method) } /** - * @brief Compares two OicUuid_t structs. + * Compares two OicUuid_t structs. + * * @return true if the two OicUuid_t structs are equal, else false. */ -bool UuidCmp(OicUuid_t *firstId, OicUuid_t *secondId) +static bool UuidCmp(OicUuid_t *firstId, OicUuid_t *secondId) { // TODO use VERIFY macros to check for null when they are merged. if(NULL == firstId || NULL == secondId) @@ -79,12 +77,9 @@ bool UuidCmp(OicUuid_t *firstId, OicUuid_t *secondId) return true; } -/** - * Set the state and clear other stateful context vars. - */ void SetPolicyEngineState(PEContext_t *context, const PEState_t state) { - if(NULL == context) + if (NULL == context) { return; } @@ -106,11 +101,11 @@ void SetPolicyEngineState(PEContext_t *context, const PEState_t state) } /** - * @brief Compare the request's subject to DevOwner. + * Compare the request's subject to DevOwner. * - * @return true if context->subjectId == GetDoxmDevOwner(), else false + * @return true if context->subjectId == GetDoxmDevOwner(), else false. */ -bool IsRequestFromDevOwner(PEContext_t *context) +static bool IsRequestFromDevOwner(PEContext_t *context) { bool retVal = false; OicUuid_t owner; @@ -128,7 +123,6 @@ bool IsRequestFromDevOwner(PEContext_t *context) return retVal; } - inline static bool IsRequestSubjectEmpty(PEContext_t *context) { OicUuid_t emptySubject = {.id={}}; @@ -142,17 +136,18 @@ inline static bool IsRequestSubjectEmpty(PEContext_t *context) true : false; } - /** * Bitwise check to see if 'permission' contains 'request'. - * @param permission The allowed CRUDN permission. - * @param request The CRUDN permission being requested. + * + * @param permission is the allowed CRUDN permission. + * @param request is the CRUDN permission being requested. + * * @return true if 'permission' bits include all 'request' bits. */ static inline bool IsPermissionAllowingRequest(const uint16_t permission, const uint16_t request) { - if(request == (request & permission)) + if (request == (request & permission)) { return true; } @@ -164,6 +159,7 @@ static inline bool IsPermissionAllowingRequest(const uint16_t permission, /** * Compare the passed subject to the wildcard (aka anonymous) subjectId. + * * @return true if 'subject' is the wildcard, false if it is not. */ static inline bool IsWildCardSubject(OicUuid_t *subject) @@ -187,15 +183,14 @@ static inline bool IsWildCardSubject(OicUuid_t *subject) /** * Copy the subject, resource and permission into the context fields. */ -void CopyParamsToContext( - PEContext_t *context, - const OicUuid_t *subjectId, - const char *resource, - const uint16_t requestedPermission) +static void CopyParamsToContext(PEContext_t *context, + const OicUuid_t *subjectId, + const char *resource, + const uint16_t requestedPermission) { size_t length = 0; - if(NULL == context || NULL == subjectId || NULL == resource) + if (NULL == context || NULL == subjectId || NULL == resource) { return; } @@ -204,7 +199,7 @@ void CopyParamsToContext( // Copy the resource string into context. length = strlen(resource) + 1; - if(0 < length) + if (0 < length) { strncpy(context->resource, resource, length); context->resource[length - 1] = '\0'; @@ -214,32 +209,32 @@ void CopyParamsToContext( context->permission = requestedPermission; } - /** * Check whether 'resource' is getting accessed within the valid time period. - * @param acl The ACL to check. - * @return - * true if access is within valid time period or if the period or recurrence is not present. - * false if period and recurrence present and the access is not within valid time period. + * + * @param acl is the ACL to check. + * + * @return true if access is within valid time period or if the period or recurrence is not present. + * false if period and recurrence present and the access is not within valid time period. */ static bool IsAccessWithinValidTime(const OicSecAcl_t *acl) { #ifndef WITH_ARDUINO //Period & Recurrence not supported on Arduino due //lack of absolute time - if(NULL== acl || NULL == acl->periods || 0 == acl->prdRecrLen) + if (NULL== acl || NULL == acl->periods || 0 == acl->prdRecrLen) { return true; } //periods & recurrences rules are paired. - if(NULL == acl->recurrences) + if (NULL == acl->recurrences) { return false; } - for(size_t i = 0; i < acl->prdRecrLen; i++) + for (size_t i = 0; i < acl->prdRecrLen; i++) { - if(IOTVTICAL_VALID_ACCESS == IsRequestWithinValidTime(acl->periods[i], + if (IOTVTICAL_VALID_ACCESS == IsRequestWithinValidTime(acl->periods[i], acl->recurrences[i])) { OIC_LOG(INFO, TAG, "Access request is in allowed time period"); @@ -256,21 +251,23 @@ static bool IsAccessWithinValidTime(const OicSecAcl_t *acl) /** * Check whether 'resource' is in the passed ACL. - * @param resource The resource to search for. - * @param acl The ACL to check. + * + * @param resource is the resource being searched. + * @param acl is the ACL to check. + * * @return true if 'resource' found, otherwise false. */ - bool IsResourceInAcl(const char *resource, const OicSecAcl_t *acl) + static bool IsResourceInAcl(const char *resource, const OicSecAcl_t *acl) { - if(NULL== acl || NULL == resource) + if (NULL== acl || NULL == resource) { return false; } - for(size_t n = 0; n < acl->resourcesLen; n++) + for (size_t n = 0; n < acl->resourcesLen; n++) { - if(0 == strcmp(resource, acl->resources[n]) || // TODO null terms? - 0 == strcmp(WILDCARD_RESOURCE_URI, acl->resources[n])) + if (0 == strcmp(resource, acl->resources[n]) || // TODO null terms? + 0 == strcmp(WILDCARD_RESOURCE_URI, acl->resources[n])) { return true; } @@ -284,16 +281,14 @@ static bool IsAccessWithinValidTime(const OicSecAcl_t *acl) * Search each ACL for requested resource. * If resource found, check for context->permission and period validity. * If the ACL is not found locally and AMACL for the resource is found - * then sends the request to AMS service for the ACL + * then sends the request to AMS service for the ACL. * Set context->retVal to result from first ACL found which contains * correct subject AND resource. - * - * @retval void */ -void ProcessAccessRequest(PEContext_t *context) +static void ProcessAccessRequest(PEContext_t *context) { OIC_LOG(DEBUG, TAG, "Entering ProcessAccessRequest()"); - if(NULL != context) + if (NULL != context) { const OicSecAcl_t *currentAcl = NULL; OicSecAcl_t *savePtr = NULL; @@ -308,7 +303,7 @@ void ProcessAccessRequest(PEContext_t *context) OIC_LOG_V(DEBUG, TAG, "%s: getting ACL..." ,__func__); currentAcl = GetACLResourceData(&context->subject, &savePtr); - if(NULL != currentAcl) + if (NULL != currentAcl) { // Found the subject, so how about resource? OIC_LOG_V(DEBUG, TAG, "%s:found ACL matching subject" ,__func__); @@ -316,17 +311,17 @@ void ProcessAccessRequest(PEContext_t *context) // Subject was found, so err changes to Rsrc not found for now. context->retVal = ACCESS_DENIED_RESOURCE_NOT_FOUND; OIC_LOG_V(DEBUG, TAG, "%s:Searching for resource..." ,__func__); - if(IsResourceInAcl(context->resource, currentAcl)) + if (IsResourceInAcl(context->resource, currentAcl)) { OIC_LOG_V(INFO, TAG, "%s:found matching resource in ACL" ,__func__); context->matchingAclFound = true; // Found the resource, so it's down to valid period & permission. context->retVal = ACCESS_DENIED_INVALID_PERIOD; - if(IsAccessWithinValidTime(currentAcl)) + if (IsAccessWithinValidTime(currentAcl)) { context->retVal = ACCESS_DENIED_INSUFFICIENT_PERMISSION; - if(IsPermissionAllowingRequest(currentAcl->permission, context->permission)) + if (IsPermissionAllowingRequest(currentAcl->permission, context->permission)) { context->retVal = ACCESS_GRANTED; } @@ -337,10 +332,9 @@ void ProcessAccessRequest(PEContext_t *context) { OIC_LOG_V(INFO, TAG, "%s:no ACL found matching subject for resource %s",__func__, context->resource); } - } - while((NULL != currentAcl) && (false == context->matchingAclFound)); + } while ((NULL != currentAcl) && (false == context->matchingAclFound)); - if(IsAccessGranted(context->retVal)) + if (IsAccessGranted(context->retVal)) { OIC_LOG_V(INFO, TAG, "%s:Leaving ProcessAccessRequest(ACCESS_GRANTED)", __func__); } @@ -355,20 +349,10 @@ void ProcessAccessRequest(PEContext_t *context) } } -/** - * Check whether a request should be allowed. - * @param context Pointer to (Initialized) Policy Engine context to use. - * @param subjectId Pointer to Id of the requesting entity. - * @param resource Pointer to URI of Resource being requested. - * @param permission Requested permission. - * @return ACCESS_GRANTED if request should go through, - * otherwise some flavor of ACCESS_DENIED - */ -SRMAccessResponse_t CheckPermission( - PEContext_t *context, - const OicUuid_t *subjectId, - const char *resource, - const uint16_t requestedPermission) +SRMAccessResponse_t CheckPermission(PEContext_t *context, + const OicUuid_t *subjectId, + const char *resource, + const uint16_t requestedPermission) { SRMAccessResponse_t retVal = ACCESS_DENIED_POLICY_ENGINE_ERROR; @@ -379,9 +363,9 @@ SRMAccessResponse_t CheckPermission( // 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 // state, return error. Otherwise, change to BUSY state and begin processing request. - if(AWAITING_REQUEST == context->state || AWAITING_AMS_RESPONSE == context->state) + if (AWAITING_REQUEST == context->state || AWAITING_AMS_RESPONSE == context->state) { - if(AWAITING_REQUEST == context->state) + if (AWAITING_REQUEST == context->state) { SetPolicyEngineState(context, BUSY); CopyParamsToContext(context, subjectId, resource, requestedPermission); @@ -389,7 +373,7 @@ SRMAccessResponse_t CheckPermission( // Before doing any processing, check if request coming // from DevOwner and if so, always GRANT. - if(IsRequestFromDevOwner(context)) + if (IsRequestFromDevOwner(context)) { context->retVal = ACCESS_GRANTED; } @@ -401,7 +385,7 @@ SRMAccessResponse_t CheckPermission( ProcessAccessRequest(context); // If matching ACL not found, and subject != wildcard, try wildcard. - if((false == context->matchingAclFound) && \ + if ((false == context->matchingAclFound) && \ (false == IsWildCardSubject(&context->subject))) { //Saving subject for Amacl check @@ -418,7 +402,7 @@ SRMAccessResponse_t CheckPermission( } //No local ACE found for the request so checking Amacl resource - if(ACCESS_GRANTED != context->retVal) + if (ACCESS_GRANTED != context->retVal) { //If subject is not empty then restore the original subject //else keep the subject to WILDCARD_SUBJECT_ID @@ -445,7 +429,7 @@ SRMAccessResponse_t CheckPermission( // Capture retVal before resetting state for next request. retVal = context->retVal; - if(!context->amsProcessing) + if (!context->amsProcessing) { OIC_LOG(INFO, TAG, "Resetting PE context and PE State to AWAITING_REQUEST"); SetPolicyEngineState(context, AWAITING_REQUEST); @@ -455,11 +439,6 @@ exit: return retVal; } -/** - * Initialize the Policy Engine. Call this before calling CheckPermission(). - * @param context Pointer to Policy Engine context to initialize. - * @return OC_STACK_OK for Success, otherwise some error value - */ OCStackResult InitPolicyEngine(PEContext_t *context) { if(NULL == context) @@ -477,12 +456,6 @@ OCStackResult InitPolicyEngine(PEContext_t *context) return OC_STACK_OK; } -/** - * De-Initialize the Policy Engine. Call this before exiting to allow Policy - * Engine to do cleanup on context. - * @param context Pointer to Policy Engine context to de-initialize. - * @return none - */ void DeInitPolicyEngine(PEContext_t *context) { if(NULL != context) diff --git a/resource/csdk/security/src/psinterface.c b/resource/csdk/security/src/psinterface.c index 809be93..bf27d58 100644 --- a/resource/csdk/security/src/psinterface.c +++ b/resource/csdk/security/src/psinterface.c @@ -44,7 +44,7 @@ const size_t DB_FILE_SIZE_BLOCK = 1023; /** * Gets the Secure Virtual Database size. * - * @param ps pointer of OCPersistentStorage for the SVR name ("acl", "cred", "pstat" etc). + * @param ps pointer of OCPersistentStorage for the SVR name ("acl", "cred", "pstat" etc). * * @return total size of the SVR database. */ diff --git a/resource/csdk/security/src/pstatresource.c b/resource/csdk/security/src/pstatresource.c index 84750e0..bfd9ae1 100644 --- a/resource/csdk/security/src/pstatresource.c +++ b/resource/csdk/security/src/pstatresource.c @@ -426,7 +426,7 @@ static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest } //Send payload to request originator - if(OC_STACK_OK != SendSRMCBORResponse(ehRequest, ehRet, NULL)) + if (OC_STACK_OK != SendSRMCBORResponse(ehRequest, ehRet, NULL)) { OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandlePstatPostRequest"); } @@ -437,9 +437,9 @@ static OCEntityHandlerResult HandlePstatPutRequest(const OCEntityHandlerRequest /** * This internal method is the entity handler for pstat resources. */ -OCEntityHandlerResult PstatEntityHandler(OCEntityHandlerFlag flag, - OCEntityHandlerRequest * ehRequest, - void *callbackParam) + OCEntityHandlerResult PstatEntityHandler(OCEntityHandlerFlag flag, + OCEntityHandlerRequest * ehRequest, + void *callbackParam) { (void)callbackParam; OCEntityHandlerResult ehRet = OC_EH_ERROR; @@ -467,7 +467,7 @@ OCEntityHandlerResult PstatEntityHandler(OCEntityHandlerFlag flag, /** * This internal method is used to create '/oic/sec/pstat' resource. */ -OCStackResult CreatePstatResource() + OCStackResult CreatePstatResource() { OCStackResult ret = OCCreateResource(&gPstatHandle, OIC_RSRC_TYPE_SEC_PSTAT, @@ -536,14 +536,9 @@ exit: return ret; } -/** - * Perform cleanup for pstat resources. - * - * @retval OC_STACK_OK for Success, otherwise some error value - */ OCStackResult DeInitPstatResource() { - if(gPstat != &gDefaultPstat) + if (gPstat != &gDefaultPstat) { DeletePstatBinData(gPstat); gPstat = NULL; diff --git a/resource/csdk/security/src/resourcemanager.c b/resource/csdk/security/src/resourcemanager.c index d4b0f35..d40c4c9 100644 --- a/resource/csdk/security/src/resourcemanager.c +++ b/resource/csdk/security/src/resourcemanager.c @@ -18,6 +18,7 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include #include "resourcemanager.h" #include "securevirtualresourcetypes.h" #include "aclresource.h" @@ -30,7 +31,6 @@ #include "oic_string.h" #include "logger.h" #include "utlist.h" -#include //#ifdef DIRECT_PAIRING #include "pconfresource.h" diff --git a/resource/csdk/security/src/secureresourcemanager.c b/resource/csdk/security/src/secureresourcemanager.c index 02fe6ed..7c233be 100644 --- a/resource/csdk/security/src/secureresourcemanager.c +++ b/resource/csdk/security/src/secureresourcemanager.c @@ -56,21 +56,11 @@ static SPResponseCallback gSPResponseHandler = NULL; */ PEContext_t g_policyEngineContext; -/** - * @brief function to register provisoning API's response callback. - * @param respHandler response handler callback. - */ -void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler) -{ - gSPResponseHandler = respHandler; -} - - static void SRMSendUnAuthorizedAccessresponse(PEContext_t *context) { CAResponseInfo_t responseInfo = {.result = CA_EMPTY}; - if(NULL == context || + if (NULL == context || NULL == context->amsMgrContext->requestInfo) { OIC_LOG_V(ERROR, TAG, "%s : NULL Parameter(s)",__func__); @@ -92,7 +82,6 @@ static void SRMSendUnAuthorizedAccessresponse(PEContext_t *context) } } - void SRMSendResponse(SRMAccessResponse_t responseVal) { OIC_LOG(DEBUG, TAG, "Sending response to remote device"); @@ -121,12 +110,11 @@ exit: SetPolicyEngineState(&g_policyEngineContext, AWAITING_REQUEST); } - /** - * @brief Handle the request from the SRM. - * @param endPoint [IN] Endpoint object from which the response is received. - * @param requestInfo [IN] Information for the request. - * @return NONE + * Handle the request from the SRM. + * + * @param endPoint object from which the response is received. + * @param requestInfo contains information for the request. */ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requestInfo) { @@ -164,7 +152,7 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ OICStrcpyPartial(newUri, MAX_URI_LENGTH + 1, requestInfo->info.resourceUri, position); //New request are only processed if the policy engine state is AWAITING_REQUEST. - if(AWAITING_REQUEST == g_policyEngineContext.state) + if (AWAITING_REQUEST == g_policyEngineContext.state) { OIC_LOG_V(DEBUG, TAG, "Processing request with uri, %s for method, %d", requestInfo->info.resourceUri, requestInfo->method); @@ -189,7 +177,7 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ VERIFY_NON_NULL(TAG, gRequestHandler, ERROR); - if(ACCESS_WAITING_FOR_AMS == response) + if (ACCESS_WAITING_FOR_AMS == response) { OIC_LOG(INFO, TAG, "Sending slow response"); @@ -222,10 +210,10 @@ exit: } /** - * @brief Handle the response from the SRM. - * @param endPoint [IN] The remote endpoint. - * @param responseInfo [IN] Response information from the endpoint. - * @return NONE + * Handle the response from the SRM. + * + * @param endPoint points to the remote endpoint. + * @param responseInfo contains response information from the endpoint. */ void SRMResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo) { @@ -248,12 +236,11 @@ void SRMResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *re } } - /** - * @brief Handle the error from the SRM. - * @param endPoint [IN] The remote endpoint. - * @param errorInfo [IN] Error information from the endpoint. - * @return NONE + * Handle the error from the SRM. + * + * @param endPoint is the remote endpoint. + * @param errorInfo contains error information from the endpoint. */ void SRMErrorHandler(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo) { @@ -265,16 +252,6 @@ void SRMErrorHandler(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errorInf } } - -/** - * @brief Register request and response callbacks. - * Requests and responses are delivered in these callbacks. - * @param reqHandler [IN] Request handler callback ( for GET,PUT ..etc) - * @param respHandler [IN] Response handler callback. - * @return - * OC_STACK_OK - No errors; Success - * OC_STACK_INVALID_PARAM - invalid parameter - */ OCStackResult SRMRegisterHandler(CARequestCallback reqHandler, CAResponseCallback respHandler, CAErrorCallback errHandler) @@ -298,13 +275,6 @@ OCStackResult SRMRegisterHandler(CARequestCallback reqHandler, return OC_STACK_OK; } -/** - * @brief Register Persistent storage callback. - * @param persistentStorageHandler [IN] Pointers to open, read, write, close & unlink handlers. - * @return - * OC_STACK_OK - No errors; Success - * OC_STACK_INVALID_PARAM - Invalid parameter - */ OCStackResult SRMRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler) { OIC_LOG(DEBUG, TAG, "SRMRegisterPersistentStorageHandler !!"); @@ -317,22 +287,11 @@ OCStackResult SRMRegisterPersistentStorageHandler(OCPersistentStorage* persisten return OC_STACK_OK; } -/** - * @brief Get Persistent storage handler pointer. - * @return - * The pointer to Persistent Storage callback handler - */ - OCPersistentStorage* SRMGetPersistentStorageHandler() { return gPersistentStorageHandler; } - -/** - * @brief Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). - * @retval OC_STACK_OK for Success, otherwise some error value - */ OCStackResult SRMInitSecureResources() { // TODO: temporarily returning OC_STACK_OK every time until default @@ -355,38 +314,21 @@ OCStackResult SRMInitSecureResources() return ret; } -/** - * @brief Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc). - * @retval none - */ void SRMDeInitSecureResources() { DestroySecureResources(); } -/** - * @brief Initialize Policy Engine. - * @return OC_STACK_OK for Success, otherwise some error value. - */ OCStackResult SRMInitPolicyEngine() { return InitPolicyEngine(&g_policyEngineContext); } -/** - * @brief Cleanup Policy Engine. - * @return none - */ void SRMDeInitPolicyEngine() { return DeInitPolicyEngine(&g_policyEngineContext); } -/** - * @brief Check the security resource URI. - * @param uri [IN] Pointers to security resource URI. - * @return true if the URI is one of security resources, otherwise false. - */ bool SRMIsSecurityResourceURI(const char* uri) { if (!uri) diff --git a/resource/csdk/security/src/srmutility.c b/resource/csdk/security/src/srmutility.c index 8f8cc7f..df0636b 100644 --- a/resource/csdk/security/src/srmutility.c +++ b/resource/csdk/security/src/srmutility.c @@ -28,53 +28,41 @@ #define TAG "SRM-UTILITY" -/** - * This method initializes the OicParseQueryIter_t struct - * - *@param query - REST query, to be parsed - *@param parseIter - OicParseQueryIter_t struct, to be initialized - * - */ -void ParseQueryIterInit(unsigned char * query, OicParseQueryIter_t * parseIter) +void ParseQueryIterInit(const unsigned char * query, OicParseQueryIter_t * parseIter) { - OIC_LOG (INFO, TAG, "Initializing coap iterator"); - if((NULL == query) || (NULL == parseIter)) + OIC_LOG(INFO, TAG, "Initializing coap iterator"); + if ((NULL == query) || (NULL == parseIter)) + { return; + } parseIter->attrPos = NULL; parseIter->attrLen = 0; parseIter->valPos = NULL; parseIter->valLen = 0; - coap_parse_iterator_init(query, strlen((char *)query), - (unsigned char *)OIC_SEC_REST_QUERY_SEPARATOR, (unsigned char *) "", 0, &parseIter->pi); + coap_parse_iterator_init((unsigned char *)query, strlen((char *)query), + (unsigned char *)OIC_SEC_REST_QUERY_SEPARATOR, + (unsigned char *) "", 0, &parseIter->pi); } -/** - * This method fills the OicParseQueryIter_t struct with next REST query's - * attribute's and value's information - * - *@param parseIter - OicParseQueryIter_t struct, has next query's attribute's & value's info - * - * @retval - * OicParseQueryIter_t * - has parsed query info - * NULL - has no query to parse - */ OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter) { - OIC_LOG (INFO, TAG, "Getting Next Query"); - if(NULL == parseIter) + OIC_LOG(INFO, TAG, "Getting Next Query"); + if (NULL == parseIter) + { return NULL; + } unsigned char * qrySeg = NULL; char * delimPos; - //Get the next query. Querys are separated by OIC_SEC_REST_QUERY_SEPARATOR + // Get the next query. Querys are separated by OIC_SEC_REST_QUERY_SEPARATOR. qrySeg = coap_parse_next(&parseIter->pi); - if(qrySeg) + if (qrySeg) { delimPos = strchr((char *)qrySeg, OIC_SEC_REST_QUERY_DELIMETER); - if(delimPos) + if (delimPos) { parseIter->attrPos = parseIter->pi.pos; parseIter->attrLen = (unsigned char *)delimPos - parseIter->pi.pos; @@ -86,15 +74,14 @@ OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter) return NULL; } - // TODO This functionality is replicated in all SVR's and therefore we need // to encapsulate it in a common method. However, this may not be the right // file for this method. -OCStackResult AddUuidArray(cJSON* jsonRoot, const char* arrayItem, - size_t *numUuids, OicUuid_t** uuids ) +OCStackResult AddUuidArray(const cJSON* jsonRoot, const char* arrayItem, + size_t *numUuids, OicUuid_t** uuids) { size_t idxx = 0; - cJSON* jsonObj = cJSON_GetObjectItem(jsonRoot, arrayItem); + cJSON* jsonObj = cJSON_GetObjectItem((cJSON *)jsonRoot, arrayItem); VERIFY_NON_NULL(TAG, jsonObj, ERROR); VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR); @@ -150,4 +137,3 @@ const char* GetOxmString(OicSecOxm_t oxmType) return NULL; } } - diff --git a/resource/csdk/security/src/svcresource.c b/resource/csdk/security/src/svcresource.c index af92133..3cfe8ee 100644 --- a/resource/csdk/security/src/svcresource.c +++ b/resource/csdk/security/src/svcresource.c @@ -308,7 +308,7 @@ exit: return ret; } -static OCEntityHandlerResult HandleSVCGetRequest (const OCEntityHandlerRequest * ehRequest) +static OCEntityHandlerResult HandleSVCGetRequest(const OCEntityHandlerRequest * ehRequest) { // Convert SVC data into JSON for transmission size_t size = 0; @@ -325,7 +325,7 @@ static OCEntityHandlerResult HandleSVCGetRequest (const OCEntityHandlerRequest * return ehRet; } -static OCEntityHandlerResult HandleSVCPostRequest (const OCEntityHandlerRequest * ehRequest) +static OCEntityHandlerResult HandleSVCPostRequest(const OCEntityHandlerRequest * ehRequest) { OCEntityHandlerResult ehRet = OC_EH_ERROR; uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData1;; @@ -359,13 +359,13 @@ static OCEntityHandlerResult HandleSVCPostRequest (const OCEntityHandlerRequest return ehRet; } -/* +/** * This internal method is the entity handler for SVC resources and * will handle REST request (GET/PUT/POST/DEL) for them. */ -OCEntityHandlerResult SVCEntityHandler (OCEntityHandlerFlag flag, - OCEntityHandlerRequest * ehRequest, - void* callbackParameter) +static OCEntityHandlerResult SVCEntityHandler(OCEntityHandlerFlag flag, + OCEntityHandlerRequest * ehRequest, + void* callbackParameter) { (void) callbackParameter; OCEntityHandlerResult ehRet = OC_EH_ERROR; @@ -396,20 +396,18 @@ OCEntityHandlerResult SVCEntityHandler (OCEntityHandlerFlag flag, return ehRet; } -/* +/** * This internal method is used to create '/oic/sec/svc' resource. */ -OCStackResult CreateSVCResource() +static OCStackResult CreateSVCResource() { - OCStackResult ret; - - ret = OCCreateResource(&gSvcHandle, - OIC_RSRC_TYPE_SEC_SVC, - OIC_MI_DEF, - OIC_RSRC_SVC_URI, - SVCEntityHandler, - NULL, - OC_OBSERVABLE); + OCStackResult ret = OCCreateResource(&gSvcHandle, + OIC_RSRC_TYPE_SEC_SVC, + OIC_MI_DEF, + OIC_RSRC_SVC_URI, + SVCEntityHandler, + NULL, + OC_OBSERVABLE); if (OC_STACK_OK != ret) { @@ -419,12 +417,12 @@ OCStackResult CreateSVCResource() return ret; } - OCStackResult InitSVCResource() { - OIC_LOG_V (DEBUG, TAG, "Begin %s ", __func__ ); OCStackResult ret = OC_STACK_ERROR; + OIC_LOG_V(DEBUG, TAG, "Begin %s ", __func__ ); + uint8_t *data = NULL; size_t size = 0; ret = GetSecureVirtualDatabaseFromPS(OIC_JSON_SVC_NAME, &data, &size); @@ -449,15 +447,10 @@ OCStackResult InitSVCResource() DeInitSVCResource(); } - OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ret); + OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__ , ret); return ret; } -/** - * Perform cleanup for SVC resources. - * - * @retval none - */ void DeInitSVCResource() { OCDeleteResource(gSvcHandle); -- 2.7.4