PSK check before ciphersuite selection
authorAndrii Shtompel <a.shtompel@samsung.com>
Wed, 25 Jan 2017 14:16:03 +0000 (16:16 +0200)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 4 Apr 2017 11:01:36 +0000 (11:01 +0000)
Checking identity added to avoid including PSK suite
if no appropriate PSK in SVR DB.

Change-Id: I118c4b5864929cc8fdd0597af855f3c06b9332dc
Signed-off-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
Signed-off-by: Andrii Shtompel <a.shtompel@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16731
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Oleksii Beketov <ol.beketov@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
20 files changed:
extlibs/timer/timer.h
resource/csdk/connectivity/api/casecurityinterface.h
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c [changed mode: 0755->0644]
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/test/ssladapter_test.cpp
resource/csdk/security/include/internal/credresource.h
resource/csdk/security/include/pkix_interface.h
resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/oxmjustworks.c
resource/csdk/security/provisioning/src/oxmmanufacturercert.c
resource/csdk/security/provisioning/src/oxmpreconfpin.c
resource/csdk/security/provisioning/src/oxmrandompin.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/directpairing.c
resource/csdk/security/src/pkix_interface.c
resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp
resource/csdk/stack/samples/linux/secure/occlientbasicops.h
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oickeepalive.c

index 4f51a1e..a5ac14e 100644 (file)
 #define TIMER_H_
 
 #include "iotivity_config.h"
-#ifdef HAVE_SYS_TIME_H
+#ifdef HAVE_TIME_H
+#include <time.h>
+#elif defined(HAVE_SYS_TIME_H)
 #include <sys/time.h>
-#endif
-#ifdef HAVE_ARDUINO_TIME_H
+#elif defined(HAVE_ARDUINO_TIME_H)
 #include <Time.h>
 #endif
 
