OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_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
}
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#elif defined(HAVE_STRINGS_H)
+#include <strings.h>
+#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
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;
+}
+
#include "cacommon.h"
#include "caipinterface.h"
#include "oic_malloc.h"
+#include "ocrandom.h"
#include "byte_array.h"
#include "octhread.h"
#include "timer.h"
g_sslCallback = tlsHandshakeCallback;
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
*/
if (NULL != uuidPos)
{
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,
CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
}
if (NULL != userIdPos)
{
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,
CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT);
}