Commit 15f62487 authored by Oleksandr Dmytrenko's avatar Oleksandr Dmytrenko Committed by Aleksey

c++ warns as error fixed

c++ warns as error fixed

Change-Id: I836560ef338ba385c4ef814963e683dd41d1c500
Signed-off-by: default avatarOleksandr Dmytrenko <o.dmytrenko@samsung.com>
parent 05ac27ae
......@@ -124,23 +124,23 @@ struct OicParseQueryIter
#define LOG_MBEDTLS_ERROR(ret) do{ \
if (0!=(ret)) {\
char *buf = (char*)OICCalloc(2048, 1);\
if (buf)\
char *_buf = (char*)OICCalloc(2048, 1);\
if (_buf)\
{\
mbedtls_strerror((ret), buf, 2048); \
OIC_LOG_V(ERROR, TAG, "mbedtls error: %s", buf); \
OICFree(buf);\
mbedtls_strerror((ret), _buf, 2048); \
OIC_LOG_V(ERROR, TAG, "mbedtls error: %s", _buf); \
OICFree(_buf);\
}\
} }while(0)
#define LOG_MBEDTLS_VERIFY_ERROR(flags) do{ \
if (0!=(flags)) { \
char *buf = (char*)OICCalloc(2048, 1); \
if (buf) \
char *_buf = (char*)OICCalloc(2048, 1); \
if (_buf) \
{ \
mbedtls_x509_crt_verify_info(buf, 2048, "", flags); \
OIC_LOG_V(ERROR, TAG, "mbedtls verify error: %s", buf); \
OICFree(buf); \
mbedtls_x509_crt_verify_info(_buf, 2048, "", flags); \
OIC_LOG_V(ERROR, TAG, "mbedtls verify error: %s", _buf); \
OICFree(_buf); \
} \
} }while(0)
......@@ -243,6 +243,22 @@ bool IsNilUuid(const OicUuid_t *uuid);
OCStackResult OC_CALL SetDeviceIdSeed(const uint8_t* seed, size_t seedSize);
#endif
/**
* cbor default init
*/
#define OC_DEFAULT_CBOR_VALUE {.parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0}
#define OC_DEFAULT_CBOR_PARSER {.end = NULL, .flags = 0}
#define OC_DEFAULT_OICPARSEQUWRYITER \
{ \
.attrPos = NULL,\
.attrLen = 0,\
.valPos = NULL,\
.valLen = 0,\
.pi = {.n=0,.separator=NULL,.delim=NULL,.dlen=0,.pos=NULL,.segment_length=0}\
}
/**
* Is the URI for a Security Virtual Resource as defined
* by Security Specification.
......
......@@ -34,7 +34,6 @@
#include "oic_string.h"
#include "experimental/ocrandom.h"
#include "ocpayload.h"
#include "utlist.h"
#include "acl_logging.h"
#include "experimental/payload_logging.h"
#include "srmresourcestrings.h"
......@@ -361,6 +360,7 @@ static size_t OicSecAclSize(const OicSecAcl_t *secAcl)
size++;
ace = ace->next;
}
OIC_LOG_V(DEBUG, TAG, "%s: %lu", __func__, size);
return size;
}
OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
......@@ -440,7 +440,7 @@ OCStackResult AclToCBORPayloadPartial(const OicSecAcl_t *secAcl,
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Creating ACL Map.");
OIC_LOG_V(DEBUG, TAG, "%s starting encoding of %s resource.",
__func__, (OIC_SEC_ACL_V1 == aclVersion)?"v1 acl":"v2 acl2");
// v1 uses "aclist" as the top-level tag, containing an "aces" object
if (OIC_SEC_ACL_V1 == aclVersion)
{
......@@ -522,6 +522,7 @@ OCStackResult AclToCBORPayloadPartial(const OicSecAcl_t *secAcl,
{
aceMapSize++;
}
validityElts = validityElts->next;
}
#ifdef MULTIPLE_OWNER
......@@ -761,7 +762,7 @@ OCStackResult AclToCBORPayloadPartial(const OicSecAcl_t *secAcl,
rsrcMapSize++;
}
OIC_LOG_V(DEBUG, TAG, "%s resource map size = %"PRIuPTR, __func__, rsrcMapSize);
OIC_LOG_V(DEBUG, TAG, "%s resource map size = %" PRIuPTR, __func__, rsrcMapSize);
cborEncoderResult = cbor_encoder_create_map(&resources, &rMap, rsrcMapSize);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Adding Resource Map.");
......@@ -1108,7 +1109,6 @@ exit:
// It parses { "aclist" : [ { ... } ] } instead of { "aclist" : { "aces" : [ ] } }
#if defined(TCP_ADAPTER) && defined(WITH_CLOUD)
OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size)
{
if (NULL == cborPayload || 0 == size)
......@@ -1116,8 +1116,8 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
return NULL;
}
OCStackResult ret = OC_STACK_ERROR;
CborValue aclCbor = { .parser = NULL };
CborParser parser = { .end = NULL };
CborValue aclCbor = OC_DEFAULT_CBOR_VALUE;
CborParser parser = OC_DEFAULT_CBOR_PARSER;
CborError cborFindResult = CborNoError;
cbor_parser_init(cborPayload, size, 0, &parser, &aclCbor);
......@@ -1125,7 +1125,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
VERIFY_NOT_NULL_RETURN(TAG, acl, ERROR, NULL);
// Enter ACL Map
CborValue aclMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
CborValue aclMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&aclCbor, &aclMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering ACL Map.");
......@@ -1146,7 +1146,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
if (strcmp(tagName, OIC_JSON_ACLIST_NAME) == 0)
{
// Enter ACES Array
CborValue acesArray = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
CborValue acesArray = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&aclMap, &acesArray);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering ACES Array.");
......@@ -1154,7 +1154,12 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
while (cbor_value_is_valid(&acesArray))
{
acesCount++;
CborValue aceMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
CborValue aceMap = OC_DEFAULT_CBOR_VALUE;
if (!cbor_value_is_container(&acesArray))
{
OIC_LOG_V(WARNING, TAG, "%s: access array is not container", __func__);
return NULL;
}
cborFindResult = cbor_value_enter_container(&acesArray, &aceMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering ACE Map.");
......@@ -1202,14 +1207,14 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
// Resources -- Mandatory
if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0)
{
CborValue resources = { .parser = NULL };
CborValue resources = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&aceMap, &resources);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering a Resource Array.");
while (cbor_value_is_valid(&resources))
{
// rMap
CborValue rMap = { .parser = NULL };
CborValue rMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&resources, &rMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Resource Map");
......@@ -1317,7 +1322,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
// Validity -- Not mandatory
if(strcmp(name, OIC_JSON_VALIDITY_NAME) == 0)
{
CborValue validitiesMap = {.parser = NULL};
CborValue validitiesMap = OC_DEFAULT_CBOR_VALUE;
size_t validitySize = 0;
cborFindResult = cbor_value_get_array_length(&aceMap, &validitySize);
......@@ -1332,7 +1337,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
VERIFY_NOT_NULL(TAG, validity, ERROR);
LL_APPEND(ace->validities, validity);
CborValue validityMap = {.parser = NULL};
CborValue validityMap = OC_DEFAULT_CBOR_VALUE;
//period (string)
cborFindResult = cbor_value_enter_container(&validitiesMap, &validityMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a validity Map.");
......@@ -1342,7 +1347,7 @@ OicSecAcl_t* CBORPayloadToCloudAcl(const uint8_t *cborPayload, const size_t size
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a Period value.");
//recurrence (string array)
CborValue recurrenceMap = {.parser = NULL};
CborValue recurrenceMap = OC_DEFAULT_CBOR_VALUE ;
cborFindResult = cbor_value_enter_container(&validityMap, &recurrenceMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a recurrence array.");
......@@ -1438,8 +1443,8 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
}
OCStackResult ret = OC_STACK_ERROR;
CborValue aclMap = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
CborValue aclCbor = { .parser = NULL };
CborParser parser = { .end = NULL };
CborValue aclCbor = OC_DEFAULT_CBOR_VALUE ;
CborParser parser = OC_DEFAULT_CBOR_PARSER ;
CborError cborFindResult = CborNoError;
char *tagName = NULL;
char *subjectTag = NULL;
......@@ -1796,7 +1801,7 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
// Resources -- Mandatory
if (0 == strcmp(name, OIC_JSON_RESOURCES_NAME))
{
CborValue resources = { .parser = NULL };
CborValue resources = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&aceMap, &resources);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering a Resource Array.");
OIC_LOG_V(DEBUG, TAG, "%s entered resources array.", __func__);
......@@ -1805,7 +1810,7 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
while (cbor_value_is_valid(&resources))
{
// rMap is the map of the current Resource being decoded
CborValue rMap = { .parser = NULL };
CborValue rMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&resources, &rMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Resource Map");
resourceCount++;
......@@ -1971,7 +1976,7 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
// Validity -- Not mandatory
if(strcmp(name, OIC_JSON_VALIDITY_NAME) == 0)
{
CborValue validitiesMap = {.parser = NULL};
CborValue validitiesMap = OC_DEFAULT_CBOR_VALUE;
size_t validitySize = 0;
cborFindResult = cbor_value_get_array_length(&aceMap, &validitySize);
......@@ -1986,7 +1991,7 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
VERIFY_NOT_NULL(TAG, validity, ERROR);
LL_APPEND(ace->validities, validity);
CborValue validityMap = {.parser = NULL};
CborValue validityMap = OC_DEFAULT_CBOR_VALUE;
//period (string)
cborFindResult = cbor_value_enter_container(&validitiesMap, &validityMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a validity Map.");
......@@ -1996,7 +2001,7 @@ static OicSecAcl_t* CBORPayloadToAclVersionOpt(const uint8_t *cborPayload, const
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a Period value.");
//recurrence (string array)
CborValue recurrenceMap = {.parser = NULL};
CborValue recurrenceMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&validityMap, &recurrenceMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding a recurrence array.");
......@@ -2340,7 +2345,7 @@ static OCStackResult RemoveAceByAceIds(AceIdList_t *aceIdList)
*/
static bool GetSubjectFromQueryString(const char *query, OicUuid_t *subject)
{
OicParseQueryIter_t parseIter = { .attrPos = NULL };
OicParseQueryIter_t parseIter = OC_DEFAULT_OICPARSEQUWRYITER;
ParseQueryIterInit((unsigned char *) query, &parseIter);
......@@ -2379,7 +2384,7 @@ exit:
static bool GetAceIdsFromQueryString(const char *query, AceIdList_t **aceid)
{
bool found = false;
OicParseQueryIter_t parseIter = { .attrPos = NULL };
OicParseQueryIter_t parseIter = OC_DEFAULT_OICPARSEQUWRYITER;
ParseQueryIterInit((unsigned char *) query, &parseIter);
......@@ -2440,7 +2445,7 @@ exit:
*/
static bool GetResourceFromQueryString(const char *query, char *resource, size_t resourceSize)
{
OicParseQueryIter_t parseIter = { .attrPos = NULL };
OicParseQueryIter_t parseIter = OC_DEFAULT_OICPARSEQUWRYITER;
ParseQueryIterInit((unsigned char *) query, &parseIter);
......@@ -3015,6 +3020,9 @@ static OCEntityHandlerResult HandleACL2PostRequest(const OCEntityHandlerRequest
OIC_LOG(INFO, TAG, "HandleACLPostRequest processing the request");
OCEntityHandlerResult ehRet = OC_EH_INTERNAL_SERVER_ERROR;
VERIFY_NOT_NULL_RETURN(TAG, ehRequest, ERROR, OC_EH_ERROR);
VERIFY_NOT_NULL_RETURN(TAG, ehRequest->payload, ERROR, OC_EH_ERROR);
// Convert CBOR into ACL data and update to SVR buffers. This will also validate the ACL data received.
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
......
......@@ -91,7 +91,7 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
CborEncoder encoder;
CborEncoder amaclMap;
int64_t cborEncoderResult = CborNoError;
CborError cborEncoderResult = CborNoError;
CborEncoder rsrcMap;
CborEncoder rlistArray;
......@@ -217,15 +217,15 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
OCStackResult ret = OC_STACK_ERROR;
CborValue amaclCbor = { .parser = NULL };
CborParser parser = { .end = NULL };
CborValue amaclCbor = OC_DEFAULT_CBOR_VALUE;
CborParser parser = OC_DEFAULT_CBOR_PARSER;
CborError cborFindResult = CborNoError;
cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
VERIFY_NOT_NULL_RETURN(TAG, headAmacl, ERROR, OC_STACK_NO_MEMORY);
CborValue amaclMap = { .parser = NULL };
CborValue amaclMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Amacl Map.");
......@@ -244,7 +244,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
if (0 == strcmp(OIC_JSON_RESOURCES_NAME, name))
{
// resource map
CborValue rsrcMap = { .parser = NULL };
CborValue rsrcMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&amaclMap, &rsrcMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Resource Map");
......@@ -266,7 +266,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
cborFindResult = cbor_value_get_array_length(&rsrcMap, &headAmacl->resourcesLen);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Finding Rlist Array Len.");
CborValue rsrcArray = { .parser = NULL };
CborValue rsrcArray = OC_DEFAULT_CBOR_VALUE;
// rlist array
cborFindResult = cbor_value_enter_container(&rsrcMap, &rsrcArray);
......@@ -279,7 +279,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
while (cbor_value_is_valid(&rsrcArray))
{
// rMap
CborValue rMap = { .parser = NULL };
CborValue rMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&rsrcArray, &rMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Rlist Map");
......
......@@ -272,6 +272,7 @@ OCStackResult OCInternalIsValidRoleCertificate(const uint8_t *buf, size_t bufLen
{
OCStackResult res = OC_STACK_ERROR;
mbedtls_x509_crt parsedCert;
bool valid = false;
OIC_LOG(DEBUG, TAG, "OCInternalIsValidRoleCertificate IN");
......@@ -310,7 +311,7 @@ OCStackResult OCInternalIsValidRoleCertificate(const uint8_t *buf, size_t bufLen
goto exit;
}
bool valid = false;
valid = false;
/* Check for at least one subjAltName with a role in it. */
for (const mbedtls_x509_general_names *nameCur = &parsedCert.subject_alt_names;
NULL != nameCur;
......@@ -446,16 +447,17 @@ OCStackResult OCInternalVerifyRoleCertificate(const OicSecKey_t *certificateChai
OicSecRole_t **roles, size_t *rolesLength,
struct tm *notValidAfter)
{
bool freeData = false;
uint8_t *data = certificateChain->data;
size_t dataLength = certificateChain->len;
VERIFY_NOT_NULL_RETURN(TAG, certificateChain, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NOT_NULL_RETURN(TAG, trustedCaCerts, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NOT_NULL_RETURN(TAG, roles, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NOT_NULL_RETURN(TAG, rolesLength, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NOT_NULL_RETURN(TAG, notValidAfter, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NOT_NULL_RETURN(TAG, certificateChain, ERROR, OC_STACK_INVALID_PARAM);
bool freeData = false;
uint8_t *data = certificateChain->data;
size_t dataLength = certificateChain->len;
int count;
int errNum;
OCStackResult res = OC_STACK_ERROR;
int mbedRet;
uint32_t flags = 0;
......@@ -467,10 +469,10 @@ OCStackResult OCInternalVerifyRoleCertificate(const OicSecKey_t *certificateChai
OIC_LOG(DEBUG, TAG, "OCInternalVerifyRoleCertificate IN");
if ((dataLength > 0) && (data[dataLength - 1] != 0))
if ((dataLength > 0) && (data[dataLength - 1] != '\0'))
{
/* mbedtls_x509_crt_parse requires null terminator */
data = OICMalloc(dataLength + 1);
data = (uint8_t*)OICMalloc(dataLength + 1);
if (data == NULL)
{
......@@ -504,17 +506,14 @@ OCStackResult OCInternalVerifyRoleCertificate(const OicSecKey_t *certificateChai
goto exit;
}
int errNum;
int count = ParseChain(&trustedCas, trustedCaCerts, &errNum);
if (0 >= count)
{
OIC_LOG(WARNING, TAG, "Could not parse trusted CA certs");
res = OC_STACK_ERROR;
goto exit;
}
count = ParseChain(&trustedCas, trustedCaCerts, &errNum);
if (0 != errNum)
{
OIC_LOG_V(WARNING, TAG, "Trusted CA certs parsing error: %d certs failed to parse", errNum);
}
if (0 >= count)
{
OIC_LOG(ERROR, TAG, "Could not parse trusted CA certs");
res = OC_STACK_ERROR;
goto exit;
}
......@@ -531,6 +530,8 @@ OCStackResult OCInternalVerifyRoleCertificate(const OicSecKey_t *certificateChai
if (0 > mbedRet)
{
OIC_LOG_V(ERROR, TAG, "Failed to verify certificate: ret = %d, flags = %u", mbedRet, flags);
LOG_MBEDTLS_ERROR(mbedRet);
LOG_MBEDTLS_VERIFY_ERROR(flags);
res = OC_STACK_INVALID_PARAM;
goto exit;
}
......
......@@ -274,6 +274,8 @@ static bool IsEmptyCred(const OicSecCred_t* cred)
{
OicUuid_t emptyUuid = OC_ZERO_UUID;
VERIFY_NOT_NULL(TAG, cred, ERROR);
VERIFY_SUCCESS(TAG, (0 == memcmp(cred->subject.id, emptyUuid.id, sizeof(emptyUuid))), DEBUG);
VERIFY_SUCCESS(TAG, !IsNonEmptyRole(&cred->roleId), DEBUG);
VERIFY_SUCCESS(TAG, (0 == cred->credId), DEBUG);
......@@ -1683,6 +1685,7 @@ bool IsSameSecOpt(const OicSecOpt_t* sk1, const OicSecOpt_t* sk2)
VERIFY_SUCCESS(TAG, (sk1->len == sk2->len), INFO);
VERIFY_SUCCESS(TAG, (sk1->encoding == sk2->encoding), INFO);
VERIFY_SUCCESS(TAG, (0 == memcmp(sk1->data, sk2->data, sk1->len)), INFO);
VERIFY_SUCCESS(TAG, (sk1->revstat == sk2->revstat), INFO);
return true;
exit:
return false;
......@@ -1827,8 +1830,9 @@ OCStackResult AddCredential(OicSecCred_t * newCred)
mbedtls_x509_crt_free(&crt);
}
#endif
OIC_LOG(DEBUG, TAG, "Adding New Cred");
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
OIC_LOG_V(DEBUG, TAG, "%s: adding cred: %d %s", __func__, newCred->credId, newCred->credUsage);
#endif /* __WITH_DTLS__ or __WITH_TLS__*/
LL_APPEND(gCred, newCred);
saveToDB:
......@@ -3329,7 +3333,6 @@ bool IsCredRowneruuidTheNilUuid()
{
return IsNilUuid(&gRownerId);
}
#if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
/* Caller must call OICFree on *der when finished. */
static int ConvertPemCertToDer(const char *pem, size_t pemLen, uint8_t** der, size_t* derLen)
......@@ -3348,7 +3351,8 @@ static int ConvertPemCertToDer(const char *pem, size_t pemLen, uint8_t** der, si
ret = mbedtls_pem_read_buffer(&ctx, pemHeader, pemFooter, (const uint8_t*) pem, NULL, 0, &usedLen);
if (ret != 0)
{
OIC_LOG_V(ERROR, TAG, "%s: failed reading PEM cert", __func__);
LOG_MBEDTLS_ERROR(ret);
OIC_LOG_V(ERROR, TAG, "%s: failed reading PEM cert: %d", __func__, ret);
goto exit;
}
......@@ -3818,6 +3822,10 @@ void GetCaCert(ByteArrayLL_t * chain, const char * usage)
LL_FOREACH(gCred, temp)
{
#ifndef NDEBUG
OIC_LOG_V(DEBUG, TAG, "%s: cred: %d %s", __func__, temp->credId, temp->credUsage);
LogCert ( temp->publicData.data, temp->publicData.len, temp->publicData.encoding, TAG_LOG );
#endif
if ((SIGNED_ASYMMETRIC_KEY == temp->credType) &&
(temp->credUsage != NULL) &&
(0 == strcmp(temp->credUsage, usage)) && (false == temp->optionalData.revstat))
......@@ -3836,6 +3844,15 @@ void GetCaCert(ByteArrayLL_t * chain, const char * usage)
OIC_LOG_V(ERROR, TAG, "%s: Failed to parse certificate chain", __func__);
}
}
else
{
OIC_LOG_V(DEBUG, TAG, "%s: cred: %d does not match by: %s",
__func__, temp->credId,
SIGNED_ASYMMETRIC_KEY != temp->credType ? "not asym key" :
temp->credUsage == NULL ? "null cred usage" :
0 != strcmp(temp->credUsage, usage) ? "invalid cred usage" :
"revstat is not false");
}
}
if(NULL == chain->cert)
{
......@@ -3910,6 +3927,7 @@ OCStackResult GetAllRoleCerts(RoleCertChain_t ** output)
}
LL_APPEND(*output, add);
add->credId = temp->credId;
OIC_LOG_V(DEBUG, TAG, "%s: add: %d", __func__, add->credId);
if (cloneSecKey(&add->certificate, &temp->publicData) != 0)
{
OIC_LOG_V(ERROR, TAG, "%s failed to copy certificate data", __func__);
......
......@@ -79,7 +79,7 @@ void DeleteCrl(OicSecCrl_t *crl)
static bool copyByteArray(const uint8_t *in, size_t in_len, uint8_t **out, size_t *out_len)
{
OICFree(*out);
uint8_t *tmp = OICMalloc(in_len);
uint8_t *tmp = (uint8_t *)OICMalloc(in_len);
if (!tmp)
{
return false;
......@@ -128,13 +128,14 @@ static CborError setCrlData(CborEncoder *out, const char *name, const OicSecKey_
CborError result = CborErrorInternalError;
size_t encodeBufferSize = 0;
size_t len = 0;
unsigned char *encodeBuffer = NULL;
int b64result = mbedtls_base64_encode(NULL, 0, &len, value->data, value->len);
VERIFY_SUCCESS(TAG, (MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL == b64result), ERROR);
size_t encodeBufferSize = len;
encodeBuffer = OICCalloc(1, encodeBufferSize);
encodeBufferSize = len;
encodeBuffer = (unsigned char *)OICCalloc(1, encodeBufferSize);
VERIFY_NOT_NULL(TAG, encodeBuffer, ERROR);
b64result = mbedtls_base64_encode(encodeBuffer, encodeBufferSize, &len, value->data, value->len);
......@@ -161,7 +162,7 @@ static CborError getCrlData(CborValue *in, const char *name, OicSecKey_t *value)
}
CborError result = CborNoError;
CborValue crlNode = { .parser = NULL };
CborValue crlNode = OC_DEFAULT_CBOR_VALUE;
unsigned char *decodeBuffer = NULL;
size_t decodeBufferSize;
......@@ -180,7 +181,7 @@ static CborError getCrlData(CborValue *in, const char *name, OicSecKey_t *value)
return CborErrorInternalError;
}
value->len = outLen;
value->data = OICCalloc(1, value->len);
value->data = (uint8_t*)OICCalloc(1, value->len);
VERIFY_NOT_NULL(TAG, value->data, ERROR);
decodeResult = mbedtls_base64_decode(value->data, value->len, &outLen, decodeBuffer, decodeBufferSize);
......@@ -338,12 +339,12 @@ OCStackResult CBORPayloadToCrl(const uint8_t *cborPayload, const size_t size,
OCStackResult ret = OC_STACK_ERROR;
OicSecCrl_t *crl = NULL;
CborValue crlCbor = {.parser = NULL};
CborParser parser = {.end = NULL};
CborValue crlCbor = OC_DEFAULT_CBOR_VALUE;
CborParser parser = OC_DEFAULT_CBOR_PARSER;
CborError cborFindResult = CborNoError;
cbor_parser_init(cborPayload, size, 0, &parser, &crlCbor);
CborValue crlMap = { .parser = NULL};
CborValue crlMap = OC_DEFAULT_CBOR_VALUE;
cborFindResult = cbor_value_enter_container(&crlCbor, &crlMap);
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed to enter Crl map");
......@@ -465,7 +466,7 @@ static bool ValidateQuery(const char * query)
bool bInterfaceQry = false; // does querystring contains 'if' query ?
bool bInterfaceMatch = false; // does 'if' query matches with oic.if.baseline ?
OicParseQueryIter_t parseIter = {.attrPos = NULL};
OicParseQueryIter_t parseIter = OC_DEFAULT_OICPARSEQUWRYITER;
ParseQueryIterInit((unsigned char*)query, &parseIter);
......@@ -821,7 +822,7 @@ void GetDerCrl(ByteArray_t* out)
}
size_t decodeBufferSize = len;
unsigned char *decodeBuffer = OICCalloc(1, decodeBufferSize);
unsigned char *decodeBuffer = (unsigned char*)OICCalloc(1, decodeBufferSize);
if (!decodeBuffer)
{
OIC_LOG(ERROR, TAG, "Can't allocate memory for base64 str");
......@@ -844,7 +845,7 @@ void GetDerCrl(ByteArray_t* out)
out->len = 0;
uint8_t *tmp = OICRealloc(out->data, crl->len);
uint8_t *tmp = (uint8_t*)OICRealloc(out->data, crl->len);
if (tmp)
{
out->data = tmp;
......
......@@ -357,13 +357,17 @@ static bool EnterRFPRO(void)
static bool EnterRESET(void)
{
bool ret = false;
OicSecDpm_t dpmZero = 0;
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
// Enable Anon DH cipher suite if appropriate
bool isAnonEnabled = false;
#endif // __WITH_DTLS__ or __WITH_TLS__
// Restore Mfr Defaults
// "Mfr Defaults" is defined by manufacturer. It could be "failsafe"
// SVRs (e.g. the hard-coded SVRs in IoTivity) or it could be a backup
// copy of the initally-provisioned SVRs (e.g. the ResetSecureResourceInPS
// function in IoTivity).
// TODO [IOT-2633]:
// TODO [IOT-2633]:
VERIFY_SUCCESS(TAG, OC_STACK_OK == ResetSecureResources(), ERROR);
// Set doxm.deviceuuid = Mfr Default (handled above)
......@@ -386,7 +390,6 @@ static bool EnterRESET(void)
VERIFY_SUCCESS(TAG, OC_STACK_OK == SetPstatRownerId(&THE_NIL_UUID), ERROR);
// clear all bits in cm and tm before setting the 2 lsbs
OicSecDpm_t dpmZero = 0;
VERIFY_SUCCESS(TAG, OC_STACK_OK == SetPstatCm(dpmZero), ERROR);
VERIFY_SUCCESS(TAG, OC_STACK_OK == SetPstatTm(dpmZero), ERROR);
......@@ -399,8 +402,6 @@ static bool EnterRESET(void)
ERROR);
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
// Enable Anon DH cipher suite if appropriate
bool isAnonEnabled = false;
VERIFY_SUCCESS(TAG,
OC_STACK_OK == EnableAnonCipherSuiteIfUnOwnedAndJustWorksSelected(&isAnonEnabled),
ERROR);
......
......@@ -846,7 +846,7 @@ static bool ValidateQuery(const char * query)
bool bMotMatch = false; // does 'mom' query value is not '0' && does query value matches with doxm.owned status?
#endif //MULTIPLE_OWNER
OicParseQueryIter_t parseIter = {.attrPos = NULL};
OicParseQueryIter_t parseIter = OC_DEFAULT_OICPARSEQUWRYITER;