index ed05a36..5851033 100644 (file)
@@ -104,10 +104,11 @@ bool CAGetSecureEndpointAttributes(const CAEndpoint_t* peer, uint32_t* allAttrib
  * This internal callback is used by CA layer to
  * retrieve all credential types from SRM
  *
- * @param[out]  list of enabled credential types for CA handshake
+ * @param[out]  list of enabled credential types for CA handshake.
+ * @param[in]   device uuid.
  *
  */
-typedef void (*CAgetCredentialTypesHandler)(bool * list);
+typedef void (*CAgetCredentialTypesHandler)(bool * list, const char* deviceId);
 /**
  * Binary structure containing PKIX related info
  * own certificate chain, public key, CA's and CRL's
old mode 100755 (executable)
new mode 100644 (file)
index 7a0ed10..5c7abcc
@@ -1271,7 +1271,8 @@ static int InitPskIdentity(mbedtls_ssl_config * config)
     OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
     return 0;
 }
-static void SetupCipher(mbedtls_ssl_config * config, CATransportAdapter_t adapter)
+static void SetupCipher(mbedtls_ssl_config * config, CATransportAdapter_t adapter,
+                        const char* deviceId)
 {
     int index = 0;
     OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
@@ -1290,7 +1291,8 @@ static void SetupCipher(mbedtls_ssl_config * config, CATransportAdapter_t adapte
         return;
     }
 
-    g_getCredentialTypesCallback(g_caSslContext->cipherFlag);
+    g_getCredentialTypesCallback(g_caSslContext->cipherFlag, deviceId);
+
     // Retrieve the PSK credential from SRM
     if (true == g_caSslContext->cipherFlag[0] && 0 != InitPskIdentity(config))
     {
@@ -1377,7 +1379,7 @@ static SslEndPoint_t * InitiateTlsHandshake(const CAEndpoint_t *endpoint)
     }
 
     //Load allowed SVR suites from SVR DB
-    SetupCipher(config, endpoint->adapter);
+    SetupCipher(config, endpoint->adapter, endpoint->remoteId);
 
     ret = u_arraylist_add(g_caSslContext->peerList, (void *) tep);
     if (!ret)
@@ -1928,7 +1930,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, size_t dat
             return CA_STATUS_FAILED;
         }
         //Load allowed TLS suites from SVR DB
-        SetupCipher(config, sep->endpoint.adapter);
+        SetupCipher(config, sep->endpoint.adapter, sep->endpoint.remoteId);
 
         ret = u_arraylist_add(g_caSslContext->peerList, (void *) peer);
         if (!ret)
index 6d52ab1..73812ec 100644 (file)
@@ -1372,11 +1372,7 @@ CASocketFd_t CAConnectTCPSession(const CAEndpoint_t *endpoint)
         OIC_LOG(ERROR, TAG, "Out of memory");
         return OC_INVALID_SOCKET;
     }
-    memcpy(svritem->sep.endpoint.addr, endpoint->addr, sizeof(svritem->sep.endpoint.addr));
-    svritem->sep.endpoint.adapter = endpoint->adapter;
-    svritem->sep.endpoint.port = endpoint->port;
-    svritem->sep.endpoint.flags = endpoint->flags;
-    svritem->sep.endpoint.ifindex = endpoint->ifindex;
+    svritem->sep.endpoint = *endpoint;
     svritem->state = CONNECTING;
     svritem->isClient = true;
 
index e805d61..c038144 100644 (file)
@@ -27,6 +27,7 @@
 #include "iotivity_config.h"
 #include "gtest/gtest.h"
 #include "time.h"
+#include "octypes.h"
 #ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
 #endif
@@ -999,8 +1000,10 @@ static void socketClose_server()
     OC_CLOSE_SOCKET(sockfd);
 }
 
-static void clutch(bool * list)
+static void clutch(bool * list, const char *deviceId)
 {
+    OC_UNUSED(deviceId);
+
     list[1] = true;
 }
 
@@ -1908,6 +1911,7 @@ static ssize_t CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf,
 static void * test0CAinitiateSslHandshake(void * arg)
 {
     CAEndpoint_t serverAddr;
+    memset(&serverAddr, 0, sizeof(serverAddr));
     serverAddr.adapter = CA_ADAPTER_TCP;
     serverAddr.flags = CA_SECURE;
     serverAddr.port = 4433;
@@ -2082,6 +2086,7 @@ static void * testCAencryptSsl(void * arg)
 {
     int ret = 0;
     CAEndpoint_t serverAddr;
+    memset(&serverAddr, 0, sizeof(serverAddr));
     serverAddr.adapter = CA_ADAPTER_TCP;
     serverAddr.flags = CA_SECURE;
     serverAddr.port = 4433;
@@ -2536,6 +2541,7 @@ static void * testCAdecryptSsl(void * arg)
     int buflen = 0;
 
     CAEndpoint_t serverAddr;
+    memset(&serverAddr, 0, sizeof(serverAddr));
     serverAddr.adapter = CA_ADAPTER_TCP;
     serverAddr.flags = CA_SECURE;
     serverAddr.port = 4433;
@@ -3084,6 +3090,7 @@ static void * testCAsslGenerateOwnerPsk(void * arg)
 {
     int ret = 0;
     CAEndpoint_t serverAddr;
+    memset(&serverAddr, 0, sizeof(serverAddr));
     serverAddr.adapter = CA_ADAPTER_TCP;
     serverAddr.flags = CA_SECURE;
     serverAddr.port = 4433;
index 486ec8a..19138fc 100644 (file)
@@ -251,10 +251,11 @@ void GetDerKey(ByteArray_t * key, const char * usage);
 /**
  * Used by CA to retrieve credential types
  *
- * @param[out] key key to be filled.
+ * @param[out] list list of suites to be filled.
  * @param[in] usage credential usage string.
+ * @param[in] device uuid.
  */
-void InitCipherSuiteListInternal(bool *list, const char * usage);
+void InitCipherSuiteListInternal(bool *list, const char * usage, const char* deviceId);
 #endif // __WITH_TLS__
 
 // Helpers shared by cred and roles resources
index 5af15ce..0d12660 100644 (file)
@@ -45,15 +45,17 @@ void GetManufacturerPkixInfo(PkiInfo_t * inf);
  * Used by CA to retrieve credential types
  *
  * @param[out] list TLS suites boolean map.
+ * @param[in]  device uuid.
  */
-void InitCipherSuiteList(bool * list);
+void InitCipherSuiteList(bool * list, const char* deviceId);
 
 /**
  * Used by CA to retrieve manufacturer credential types
  *
  * @param[out] list TLS suites boolean map.
+ * @param[in]  device uuid.
  */
-void InitManufacturerCipherSuiteList(bool * list);
+void InitManufacturerCipherSuiteList(bool * list, const char* deviceId);
 #ifdef __cplusplus
 }
 #endif
