[IOT-2395] security: tcp provisioning fix
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Thu, 8 Jun 2017 11:29:54 +0000 (14:29 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Mon, 26 Jun 2017 13:38:20 +0000 (13:38 +0000)
Security provisioning samples via tcp fixed

Change-Id: Iff96834af80413053dee9318a352132eeaf60ebb
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20641
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Alex Kelley <alexke@microsoft.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/include/pmtypes.h
resource/csdk/security/provisioning/sample/provisioningclient.c
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/provisioning/src/pmutility.c
resource/csdk/security/src/secureresourcemanager.c

index 60e0255..384d57f 100644 (file)
@@ -69,6 +69,7 @@ typedef struct OCProvisionDev
     uint16_t        securePort;      /**< secure port **/
 #ifdef WITH_TCP
     uint16_t        tcpPort;         /**< tcp port **/
+    uint16_t        tcpSecurePort;   /**< secure tcp port **/
 #endif
     char            secVer[OIC_SEC_MAX_VER_LEN];         /**< security version **/
     DeviceStatus    devStatus;       /**< status of device **/
index 3853e97..3755d18 100644 (file)
@@ -2747,7 +2747,7 @@ static void setDevProtocol(OCProvisionDev_t* lst)
             lst->connType |= CT_ADAPTER_TCP; //set TCP flag
             lst->endpoint.adapter = OC_ADAPTER_TCP;
             lst->endpoint.port = lst->tcpPort;
-            lst->securePort = lst->tcpPort;
+            lst->securePort = lst->tcpSecurePort;
         }
         lst = lst->next;
     }
index 55b2267..6e14e56 100644 (file)
@@ -687,7 +687,7 @@ static OCStackResult SaveSubOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selectedDeviceInfo->tcpPort;
+        endpoint.port = selectedDeviceInfo->tcpSecurePort;
     }
 #endif
 
index ce2ce65..68dc33c 100644 (file)
@@ -785,7 +785,7 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selectedDeviceInfo->tcpPort;
+        endpoint.port = selectedDeviceInfo->tcpSecurePort;
     }
 #endif
 
@@ -1759,7 +1759,7 @@ static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = deviceInfo->tcpPort;
+        endpoint.port = deviceInfo->tcpSecurePort;
     }
 #endif
 
index 244f7f1..2e60511 100644 (file)
@@ -132,7 +132,7 @@ OCStackResult CreateSecureSessionJustWorksCallback(OTMContext_t* otmCtx)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selDevInfo->tcpPort;
+        endpoint.port = selDevInfo->tcpSecurePort;
     }
 #endif
 
index 4702398..2976d76 100644 (file)
@@ -164,7 +164,7 @@ OCStackResult CreateSecureSessionMCertificateCallback(OTMContext_t* otmCtx)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selDevInfo->tcpPort;
+        endpoint.port = selDevInfo->tcpSecurePort;
     }
 #endif
 
index 9253f80..c2c7228 100644 (file)
@@ -214,7 +214,7 @@ OCStackResult CreateSecureSessionPreconfigPinCallback(OTMContext_t* otmCtx)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selDevInfo->tcpPort;
+        endpoint.port = selDevInfo->tcpSecurePort;
     }
 #endif
 
index 372051c..237d42f 100644 (file)
@@ -166,7 +166,7 @@ OCStackResult CreateSecureSessionRandomPinCallback(OTMContext_t* otmCtx)
 #ifdef WITH_TCP
     else if (CA_ADAPTER_TCP == endpoint.adapter)
     {
-        endpoint.port = selDevInfo->tcpPort;
+        endpoint.port = selDevInfo->tcpSecurePort;
     }
 #endif
 
index 2b2c37a..8998992 100644 (file)
@@ -356,6 +356,7 @@ static OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList,
                                        uint16_t port, uint16_t securePort
 #ifdef __WITH_TLS__
                                        ,uint16_t tcpPort
+                                       ,uint16_t tcpSecurePort
 #endif
                                        )
 {
@@ -372,6 +373,7 @@ static OCStackResult UpdateSecurePortOfDevice(OCProvisionDev_t **ppDevicesList,
 
 #ifdef __WITH_TLS__
     ptr->tcpPort = tcpPort;
+    ptr->tcpSecurePort = tcpSecurePort;
 #endif
 
     return OC_STACK_OK;
@@ -724,6 +726,10 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
             }
 
             uint16_t securePort = 0;
+#ifdef __WITH_TLS__
+            uint16_t tcpPort = 0;
+            uint16_t tcpSecurePort = 0;
+#endif
             OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
 
             // Use seure port of doxm for OTM and Provision.
@@ -765,11 +771,45 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
                     }
                     eps = eps->next;
                 }
+#ifdef __WITH_TLS__
+                eps = resPayload->eps;
+                while (eps != NULL)
+                {
+                    if ((eps->family & OC_FLAG_SECURE) &&
+                        ((OC_IP_USE_V6 == clientResponse->devAddr.flags &&
+                          strchr(eps->addr, ':')) ||
+                         (OC_IP_USE_V4 == clientResponse->devAddr.flags &&
+                          strchr(eps->addr, '.'))) &&
+                        0 == strncmp(eps->tps, COAPS_TCP_PREFIX, strlen(COAPS_TCP_PREFIX)-3))
+                    {
+                            tcpSecurePort = eps->port;
+                            break;
+                    }
+                    eps = eps->next;
+                }
+                eps = resPayload->eps;
+                while (eps != NULL)
+                {
+                    if(((OC_IP_USE_V6 == clientResponse->devAddr.flags && strchr(eps->addr, ':')) ||
+                        (OC_IP_USE_V4 == clientResponse->devAddr.flags && strchr(eps->addr, '.'))) &&
+                        0 == strncmp(eps->tps, COAP_TCP_PREFIX, strlen(COAP_TCP_PREFIX)-3)
+                      )
+                    {
+                        tcpPort =  eps->port;
+                        break;
+                    }
+                    eps = eps->next;
+                }
+#endif
                 if (!securePort)
                 {
                     OIC_LOG(INFO, TAG, "Can not find secure port information.");
                     return OC_STACK_DELETE_TRANSACTION;
                 }
+                else
+                {
+                    OIC_LOG_V(INFO, TAG, "%s: secure port: %d", __func__, securePort);
+                }
             }
             else
             {
@@ -794,7 +834,8 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
                                                          clientResponse->devAddr.port,
                                                          securePort
 #ifdef __WITH_TLS__
-                                                         ,resPayload->tcpPort
+                                                         ,tcpPort
+                                                         ,tcpSecurePort
 #endif
                                                          );
             if (OC_STACK_OK != res)
index bd447b6..d854464 100644 (file)
@@ -139,6 +139,16 @@ void SRMGenerateResponse(SRMRequestContext_t *context)
 // Set the value of context->resourceUri, based on the context->requestInfo.
 static void SetResourceUriAndType(SRMRequestContext_t *context)
 {
+    if (NULL == context || NULL == context->requestInfo ||
+        NULL == context->requestInfo->info.resourceUri)
+    {
+        OIC_LOG_V(INFO, TAG, "%s : %s is NULL", __func__,
+            (NULL == context) ? "context" :
+            (NULL == context->requestInfo) ? "context->requestInfo" :
+            "context->requestInfo->info.resourceUri");
+        return;
+    }
+
     char *uri = strstr(context->requestInfo->info.resourceUri, "?");
     size_t position = 0;