diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d000fc..9db1f75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,14 +18,15 @@ option (WITH_LIBCOAP "Enable libcoap CoAP support)" ON) option (WITH_ERBIUM "Enable Erbium CoAP support)" OFF) option (WITH_GNUTLS "Enable GnuTLS DTLS support" OFF) option (WITH_CYASSL "Enable CyaSSL DTLS support" OFF) +option (WITH_TINYDTLS "Enable TinyDTLS DTLS support" OFF) if (WITH_ERBIUM) message (WARNING "Disabling libcoap support") set (WITH_LIBCOAP OFF) endif () -if (WITH_GNUTLS AND WITH_CYASSL) - message (FATAL_ERROR "WITH_GNUTLS and WITH_CYASSL are mutually exclusive and cannot be specified together." ) +if (WITH_GNUTLS AND (WITH_CYASSL OR WITH_TINYDTLS)) + message (FATAL_ERROR "WITH_GNUTLS, WITH_CYASSL and WITH_TINYDTLS are mutually exclusive and cannot be specified together." ) endif () diff --git a/core/src/bootstrap/lwm2m_bootstrap_psk.h b/core/src/bootstrap/lwm2m_bootstrap_psk.h new file mode 100644 index 0000000..7564fdf --- /dev/null +++ b/core/src/bootstrap/lwm2m_bootstrap_psk.h @@ -0,0 +1,43 @@ +/************************************************************************************************************************ + Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +************************************************************************************************************************/ + + +#ifndef LWM2M_BOOTSTRAP_PSK_H_ +#define LWM2M_BOOTSTRAP_PSK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +const char * pskIdentity = "oFIrQFrW8EWcZ5u7eGfrkw"; + +const uint8_t pskKey[] = { + 0x7C, 0xCD, 0xE1, 0x4A, 0x5C, 0xF3, 0xB7, 0x1C, 0x0C, 0x08, 0xC8, 0xB7, 0xF9, 0xE5 +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* LWM2M_BOOTSTRAP_PSK_H_ */ diff --git a/core/src/bootstrap/lwm2m_bootstrap_server.c b/core/src/bootstrap/lwm2m_bootstrap_server.c index 3b7fb55..98eb0b4 100644 --- a/core/src/bootstrap/lwm2m_bootstrap_server.c +++ b/core/src/bootstrap/lwm2m_bootstrap_server.c @@ -46,6 +46,7 @@ #include "lwm2m_object_defs.h" #include "bootstrap/lwm2m_bootstrap.h" #include "bootstrap/lwm2m_bootstrap_cert.h" +#include "bootstrap/lwm2m_bootstrap_psk.h" #define DEFAULT_IP_ADDRESS "0.0.0.0" @@ -201,6 +202,7 @@ static int Bootstrap_Start(Options * options) if (options->Secure) { coap_SetCertificate(bootsrapCert, sizeof(bootsrapCert), CertificateFormat_PEM); + coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); } Lwm2mContextType * context = Lwm2mCore_Init(coap); diff --git a/core/src/client/lwm2m_client.c b/core/src/client/lwm2m_client.c index 10a129b..b73a24c 100644 --- a/core/src/client/lwm2m_client.c +++ b/core/src/client/lwm2m_client.c @@ -55,6 +55,7 @@ #include "lwm2m_xml_interface.h" #include "lwm2m_object_defs.h" #include "lwm2m_client_cert.h" +#include "lwm2m_client_psk.h" #define DEFAULT_COAP_PORT (6000) @@ -202,6 +203,7 @@ static int Lwm2mClient_Start(Options * options) } coap_SetCertificate(clientCert, sizeof(clientCert), CertificateFormat_PEM); + coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); // if required read the bootstrap information from a file const BootstrapInfo * factoryBootstrapInfo; diff --git a/core/src/client/lwm2m_client_psk.h b/core/src/client/lwm2m_client_psk.h new file mode 100644 index 0000000..368f31f --- /dev/null +++ b/core/src/client/lwm2m_client_psk.h @@ -0,0 +1,43 @@ +/************************************************************************************************************************ + Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +************************************************************************************************************************/ + + +#ifndef LWM2M_CLIENT_PSK_H_ +#define LWM2M_CLIENT_PSK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +const char * pskIdentity = "oFIrQFrW8EWcZ5u7eGfrkw"; + +const uint8_t pskKey[] = { + 0x7C, 0xCD, 0xE1, 0x4A, 0x5C, 0xF3, 0xB7, 0x1C, 0x0C, 0x08, 0xC8, 0xB7, 0xF9, 0xE5 +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* LWM2M_CLIENT_PSK_H_ */ diff --git a/core/src/common/CMakeLists.txt b/core/src/common/CMakeLists.txt index a211546..7464522 100644 --- a/core/src/common/CMakeLists.txt +++ b/core/src/common/CMakeLists.txt @@ -32,7 +32,12 @@ if (WITH_CYASSL) list (APPEND awa_common_SOURCES dtls_abstraction_cyassl.c) endif () -if (NOT WITH_GNUTLS AND NOT WITH_CYASSL) +if (WITH_TINYDTLS) + list (APPEND awa_common_SOURCES dtls_abstraction_tinydtls.c) +endif () + + +if (NOT WITH_GNUTLS AND NOT WITH_CYASSL AND NOT WITH_TINYDTLS) list (APPEND awa_common_SOURCES dtls_abstraction_dummy.c) endif () @@ -52,6 +57,11 @@ if (WITH_ERBIUM) list (APPEND awa_common_INCLUDE_DIRS ${LIBCOAP_INCLUDE_DIR}) endif () +if (WITH_TINYDTLS) + list (APPEND awa_common_INCLUDE_DIRS ${TINYDTLS_INCLUDE_DIR}) +endif () + + set (awa_common_LIBS libxml_static libb64_static @@ -79,6 +89,10 @@ if (WITH_GNUTLS) list (APPEND awa_common_LIBS gnutls) endif () +if (WITH_TINYDTLS) + list (APPEND awa_common_LIBS tinydtls_static) +endif () + if (ENABLE_GCOV) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") diff --git a/core/src/common/coap_abstraction.h b/core/src/common/coap_abstraction.h index fe6bd50..05c19a3 100644 --- a/core/src/common/coap_abstraction.h +++ b/core/src/common/coap_abstraction.h @@ -78,7 +78,7 @@ extern const char * coap_LibraryName; CoapInfo * coap_Init(const char * ipAddress, int port, bool secure, int logLevel); void coap_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat format); -void coap_SetPSK(const char * identity, uint8_t * key, int keyLength); +void coap_SetPSK(const char * identity, const uint8_t * key, int keyLength); int coap_Destroy(void); void coap_Process(void); diff --git a/core/src/common/coap_abstraction_contiki.c b/core/src/common/coap_abstraction_contiki.c index ce21b32..d2403ac 100644 --- a/core/src/common/coap_abstraction_contiki.c +++ b/core/src/common/coap_abstraction_contiki.c @@ -486,7 +486,7 @@ void coap_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat (void)format; } -void coap_SetPSK(const char * identity, uint8_t * key, int keyLength) +void coap_SetPSK(const char * identity, const uint8_t * key, int keyLength) { (void)identity; (void)key; diff --git a/core/src/common/coap_abstraction_erbium.c b/core/src/common/coap_abstraction_erbium.c index c7c8088..a597b7a 100644 --- a/core/src/common/coap_abstraction_erbium.c +++ b/core/src/common/coap_abstraction_erbium.c @@ -116,7 +116,7 @@ void coap_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat NetworkSocket_SetCertificate(networkSocket, cert, certLength, format); } -void coap_SetPSK(const char * identity, uint8_t * key, int keyLength) +void coap_SetPSK(const char * identity, const uint8_t * key, int keyLength) { NetworkSocket_SetPSK(networkSocket, identity, key, keyLength); } diff --git a/core/src/common/coap_abstraction_libcoap.c b/core/src/common/coap_abstraction_libcoap.c index 941b5b8..c24cabb 100644 --- a/core/src/common/coap_abstraction_libcoap.c +++ b/core/src/common/coap_abstraction_libcoap.c @@ -1183,7 +1183,7 @@ void coap_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat (void)format; } -void coap_SetPSK(const char * identity, uint8_t * key, int keyLength) +void coap_SetPSK(const char * identity, const uint8_t * key, int keyLength) { (void)identity; (void)key; diff --git a/core/src/common/dtls_abstraction.h b/core/src/common/dtls_abstraction.h index 89a8b8b..8af9eb6 100644 --- a/core/src/common/dtls_abstraction.h +++ b/core/src/common/dtls_abstraction.h @@ -57,7 +57,7 @@ void DTLS_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat void DTLS_SetNetworkSendCallback(DTLS_NetworkSendCallback sendCallback); -void DTLS_SetPSK(const char * identity, uint8_t * key, int keyLength); +void DTLS_SetPSK(const char * identity, const uint8_t * key, int keyLength); bool DTLS_Decrypt(NetworkAddress * sourceAddress, uint8_t * encrypted, int encryptedLength, uint8_t * decryptBuffer, int decryptBufferLength, int * decryptedLength, void *context); diff --git a/core/src/common/dtls_abstraction_cyassl.c b/core/src/common/dtls_abstraction_cyassl.c index 95809ca..3d02dac 100644 --- a/core/src/common/dtls_abstraction_cyassl.c +++ b/core/src/common/dtls_abstraction_cyassl.c @@ -65,8 +65,8 @@ int certificateLength = 0; CertificateFormat certificateFormat; const char * pskIdentity = NULL; -uint8_t * pskKey; -int pskKeyLength; +const uint8_t * pskKey = NULL; +int pskKeyLength = 0; DTLS_NetworkSendCallback NetworkSend = NULL; @@ -129,7 +129,7 @@ void DTLS_SetNetworkSendCallback(DTLS_NetworkSendCallback sendCallback) NetworkSend = sendCallback; } -void DTLS_SetPSK(const char * identity, uint8_t * key, int keyLength) +void DTLS_SetPSK(const char * identity, const uint8_t * key, int keyLength) { pskIdentity = identity; pskKey = key; diff --git a/core/src/common/dtls_abstraction_dummy.c b/core/src/common/dtls_abstraction_dummy.c index 5cffaf4..688a411 100644 --- a/core/src/common/dtls_abstraction_dummy.c +++ b/core/src/common/dtls_abstraction_dummy.c @@ -44,7 +44,7 @@ void DTLS_SetNetworkSendCallback(DTLS_NetworkSendCallback sendCallback) { } -void DTLS_SetPSK(const char * identity, uint8_t * key, int keyLength) +void DTLS_SetPSK(const char * identity, const uint8_t * key, int keyLength) { } diff --git a/core/src/common/dtls_abstraction_gnutls.c b/core/src/common/dtls_abstraction_gnutls.c index 0c88687..b74375e 100644 --- a/core/src/common/dtls_abstraction_gnutls.c +++ b/core/src/common/dtls_abstraction_gnutls.c @@ -132,10 +132,10 @@ void DTLS_SetNetworkSendCallback(DTLS_NetworkSendCallback sendCallback) NetworkSend = sendCallback; } -void DTLS_SetPSK(const char * identity, uint8_t * key, int keyLength) +void DTLS_SetPSK(const char * identity, const uint8_t * key, int keyLength) { pskIdentity = identity; - pskKey.data = key; + pskKey.data = (unsigned char *)key; pskKey.size = keyLength; } diff --git a/core/src/common/dtls_abstraction_tinydtls.c b/core/src/common/dtls_abstraction_tinydtls.c new file mode 100644 index 0000000..645ca9f --- /dev/null +++ b/core/src/common/dtls_abstraction_tinydtls.c @@ -0,0 +1,443 @@ +/************************************************************************************************************************ + Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +************************************************************************************************************************/ + +#include +#include + +#include "lwm2m_debug.h" +#include "dtls_abstraction.h" + +#ifndef DTLSv12 +#define DTLSv12 +#endif + +// TinyDTLS does not support full Certificate 8-( +//#ifndef DTLS_ECC +//#define DTLS_ECC +//#endif + +#ifndef DTLS_PSK +#define DTLS_PSK +#endif + +#include + +#define TINY_DTLS_SUCCESS (0) + +typedef enum +{ + CredentialType_NotSet, + CredentialType_ClientPSK, + CredentialType_ServerPSK +}CredentialType; + + +typedef struct +{ + NetworkAddress * NetworkAddress; + session_t Session; + dtls_context_t * Context; + dtls_handler_t Callbacks; + + void * Credentials; + uint8_t CredentialType; + bool SessionEstablished; + void * UserContext; + uint8_t * Buffer; + int BufferLength; +}DTLS_Session; + +#ifndef MAX_DTLS_SESSIONS + #define MAX_DTLS_SESSIONS 3 +#endif + +const char * DTLS_LibraryName = "TinyDTLS"; + +static DTLS_Session sessions[MAX_DTLS_SESSIONS]; + +static uint8_t * certificate = NULL; +static int certificateLength = 0; +static CertificateFormat certificateFormat; + +static const char * pskIdentity = NULL; +static const uint8_t * pskKey = NULL; +static int pskKeyLength = 0; + +static DTLS_NetworkSendCallback NetworkSend = NULL; + + +static DTLS_Session * AllocateSession(NetworkAddress * address, bool client, void * context); +static DTLS_Session * GetSession(NetworkAddress * address); +static void SetupNewSession(int index, NetworkAddress * networkAddress, bool client); +static void FreeSession(DTLS_Session * session); +#ifdef DTLS_ECC +static int CertificateVerify(struct dtls_context_t *ctx, const session_t *session, const unsigned char *other_pub_x, const unsigned char *other_pub_y, size_t key_size); +#endif +static int DecryptCallBack(struct dtls_context_t *context, session_t *session, uint8 *recieveBuffer, size_t receiveBufferLegth); +static int EncryptCallBack(struct dtls_context_t *context, session_t *session, uint8 * sendBuffer, size_t sendBufferLength); +static int EventCallBack(struct dtls_context_t *context, session_t *session, dtls_alert_level_t level, unsigned short code); +static int PSKCallBack(struct dtls_context_t *ctx, const session_t *session, dtls_credentials_type_t type, const unsigned char *id, + size_t id_len, unsigned char *result, size_t result_length); +static int SSLSendCallBack(struct dtls_context_t *context, session_t *session, uint8 * sendBuffer, size_t sendBufferLength); + + +void DTLS_Init(void) +{ + memset(sessions,0,sizeof(DTLS_Session) * MAX_DTLS_SESSIONS); + dtls_init(); +} + +void DTLS_Shutdown(void) +{ + int index; + for (index = 0;index < MAX_DTLS_SESSIONS; index++) + { + if (sessions[index].Context) + { + FreeSession(&sessions[index]); + } + } +} + +void DTLS_SetCertificate(const uint8_t * cert, int certLength, CertificateFormat format) +{ + certificate = (uint8_t *)cert; + certificateLength = certLength; + certificateFormat = format; +} + +void DTLS_SetNetworkSendCallback(DTLS_NetworkSendCallback sendCallback) +{ + NetworkSend = sendCallback; +} + +void DTLS_SetPSK(const char * identity, const uint8_t * key, int keyLength) +{ + pskIdentity = identity; + pskKey = key; + pskKeyLength = keyLength; +} + + +bool DTLS_Decrypt(NetworkAddress * sourceAddress, uint8_t * encrypted, int encryptedLength, uint8_t * decryptBuffer, int decryptBufferLength, int * decryptedLength, void *context) +{ + bool result = false; + bool tryAgain = true; + DTLS_Session * session = GetSession(sourceAddress); + if (!session) + { + session = AllocateSession(sourceAddress, false, context); + } + while (session && tryAgain) + { + tryAgain = false; + session->Buffer = decryptBuffer; + session->BufferLength = decryptBufferLength; + bool hadSessionEstablished = session->SessionEstablished; + if (dtls_handle_message(session->Context, &session->Session, encrypted, encryptedLength) == TINY_DTLS_SUCCESS) + { + *decryptedLength = decryptBufferLength - session->BufferLength; + if (session->SessionEstablished) + { + result = (*decryptedLength > 0); + } + else + { + if (hadSessionEstablished) + tryAgain = true; + dtls_peer_t * peer = dtls_get_peer(session->Context, &session->Session); + if (peer) + { + session->SessionEstablished = (dtls_peer_state(peer) == DTLS_STATE_CONNECTED); + } + } + } + else + { + *decryptedLength = 0; + if (session->SessionEstablished) + { + FreeSession(session); + session = AllocateSession(sourceAddress, false, context); + tryAgain = true; + } + } + } + return result; +} + +bool DTLS_Encrypt(NetworkAddress * destAddress, uint8_t * plainText, int plainTextLength, uint8_t * encryptedBuffer, int encryptedBufferLength, int * encryptedLength, void *context) +{ + bool result = false; + DTLS_Session * session = GetSession(destAddress); + if (session) + { + if (session->SessionEstablished) + { + session->Callbacks.write = EncryptCallBack; + session->Buffer = encryptedBuffer; + session->BufferLength = encryptedBufferLength; + int written = dtls_write(session->Context, &session->Session, plainText, plainTextLength); + if (written >= 0) + { + *encryptedLength = encryptedBufferLength - session->BufferLength; + result = (*encryptedLength > 0); + } + } + else + { + session->UserContext = context; + session->Callbacks.write = SSLSendCallBack; + } + } + else + { + session = AllocateSession(destAddress, true, context); + if (session) + { + dtls_connect(session->Context, &session->Session); + } + } + return result; +} + +static DTLS_Session * AllocateSession(NetworkAddress * address, bool client, void * context) +{ + DTLS_Session * result = NULL; + int index; + for (index = 0;index < MAX_DTLS_SESSIONS; index++) + { + if (!sessions[index].Context) + { + SetupNewSession(index, address, client); + sessions[index].UserContext = context; + sessions[index].Callbacks.write = SSLSendCallBack; + result = &sessions[index]; + break; + } + } + return result; +} + +static DTLS_Session * GetSession(NetworkAddress * address) +{ + DTLS_Session * result = NULL; + int index; + for (index = 0;index < MAX_DTLS_SESSIONS; index++) + { + if (NetworkAddress_Compare(sessions[index].NetworkAddress,address) == 0) + { + result = &sessions[index]; + break; + } + } + return result; +} + +static void SetupNewSession(int index, NetworkAddress * networkAddress, bool client) +{ + DTLS_Session * session = &sessions[index]; + if (!client) + session->Callbacks.event = EventCallBack; + session->Callbacks.read = DecryptCallBack; + session->Callbacks.write = SSLSendCallBack; +#ifdef DTLS_PSK + session->Callbacks.get_psk_info = PSKCallBack; +#endif +#ifdef DTLS_ECC + session->Callbacks.get_ecdsa_key = GetCertificate; + session->Callbacks.verify_ecdsa_key = CertificateVerify; +#endif + session->NetworkAddress = networkAddress; + session->Context = dtls_new_context(session); + if (session->Context) + { + dtls_set_handler(session->Context, &session->Callbacks); +// if (!client) +// { +// //dtls_peer_t *peer = +// dtls_new_peer(&session->Session); +// } + } +} + +static void FreeSession(DTLS_Session * session) +{ + if (session->Context) + { + dtls_peer_t * peer = dtls_get_peer(session->Context, &session->Session); + if (peer) + { + dtls_reset_peer(session->Context, peer); + } + dtls_free_context(session->Context); + } + memset(session,0, sizeof(DTLS_Session)); +} + +#if GNUTLS_VERSION_MAJOR >= 3 +static int CertificateVerify(gnutls_session_t session) +{ + return 0; +} +#endif + +static int DecryptCallBack(struct dtls_context_t *context, session_t *session, uint8 *recieveBuffer, size_t receiveBufferLegth) +{ + int result; + DTLS_Session * dtlsSession = (DTLS_Session *)dtls_get_app_data(context); + if (dtlsSession->BufferLength > 0) + { + if (receiveBufferLegth < dtlsSession->BufferLength) + { + result = receiveBufferLegth; + } + else + { + result = dtlsSession->BufferLength; + } + memcpy(dtlsSession->Buffer, recieveBuffer, result); + dtlsSession->BufferLength = dtlsSession->BufferLength - result; + dtlsSession->Buffer += result; + } + else + { + result = -1; + } + return result; +} +static int EncryptCallBack(struct dtls_context_t *context, session_t *session, uint8 * sendBuffer, size_t sendBufferLength) +{ + int result; + DTLS_Session * dtlsSession = (DTLS_Session *)dtls_get_app_data(context); + if (dtlsSession->BufferLength > 0) + { + if (sendBufferLength < dtlsSession->BufferLength) + { + result = sendBufferLength; + } + else + { + result = dtlsSession->BufferLength; + } + memcpy(dtlsSession->Buffer, sendBuffer, result); + dtlsSession->BufferLength = dtlsSession->BufferLength - result; + dtlsSession->Buffer += result; + } + else + { + result = 0; + } + return result; +} + +static int EventCallBack(struct dtls_context_t *context, session_t *session, dtls_alert_level_t level, unsigned short code) +{ + if (code == DTLS_EVENT_CONNECTED) + { + DTLS_Session * dtlsSession = (DTLS_Session *)dtls_get_app_data(context); + if (dtlsSession) + { + if (dtlsSession->SessionEstablished) + { + dtlsSession->Callbacks.write = NULL; + dtls_peer_t * peer = dtls_get_peer(context, session); + if (peer) + { + dtls_reset_peer(context, peer); + } + dtlsSession->Callbacks.write = SSLSendCallBack; + } + dtlsSession->SessionEstablished = false; + } + } + return 0; +} + +static int PSKCallBack(struct dtls_context_t *ctx, const session_t *session, dtls_credentials_type_t type, const unsigned char *id, + size_t id_len, unsigned char *result, size_t result_length) +{ + switch (type) + { + case DTLS_PSK_HINT: + case DTLS_PSK_IDENTITY: + if (id_len) + { + Lwm2m_Debug("got psk_identity_hint: '%.*s'\n", (int)id_len, id); + } + int pskIdentityLength = strlen(pskIdentity); + if (result_length < pskIdentityLength) + { + Lwm2m_Warning("cannot set psk_identity -- buffer too small\n"); + return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR); + } + + memcpy(result, pskIdentity, pskIdentityLength); + return pskIdentityLength; + case DTLS_PSK_KEY: + pskIdentityLength = strlen(pskIdentity); + if (id_len != pskIdentityLength || memcmp(pskIdentity, id, id_len) != 0) + { + Lwm2m_Warning("PSK for unknown id requested, exiting\n"); + return dtls_alert_fatal_create(DTLS_ALERT_ILLEGAL_PARAMETER); + } + else if (result_length < pskKeyLength) + { + Lwm2m_Warning("cannot set psk -- buffer too small\n"); + return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR); + } + + memcpy(result, pskKey, pskKeyLength); + return pskKeyLength; + default: + Lwm2m_Warning("unsupported request type: %d\n", type); + } + + return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR); +} + + +static int SSLSendCallBack(struct dtls_context_t *context, session_t *session, uint8 * sendBuffer, size_t sendBufferLength) +{ + int result; + DTLS_Session * dtlsSession = (DTLS_Session *)dtls_get_app_data(context); + if (NetworkSend) + { + NetworkTransmissionError error = NetworkSend(dtlsSession->NetworkAddress, sendBuffer, sendBufferLength, dtlsSession->UserContext); + if (error == NetworkTransmissionError_None) + result = sendBufferLength; + else + result = 0; + } + else + { + result = 0; + } + return result; +} + +#ifdef DTLS_ECC +static int CertificateVerify(struct dtls_context_t *ctx, const session_t *session, const unsigned char *other_pub_x, const unsigned char *other_pub_y, size_t key_size) +{ + return TINY_DTLS_SUCCESS; +} +#endif diff --git a/core/src/common/network_abstraction.h b/core/src/common/network_abstraction.h index c290e22..c428d58 100644 --- a/core/src/common/network_abstraction.h +++ b/core/src/common/network_abstraction.h @@ -78,7 +78,7 @@ int NetworkSocket_GetFileDescriptor(NetworkSocket * networkSocket); void NetworkSocket_SetCertificate(NetworkSocket * networkSocket, const uint8_t * cert, int certLength, CertificateFormat format); -void NetworkSocket_SetPSK(NetworkSocket * networkSocket, const char * identity, uint8_t * key, int keyLength); +void NetworkSocket_SetPSK(NetworkSocket * networkSocket, const char * identity, const uint8_t * key, int keyLength); bool NetworkSocket_StartListening(NetworkSocket * networkSocket); diff --git a/core/src/common/network_abstraction_linux.c b/core/src/common/network_abstraction_linux.c index b1a3d90..5371909 100644 --- a/core/src/common/network_abstraction_linux.c +++ b/core/src/common/network_abstraction_linux.c @@ -463,7 +463,7 @@ void NetworkSocket_SetCertificate(NetworkSocket * networkSocket, const uint8_t * DTLS_SetCertificate(cert, certLength, format); } -void NetworkSocket_SetPSK(NetworkSocket * networkSocket, const char * identity, uint8_t * key, int keyLength) +void NetworkSocket_SetPSK(NetworkSocket * networkSocket, const char * identity, const uint8_t * key, int keyLength) { DTLS_SetPSK(identity, key, keyLength); diff --git a/core/src/server/lwm2m_server.c b/core/src/server/lwm2m_server.c index 2387c34..1500538 100644 --- a/core/src/server/lwm2m_server.c +++ b/core/src/server/lwm2m_server.c @@ -48,6 +48,7 @@ #include "lwm2m_object_defs.h" #include "lwm2m_core.h" #include "lwm2m_server_cert.h" +#include "lwm2m_server_psk.h" #define DEFAULT_IP_ADDRESS "0.0.0.0" @@ -74,7 +75,6 @@ static const char * version = VERSION; // from Makefile static volatile int quit = 0; - static void PrintOptions(const Options * options); static void Lwm2m_CtrlCSignalHandler(int dummy) @@ -211,6 +211,7 @@ static int Lwm2mServer_Start(Options * options) if (options->Secure) { coap_SetCertificate(serverCert, sizeof(serverCert), CertificateFormat_PEM); + coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); } Lwm2mContextType * context = Lwm2mCore_Init(NULL, options->ContentType); // NULL, don't map coap with objectStore diff --git a/core/src/server/lwm2m_server_psk.h b/core/src/server/lwm2m_server_psk.h new file mode 100644 index 0000000..8d40836 --- /dev/null +++ b/core/src/server/lwm2m_server_psk.h @@ -0,0 +1,42 @@ +/************************************************************************************************************************ + Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +************************************************************************************************************************/ + + +#ifndef LWM2M_SERVER_PSK_H_ +#define LWM2M_SERVER_PSK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +const char * pskIdentity = "oFIrQFrW8EWcZ5u7eGfrkw"; + +const uint8_t pskKey[] = { + 0x7C, 0xCD, 0xE1, 0x4A, 0x5C, 0xF3, 0xB7, 0x1C, 0x0C, 0x08, 0xC8, 0xB7, 0xF9, 0xE5 +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* LWM2M_SERVER_PSK_H_ */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2579e37..7005188 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -9,6 +9,10 @@ if (WITH_JSON) add_subdirectory (jsmn) endif () +if (WITH_TINYDTLS) + add_subdirectory (tinydtls) +endif () + if (BUILD_TESTS) # gtest is CMake-enabled # defines libraries 'gtest' and 'gtest-main' diff --git a/lib/tinydtls/CMakeLists.txt b/lib/tinydtls/CMakeLists.txt new file mode 100644 index 0000000..749f751 --- /dev/null +++ b/lib/tinydtls/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(tinydtls NONE) + +if (DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_EXTRA_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) +endif() + +Include (ExternalProject) +ExternalProject_Add(tinydtls + GIT_REPOSITORY https://git.eclipse.org/r/tinydtls/org.eclipse.tinydtls + GIT_TAG 0016138fe3998552eee3987a1c09da43a23c9fb5 + CMAKE_ARGS ${CMAKE_EXTRA_ARGS} + SOURCE_DIR "${CMAKE_BINARY_DIR}/tinydtls-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/tinydtls-build" + UPDATE_COMMAND "" + INSTALL_COMMAND "" + PATCH_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/apply_patches ${CMAKE_CURRENT_SOURCE_DIR}/patches +) + +# for now use a global variable for this until we find a way of setting the property on the tinydtls_static target +set (TINYDTLS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/tinydtls-src ${CMAKE_BINARY_DIR}/tinydtls-build CACHE INTERNAL "") + +add_library(tinydtls_static STATIC IMPORTED GLOBAL) +set_target_properties(tinydtls_static PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/tinydtls-build/libtinydtls.a") +#set_target_properties(tinydtls_static PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${TINYDTLS_INCLUDE_DIR}) + + diff --git a/lib/tinydtls/apply_patches b/lib/tinydtls/apply_patches new file mode 100755 index 0000000..7705bff --- /dev/null +++ b/lib/tinydtls/apply_patches @@ -0,0 +1,3 @@ +#!/bin/sh + +for x in $1/*.patch; do patch < $x; done diff --git a/lib/tinydtls/patches/001-tinydtls.cmake.patch b/lib/tinydtls/patches/001-tinydtls.cmake.patch new file mode 100644 index 0000000..737a9f9 --- /dev/null +++ b/lib/tinydtls/patches/001-tinydtls.cmake.patch @@ -0,0 +1,145 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +new file mode 100644 +index 0000000..c42591b +--- /dev/null ++++ b/CMakeLists.txt +@@ -0,0 +1,139 @@ ++cmake_minimum_required(VERSION 2.8.2) ++Include (CheckIncludeFile) ++Include (CheckFunctionExists) ++Include (CheckTypeSize) ++set (DTLS_PSK 1) ++set (STDC_HEADERS 1) ++set (PACKAGE_BUGREPORT "") ++set (PACKAGE_NAME "libtinydtls") ++set (PACKAGE_VERSION "0.8.6") ++set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") ++set (PACKAGE_TARNAME "${PACKAGE_NAME}") ++set (PACKAGE_URL "") ++#set (AC_APPLE_UNIVERSAL_BUILD 1) ++check_include_file (arpa/inet.h HAVE_ARPA_INET_H) ++check_include_file (assert.h HAVE_ASSERT_H) ++check_include_file (fcntl.h HAVE_FCNTL_H) ++check_function_exists (fls HAVE_FLS) ++check_include_file (inttypes.h, HAVE_INTTYPES_H) ++check_include_file (limits.h HAVE_LIMITS_H) ++check_include_file (malloc.h HAVE_MALLOC) ++check_include_file (memory.h HAVE_MEMORY_H) ++check_function_exists (memset HAVE_MEMSET) ++check_include_file (netdb.h HAVE_NETDB_H) ++check_include_file (netinet/in.h HAVE_NETINET_IN_H) ++check_function_exists (select HAVE_SELECT) ++check_function_exists (socket HAVE_SOCKET) ++check_function_exists (getaddrinfo HAVE_GETADDRINFO) ++check_include_file (stddef.h HAVE_STDDEF_H) ++check_include_file (stdint.h HAVE_STDINT_H) ++check_include_file (stdlib.h HAVE_STDLIB_H) ++check_include_file (strings.h HAVE_STRINGS_H) ++check_include_file (string.h HAVE_STRING_H) ++check_function_exists (strcasecmp HAVE_STRCASECMP) ++check_function_exists (strnlen HAVE_STRNLEN) ++check_function_exists (strrchr HAVE_STRRCHR) ++check_function_exists (strdup HAVE_STRDUP) ++check_function_exists (strerror HAVE_STRERROR) ++check_function_exists (vprintf HAVE_VPRINTF) ++check_include_file (sys/param.h HAVE_SYS_PARAM_H) ++check_include_file (syslog.h HAVE_SYSLOG_H) ++check_include_file (sys/socket.h HAVE_SYS_SOCKET_H) ++check_include_file (sys/stat.h HAVE_SYS_STAT_H) ++check_include_file (sys/time.h HAVE_SYS_TIME_H) ++check_include_file (sys/types.h HAVE_SYS_TYPES_H) ++check_include_file (sys/unistd.h HAVE_SYS_UNISTD_H) ++check_include_file (time.h HAVE_TIME_H) ++check_include_file (unistd.h HAVE_UNISTD_H) ++ ++ ++ ++ ++set (CMAKE_EXTRA_INCLUDE_FILES netinet/in.h) ++check_type_size("struct in_pktinfo" SIZEOF_PKTINFO) ++if (SIZEOF_PKTINFO) ++ set (HAVE_PKTINFO 1) ++else () ++ set (HAVE_PKTINFO 0) ++endif () ++ ++check_type_size("struct in6_pktinfo" SIZEOF_PKT6INFO) ++if (SIZEOF_PKT6INFO) ++ set (HAVE_PKT6INFO 1) ++else () ++ set (HAVE_PKT6INFO 0) ++endif () ++ ++configure_file (dtls_config.h.cmake dtls_config.h) ++ ++set (tinydtls_SOURCES ++ dtls.c ++ crypto.c ++ ccm.c ++ hmac.c ++ netq.c ++ peer.c ++ dtls_time.c ++ session.c ++ dtls_debug.c ++ aes/rijndael.c ++ sha2/sha2.c ++ ecc/ecc.c ++) ++ ++# fetch the INCLUDE_DIRECTORIES properties of non-linked dependencies: ++# (it is not possible to link with an OBJECT library, so these are not automatic) ++#get_property (LIB_XML_INCLUDE_DIR TARGET libxml_static PROPERTY INCLUDE_DIRECTORIES) ++ ++ ++set (tinydtls_INCLUDE_DIRS ++ ${CMAKE_CURRENT_BINARY_DIR} ++ ${CMAKE_CURRENT_SOURCE_DIR} ++ ${CMAKE_CURRENT_SOURCE_DIR}/aes ++ ${CMAKE_CURRENT_SOURCE_DIR}/sha2 ++ ${CMAKE_CURRENT_SOURCE_DIR}/ecc ++) ++ ++set (tinydtls_LIBS ++) ++ ++if (ENABLE_GCOV) ++ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage") ++ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") ++endif () ++ ++if (DEBUG) ++ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0") ++endif () ++ ++# From TinyDTLS Makefiles ++add_definitions (-DDTLS_PSK) ++add_definitions (-DDTLSv12) ++add_definitions (-DWITH_SHA256) ++add_definitions (-DNDEBUG) ++add_definitions (-DPOSIX) ++ ++ ++# static library libtinydtls.a ++add_library (tinydtls_static STATIC ${tinydtls_SOURCES}) ++set_target_properties (tinydtls_static PROPERTIES OUTPUT_NAME "tinydtls") ++set_target_properties (tinydtls_static PROPERTIES POSITION_INDEPENDENT_CODE ON) ++target_include_directories(tinydtls_static PUBLIC ${tinydtls_INCLUDE_DIRS}) ++target_link_libraries (tinydtls_static ${tinydtls_LIBS}) ++ ++# TODO - needed? c.f. libawa_static) ++#if (ENABLE_GCOV) ++# target_link_libraries (tinydtls_static gcov) ++#endif () ++ ++# libtinydtls.so ++add_library (tinydtls_shared SHARED ${tinydtls_SOURCES}) ++set_target_properties (tinydtls_shared PROPERTIES OUTPUT_NAME "tinydtls") ++set_target_properties (tinydtls_shared PROPERTIES POSITION_INDEPENDENT_CODE ON) ++target_include_directories (tinydtls_shared PUBLIC ${tinydtls_INCLUDE_DIRS}) ++target_link_libraries (tinydtls_shared ${tinydtls_LIBS}) ++ ++install (TARGETS tinydtls_shared ++ LIBRARY DESTINATION lib ++) ++ diff --git a/lib/tinydtls/patches/002-tinydtls.h.patch b/lib/tinydtls/patches/002-tinydtls.h.patch new file mode 100644 index 0000000..ac24af7 --- /dev/null +++ b/lib/tinydtls/patches/002-tinydtls.h.patch @@ -0,0 +1,34 @@ +diff --git a/tinydtls.h b/tinydtls.h +new file mode 100644 +index 0000000..4e18909 +--- /dev/null ++++ b/tinydtls.h +@@ -0,0 +1,27 @@ ++/******************************************************************************* ++ * ++ * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others. ++ * All rights reserved. This program and the accompanying materials ++ * are made available under the terms of the Eclipse Public License v1.0 ++ * and Eclipse Distribution License v. 1.0 which accompanies this distribution. ++ * ++ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html ++ * and the Eclipse Distribution License is available at ++ * http://www.eclipse.org/org/documents/edl-v10.php. ++ * ++ * Contributors: ++ * Olaf Bergmann - initial API and implementation ++ * Hauke Mehrtens - memory optimization, ECC integration ++ * ++ *******************************************************************************/ ++ ++/** ++ * @file tinydtls.h ++ * @brief public tinydtls API ++ */ ++ ++#ifndef _DTLS_TINYDTLS_H_ ++#define _DTLS_TINYDTLS_H_ ++ ++ ++#endif /* _DTLS_TINYDTLS_H_ */ + diff --git a/lib/tinydtls/patches/003-dtls_config.h.patch b/lib/tinydtls/patches/003-dtls_config.h.patch new file mode 100644 index 0000000..e6d961b --- /dev/null +++ b/lib/tinydtls/patches/003-dtls_config.h.patch @@ -0,0 +1,161 @@ +diff --git a/dtls_config.h.cmake b/dtls_config.h.cmake +new file mode 100644 +index 0000000..dcbc0a1 +--- /dev/null ++++ b/dtls_config.h.cmake +@@ -0,0 +1,155 @@ ++#ifndef _DTLS_CONFIG_H_ ++#define _DTLS_CONFIG_H_ ++ ++/* Define if building universal (internal helper macro) */ ++#cmakedefine AC_APPLE_UNIVERSAL_BUILD @AC_APPLE_UNIVERSAL_BUILD@ ++ ++/* Define to 1 if building with ECC support. */ ++#cmakedefine DTLS_ECC @DTLS_ECC@ ++ ++/* Define to 1 if building with PSK support */ ++#cmakedefine DTLS_PSK @DTLS_PSK@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_ARPA_INET_H @HAVE_ARPA_INET_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_ASSERT_H @HAVE_ASSERT_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_FCNTL_H @HAVE_FCNTL_H@ ++ ++/* Define to 1 if you have the `fls' function. */ ++#cmakedefine HAVE_FLS @HAVE_FLS@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ ++ ++/* Define to 1 if your system has a GNU libc compatible `malloc' function, and ++ to 0 otherwise. */ ++#cmakedefine HAVE_MALLOC @HAVE_MALLOC@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ ++ ++/* Define to 1 if you have the `memset' function. */ ++#cmakedefine HAVE_MEMSET @HAVE_MEMSET@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_NETDB_H @HAVE_NETDB_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_NETINET_IN_H @HAVE_NETINET_IN_H@ ++ ++/* Define to 1 if you have the `select' function. */ ++#cmakedefine HAVE_SELECT @HAVE_SELECT@ ++ ++/* Define to 1 if struct sockaddr_in6 has a member sin6_len. */ ++#cmakedefine HAVE_SOCKADDR_IN6_SIN6_LEN @HAVE_SOCKADDR_IN6_SIN6_LEN@ ++ ++/* Define to 1 if you have the `socket' function. */ ++#cmakedefine HAVE_SOCKET @HAVE_SOCKET@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_STDDEF_H @HAVE_STDDEF_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ ++ ++/* Define to 1 if you have the `strdup' function. */ ++#cmakedefine HAVE_STRDUP @HAVE_STRDUP@ ++ ++/* Define to 1 if you have the `strerror' function. */ ++#cmakedefine HAVE_STRERROR @HAVE_STRERROR@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ ++ ++/* Define to 1 if you have the `strnlen' function. */ ++#cmakedefine HAVE_STRNLEN @HAVE_STRNLEN@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_PARAM_H @HAVE_SYS_PARAM_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_SOCKET_H @HAVE_SYS_SOCKET_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_TIME_H @HAVE_SYS_TIME_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_TIME_H @HAVE_TIME_H@ ++ ++/* Define to 1 if you have the header file. */ ++#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ ++ ++/* Define to 1 if you have the `vprintf' function. */ ++#cmakedefine HAVE_VPRINTF @HAVE_VPRINTF@ ++ ++/* Define to the address where bug reports for this package should be sent. */ ++#cmakedefine PACKAGE_BUGREPORT "" ++ ++/* Define to the full name of this package. */ ++#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" ++ ++/* Define to the full name and version of this package. */ ++#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" ++ ++/* Define to the one symbol short name of this package. */ ++#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" ++ ++/* Define to the home page for this package. */ ++#cmakedefine PACKAGE_URL "@PACKAGE_URL@" ++ ++/* Define to the version of this package. */ ++#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" ++ ++/* Define to 1 if you have the ANSI C header files. */ ++#cmakedefine STDC_HEADERS @STDC_HEADERS@ ++ ++/* Define to 1 if building for Contiki. */ ++#cmakedefine WITH_CONTIKI @WITH_CONTIKI@ ++ ++/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most ++ significant byte first (like Motorola and SPARC, unlike Intel). */ ++#if defined AC_APPLE_UNIVERSAL_BUILD ++# if defined __BIG_ENDIAN__ ++# define WORDS_BIGENDIAN 1 ++# endif ++#else ++# ifndef WORDS_BIGENDIAN ++# undef WORDS_BIGENDIAN ++# endif ++#endif ++ ++/* Define to `__inline__' or `__inline' if that's what the C compiler ++ calls it, or to nothing if 'inline' is not supported under any name. */ ++#ifndef __cplusplus ++#cmakedefine inline ++#endif ++ ++/* Define to rpl_malloc if the replacement function should be used. */ ++/* #cmakedefine malloc */ ++ ++/* Define to `unsigned int' if does not define. */ ++/* #cmakedefine size_t */ ++ ++ ++#ifdef WITH_CONTIKI ++#include "platform-specific/platform.h" ++#endif ++ ++#endif /* _DTLS_CONFIG_H_ */ ++