index fd8c89d..569e0bd 100644 (file)
@@ -57,6 +57,7 @@
 #include "oxmpreconfpin.h"
 #include "oxmrandompin.h"
 #include "otmcontextlist.h"
+#include "ocstackinternal.h"
 #include "mbedtls/ssl_ciphersuites.h"
 #include "ocrandom.h"
 
@@ -660,11 +661,18 @@ static OCStackResult SaveSubOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     OCStackResult res = OC_STACK_ERROR;
 
     CAEndpoint_t endpoint;
-    memset(&endpoint, 0x00, sizeof(CAEndpoint_t));
-    OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE_CA, selectedDeviceInfo->endpoint.addr);
-    endpoint.addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
-    endpoint.port = selectedDeviceInfo->securePort;
-    endpoint.adapter = selectedDeviceInfo->endpoint.adapter;
+    CopyDevAddrToEndpoint(&selectedDeviceInfo->endpoint, &endpoint);
+
+    if (CA_ADAPTER_IP == endpoint.adapter)
+    {
+        endpoint.port = selectedDeviceInfo->securePort;
+    }
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
+    {
+        endpoint.port = selectedDeviceInfo->tcpPort;
+    }
+#endif
 
     OicUuid_t ownerDeviceID = {.id={0}};
     if (OC_STACK_OK != GetDoxmDeviceID(&ownerDeviceID))
index 62820b4..808b639 100644 (file)
@@ -776,12 +776,18 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
     OCStackResult res = OC_STACK_ERROR;
 
     CAEndpoint_t endpoint;
-    memset(&endpoint, 0x00, sizeof(CAEndpoint_t));
-    OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE_CA, selectedDeviceInfo->endpoint.addr);
-    endpoint.addr[MAX_ADDR_STR_SIZE_CA - 1] = '\0';
-    endpoint.port = selectedDeviceInfo->securePort;
-    endpoint.adapter = selectedDeviceInfo->endpoint.adapter;
-    uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = { 0 };
+    CopyDevAddrToEndpoint(&selectedDeviceInfo->endpoint, &endpoint);
+
+    if (CA_ADAPTER_IP == endpoint.adapter)
+    {
+        endpoint.port = selectedDeviceInfo->securePort;
+    }
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
+    {
+        endpoint.port = selectedDeviceInfo->tcpPort;
+    }
+#endif
 
     OicUuid_t ownerDeviceID = {.id={0}};
     if (OC_STACK_OK != GetDoxmDeviceID(&ownerDeviceID))
@@ -792,6 +798,8 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
 
     OicSecKey_t ownerKey;
     memset(&ownerKey, 0, sizeof(ownerKey));
+
+    uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = { 0 };
     ownerKey.data = ownerPSK;
     ownerKey.len = OWNER_PSK_LENGTH_128;
     ownerKey.encoding = OIC_ENCODING_RAW;
@@ -1740,6 +1748,15 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
     OicSecAcl_t* ownerAcl = NULL;
     assert(deviceInfo->connType & CT_FLAG_SECURE);
 
