Commit d026fc6e authored by js126.lee's avatar js126.lee Committed by Randeep

Add OCConvertStringToUuid on C_common

Patch 1,2: Expose ConvertStrToUUID on OC stack to use common
Ptach 3: Add OCConvertStringToUuid on C_common

Change-Id: Icf9b0ee1bda6fa4d914c696fbbdc27e0998a7262
Signed-off-by: default avatarjs126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14605Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarChul Lee <chuls.lee@samsung.com>
Reviewed-by: default avatarJoonghwan Lee <jh05.lee@samsung.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent 647b5383
...@@ -124,6 +124,19 @@ OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]); ...@@ -124,6 +124,19 @@ OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]);
OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE], OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE],
char uuidString[UUID_STRING_SIZE]); char uuidString[UUID_STRING_SIZE]);
/**
* Convert a C style string to a UUID based on RFC 4122
*
* @param[in] uuidString
* a 37 byte length string to fill with the string
* representation of the passed UUID.
* @param[out] uuid
* The 16 byte array filled with UUID data
* @retval RAND_UUID_OK for success, otherwise an error value
*/
OCRandomUuidResult OCConvertStringToUuid(const char uuidString[UUID_STRING_SIZE],
uint8_t uuid[UUID_SIZE]);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#elif defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
...@@ -375,3 +380,39 @@ OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE], ...@@ -375,3 +380,39 @@ OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE],
return RAND_UUID_OK; return RAND_UUID_OK;
} }
OCRandomUuidResult OCConvertStringToUuid(const char uuidString[UUID_STRING_SIZE],
uint8_t uuid[UUID_SIZE])
{
if(NULL == uuidString || NULL == uuid)
{
return RAND_UUID_INVALID_PARAM;
}
size_t urnIdx = 0;
size_t uuidIdx = 0;
size_t strUuidLen = 0;
char convertedUuid[UUID_SIZE * 2] = {0};
strUuidLen = strlen(uuidString);
if((UUID_STRING_SIZE - 1) == strUuidLen)
{
for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_SIZE ; uuidIdx++, urnIdx+=2)
{
if(*(uuidString + urnIdx) == '-')
{
urnIdx++;
}
sscanf(uuidString + urnIdx, "%2hhx", &convertedUuid[uuidIdx]);
}
}
else
{
return RAND_UUID_CONVERT_ERROR;
}
memcpy(uuid, convertedUuid, UUID_SIZE);
return RAND_UUID_OK;
}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "cacommon.h" #include "cacommon.h"
#include "caipinterface.h" #include "caipinterface.h"
#include "oic_malloc.h" #include "oic_malloc.h"
#include "ocrandom.h"
#include "byte_array.h" #include "byte_array.h"
#include "camutex.h" #include "camutex.h"
#include "timer.h" #include "timer.h"
...@@ -1634,55 +1635,6 @@ void CAsetSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback) ...@@ -1634,55 +1635,6 @@ void CAsetSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback)
g_sslCallback = tlsHandshakeCallback; g_sslCallback = tlsHandshakeCallback;
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
} }
// TODO move ConvertStrToUuid function to common module
/*
* Converts string UUID to CARemoteId_t
*
* @param strUuid Device UUID in string format
* @param uuid converted UUID in CARemoteId_t format
*
* @return 0 for success.
* */
static int ConvertStrToUuid(const char* strUuid, CARemoteId_t* uuid)
{
if(NULL == strUuid || NULL == uuid)
{
OIC_LOG(ERROR, NET_SSL_TAG, "ConvertStrToUuid : Invalid param");
return -1;
}
size_t urnIdx = 0;
size_t uuidIdx = 0;
size_t strUuidLen = 0;
char convertedUuid[UUID_LENGTH * 2] = {0};
strUuidLen = strlen(strUuid);
if(0 == strUuidLen)
{
OIC_LOG(INFO, NET_SSL_TAG, "The empty string detected, The UUID will be converted to "\
"\"00000000-0000-0000-0000-000000000000\"");
}
else if(UUID_LENGTH * 2 + 4 == strUuidLen)
{
for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_LENGTH ; uuidIdx++, urnIdx+=2)
{
if(*(strUuid + urnIdx) == '-')
{
urnIdx++;
}
sscanf(strUuid + urnIdx, "%2hhx", &convertedUuid[uuidIdx]);
}
}
else
{
OIC_LOG(ERROR, NET_SSL_TAG, "Invalid string uuid format");
return -1;
}
memcpy(uuid->id, convertedUuid, UUID_LENGTH);
uuid->id_length = UUID_LENGTH;
return 0;
}
/* Read data from TLS connection /* Read data from TLS connection
*/ */
...@@ -1790,7 +1742,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d ...@@ -1790,7 +1742,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
if (NULL != uuidPos) if (NULL != uuidPos)
{ {
memcpy(uuid, (char*) uuidPos + sizeof(UUID_PREFIX) - 1, UUID_LENGTH * 2 + 4); memcpy(uuid, (char*) uuidPos + sizeof(UUID_PREFIX) - 1, UUID_LENGTH * 2 + 4);
ret = ConvertStrToUuid(uuid, &peer->sep.identity); ret = OCConvertStringToUuid(uuid, peer->sep.identity.id);
SSL_CHECK_FAIL(peer, ret, "Failed to convert subject", 1, SSL_CHECK_FAIL(peer, ret, "Failed to convert subject", 1,
CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT); CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
} }
...@@ -1804,7 +1756,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d ...@@ -1804,7 +1756,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d
if (NULL != userIdPos) if (NULL != userIdPos)
{ {
memcpy(uuid, (char*) userIdPos + sizeof(USERID_PREFIX) - 1, UUID_LENGTH * 2 + 4); memcpy(uuid, (char*) userIdPos + sizeof(USERID_PREFIX) - 1, UUID_LENGTH * 2 + 4);
ret = ConvertStrToUuid(uuid, &peer->sep.userId); ret = OCConvertStringToUuid(uuid, peer->sep.userId.id);
SSL_CHECK_FAIL(peer, ret, "Failed to convert subject alt name", 1, SSL_CHECK_FAIL(peer, ret, "Failed to convert subject alt name", 1,
CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT); CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment