env.AppendUnique(LIBPATH = [src_dir + '/resource/csdk/connectivity/lib/android'])
env.AppendUnique(LIBS = ['log', 'coap'])
+# Build mbedtls as ocstack uses hash functions from mbedcrypto.lib.
+env.SConscript('#extlibs/mbedtls/SConscript')
+
if env.get('SECURED') == '1':
- env.SConscript('#extlibs/mbedtls/SConscript')
env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
-
+else:
+ env.AppendUnique(LIBS = ['mbedcrypto'])
+
# From android-5 (API > 20), all application must be built with flags '-fPIE' '-pie'.
# Due to the limitation of Scons, it's required to added it into the command line
# directly (otherwise, it will also be added when build share library)
os.path.join(Dir('.').abspath, 'oic_time', 'include'),
os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
- os.path.join(Dir('.').abspath, 'octhread', 'include')
+ os.path.join(Dir('.').abspath, 'octhread', 'include'),
+ os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
+ '#/extlibs/mbedtls/mbedtls/include'
])
if target_os not in ['tizen']:
'oic_string/src/oic_string.c',
'oic_malloc/src/oic_malloc.c',
'oic_time/src/oic_time.c',
- 'ocrandom/src/ocrandom.c'
+ 'ocrandom/src/ocrandom.c',
+ 'oic_platform/src/oic_platform.c'
]
if env['POSIX_SUPPORTED']:
--- /dev/null
+/* *****************************************************************
+ *
+ * Copyright 2017 Microsoft
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef OIC_OICPLATFORM_H_
+#define OIC_OICPLATFORM_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+#define OIC_UUID_LENGTH 16
+
+/**
+ * Function returns a UUID that can be used for platform ID.
+ *
+ * @param[in] platformUuid The generated UUID.
+ *
+ * @return true if successful.
+ */
+bool OICGetPlatformUuid(uint8_t platformUuid[OIC_UUID_LENGTH]);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+#endif
--- /dev/null
+/* *****************************************************************
+ *
+ * Copyright 2017 Microsoft
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+#include "iotivity_config.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <mbedtls/md.h>
+#include "logger.h"
+#include "iotivity_debug.h"
+#include "oic_platform.h"
+#include "ocrandom.h"
+#include "oic_string.h"
+
+#define TAG "OIC_PLATFORM"
+
+#if defined(__unix__) || defined(_WIN32)
+// Create a UUID for using the "Name-Based UUID" mechanism specified in
+// RFC 4122 section 4.3 (see http://tools.ietf.org/html/rfc4122#section-4.3).
+bool HashStrToUuid(const char* str, size_t len, uint8_t platformUuid[OIC_UUID_LENGTH])
+{
+ if ((str == NULL) || (len == 0))
+ {
+ return false;
+ }
+
+ unsigned char hash[MBEDTLS_MD_MAX_SIZE];
+ int mbedret = mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
+ (const unsigned char*)str,
+ len,
+ hash);
+ if (mbedret != 0)
+ {
+ OIC_LOG_V(WARNING, TAG, "Failed mbedtls_md(), error: %d.", mbedret);
+ return false;
+ }
+
+ // Set octets zero through 3 of the time_low field to octets zero through 3 of the hash.
+ // Set octets zero and one of the time_mid field to octets 4 and 5 of the hash.
+ // Set octets zero and one of the time_hi_and_version field to octets 6 and 7 of the hash.
+ // Set the clock_seq_hi_and_reserved field to octet 8 of the hash.
+ // Set the clock_seq_low field to octet 9 of the hash.
+ // Set octets zero through five of the node field to octets 10 through 15 of the hash.
+ memcpy(platformUuid, hash, OIC_UUID_LENGTH);
+
+ // Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field
+ // to the appropriate 4-bit version number from Section 4.1.3.
+ platformUuid[6] &= 0x0F; // Set high bits to 0000.
+ platformUuid[6] |= 0x50; // Set high bits to 0101 to indicate a name-based GUID with SHA-1.
+
+ // Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero
+ // and one, respectively.
+ platformUuid[8] &= 0x3F; // Set the two highest bits to 00.
+ platformUuid[8] |= 0x40; // Set the two highest bits to 01.
+
+ return true;
+}
+#endif
+
+// Buffer size for computer name.
+#define MAX_COMPUTER_NAME_LENGTH 256
+
+// This functions returns UUID generated from host name.
+bool OICGetPlatformUuid(uint8_t platformUuid[OIC_UUID_LENGTH])
+{
+#if defined(__unix__) || defined(_WIN32)
+ // Get host name.
+ char hostname[MAX_COMPUTER_NAME_LENGTH] = { 0 };
+ if (gethostname(hostname, MAX_COMPUTER_NAME_LENGTH) != 0)
+ {
+ OIC_LOG_V(WARNING, TAG, "Failed gethostname() errno: %s", strerror(errno));
+ return false;
+ }
+
+ // Get FDQN of the computer.
+ char fqdnComputerName[MAX_COMPUTER_NAME_LENGTH] = { 0 };
+ struct addrinfo* addrInfo;
+ struct addrinfo hints = { .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM,
+ .ai_flags = AI_CANONNAME };
+ if (getaddrinfo(hostname, NULL, &hints, &addrInfo) == 0)
+ {
+ for(struct addrinfo* iter = addrInfo; iter != NULL; iter = iter->ai_next)
+ {
+ if (iter->ai_canonname != NULL)
+ {
+ OICStrcpy(fqdnComputerName, MAX_COMPUTER_NAME_LENGTH, iter->ai_canonname);
+ break;
+ }
+ }
+
+ if (NULL != addrInfo)
+ {
+ freeaddrinfo(addrInfo);
+ addrInfo = NULL;
+ }
+ }
+ else
+ {
+ OIC_LOG_V(WARNING, TAG, "Failed getaddrinfo() errno: %s, use hostname.", strerror(errno));
+
+ // Use hostname as getaddrinfo() failed.
+ OICStrcpy(fqdnComputerName, MAX_COMPUTER_NAME_LENGTH, hostname);
+ }
+
+ if (!HashStrToUuid(fqdnComputerName, strlen(fqdnComputerName), platformUuid))
+ {
+ OIC_LOG_V(WARNING, TAG, "Failed HashStrToUuid()");
+ return false;
+ }
+
+ return true;
+#else
+ OIC_LOG_V(WARNING, TAG, "Unsupported platform.");
+ return false;
+#endif
+}
connectivity_env.AppendUnique(CA_SRC = [os.path.join(ca_path,
'adapter_util/cafragmentation.c')])
+# Build mbedtls as ocstack uses hash functions from mbedcrypto.lib.
+tls_path = 'extlibs/mbedtls';
+tls_headers_path = 'mbedtls/include';
+if ca_os == 'tizen' and os.path.exists(root_dir + '/' + tls_path):
+ connectivity_env.SConscript(os.path.join(root_dir, tls_path + '/SConscript'))
+ connectivity_env.AppendUnique(CPPPATH = [os.path.join(root_dir, tls_path + '/' + tls_headers_path)])
+else:
+ if ca_os != 'android':
+ connectivity_env.SConscript('#' + tls_path + '/SConscript')
+ connectivity_env.AppendUnique(CPPPATH = ['#' + tls_path + '/' + tls_headers_path])
+
if connectivity_env.get('SECURED') == '1':
connectivity_env.AppendUnique(CPPPATH = ['#extlibs/timer'])
connectivity_env.AppendUnique(CPPPATH = [src_dir + '/resource/csdk/security/include'])
connectivity_env.AppendUnique(CPPPATH = [os.path.join(root_dir, 'external/inc')])
- tls_path = 'extlibs/mbedtls';
- tls_headers_path = 'mbedtls/include';
- if ca_os == 'tizen' and os.path.exists(root_dir + '/' + tls_path):
- connectivity_env.SConscript(os.path.join(root_dir, tls_path + '/SConscript'))
- connectivity_env.AppendUnique(CPPPATH = [os.path.join(root_dir, tls_path + '/' + tls_headers_path)])
- else:
- if ca_os != 'android':
- connectivity_env.SConscript('#' + tls_path + '/SConscript')
- connectivity_env.AppendUnique(CPPPATH = ['#' + tls_path + '/' + tls_headers_path])
+ if ca_os != 'tizen' or os.path.exists(root_dir + '/' + tls_path) == False:
connectivity_env.AppendUnique(CA_SRC = [os.path.join(ca_path, 'adapter_util/ca_adapter_net_ssl.c')])
ca_common_src = None
liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
if env.get('SECURED') == '1':
- liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
+ liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509'])
if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
if env.get('LOGGING'):
liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-liboctbstack_env.Append(LIBS = ['c_common'])
+liboctbstack_env.Append(LIBS = ['c_common', 'mbedcrypto'])
if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
liboctbstack_env.Prepend(LIBS = ['routingmanager'])
OCStackResult OCGetPropertyValue(OCPayloadType type, const char *propName, void **value);
/**
-* Get the registered persistent storage handler. All modules must use this to obtain access to
+* Get the registered persistent storage handler. All modules must use this to obtain access to
* persistent storage.
*
* @return pointer to OCPersistentStorage structure on success and NULL otherwise.
#include "ocendpoint.h"
#include "ocatomic.h"
#include "platform_features.h"
+#include "oic_platform.h"
#if defined(TCP_ADAPTER) && defined(WITH_CLOUD)
#include "occonnectionmanager.h"
result = InitializeDeviceProperties();
}
+ // Initialize platform ID of OC_RSRVD_RESOURCE_TYPE_PLATFORM.
+ // Multiple devices or applications running on the same IoTivity platform should have the same
+ // platform ID.
+ if (OC_STACK_OK == result)
+ {
+ uint8_t platformID[OIC_UUID_LENGTH];
+ char uuidString[UUID_STRING_SIZE];
+
+ if (!OICGetPlatformUuid(platformID))
+ {
+ OIC_LOG(WARNING, TAG, "Failed OICGetPlatformUuid(), generate random uuid.");
+ OCGenerateUuid(platformID);
+ }
+
+ if (OCConvertUuidToString(platformID, uuidString))
+ {
+ // Set the platform ID.
+ // Application can overwrite the value set here by calling similar
+ // OCSetPropertyValue(OC_RSRVD_PLATFORM_ID, ...).
+ result = OCSetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_PLATFORM_ID, uuidString);
+ }
+ else
+ {
+ result = OC_STACK_ERROR;
+ OIC_LOG(ERROR, TAG, "Failed OCConvertUuidToString() for platform ID.");
+ }
+ }
+
return result;
}
stacktest_env.PrependUnique(LIBS = ['octbstack_test',
'ocsrm',
'connectivity_abstraction',
- 'coap'])
+ 'coap',
+ 'mbedcrypto'])
if target_os != 'darwin':
stacktest_env.PrependUnique(LIBS = ['oc_logger'])
if stacktest_env.get('SECURED') == '1':
- stacktest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])
+ stacktest_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509'])
if stacktest_env.get('LOGGING'):
stacktest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
'oc_logger',
'connectivity_abstraction',
'coap',
- 'timer'])
+ 'timer',
+ 'mbedcrypto'])
if unittests_env.get('SECURED') == '1':
- unittests_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509','mbedcrypto'])
+ unittests_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509'])
if unittests_env.get('LOGGING'):
unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])