+    CAEndpoint_t endpoint;
+    CopyDevAddrToEndpoint(&deviceInfo->endpoint, &endpoint);
+
+    if (CA_STATUS_OK != CAInitiateHandshake(&endpoint))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to pass ssl handshake");
+        return OC_STACK_ERROR;
+    }
+
     if(!PMGenerateQuery(true,
                         deviceInfo->endpoint.addr, deviceInfo->securePort,
                         deviceInfo->connType,
index 550b2fb..47cfafe 100644 (file)
@@ -28,6 +28,7 @@
 #include "logger.h"
 #include "pmtypes.h"
 #include "ownershiptransfermanager.h"
+#include "ocstackinternal.h"
 #include "mbedtls/ssl_ciphersuites.h"
 
 #define TAG "OIC_OXM_JustWorks"
@@ -108,26 +109,22 @@ OCStackResult CreateSecureSessionJustWorksCallback(OTMContext_t* otmCtx)
     }
     OIC_LOG(INFO, TAG, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA256 cipher suite selected.");
 
-    OCProvisionDev_t *selDevInfo = otmCtx->selectedDeviceInfo;
     CAEndpoint_t endpoint;
-    memcpy(&endpoint, &selDevInfo->endpoint, sizeof(CAEndpoint_t));
+    OCProvisionDev_t *selDevInfo = otmCtx->selectedDeviceInfo;
+    CopyDevAddrToEndpoint(&selDevInfo->endpoint, &endpoint);
 
-    if(CA_ADAPTER_IP == endpoint.adapter)
+    if (CA_ADAPTER_IP == endpoint.adapter)
     {
         endpoint.port = selDevInfo->securePort;
-        caresult = CAInitiateHandshake(&endpoint);
     }
-    else if (CA_ADAPTER_GATT_BTLE == endpoint.adapter)
-    {
-        caresult = CAInitiateHandshake(&endpoint);
-    }
-#ifdef __WITH_TLS__
-    else
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
         endpoint.port = selDevInfo->tcpPort;
-        caresult = CAinitiateSslHandshake(&endpoint);
     }
 #endif
+
+    caresult = CAInitiateHandshake(&endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OIC_LOG_V(ERROR, TAG, "DTLS/TLS handshake failure.");
index 671f78f..b8c303a 100644 (file)
@@ -37,6 +37,7 @@
 #include "srmresourcestrings.h"
 #include "pkix_interface.h"
 #include "mbedtls/ssl_ciphersuites.h"
+#include "ocstackinternal.h"
 
 #define TAG "OXM_MCertificate"
 
@@ -137,16 +138,22 @@ OCStackResult CreateSecureSessionMCertificateCallback(OTMContext_t* otmCtx)
     }
     OIC_LOG(INFO, TAG, "MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 cipher suite selected.");
 
+    CAEndpoint_t endpoint;
     OCProvisionDev_t* selDevInfo = otmCtx->selectedDeviceInfo;
-    CAEndpoint_t *endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
-    if (NULL == endpoint)
+    CopyDevAddrToEndpoint(&selDevInfo->endpoint, &endpoint);
+
+    if (CA_ADAPTER_IP == endpoint.adapter)
+    {
+        endpoint.port = selDevInfo->securePort;
+    }
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        return OC_STACK_NO_MEMORY;
+        endpoint.port = selDevInfo->tcpPort;
     }
