[IOT-2322][CHP][SampleApp] Coap http proxy is not working in secured mode 57/20257/8
authorVeeraj Khokale <veeraj.sk@samsung.com>
Tue, 23 May 2017 04:31:01 +0000 (13:31 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 23 May 2017 08:21:20 +0000 (08:21 +0000)
1. Update dat files for proxy samples to be same as linux
   secure samples.
2. Modify logic to form server address according to linux
   secure samples while initiating proxy request.
3. Since request URI is NULL for proxy request check this
   condition before asserting role certificates in OCDoRequest().
   This also removes the need for NULL check of request info
   resource uri.

Change-Id: I20003ac7c7781666bbd4aa8955c4cc18b5a3262f
Signed-off-by: Veeraj Khokale <veeraj.sk@samsung.com>
Signed-off-by: uzchoi <uzchoi@samsung.com>
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20257
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
resource/csdk/stack/src/ocstack.c [changed mode: 0644->0755]
service/coap-http-proxy/samples/oic_svr_db_client_devowner.dat
service/coap-http-proxy/samples/oic_svr_db_client_devowner.json
service/coap-http-proxy/samples/oic_svr_db_server.dat
service/coap-http-proxy/samples/oic_svr_db_server.json
service/coap-http-proxy/samples/proxy_client.c

old mode 100644 (file)
new mode 100755 (executable)
index fcc2c04..6ec0c37
@@ -3288,6 +3288,7 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
     OCDevAddr *devAddr = NULL;
     char *resourceUri = NULL;
     char *resourceType = NULL;
+    bool isProxyRequest = false;
 
     /*
      * Support original behavior with address on resourceUri argument.
@@ -3305,10 +3306,14 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
             goto exit;
         }
     }
-    else if (!checkProxyUri(options, numOptions))
+    else
     {
-        OIC_LOG(ERROR, TAG, "Request doesn't contain RequestURI/Proxy URI");
-        goto exit;
+        isProxyRequest = checkProxyUri(options, numOptions);
+        if (!isProxyRequest)
+        {
+            OIC_LOG(ERROR, TAG, "Request doesn't contain RequestURI/Proxy URI");
+            goto exit;
+        }
     }
 
     switch (method)
@@ -3612,11 +3617,11 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
 
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     /* Check whether we should assert role certificates before making this request. */
-    if ((endpoint.flags & CA_SECURE) && (NULL != requestInfo.info.resourceUri) &&
-        (strcmp(requestInfo.info.resourceUri, OIC_RSRC_ROLES_URI) != 0) &&
-        (strcmp(requestInfo.info.resourceUri, OIC_RSRC_DOXM_URI) != 0) &&
+    if ((endpoint.flags & CA_SECURE) && (isProxyRequest ||
+        ((strcmp(requestInfo.info.resourceUri, OIC_RSRC_ROLES_URI) != 0) &&
+        (strcmp(requestInfo.info.resourceUri, OIC_RSRC_DOXM_URI) != 0)) &&
         ((CT_ADAPTER_TCP == connectivityType) &&
-                strcmp(requestInfo.info.resourceUri, OC_RSRVD_KEEPALIVE_URI) != 0))
+                strcmp(requestInfo.info.resourceUri, OC_RSRVD_KEEPALIVE_URI) != 0)))
     {
         CASecureEndpoint_t sep;
         CAResult_t caRes = CAGetSecureEndpointData(&endpoint, &sep);
@@ -3629,8 +3634,12 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
              * it fails, that's OK, roles will get asserted "automatically" when PSK
              * credentials are used.
              */
-            OIC_LOG_V(DEBUG, TAG, "%s: going to try to assert roles before doing request to %s ",
-                      __func__, requestInfo.info.resourceUri);
+            if (!isProxyRequest)
+            {
+                OIC_LOG_V(DEBUG, TAG, "%s: going to try to assert roles before doing request to %s ",
+                          __func__, requestInfo.info.resourceUri);
+            }
+
             OCDevAddr da;
             CopyEndpointToDevAddr(&endpoint, &da);
             OCStackResult assertResult = OCAssertRoles((void*)ASSERT_ROLES_CTX, &da,
index 184e10f..dbe0f6f 100644 (file)
Binary files a/service/coap-http-proxy/samples/oic_svr_db_client_devowner.dat and b/service/coap-http-proxy/samples/oic_svr_db_client_devowner.dat differ
index a5e4772..3f6c2be 100644 (file)
@@ -1,90 +1,65 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/acl",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.acl"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "32323232-3232-3232-3232-323232323232"\r
-    },\r
-    "pstat": {\r
-        "dos": {"s": 3, "p": false},\r
-        "isop": true,\r
-        "deviceuuid": "32323232-3232-3232-3232-323232323232",\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232",\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": true,\r
-        "deviceuuid": "32323232-3232-3232-3232-323232323232",\r
-        "devowneruuid": "32323232-3232-3232-3232-323232323232",\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    },\r
-    "cred": {\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "31313131-3131-3131-3131-313131313131",\r
-                "credtype": 1,\r
-                "privatedata": {\r
-                    "data": "AAAAAAAAAAAAAAAA",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    }\r
-}\r
+{
+    "acl": {
+        "aclist2": [
+            {
+                "aceid": 1,
+                "subject": {
+                  "conntype": "anon-clear"
+                },
+                "resources": [
+                    { "href": "/oic/res" },
+                    { "href": "/oic/d" },
+                    { "href": "/oic/p" },
+                    { "href": "/oic/sec/doxm" }
+                ],
+                "permission": 2
+            },
+            {
+                "aceid": 2,
+                "subject": {
+                  "conntype": "auth-crypt"
+                },
+                "resources": [
+                    { "href": "/oic/res" },
+                    { "href": "/oic/d" },
+                    { "href": "/oic/p" },
+                    { "href": "/oic/sec/doxm" }
+                ],
+                "permission": 2
+            }
+        ],
+        "rowneruuid" : "32323232-3232-3232-3232-323232323232"
+    },
+    "pstat": {
+        "dos": {"s": 3, "p": false},
+        "isop": true,
+        "rowneruuid": "32323232-3232-3232-3232-323232323232",
+        "cm": 0,
+        "tm": 0,
+        "om": 4,
+        "sm": 4
+        },
+    "doxm": {
+        "oxms": [0],
+        "oxmsel": 0,
+        "sct": 1,
+        "owned": true,
+        "deviceuuid": "32323232-3232-3232-3232-323232323232",
+        "devowneruuid": "32323232-3232-3232-3232-323232323232",
+        "rowneruuid": "32323232-3232-3232-3232-323232323232"
+    },
+    "cred": {
+        "creds": [
+            {
+                "credid": 1,
+                "subjectuuid": "31313131-3131-3131-3131-313131313131",
+                "credtype": 1,
+                "privatedata": {
+                    "data": "AAAAAAAAAAAAAAAA",
+                    "encoding": "oic.sec.encoding.raw"
+                }
+            }
+        ],
+        "rowneruuid": "32323232-3232-3232-3232-323232323232"
+    }
+}
index ad154f7..7b8e676 100644 (file)
Binary files a/service/coap-http-proxy/samples/oic_svr_db_server.dat and b/service/coap-http-proxy/samples/oic_svr_db_server.dat differ
index c985873..bef7858 100644 (file)
 {\r
     "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/acl",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.acl"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
+        "aclist2": [\r
+            {\r
+                "aceid": 1,\r
+                "subject": {\r
+                  "conntype": "anon-clear"\r
                 },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
+                "resources": [\r
+                    {\r
+                        "href": "/oic/res",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.res"],\r
+                        "if": ["oic.if.ll"]\r
+                    },{\r
+                        "href": "/oic/d",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.d"],\r
+                        "if": ["oic.if.baseline", "oic.if.r"]\r
+                    },{\r
+                        "href": "/oic/p",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.p"],\r
+                        "if": ["oic.if.baseline", "oic.if.r"]\r
+                    }\r
+                ],\r
+                "permission": 2\r
+            },\r
+            {\r
+                "aceid": 2,\r
+                "subject": {\r
+                  "conntype": "auth-crypt"\r
                 },\r
-                {\r
-                    "subjectuuid": "32323232-3232-3232-3232-323232323232",\r
-                    "resources": [\r
-                        {\r
-                            "href": "*",\r
-                            "rel": "",\r
-                            "rt": ["*"],\r
-                            "if": ["*"]\r
-                        }\r
-                    ],\r
-                    "permission": 7\r
+                "resources": [\r
+                    {\r
+                        "href": "/oic/res",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.res"],\r
+                        "if": ["oic.if.ll"]\r
+                    },{\r
+                        "href": "/oic/d",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.d"],\r
+                        "if": ["oic.if.baseline", "oic.if.r"]\r
+                    },{\r
+                        "href": "/oic/p",\r
+                        "rel": "",\r
+                        "rt": ["oic.wk.p"],\r
+                        "if": ["oic.if.baseline", "oic.if.r"]\r
+                    }\r
+                ],\r
+                "permission": 2\r
+            },\r
+            {\r
+                "aceid": 3,\r
+                "subject": {\r
+                    "uuid": "32323232-3232-3232-3232-323232323232"\r
                 },\r
-                {\r
-                    "subjectuuid": "31393139-3139-3139-3139-313931393139",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/a/led",\r
-                            "rel": "",\r
-                            "rt": ["oic.core"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 7\r
+                "resources": [\r
+                    {\r
+                        "href": "*",\r
+                        "rel": "",\r
+                        "rt": ["*"],\r
+                        "if": ["*"]\r
+                    }\r
+                ],\r
+                "permission": 7\r
+            },\r
+            {\r
+                "aceid": 4,\r
+                "subject": {\r
+                    "uuid": "31393139-3139-3139-3139-313931393139"\r
                 },\r
-                {\r
-                    "subjectuuid": "37373737-3737-3737-3737-373737373737",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/a/led",\r
-                            "rel": "",\r
-                            "rt": ["oic.core"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 6\r
-                }\r
-            ]\r
-        },\r
+                "resources": [\r
+                    {\r
+                        "href": "/a/led",\r
+                        "rel": "",\r
+                        "rt": ["oic.core"],\r
+                        "if": ["oic.if.baseline"]\r
+                    }\r
+                ],\r
+                "permission": 7\r
+            },\r
+            {\r
+                "aceid": 5,\r
+                "subject": {\r
+                    "uuid": "37373737-3737-3737-3737-373737373737"\r
+                },\r
+                "resources": [\r
+                    {\r
+                        "href": "/a/led",\r
+                        "rel": "",\r
+                        "rt": ["oic.core"],\r
+                        "if": ["oic.if.baseline"]\r
+                    }\r
+                ],\r
+                "permission": 6\r
+            }\r
+        ],\r
         "rowneruuid" : "31313131-3131-3131-3131-313131313131"\r
     },\r
     "pstat": {\r
         "dos": {"s": 3, "p": false},\r
         "isop": true,\r
-        "deviceuuid": "31313131-3131-3131-3131-313131313131",\r
         "rowneruuid": "31313131-3131-3131-3131-313131313131",\r
         "cm": 0,\r
         "tm": 0,\r
index e876ced..ad3156b 100644 (file)
@@ -284,10 +284,20 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
             return OC_STACK_KEEP_TRANSACTION;
         }
 
-        if (resource->secure)
+        OCEndpointPayload* eps = resource->eps;
+        while (NULL != eps)
         {
-            serverAddr.flags |= OC_SECURE;
-            serverAddr.port = resource->port;
+            if (eps->family & OC_FLAG_SECURE)
+            {
+                if (0 == strcmp(eps->tps, "coaps"))
+                {
+                    strncpy(serverAddr.addr, eps->addr, sizeof(serverAddr.addr));
+                    serverAddr.port = eps->port;
+                    serverAddr.flags = (OCTransportFlags)(eps->family | OC_SECURE);
+                    serverAddr.adapter = OC_ADAPTER_IP;
+                }
+            }
+            eps = eps->next;
         }
 
         switch (testCase)