-    memcpy(endpoint,&selDevInfo->endpoint,sizeof(CAEndpoint_t));
-    endpoint->port = selDevInfo->securePort;
-    caresult = CAInitiateHandshake(endpoint);
-    OICFree(endpoint);
+#endif
+
+    caresult = CAInitiateHandshake(&endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OIC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
index 7b5d902..ff97daf 100644 (file)
@@ -36,6 +36,7 @@
 #include "ownershiptransfermanager.h"
 #include "pinoxmcommon.h"
 #include "srmresourcestrings.h"
+#include "ocstackinternal.h"
 #include "mbedtls/ssl_ciphersuites.h"
 
 #define TAG "OIC_OXM_PreconfigPIN"
@@ -194,16 +195,22 @@ OCStackResult CreateSecureSessionPreconfigPinCallback(OTMContext_t* otmCtx)
     }
     OIC_LOG(INFO, TAG, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 cipher suite selected.");
 
+    CAEndpoint_t endpoint;
     OCProvisionDev_t* selDevInfo = otmCtx->selectedDeviceInfo;
-    CAEndpoint_t *endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
-    if (NULL == endpoint)
+    CopyDevAddrToEndpoint(&selDevInfo->endpoint, &endpoint);
+
+    if (CA_ADAPTER_IP == endpoint.adapter)
+    {
+        endpoint.port = selDevInfo->securePort;
+    }
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        return OC_STACK_NO_MEMORY;
+        endpoint.port = selDevInfo->tcpPort;
     }
-    memcpy(endpoint,&selDevInfo->endpoint,sizeof(CAEndpoint_t));
-    endpoint->port = selDevInfo->securePort;
-    caresult = CAInitiateHandshake(endpoint);
-    OICFree(endpoint);
+#endif
+
+    caresult = CAInitiateHandshake(&endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OIC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
index 217f360..ee35575 100644 (file)
@@ -34,6 +34,7 @@
 #include "oxmrandompin.h"
 #include "ownershiptransfermanager.h"
 #include "pinoxmcommon.h"
+#include "ocstackinternal.h"
 #include "mbedtls/ssl_ciphersuites.h"
 
 #define TAG "OIC_OXM_RandomPIN"
@@ -146,26 +147,22 @@ OCStackResult CreateSecureSessionRandomPinCallback(OTMContext_t* otmCtx)
     }
     OIC_LOG(INFO, TAG, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 cipher suite selected.");
 
-    OCProvisionDev_t* selDevInfo = otmCtx->selectedDeviceInfo;
     CAEndpoint_t endpoint;
-    memcpy(&endpoint, &selDevInfo->endpoint, sizeof(CAEndpoint_t));
+    OCProvisionDev_t* selDevInfo = otmCtx->selectedDeviceInfo;
+    CopyDevAddrToEndpoint(&selDevInfo->endpoint, &endpoint);
 
-    if(CA_ADAPTER_IP == endpoint.adapter)
+    if (CA_ADAPTER_IP == endpoint.adapter)
     {
         endpoint.port = selDevInfo->securePort;
-        caresult = CAInitiateHandshake(&endpoint);
     }
-    else if (CA_ADAPTER_GATT_BTLE == endpoint.adapter)
-    {
-        caresult = CAInitiateHandshake(&endpoint);
-    }
-#ifdef __WITH_TLS__
-    else
+#ifdef WITH_TCP
+    else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
         endpoint.port = selDevInfo->tcpPort;
-        caresult = CAinitiateSslHandshake(&endpoint);
     }
 #endif
+
+    caresult = CAInitiateHandshake(&endpoint);
     if (CA_STATUS_OK != caresult)
     {
         OIC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
index 3b665b9..4bfa901 100644 (file)
@@ -3363,7 +3363,7 @@ void GetDerKey(ByteArray_t * key, const char * usage)
     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
 }
 
-void InitCipherSuiteListInternal(bool * list, const char * usage)
+void InitCipherSuiteListInternal(bool * list, const char * usage, const char *deviceId)
 {
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     if (NULL == list || NULL == usage)
@@ -3385,8 +3385,15 @@ void InitCipherSuiteListInternal(bool * list, const char * usage)
             }
             case SYMMETRIC_PAIR_WISE_KEY:
             {
-                list[0] = true;
-                OIC_LOG(DEBUG, TAG, "SYMMETRIC_PAIR_WISE_KEY found");
+                OicUuid_t uuid;
+
+                if (NULL == deviceId ||
+                    OC_STACK_OK != ConvertStrToUuid(deviceId, &uuid) ||
+                    0 == memcmp(uuid.id, temp->subject.id, sizeof(uuid.id)))
+                {
+                    list[0] = true;
+                    OIC_LOG(DEBUG, TAG, "SYMMETRIC_PAIR_WISE_KEY found");
+                }
                 break;
             }
             case SIGNED_ASYMMETRIC_KEY:
index 3387d6a..4c1ad97 100644 (file)
@@ -51,6 +51,7 @@
 #include "pmtypes.h"
 #include "pmutility.h"
 #include "srmutility.h"
+#include "ocstackinternal.h"
 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
 #include <mbedtls/ssl_ciphersuites.h>
 #endif
@@ -635,15 +636,12 @@ static OCStackApplicationResult DirectPairingHandler(void *ctx, OCDoHandle UNUSE
             VERIFY_SUCCESS(TAG, CA_STATUS_OK == caresult, ERROR);
 
             // initiate dtls
-            CAEndpoint_t *endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
-            VERIFY_NOT_NULL(TAG, endpoint, FATAL);
-            memcpy(endpoint,&dpairData->peer->endpoint,sizeof(CAEndpoint_t));
-            endpoint->port = dpairData->peer->securePort;
-            OIC_LOG_V(INFO, TAG, "Initiate DTLS handshake to %s(%d)", endpoint->addr,
-                    endpoint->port);
-
-            caresult = CAInitiateHandshake(endpoint);
-            OICFree(endpoint);
+            CAEndpoint_t endpoint;
+            CopyDevAddrToEndpoint(&dpairData->peer->endpoint, &endpoint);
+            endpoint.port = dpairData->peer->securePort;
+            OIC_LOG_V(INFO, TAG, "Initiate DTLS handshake to %s(%d)", endpoint.addr,
+                    endpoint.port);
+            caresult = CAInitiateHandshake(&endpoint);
             VERIFY_SUCCESS(TAG, CA_STATUS_OK == caresult, ERROR);
 #endif // __WITH_DTLS__ or __WITH_TLS__
 
index 5303efc..672480a 100644 (file)
@@ -76,7 +76,7 @@ void GetManufacturerPkixInfo(PkiInfo_t * inf)
     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
 }
 
-void InitCipherSuiteList(bool * list)
+void InitCipherSuiteList(bool * list, const char* deviceId)
 {
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     if (NULL == list)
@@ -85,11 +85,11 @@ void InitCipherSuiteList(bool * list)
         OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
         return;
     }
-    InitCipherSuiteListInternal(list, TRUST_CA);
+    InitCipherSuiteListInternal(list, TRUST_CA, deviceId);
     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
 }
 
-void InitManufacturerCipherSuiteList(bool * list)
+void InitManufacturerCipherSuiteList(bool * list, const char* deviceId)
 {
     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
     if (NULL == list)
@@ -98,6 +98,6 @@ void InitManufacturerCipherSuiteList(bool * list)
         OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
         return;
     }
-    InitCipherSuiteListInternal(list, MF_TRUST_CA);
+    InitCipherSuiteListInternal(list, MF_TRUST_CA, deviceId);
     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
 }
index d730702..534a93b 100644 (file)
@@ -53,7 +53,6 @@ static int WithTcp = 0;
 
 static char DISCOVERY_QUERY[] = "%s/oic/res";
 OCConnectivityType discoveryReqConnType = CT_ADAPTER_IP;
-static OCDevAddr endpoint;
 
 static std::string coapServerResource;
 static int coapSecureResource;
@@ -198,21 +197,20 @@ OCStackApplicationResult discoveryReqCB(void *, OCDoHandle,
             OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
 
             ocConnType = clientResponse->connType;
-            endpoint = clientResponse->devAddr;
 
             if (parseClientResponse(clientResponse) != -1)
             {
                 switch (TestCase)
                 {
                     case TEST_NON_CON_OP:
-                        InitGetRequest(OC_LOW_QOS);
-                        InitPutRequest(OC_LOW_QOS);
-                        InitPostRequest(OC_LOW_QOS);
+                        InitGetRequest(&clientResponse->devAddr, OC_LOW_QOS);
+                        InitPutRequest(&clientResponse->devAddr, OC_LOW_QOS);
+                        InitPostRequest(&clientResponse->devAddr, OC_LOW_QOS);
                         break;
                     case TEST_CON_OP:
-                        InitGetRequest(OC_HIGH_QOS);
-                        InitPutRequest(OC_HIGH_QOS);
-                        InitPostRequest(OC_HIGH_QOS);
+                        InitGetRequest(&clientResponse->devAddr, OC_HIGH_QOS);
+                        InitPutRequest(&clientResponse->devAddr, OC_HIGH_QOS);
+                        InitPostRequest(&clientResponse->devAddr, OC_HIGH_QOS);
                         break;
                 }
             }
@@ -222,21 +220,17 @@ OCStackApplicationResult discoveryReqCB(void *, OCDoHandle,
     return (UnicastDiscovery) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
 
 }
-int InitPutRequest(OCQualityOfService qos)
+int InitPutRequest(OCDevAddr *endpoint, OCQualityOfService qos)
 {
     OIC_LOG_V(INFO, TAG, "Executing %s", __func__);
     std::ostringstream query;
     query << coapServerResource;
-    if (WithTcp)
-    {
-        endpoint.adapter = OC_ADAPTER_TCP;
-    }
-    endpoint.flags = (OCTransportFlags)(endpoint.flags | OC_SECURE);
-    return (InvokeOCDoResource(query, OC_REST_PUT, &endpoint,
+
+    return (InvokeOCDoResource(query, OC_REST_PUT, endpoint,
                                ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS), putReqCB, NULL, 0));
 }
 
-int InitPostRequest(OCQualityOfService qos)
+int InitPostRequest(OCDevAddr *endpoint, OCQualityOfService qos)
 {
     OCStackResult result;
 
@@ -244,14 +238,8 @@ int InitPostRequest(OCQualityOfService qos)
     std::ostringstream query;
     query << coapServerResource;
 
-    if (WithTcp)
-    {
-        endpoint.adapter = OC_ADAPTER_TCP;
-    }
-    endpoint.flags = (OCTransportFlags)(endpoint.flags | OC_SECURE);
-
     // First POST operation (to create an LED instance)
-    result = InvokeOCDoResource(query, OC_REST_POST, &endpoint,
+    result = InvokeOCDoResource(query, OC_REST_POST, endpoint,
                                 ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS),
                                 postReqCB, NULL, 0);
     if (OC_STACK_OK != result)
@@ -261,7 +249,7 @@ int InitPostRequest(OCQualityOfService qos)
     }
 
     // Second POST operation (to create an LED instance)
-    result = InvokeOCDoResource(query, OC_REST_POST, &endpoint,
+    result = InvokeOCDoResource(query, OC_REST_POST, endpoint,
                                 ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS),
                                 postReqCB, NULL, 0);
     if (OC_STACK_OK != result)
@@ -271,7 +259,7 @@ int InitPostRequest(OCQualityOfService qos)
 
     // This POST operation will update the original resourced /a/led (as long as
     // the server is set to max 2 /lcd resources)
-    result = InvokeOCDoResource(query, OC_REST_POST, &endpoint,
+    result = InvokeOCDoResource(query, OC_REST_POST, endpoint,
                                 ((qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS),
                                 postReqCB, NULL, 0);
     if (OC_STACK_OK != result)
@@ -281,18 +269,13 @@ int InitPostRequest(OCQualityOfService qos)
     return result;
 }
 
-int InitGetRequest(OCQualityOfService qos)
+int InitGetRequest(OCDevAddr *endpoint, OCQualityOfService qos)
 {
     OIC_LOG_V(INFO, TAG, "Executing %s", __func__);
     std::ostringstream query;
     query << coapServerResource;
-    if (WithTcp)
-    {
-        endpoint.adapter = OC_ADAPTER_TCP;
-    }
-    endpoint.flags = (OCTransportFlags)(endpoint.flags | OC_SECURE);
 
-    return (InvokeOCDoResource(query, OC_REST_GET, &endpoint,
+    return (InvokeOCDoResource(query, OC_REST_GET, endpoint,
                                ((qos == OC_HIGH_QOS) ?  OC_HIGH_QOS : OC_LOW_QOS),
                                getReqCB, NULL, 0));
 }
@@ -487,19 +470,27 @@ int parseClientResponse(OCClientResponse *clientResponse)
             res = res->next;
             continue;
         }
+        OCDevAddr *endpoint = &clientResponse->devAddr;
+        if (WithTcp)
+        {
+#ifdef TCP_ADAPTER
+            endpoint->adapter = OC_ADAPTER_TCP;
+#endif
+        }
         if (res->secure)
         {
+            endpoint->flags = (OCTransportFlags)(endpoint->flags | OC_SECURE);
             if (WithTcp)
             {
 #ifdef TCP_ADAPTER
                 OIC_LOG_V(INFO, TAG, "SECUREPORT tcp: %d", res->tcpPort);
-                endpoint.port = res->tcpPort;
+                endpoint->port = res->tcpPort;
 #endif
             }
             else
             {
                 OIC_LOG_V(INFO, TAG, "SECUREPORT udp: %d", res->port);
-                endpoint.port = res->port;
+                endpoint->port = res->port;
             }
             coapSecureResource = 1;
         }
index 4a07306..598b3b6 100644 (file)
@@ -68,9 +68,9 @@ std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
 /* Following are initialization functions for GET, PUT
  * POST & Discovery operations
  */
-int InitPutRequest(OCQualityOfService qos);
-int InitGetRequest(OCQualityOfService qos);
-int InitPostRequest(OCQualityOfService qos);
+int InitPutRequest(OCDevAddr *endpoint, OCQualityOfService qos);
+int InitGetRequest(OCDevAddr *endpoint, OCQualityOfService qos);
+int InitPostRequest(OCDevAddr *endpoint, OCQualityOfService qos);
 int InitDiscovery();
 
 /* Function to retrieve ip address, port no. of the server
index 2b4e55d..82b61ed 100755 (executable)
@@ -556,6 +556,7 @@ void CopyEndpointToDevAddr(const CAEndpoint_t *in, OCDevAddr *out)
     out->adapter = (OCTransportAdapter)in->adapter;
     out->flags = CAToOCTransportFlags(in->flags);
     OICStrcpy(out->addr, sizeof(out->addr), in->addr);
+    OICStrcpy(out->remoteId, sizeof(out->remoteId), in->remoteId);
     out->port = in->port;
     out->ifindex = in->ifindex;
 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
index 68c72b3..57ec5b7 100644 (file)
@@ -754,12 +754,7 @@ KeepAliveEntry_t *AddKeepAliveEntry(const CAEndpoint_t *endpoint, OCMode mode,
 
     entry->mode = mode;
     entry->timeStamp = OICGetCurrentTime(TIME_IN_US);
-    entry->remoteAddr.adapter = endpoint->adapter;
-    entry->remoteAddr.flags = endpoint->flags;
-    entry->remoteAddr.ifindex = endpoint->ifindex;
-    entry->remoteAddr.port = endpoint->port;
-    strncpy(entry->remoteAddr.addr, endpoint->addr, sizeof(entry->remoteAddr.addr));
-
+    entry->remoteAddr = *endpoint;
     entry->intervalSize = DEFAULT_INTERVAL_COUNT;
     entry->intervalInfo = intervalInfo;
     if (!entry->intervalInfo)