diff --git a/.gitmodules b/.gitmodules index c2ac3f3c1913a6e19e5e73d04e30f33a7716dee1..4243e61088f3ce7e26cf24ecea2429b80ae42920 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "extlibs/iotivity-lite"] path = extlibs/iotivity-lite - url = https://gerrit.iotivity.org/gerrit/iotivity-lite - branch = swig + url = https://gitlab.iotivity.org/iotivity/iotivity-lite.git + branch = master diff --git a/README.md b/README.md index f49cd7ab4f6a49be6c9e5e586dfc8dbe05340aee..02c0b3f5a87c8b42980bc094615350a1ec01e8d9 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,8 @@ git checkout swig ``` 2. Apply all patchs of the OTGC in IoTivity-lite ``` -git apply /extlibs/patchs/remove_cred_by_credid.patch -git apply /extlibs/patchs/bwt_fix.patch -git apply /extlibs/patchs/timeout_fix.patch +git apply /extlibs/patchs/fix_swig_flags.patch +git apply /extlibs/patchs/ignore_cloud_discover_resources.patch ``` 3. Go to the **android** directory. ``` diff --git a/extlibs/iotivity-lite b/extlibs/iotivity-lite index 66a2d08784903110b7dead5b9a518933a355e1e6..89a79af890df2084d7ae1e33522b6d0e24a3e9a3 160000 --- a/extlibs/iotivity-lite +++ b/extlibs/iotivity-lite @@ -1 +1 @@ -Subproject commit 66a2d08784903110b7dead5b9a518933a355e1e6 +Subproject commit 89a79af890df2084d7ae1e33522b6d0e24a3e9a3 diff --git a/extlibs/patchs/bwt_fix.patch b/extlibs/patchs/bwt_fix.patch deleted file mode 100644 index b7d3113498ce0c79d63412d83b275e34d43bcb08..0000000000000000000000000000000000000000 --- a/extlibs/patchs/bwt_fix.patch +++ /dev/null @@ -1,126 +0,0 @@ -diff --git a/api/oc_server_api.c b/api/oc_server_api.c -index 198fef46..e94cbcb3 100644 ---- a/api/oc_server_api.c -+++ b/api/oc_server_api.c -@@ -395,7 +395,13 @@ oc_send_separate_response(oc_separate_response_t *handle, - oc_string(cur->uri), oc_string_len(cur->uri), &cur->endpoint, - cur->method, NULL, 0, OC_BLOCKWISE_SERVER); - if (response_state) { -- goto next_separate_request; -+ if (response_state->payload_size == -+ response_state->next_block_offset) { -+ oc_blockwise_free_response_buffer(response_state); -+ response_state = NULL; -+ } else { -+ continue; -+ } - } - response_state = oc_blockwise_alloc_response_buffer( - oc_string(cur->uri), oc_string_len(cur->uri), &cur->endpoint, -diff --git a/messaging/coap/engine.c b/messaging/coap/engine.c -index f7bcfce3..b7c1b91a 100644 ---- a/messaging/coap/engine.c -+++ b/messaging/coap/engine.c -@@ -274,6 +274,15 @@ coap_receive(oc_message_t *msg) - href, href_len, &msg->endpoint, message->code, message->uri_query, - message->uri_query_len, OC_BLOCKWISE_SERVER); - -+ if (request_buffer && request_buffer->payload_size == -+ request_buffer->next_block_offset) { -+ if ((request_buffer->next_block_offset - incoming_block_len) != -+ block1_offset) { -+ oc_blockwise_free_request_buffer(request_buffer); -+ request_buffer = NULL; -+ } -+ } -+ - if (!request_buffer && block1_num == 0) { - OC_DBG("creating new block-wise request buffer"); - request_buffer = oc_blockwise_alloc_request_buffer( -@@ -307,7 +316,6 @@ coap_receive(oc_message_t *msg) - block1_size); - request_buffer->payload_size = - request_buffer->next_block_offset; -- request_buffer->ref_count = 0; - goto request_handler; - } - } -@@ -325,6 +333,13 @@ coap_receive(oc_message_t *msg) - response_buffer = oc_blockwise_find_response_buffer( - href, href_len, &msg->endpoint, message->code, message->uri_query, - message->uri_query_len, OC_BLOCKWISE_SERVER); -+ -+ if (response_buffer && (response_buffer->next_block_offset - -+ block2_offset) > block2_size) { -+ oc_blockwise_free_response_buffer(response_buffer); -+ response_buffer = NULL; -+ } -+ - if (response_buffer) { - OC_DBG("continuing ongoing block-wise transfer"); - uint32_t payload_size = 0; -@@ -342,7 +357,6 @@ coap_receive(oc_message_t *msg) - (oc_blockwise_response_state_t *)response_buffer; - coap_set_header_etag(response, response_state->etag, - COAP_ETAG_LEN); -- response_buffer->ref_count = more; - goto send_message; - } else { - OC_ERR("could not dispatch block"); -@@ -410,6 +424,13 @@ coap_receive(oc_message_t *msg) - request_buffer->payload_size = incoming_block_len; - request_buffer->ref_count = 0; - } -+ response_buffer = oc_blockwise_find_response_buffer( -+ href, href_len, &msg->endpoint, message->code, message->uri_query, -+ message->uri_query_len, OC_BLOCKWISE_SERVER); -+ if (response_buffer) { -+ oc_blockwise_free_response_buffer(response_buffer); -+ response_buffer = NULL; -+ } - goto request_handler; - } else { - OC_ERR("incoming payload size exceeds block size"); -diff --git a/messaging/coap/observe.c b/messaging/coap/observe.c -index 62192fa5..2847d526 100644 ---- a/messaging/coap/observe.c -+++ b/messaging/coap/observe.c -@@ -313,7 +313,12 @@ coap_notify_collection_observers(oc_resource_t *resource, - oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, NULL, 0, - OC_BLOCKWISE_SERVER); - if (response_state) { -- continue; -+ if (response_state->payload_size == response_state->next_block_offset) { -+ oc_blockwise_free_response_buffer(response_state); -+ response_state = NULL; -+ } else { -+ continue; -+ } - } - response_state = oc_blockwise_alloc_response_buffer( - oc_string(obs->resource->uri) + 1, -@@ -480,8 +485,7 @@ coap_remove_observers_on_dos_change(size_t device, bool reset) - coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list); - while (obs != NULL) { - if (obs->endpoint.device == device && -- (reset || -- !oc_sec_check_acl(OC_GET, obs->resource, &obs->endpoint))) { -+ (reset || !oc_sec_check_acl(OC_GET, obs->resource, &obs->endpoint))) { - coap_observer_t *o = obs; - coap_packet_t notification[1]; - #ifdef OC_TCP -@@ -638,7 +642,13 @@ coap_notify_observers(oc_resource_t *resource, - oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, - NULL, 0, OC_BLOCKWISE_SERVER); - if (response_state) { -- continue; -+ if (response_state->payload_size == -+ response_state->next_block_offset) { -+ oc_blockwise_free_response_buffer(response_state); -+ response_state = NULL; -+ } else { -+ continue; -+ } - } - response_state = oc_blockwise_alloc_response_buffer( - oc_string(obs->resource->uri) + 1, diff --git a/extlibs/patchs/fix_swig_flags.patch b/extlibs/patchs/fix_swig_flags.patch new file mode 100644 index 0000000000000000000000000000000000000000..4817989f474838e983a4ad4057ec5aff75d92119 --- /dev/null +++ b/extlibs/patchs/fix_swig_flags.patch @@ -0,0 +1,20 @@ +diff --git a/swig/Makefile b/swig/Makefile +index 8c42bd3c..83321526 100644 +--- a/swig/Makefile ++++ b/swig/Makefile +@@ -77,6 +77,7 @@ endif + + ifneq ($(SECURE),0) + EXTRA_FLAG += -DOC_SECURITY ++ SWIG_CFLAG += -DOC_SECURITY + endif + + ifeq ($(IDD), 1) +@@ -85,6 +86,7 @@ endif + + ifneq ($(PKI),0) + EXTRA_FLAG += -DOC_PKI ++ SWIG_CFLAG += -DOC_PKI + endif + + ifeq ($(TCP),1) diff --git a/extlibs/patchs/ignore_cloud_discover_resources.patch b/extlibs/patchs/ignore_cloud_discover_resources.patch new file mode 100644 index 0000000000000000000000000000000000000000..1cd039fc154821ba3436455fc2172b35ddc9be67 --- /dev/null +++ b/extlibs/patchs/ignore_cloud_discover_resources.patch @@ -0,0 +1,13 @@ +diff --git a/swig/swig_interfaces/oc_cloud.i b/swig/swig_interfaces/oc_cloud.i +index 96efda20..dfb825ed 100644 +--- a/swig/swig_interfaces/oc_cloud.i ++++ b/swig/swig_interfaces/oc_cloud.i +@@ -331,4 +331,6 @@ int jni_cloud_provision_conf_resource(oc_cloud_context_t *ctx, + } + %} + +-%include "oc_cloud.h" +\ No newline at end of file ++%ignore oc_cloud_discover_resources; ++ ++%include "oc_cloud.h" diff --git a/extlibs/patchs/remove_cred_by_credid.patch b/extlibs/patchs/remove_cred_by_credid.patch deleted file mode 100644 index c2f1a476d1eaed9032d2ffdec24a8a532b85d334..0000000000000000000000000000000000000000 --- a/extlibs/patchs/remove_cred_by_credid.patch +++ /dev/null @@ -1,49 +0,0 @@ -diff --git a/include/oc_pki.h b/include/oc_pki.h -index acbab8c7..c16b512b 100644 ---- a/include/oc_pki.h -+++ b/include/oc_pki.h -@@ -45,6 +45,9 @@ int oc_pki_add_trust_anchor(size_t device, const unsigned char *cert, - void oc_pki_set_security_profile(size_t device, - oc_sp_types_t supported_profiles, - oc_sp_types_t current_profile, int mfg_credid); -+ -+void oc_pki_remove_credential_by_credid(size_t device, long credid); -+ - #ifdef __cplusplus - } - #endif -diff --git a/security/oc_pki.c b/security/oc_pki.c -index a9306c23..52755576 100644 ---- a/security/oc_pki.c -+++ b/security/oc_pki.c -@@ -354,6 +354,17 @@ oc_pki_add_trust_anchor(size_t device, const unsigned char *cert, - return pki_add_trust_anchor(device, cert, cert_size, OC_CREDUSAGE_TRUSTCA); - } - -+void -+oc_pki_remove_credential_by_credid(size_t device, long credid) -+{ -+ oc_sec_cred_t *cred = oc_sec_get_cred_by_credid(credid, device); -+ if (cred) -+ { -+ oc_sec_remove_cred(cred, device); -+ oc_sec_dump_cred(device); -+ } -+} -+ - #else /* OC_PKI */ - typedef int dummy_declaration; - #endif /* !OC_PKI */ -diff --git a/swig/swig_interfaces/oc_pki.i b/swig/swig_interfaces/oc_pki.i -index 2765e562..9910770c 100644 ---- a/swig/swig_interfaces/oc_pki.i -+++ b/swig/swig_interfaces/oc_pki.i -@@ -105,4 +105,6 @@ void jni_pki_set_security_profile(size_t device, - } - %} - --%include "oc_pki.h" -\ No newline at end of file -+%rename (removeCredentialByCredid) oc_pki_remove_credential_by_credid; -+ -+%include "oc_pki.h" diff --git a/extlibs/patchs/timeout_fix.patch b/extlibs/patchs/timeout_fix.patch deleted file mode 100644 index 9a84a776d1c06c4c07151ce679dcd6c4aca872d3..0000000000000000000000000000000000000000 --- a/extlibs/patchs/timeout_fix.patch +++ /dev/null @@ -1,269 +0,0 @@ -diff --git a/onboarding_tool/obtmain.c b/onboarding_tool/obtmain.c -index 65bf47fa..a4b066ad 100644 ---- a/onboarding_tool/obtmain.c -+++ b/onboarding_tool/obtmain.c -@@ -301,7 +301,7 @@ unowned_device_cb(oc_uuid_t *uuid, oc_endpoint_t *eps, void *data) - eps = eps->next; - } - -- oc_do_get("/oic/d", ep, NULL, &get_device, LOW_QOS, unowned_devices); -+ oc_do_get("/oic/d", ep, NULL, &get_device, HIGH_QOS, unowned_devices); - } - - static void -@@ -319,7 +319,7 @@ owned_device_cb(oc_uuid_t *uuid, oc_endpoint_t *eps, void *data) - eps = eps->next; - } - -- oc_do_get("/oic/d", ep, NULL, &get_device, LOW_QOS, owned_devices); -+ oc_do_get("/oic/d", ep, NULL, &get_device, HIGH_QOS, owned_devices); - } - - static void -@@ -1270,9 +1270,9 @@ main(void) - - int init; - -- static const oc_handler_t handler = {.init = app_init, -- .signal_event_loop = signal_event_loop, -- .requests_entry = issue_requests }; -+ static const oc_handler_t handler = { .init = app_init, -+ .signal_event_loop = signal_event_loop, -+ .requests_entry = issue_requests }; - - oc_storage_config("./onboarding_tool_creds"); - oc_set_factory_presets_cb(factory_presets_cb, NULL); -diff --git a/security/oc_obt.c b/security/oc_obt.c -index b6c28499..ebcc8320 100644 ---- a/security/oc_obt.c -+++ b/security/oc_obt.c -@@ -358,17 +358,9 @@ free_otm_state(oc_otm_ctx_t *o, int status, oc_obt_otm_t otm) - oc_memb_free(&oc_otm_ctx_m, o); - } - --oc_event_callback_retval_t --oc_obt_otm_request_timeout_cb(void *data) --{ -- free_otm_state(data, -1, 0); -- return OC_EVENT_DONE; --} -- - void - oc_obt_free_otm_ctx(oc_otm_ctx_t *ctx, int status, oc_obt_otm_t otm) - { -- oc_remove_delayed_callback(ctx, oc_obt_otm_request_timeout_cb); - free_otm_state(ctx, status, otm); - } - -@@ -772,13 +764,6 @@ free_hard_reset_ctx(oc_hard_reset_ctx_t *ctx, int status) - oc_memb_free(&oc_hard_reset_ctx_m, ctx); - } - --static oc_event_callback_retval_t --hard_reset_timeout_cb(void *data) --{ -- free_hard_reset_ctx(data, -1); -- return OC_EVENT_DONE; --} -- - static void - hard_reset_cb(int status, void *data) - { -@@ -787,7 +772,6 @@ hard_reset_cb(int status, void *data) - return; - } - d->switch_dos = NULL; -- oc_remove_delayed_callback(data, hard_reset_timeout_cb); - free_hard_reset_ctx(data, status); - } - -@@ -821,7 +805,6 @@ oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, - } - - oc_list_add(oc_hard_reset_ctx_l, d); -- oc_set_delayed_callback(d, hard_reset_timeout_cb, OBT_CB_TIMEOUT); - - return 0; - } -@@ -855,17 +838,9 @@ free_credprov_state(oc_credprov_ctx_t *p, int status) - oc_memb_free(&oc_credprov_ctx_m, p); - } - --static oc_event_callback_retval_t --credprov_request_timeout_cb(void *data) --{ -- free_credprov_state(data, -1); -- return OC_EVENT_DONE; --} -- - static void - free_credprov_ctx(oc_credprov_ctx_t *ctx, int status) - { -- oc_remove_delayed_callback(ctx, credprov_request_timeout_cb); - free_credprov_state(ctx, status); - } - -@@ -1382,7 +1357,6 @@ oc_obt_provision_role_certificate(oc_role_t *roles, oc_uuid_t *uuid, - } - - oc_list_add(oc_credprov_ctx_l, p); -- oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT); - - return 0; - } -@@ -1431,7 +1405,6 @@ oc_obt_provision_identity_certificate(oc_uuid_t *uuid, oc_obt_status_cb_t cb, - } - - oc_list_add(oc_credprov_ctx_l, p); -- oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT); - - return 0; - } -@@ -1479,7 +1452,6 @@ oc_obt_provision_pairwise_credentials(oc_uuid_t *uuid1, oc_uuid_t *uuid2, - } - - oc_list_add(oc_credprov_ctx_l, p); -- oc_set_delayed_callback(p, credprov_request_timeout_cb, OBT_CB_TIMEOUT); - - return 0; - } -@@ -1683,17 +1655,9 @@ free_acl2prov_state(oc_acl2prov_ctx_t *request, int status) - oc_memb_free(&oc_acl2prov_m, request); - } - --static oc_event_callback_retval_t --acl2prov_timeout_cb(void *data) --{ -- free_acl2prov_state(data, -1); -- return OC_EVENT_DONE; --} -- - static void - free_acl2prov_ctx(oc_acl2prov_ctx_t *r, int status) - { -- oc_remove_delayed_callback(r, acl2prov_timeout_cb); - free_acl2prov_state(r, status); - } - -@@ -1861,7 +1825,6 @@ oc_obt_provision_ace(oc_uuid_t *uuid, oc_sec_ace_t *ace, - } - - oc_list_add(oc_acl2prov_l, r); -- oc_set_delayed_callback(r, acl2prov_timeout_cb, OBT_CB_TIMEOUT); - - return 0; - } -diff --git a/security/oc_obt_internal.h b/security/oc_obt_internal.h -index d2f0dd3d..9d4d7f71 100644 ---- a/security/oc_obt_internal.h -+++ b/security/oc_obt_internal.h -@@ -28,9 +28,7 @@ extern "C" - { - #endif - --#define DISCOVERY_CB_PERIOD (5) --/* Worst case timeout for all onboarding/provisioning sequences */ --#define OBT_CB_TIMEOUT (15) -+#define DISCOVERY_CB_PERIOD (60) - - /* Used for tracking owned/unowned devices in oc_obt's internal caches */ - typedef struct oc_device_t -diff --git a/security/oc_obt_otm_cert.c b/security/oc_obt_otm_cert.c -index 062b38cb..0f511a64 100644 ---- a/security/oc_obt_otm_cert.c -+++ b/security/oc_obt_otm_cert.c -@@ -396,7 +396,7 @@ obt_cert_7(oc_client_response_t *data) - } - - /** 7) post acl rowneruuid -- */ -+ */ - oc_device_t *device = o->device; - oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint); - -@@ -648,7 +648,6 @@ oc_obt_perform_cert_otm(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, - */ - oc_endpoint_t *ep = oc_obt_get_unsecure_endpoint(device->endpoint); - if (oc_do_get("/oic/d", ep, NULL, &obt_cert_2, HIGH_QOS, o)) { -- oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT); - return 0; - } - -diff --git a/security/oc_obt_otm_justworks.c b/security/oc_obt_otm_justworks.c -index c1ea607e..f4ffeaab 100644 ---- a/security/oc_obt_otm_justworks.c -+++ b/security/oc_obt_otm_justworks.c -@@ -395,7 +395,7 @@ obt_jw_7(oc_client_response_t *data) - } - - /** 7) post acl rowneruuid -- */ -+ */ - oc_device_t *device = o->device; - oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint); - -@@ -647,7 +647,6 @@ oc_obt_perform_just_works_otm(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, - */ - oc_endpoint_t *ep = oc_obt_get_unsecure_endpoint(device->endpoint); - if (oc_do_get("/oic/d", ep, NULL, &obt_jw_2, HIGH_QOS, o)) { -- oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT); - return 0; - } - -diff --git a/security/oc_obt_otm_randompin.c b/security/oc_obt_otm_randompin.c -index 98fb7b1e..b1d03198 100644 ---- a/security/oc_obt_otm_randompin.c -+++ b/security/oc_obt_otm_randompin.c -@@ -396,7 +396,7 @@ obt_rdp_6(oc_client_response_t *data) - } - - /** 6) post acl rowneruuid -- */ -+ */ - oc_device_t *device = o->device; - oc_endpoint_t *ep = oc_obt_get_secure_endpoint(device->endpoint); - -@@ -645,7 +645,6 @@ oc_obt_perform_random_pin_otm(oc_uuid_t *uuid, const unsigned char *pin, - oc_tls_close_connection(ep); - oc_tls_select_psk_ciphersuite(); - if (oc_do_get("/oic/d", ep, NULL, &obt_rdp_2, HIGH_QOS, o)) { -- oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT); - return 0; - } - -@@ -718,7 +717,6 @@ oc_obt_request_random_pin(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb, - oc_rep_set_int(root, oxmsel, 1); - oc_rep_end_root_object(); - if (oc_do_post()) { -- oc_set_delayed_callback(o, oc_obt_otm_request_timeout_cb, OBT_CB_TIMEOUT); - return 0; - } - } -diff --git a/security/oc_tls.c b/security/oc_tls.c -index ba25168f..983ecbe2 100644 ---- a/security/oc_tls.c -+++ b/security/oc_tls.c -@@ -338,6 +338,7 @@ oc_tls_inactive(void *data) - return OC_EVENT_CONTINUE; - } - mbedtls_ssl_close_notify(&peer->ssl_ctx); -+ mbedtls_ssl_close_notify(&peer->ssl_ctx); - oc_tls_free_peer(peer, true); - } - OC_DBG("oc_tls: Terminating DTLS inactivity callback"); -@@ -1292,6 +1293,7 @@ oc_tls_close_connection(oc_endpoint_t *endpoint) - { - oc_tls_peer_t *peer = oc_tls_get_peer(endpoint); - if (peer) { -+ mbedtls_ssl_close_notify(&peer->ssl_ctx); - mbedtls_ssl_close_notify(&peer->ssl_ctx); - oc_tls_free_peer(peer, false); - } -@@ -1687,6 +1689,7 @@ read_application_data(oc_tls_peer_t *peer) - if (peer->role == MBEDTLS_SSL_IS_SERVER && - (peer->endpoint.flags & TCP) == 0) { - mbedtls_ssl_close_notify(&peer->ssl_ctx); -+ mbedtls_ssl_close_notify(&peer->ssl_ctx); - } - oc_tls_free_peer(peer, false); - return; diff --git a/otgc/build.gradle b/otgc/build.gradle index 57261f8fe2e989a33cf6b233073ee40a80d8ca40..91bc28abf878c092e3edc57e37dd550169b49a8c 100644 --- a/otgc/build.gradle +++ b/otgc/build.gradle @@ -30,7 +30,7 @@ android { minSdkVersion 21 targetSdkVersion 28 versionCode 13 - versionName "2.9.0" + versionName "2.10.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" compileOptions { diff --git a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/AmsRepository.java b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/AmsRepository.java index e745f2fbe5364a67846aee5b5519ecd3e5cfd3cd..01c31009276c51ee21eb8662aa68fbafb41cddc5 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/AmsRepository.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/AmsRepository.java @@ -22,28 +22,19 @@ package org.openconnectivity.otgc.data.repository; -import org.iotivity.CborEncoder; import org.iotivity.OCAceConnectionType; import org.iotivity.OCAceResource; import org.iotivity.OCAceWildcard; -import org.iotivity.OCClientResponse; -import org.iotivity.OCEndpoint; -import org.iotivity.OCEndpointUtil; -import org.iotivity.OCMain; import org.iotivity.OCObt; +import org.iotivity.OCObtAclHandler; import org.iotivity.OCObtDeviceStatusHandler; -import org.iotivity.OCQos; -import org.iotivity.OCResponseHandler; +import org.iotivity.OCObtStatusHandler; import org.iotivity.OCSecurityAce; -import org.iotivity.OCStatus; +import org.iotivity.OCSecurityAcl; import org.iotivity.OCUuid; import org.iotivity.OCUuidUtil; -import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAce; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAceResource; -import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAceSubject; -import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAceSubjectType; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAcl; -import org.openconnectivity.otgc.utils.constant.OcfResourceUri; import org.openconnectivity.otgc.utils.constant.OcfWildcard; import java.io.IOException; @@ -65,64 +56,33 @@ public class AmsRepository { } - public Single getAcl(String endpoint, String deviceId) { + public Single getAcl(String deviceId) { return Single.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, uuid); - OCResponseHandler handler = (OCClientResponse response) -> { - if (response.getCode().equals(OCStatus.OC_STATUS_OK)) { - OcAcl acl = new OcAcl(); - acl.parseOCRepresentation(response.getPayload()); - emitter.onSuccess(acl); - } else { - Timber.d("GET ACL error - Status code: " + response.getCode()); - emitter.onError(new Exception("GET ACL error - Status code: " + response.getCode())); - } - }; - - if (!OCMain.doGet(OcfResourceUri.ACL2_URI, ep, null, handler, OCQos.HIGH_QOS)) { - emitter.onError(new Exception("GET ACL error")); - } - - OCEndpointUtil.freeEndpoint(ep); - }); - } + OCObtAclHandler handler = (OCSecurityAcl acl) -> { + if (acl != null) { + OcAcl aclRet = new OcAcl(); + aclRet.parseOCRepresentation(acl); + emitter.onSuccess(aclRet); - private Completable provisionAcl(String endpoint, String deviceId, OcAcl acl) { - return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, uuid); - - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_CHANGED)) { - Timber.d("Provision ACL succeeded"); - emitter.onComplete(); + /* Freeing the ACL structure */ + OCObt.freeAcl(acl); } else { - emitter.onError(new IOException("Provision ACE error")); + String error = "GET ACL error"; + Timber.d(error); + emitter.onError(new Exception(error)); } }; - if (OCMain.initPost(OcfResourceUri.ACL2_URI, ep, null, handler, OCQos.LOW_QOS)) { - CborEncoder root = acl.parseToCbor(); - - if (OCMain.doPost()) { - Timber.d("Sent POST request to /oic/sec/acl2"); - } else { - String error = "Could not send POST request to /oic/sec/acl2"; - Timber.e(error); - emitter.onError(new Exception(error)); - } + int ret = OCObt.retrieveAcl(uuid, handler); + if (ret >= 0) { + Timber.d("Successfully issued request to RETRIEVE /oic/sec/acl2"); } else { - String error = "Could not init POST request to /oic/sec/acl2"; + String error = "ERROR issuing request to RETRIEVE /oic/sec/acl2"; Timber.e(error); emitter.onError(new Exception(error)); } - - OCEndpointUtil.freeEndpoint(ep); }); } @@ -162,22 +122,6 @@ public class AmsRepository { }); } - public Completable provisionUuidAcl(String endpoint, String deviceId, String subjectId, List verticalResources, long permission) { - OcAceSubject subject = new OcAceSubject(); - subject.setType(OcAceSubjectType.UUID_TYPE); - subject.setUuid(subjectId); - OcAce ace = new OcAce(); - ace.setSubject(subject); - ace.setPermission((permission)); - ace.setResources(getResources(verticalResources)); - List aceList = new ArrayList<>(); - aceList.add(ace); - - OcAcl acl = new OcAcl(); - acl.setAceList(aceList); - return provisionAcl(endpoint, deviceId, acl); - } - public Completable provisionUuidAce(String deviceId, String subjectId, List verticalResources, long permission) { OCUuid di = OCUuidUtil.stringToUuid(subjectId); @@ -191,23 +135,6 @@ public class AmsRepository { return provisionAce(deviceId, ace, verticalResources, permission); } - public Completable provisionRoleAcl(String endpoint, String deviceId, String roleId, String roleAuthority, List verticalResources, long permission) { - OcAceSubject subject = new OcAceSubject(); - subject.setType(OcAceSubjectType.ROLE_TYPE); - subject.setRoleId(roleId); - subject.setAuthority(roleAuthority); - OcAce ace = new OcAce(); - ace.setSubject(subject); - ace.setPermission(permission); - ace.setResources(getResources(verticalResources)); - List aceList = new ArrayList<>(); - aceList.add(ace); - - OcAcl acl = new OcAcl(); - acl.setAceList(aceList); - return provisionAcl(endpoint, deviceId, acl); - } - public Completable provisionRoleAce(String deviceId, String roleId, String roleAuthority, List verticalResources, long permission) { OCSecurityAce ace = OCObt.newAceForRole(roleId, roleAuthority); if (ace == null) { @@ -219,22 +146,6 @@ public class AmsRepository { return provisionAce(deviceId, ace, verticalResources, permission); } - public Completable provisionConntypeAcl(String endpoint, String deviceId, boolean isAuthCrypt, List verticalResources, long permission) { - OcAceSubject subject = new OcAceSubject(); - subject.setType(OcAceSubjectType.CONN_TYPE); - subject.setConnType(isAuthCrypt ? "auth-crypt" : "anon-clear"); - OcAce ace = new OcAce(); - ace.setSubject(subject); - ace.setPermission(permission); - ace.setResources(getResources(verticalResources)); - List aceList = new ArrayList<>(); - aceList.add(ace); - - OcAcl acl = new OcAcl(); - acl.setAceList(aceList); - return provisionAcl(endpoint, deviceId, acl); - } - public Completable provisionConntypeAce(String deviceId, boolean isAuthCrypt, List verticalResources, long permission) { OCSecurityAce ace = OCObt.newAceForConnection(isAuthCrypt ? OCAceConnectionType.OC_CONN_AUTH_CRYPT : OCAceConnectionType.OC_CONN_ANON_CLEAR); if (ace == null) { @@ -298,29 +209,27 @@ public class AmsRepository { }); } - public Completable deleteAcl(String endpoint, String deviceId, long aceId) { + public Completable deleteAcl(String deviceId, long aceId) { return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, uuid); - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_DELETED)) { + OCObtStatusHandler handler = (int status) -> { + if (status >= 0) { Timber.d("Delete ACE succeeded"); emitter.onComplete(); } else { - emitter.onError(new IOException("Delete ACE error")); + emitter.onError(new Exception("Delete ACE error")); } }; - if (!OCMain.doDelete(OcfResourceUri.ACL2_URI, ep, OcfResourceUri.DELETE_ACE_QUERY + aceId, handler, OCQos.HIGH_QOS)) { + int ret = OCObt.deleteAceByAceId(uuid, (int)aceId, handler); + if (ret >= 0) { + Timber.d("Successfully issued request to DELETE /oic/sec/acl2 with aceid=" + aceId); + } else { String error = "Could not send DELETE request to /oic/sec/acl2 with aceid=" + aceId; Timber.e(error); emitter.onError(new Exception(error)); } - - OCEndpointUtil.freeEndpoint(ep); }); } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/CmsRepository.java b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/CmsRepository.java index 682e57fdcbdb8a7c7c8e1dc0e3e9edeb6331370b..b21484de76f64f1376deb039b206db9d071e25d7 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/CmsRepository.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/CmsRepository.java @@ -23,26 +23,16 @@ package org.openconnectivity.otgc.data.repository; import org.iotivity.*; -import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredPrivateData; -import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredPublicData; -import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredRole; -import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredentials; import org.openconnectivity.otgc.domain.model.resource.secure.csr.OcCsr; -import org.openconnectivity.otgc.utils.constant.OcfCredType; -import org.openconnectivity.otgc.utils.constant.OcfCredUsage; -import org.openconnectivity.otgc.utils.constant.OcfEncoding; import org.openconnectivity.otgc.utils.constant.OcfResourceUri; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; import io.reactivex.Completable; -import io.reactivex.CompletableSource; import io.reactivex.Single; import timber.log.Timber; @@ -54,30 +44,33 @@ public class CmsRepository { } - public Single getCredentials(String endpoint, String deviceId) { + public Single getCredentials(String deviceId) { return Single.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, uuid); - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK)) { + OCObtCredsHandler handler = (OCCreds credentials) -> { + if (credentials != null) { OcCredentials creds = new OcCredentials(); - creds.parseOCRepresentation(response.getPayload()); + creds.parseOCRepresentation(credentials); emitter.onSuccess(creds); + /* Freeing the credential structure */ + OCObt.freeCreds(credentials); } else { String error = "GET credentials error"; + Timber.e(error); emitter.onError(new Exception(error)); } }; - if (!OCMain.doGet(OcfResourceUri.CRED_URI, ep, null, handler, OCQos.HIGH_QOS)) { + int ret = OCObt.retrieveCreds(uuid, handler); + if (ret >= 0) { + System.out.println("\nSuccessfully issued request to RETRIEVE /oic/sec/cred"); + Timber.d("Successfully issued request to retrieve the credentials"); + } else { String error = "GET credentials error"; + Timber.e(error); emitter.onError(new Exception(error)); } - - OCEndpointUtil.freeEndpoint(ep); }); } @@ -106,108 +99,6 @@ public class CmsRepository { }); } - public Completable provisionTrustAnchor(String endpoint, String deviceId, String rootCert) { - return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid di = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, di); - - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_CHANGED)) { - Timber.d("Provision root certificate succeeded"); - emitter.onComplete(); - } else { - emitter.onError(new IOException("Provision root certificate error")); - } - }; - - if (OCMain.initPost(OcfResourceUri.CRED_URI, ep, null, handler, OCQos.HIGH_QOS)) { - OcCredPublicData publicData = new OcCredPublicData(); - publicData.setPemData(rootCert); - publicData.setEncoding(OcfEncoding.OC_ENCODING_PEM); - - OcCredential cred = new OcCredential(); - cred.setSubjectuuid("*"); - cred.setCredtype(OcfCredType.OC_CREDTYPE_CERT); - cred.setCredusage(OcfCredUsage.OC_CREDUSAGE_TRUSTCA); - cred.setPublicData(publicData); - List credList = new ArrayList<>(); - credList.add(cred); - - OcCredentials creds = new OcCredentials(); - creds.setCredList(credList); - - CborEncoder root = creds.parseToCbor(); - if (OCMain.doPost()) { - Timber.d("Sent POST request to /oic/sec/cred"); - } else { - String error = "Could not send POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - } else { - String error = "Could not init POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - - OCEndpointUtil.freeEndpoint(ep); - }); - } - - public Completable provisionIdentityCertificate(String endpoint, String deviceId, String rootCert, String identityCert) { - return provisionTrustAnchor(endpoint, deviceId, rootCert) - .andThen( - Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid di = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, di); - - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_CHANGED)) { - Timber.d("Provision identity certificate succeeded"); - emitter.onComplete(); - } else { - emitter.onError(new IOException("Provision identity certificate error")); - } - }; - - if (OCMain.initPost(OcfResourceUri.CRED_URI, ep, null, handler, OCQos.HIGH_QOS)) { - OcCredPublicData publicData = new OcCredPublicData(); - publicData.setPemData(identityCert); - publicData.setEncoding(OcfEncoding.OC_ENCODING_PEM); - - OcCredential cred = new OcCredential(); - cred.setSubjectuuid(deviceId); - cred.setCredtype(OcfCredType.OC_CREDTYPE_CERT); - cred.setCredusage(OcfCredUsage.OC_CREDUSAGE_CERT); - cred.setPublicData(publicData); - List credList = new ArrayList<>(); - credList.add(cred); - - OcCredentials creds = new OcCredentials(); - creds.setCredList(credList); - - CborEncoder root = creds.parseToCbor(); - if (OCMain.doPost()) { - Timber.d("Sent POST request to /oic/sec/cred"); - } else { - String error = "Could not send POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - } else { - String error = "Could not init POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - - OCEndpointUtil.freeEndpoint(ep); - })); - } - public Completable provisionIdentityCertificate(String deviceId) { return Completable.create(emitter -> { OCUuid di = OCUuidUtil.stringToUuid(deviceId); @@ -228,61 +119,6 @@ public class CmsRepository { }); } - public Completable provisionRoleCertificate(String endpoint, String deviceId, String roleCert, String roleId, String roleAuthority) { - return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid di = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, di); - - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_CHANGED)) { - Timber.d("Provision role certificate succeeded"); - emitter.onComplete(); - } else { - emitter.onError(new IOException("Provision role certificate error")); - } - }; - - if (OCMain.initPost(OcfResourceUri.CRED_URI, ep, null, handler, OCQos.HIGH_QOS)) { - OcCredPublicData publicData = new OcCredPublicData(); - publicData.setPemData(roleCert); - publicData.setEncoding(OcfEncoding.OC_ENCODING_PEM); - - OcCredRole role = new OcCredRole(); - role.setRole(roleId); - role.setAuthority(roleAuthority); - - OcCredential cred = new OcCredential(); - cred.setSubjectuuid(deviceId); - cred.setCredtype(OcfCredType.OC_CREDTYPE_CERT); - cred.setCredusage(OcfCredUsage.OC_CREDUSAGE_ROLECERT); - cred.setPublicData(publicData); - cred.setRoleid(role); - List credList = new ArrayList<>(); - credList.add(cred); - - OcCredentials creds = new OcCredentials(); - creds.setCredList(credList); - - CborEncoder root = creds.parseToCbor(); - if (OCMain.doPost()) { - Timber.d("Sent POST request to /oic/sec/cred"); - } else { - String error = "Could not send POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - } else { - String error = "Could not init POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - - OCEndpointUtil.freeEndpoint(ep); - }); - } - public Completable provisionRoleCertificate(String deviceId, String roleId, String roleAuthority) { return Completable.create(emitter -> { OCUuid di = OCUuidUtil.stringToUuid(deviceId); @@ -306,55 +142,6 @@ public class CmsRepository { }); } - public Completable createPskCredential(String endpoint, String deviceId, String targetUuid, byte[] symmetricKey) { - return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid di = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, di); - - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code.equals(OCStatus.OC_STATUS_OK) || code.equals(OCStatus.OC_STATUS_CHANGED)) { - Timber.d("Provision identity certificate succeeded"); - emitter.onComplete(); - } else { - emitter.onError(new IOException("Provision identity certificate error")); - } - }; - - if (OCMain.initPost(OcfResourceUri.CRED_URI, ep, null, handler, OCQos.HIGH_QOS)) { - OcCredPrivateData privateData = new OcCredPrivateData(); - privateData.setDataDer(symmetricKey); - privateData.setEncoding(OcfEncoding.OC_ENCODING_RAW); - - OcCredential cred = new OcCredential(); - cred.setSubjectuuid(targetUuid); - cred.setCredtype(OcfCredType.OC_CREDTYPE_PSK); - cred.setPrivateData(privateData); - List credList = new ArrayList<>(); - credList.add(cred); - - OcCredentials creds = new OcCredentials(); - creds.setCredList(credList); - - CborEncoder root = creds.parseToCbor(); - if (OCMain.doPost()) { - Timber.d("Sent POST request to /oic/sec/cred"); - } else { - String error = "Could not send POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - } else { - String error = "Could not init POST request to /oic/sec/cred"; - Timber.e(error); - emitter.onError(new Exception(error)); - } - - OCEndpointUtil.freeEndpoint(ep); - }); - } - public Completable provisionPairwiseCredential(String clientId, String serverId) { return Completable.create(emitter -> { OCUuid cliendDi = OCUuidUtil.stringToUuid(clientId); @@ -382,16 +169,12 @@ public class CmsRepository { }); } - public Completable deleteCredential(String endpoint, String deviceId, long credId) { + public Completable deleteCredential(String deviceId, long credId) { return Completable.create(emitter -> { - OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]); - OCUuid di = OCUuidUtil.stringToUuid(deviceId); - OCEndpointUtil.setDi(ep, di); + OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); - OCResponseHandler handler = (OCClientResponse response) -> { - OCStatus code = response.getCode(); - if (code == OCStatus.OC_STATUS_OK - || code == OCStatus.OC_STATUS_DELETED) { + OCObtStatusHandler handler = (int status) -> { + if (status >= 0) { Timber.d("Delete credential success"); emitter.onComplete(); } else { @@ -401,13 +184,22 @@ public class CmsRepository { } }; - if (!OCMain.doDelete(OcfResourceUri.CRED_URI, ep, OcfResourceUri.DELETE_CRED_QUERY + credId, handler, OCQos.HIGH_QOS)) { + int ret = OCObt.deleteCredByCredId(uuid, (int)credId, handler); + if (ret >= 0) { + Timber.d("Successfully issued request to DELETE /oic/sec/cred"); + } else { String error = "DELETE request to /oic/sec/cred error"; Timber.d(error); emitter.onError(new Exception(error)); } + }); + } - OCEndpointUtil.freeEndpoint(ep); + public Single retrieveOwnCredentials() { + return Single.create(emitter -> { + OcCredentials creds = new OcCredentials(); + creds.parseOCRepresentation(OCObt.retrieveOwnCreds()); + emitter.onSuccess(creds); }); } @@ -425,10 +217,17 @@ public class CmsRepository { }); } - public Completable removeTrustAnchor(long device, long credid) { + public Completable removeTrustAnchor(long credid) { return Completable.create(emitter -> { - OCPki.removeCredentialByCredid(device, (int)credid); - emitter.onComplete(); + int ret = OCObt.deleteOwnCredByCredId((int)credid); + if (ret >= 0) { + Timber.d("Successfully DELETED cred"); + emitter.onComplete(); + } else { + String error = "ERROR DELETING cred"; + Timber.e(error); + emitter.onError(new Exception(error)); + } }); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IORepository.java b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IORepository.java index c98c061b0d8eb6a2a20791949bb9e1e43b749fac..17f2c81162f09ae71a4e22e00047b68a839ad756 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IORepository.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IORepository.java @@ -168,8 +168,10 @@ public class IORepository { byte[] fileBytes; try (InputStream inputStream = mContext.getAssets().open(path)) { - fileBytes = new byte[inputStream.available()]; + int numBytes = inputStream.available() + 1; + fileBytes = new byte[numBytes]; inputStream.read(fileBytes); + fileBytes[numBytes - 1] = '\0'; } return fileBytes; diff --git a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IotivityRepository.java b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IotivityRepository.java index 41268d0809dfcb62044c088d7e64e3d918df1ea4..604f92ac27eede1984eced4269ec1a013ae2ebda 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IotivityRepository.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/data/repository/IotivityRepository.java @@ -26,7 +26,10 @@ import android.content.Context; import org.iotivity.CborEncoder; import org.iotivity.OCBufferSettings; import org.iotivity.OCClientResponse; +import org.iotivity.OCCloud; import org.iotivity.OCCoreRes; +import org.iotivity.OCDiscoveryAllHandler; +import org.iotivity.OCDiscoveryFlags; import org.iotivity.OCEndpoint; import org.iotivity.OCEndpointUtil; import org.iotivity.OCFactoryPresetsHandler; @@ -64,6 +67,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -519,6 +523,68 @@ public class IotivityRepository { }); } + public Observable discoverAllResources(String deviceId) { + return Observable.create(emitter -> { + OCUuid uuid = OCUuidUtil.stringToUuid(deviceId); + + OCDiscoveryAllHandler handler = + (String anchor, String uri, String[] types, int interfaceMask, OCEndpoint endpoints, + int resourcePropertiesMask, boolean more) -> { + OcResource resource = new OcResource(); + resource.setAnchor(anchor); + resource.setHref(uri); + + List epList = new ArrayList<>(); + OCEndpoint ep = endpoints; + while (ep != null) { + OcEndpoint endpoint = new OcEndpoint(); + endpoint.setEndpoint(OCEndpointUtil.toString(ep)); + epList.add(endpoint); + ep = ep.getNext(); + } + resource.setEndpoints(epList); + resource.setPropertiesMask((long)resourcePropertiesMask); + resource.setResourceTypes(Arrays.asList(types)); + emitter.onNext(resource); + + if(!more) { + emitter.onComplete(); + return OCDiscoveryFlags.OC_STOP_DISCOVERY; + } + return OCDiscoveryFlags.OC_CONTINUE_DISCOVERY; + }; + + int ret = OCObt.discoverAllResources(uuid, handler); + if (ret >= 0) + { + Timber.d("Successfully issued resource discovery request"); + } else { + String error = "ERROR issuing resource discovery request"; + Timber.e(error); + emitter.onError(new Exception(error)); + } + }); + } + + public Single> discoverVerticalResources(String deviceId) { + return discoverAllResources(deviceId) + .toList() + .map(resources -> { + List resourceList = new ArrayList<>(); + for (OcResource resource : resources) { + for (String resourceType : resource.getResourceTypes()) { + if (OcfResourceType.isVerticalResourceType(resourceType) + && !resourceType.startsWith("oic.d.")) { + resourceList.add(resource); + break; + } + } + } + + return resourceList; + }); + } + public Single findResource(String host, String resourceType) { return Single.create(emitter -> { OCEndpoint ep = OCEndpointUtil.stringToEndpoint(host, new String[1]); diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAce.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAce.java index 4348560eb3d1b924f279c41435f8b551ddb047a4..f5c183bcaf2e5afba6e5d1793494615c2fa3a962 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAce.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAce.java @@ -22,18 +22,16 @@ package org.openconnectivity.otgc.domain.model.resource.secure.acl; -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCAceResource; +import org.iotivity.OCSecurityAce; import java.util.ArrayList; import java.util.List; public class OcAce { - private Long aceid; - private Long permission; + private Integer aceid; + private Integer permission; private OcAceSubject subject; private List resources; @@ -41,19 +39,19 @@ public class OcAce { this.resources = new ArrayList<>(); } - public Long getAceid() { + public Integer getAceid() { return aceid; } - public void setAceid(Long aceid) { + public void setAceid(Integer aceid) { this.aceid = aceid; } - public Long getPermission() { + public Integer getPermission() { return permission; } - public void setPermission(Long permission) { + public void setPermission(Integer permission) { this.permission = permission; } @@ -73,56 +71,27 @@ public class OcAce { this.resources = resources; } - public void parseOCRepresentation(OCRepresentation rep) { + public void parseOCRepresentation(OCSecurityAce ace) { /* aceid */ - Long aceid = OCRep.getLong(rep, OcfResourceAttributeKey.ACE_ID_KEY); + Integer aceid = ace.getAceid(); this.setAceid(aceid); /* permission */ - Long permission = OCRep.getLong(rep, OcfResourceAttributeKey.PERMISSION_KEY); + Integer permission = ace.getPermission(); this.setPermission(permission); /* subject */ - OCRepresentation subjectObj = OCRep.getObject(rep, OcfResourceAttributeKey.SUBJECT_KEY); OcAceSubject subject = new OcAceSubject(); - subject.parseOCRepresentation(subjectObj); + subject.parseOCRepresentation(ace.getSubjectType(), ace.getSubject()); this.setSubject(subject); /* resources */ - OCRepresentation resourcesObj = OCRep.getObjectArray(rep, OcfResourceAttributeKey.RESOURCES_KEY); + OCAceResource res = ace.getResourcesListHead(); List resources = new ArrayList<>(); - while (resourcesObj != null) { + while (res != null) { OcAceResource resource = new OcAceResource(); - resource.parseOCRepresentation(resourcesObj.getValue().getObject()); + resource.parseOCRepresentation(res); resources.add(resource); - resourcesObj = resourcesObj.getNext(); - } - this.setResources(resources); - } - - public void parseToCbor(CborEncoder aclist2) { - CborEncoder aceObj = OCRep.beginObject(aclist2); - /* aceid */ - if (this.getAceid() != null) { - OCRep.setLong(aceObj, OcfResourceAttributeKey.ACE_ID_KEY, this.getAceid()); - } - /* subject */ - if (this.getSubject() != null) { - CborEncoder subjectObj = OCRep.openObject(aceObj, OcfResourceAttributeKey.SUBJECT_KEY); - this.getSubject().parseToCbor(subjectObj); - OCRep.closeObject(aceObj, subjectObj); + res = res.getNext(); } - /* resources */ - if (this.getResources() != null) { - CborEncoder resArray = OCRep.openArray(aceObj, OcfResourceAttributeKey.RESOURCES_KEY); - for (OcAceResource res : this.getResources()) { - res.parseToCbor(resArray); - } - OCRep.closeArray(aceObj, resArray); - } - /* permission */ - if (this.getPermission() != 0) { - OCRep.setLong(aceObj, OcfResourceAttributeKey.PERMISSION_KEY, this.getPermission()); - } - - OCRep.closeObject(aclist2, aceObj); + this.setResources(resources); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceResource.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceResource.java index 392ad22e5c87e44fd7c8bac4b615f6433ccf92a3..9ee86fcfcd7aa6074f9df83391b6d65f480cc8e2 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceResource.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceResource.java @@ -22,13 +22,9 @@ package org.openconnectivity.otgc.domain.model.resource.secure.acl; -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCAceResource; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class OcAceResource { @@ -75,49 +71,26 @@ public class OcAceResource { this.interfaces = interfaces; } - public void parseOCRepresentation(OCRepresentation rep) { - /* href */ - String href = OCRep.getString(rep, OcfResourceAttributeKey.HREF_KEY); - this.setHref(href); - /* wc */ - String wc = OCRep.getString(rep, OcfResourceAttributeKey.WILDCARD_KEY); - this.setWildCard(wc); - /* rt */ - String[] resourceTypes = OCRep.getStringArray(rep, OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - this.setResourceTypes(resourceTypes != null ? Arrays.asList(resourceTypes) : null); - /* if */ - String[] interfaces = OCRep.getStringArray(rep, OcfResourceAttributeKey.INTERFACES_KEY); - this.setInterfaces(interfaces != null ? Arrays.asList(interfaces) : null); - } - - public void parseToCbor(CborEncoder resArray) { - CborEncoder resObj = OCRep.beginObject(resArray); - - /* href */ - if (this.getHref() != null && !this.getHref().isEmpty()) { - OCRep.setTextString(resObj, OcfResourceAttributeKey.HREF_KEY, this.getHref()); - } - /* wc */ - if (this.getWildcard() != null && !this.getWildcard().isEmpty()) { - OCRep.setTextString(resObj, OcfResourceAttributeKey.WILDCARD_KEY, this.getWildcard()); - } - /* rt */ - if (this.getResourceTypes() != null && !this.getResourceTypes().isEmpty()) { - CborEncoder resourceType = OCRep.openArray(resObj, OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - for (String rtStr : this.getResourceTypes()) { - OCRep.addTextString(resourceType, rtStr); - } - OCRep.closeArray(resObj, resourceType); - } - /* if */ - if (this.getInterfaces() != null && !this.getInterfaces().isEmpty()) { - CborEncoder interfaces = OCRep.openArray(resObj, OcfResourceAttributeKey.INTERFACES_KEY); - for (String ifStr : this.getInterfaces()) { - OCRep.addTextString(interfaces, ifStr); + public void parseOCRepresentation(OCAceResource res) { + if (res.getHref() != null && !res.getHref().isEmpty()) { + /* href */ + String href = res.getHref(); + this.setHref(href); + } else if (res.getWildcard() != null) { + /* wc */ + switch (res.getWildcard()) { + case OC_ACE_WC_ALL: + this.setWildCard("*"); + break; + case OC_ACE_WC_ALL_SECURED: + this.setWildCard("+"); + break; + case OC_ACE_WC_ALL_PUBLIC: + this.setWildCard("-"); + break; + default: + break; } - OCRep.closeArray(resObj, interfaces); } - - OCRep.closeObject(resArray, resObj); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceSubject.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceSubject.java index bd7838b8680b3ef0ab922737311876e1b1a6dd5b..9846077bac953b132d0aa3fe963e8b5596e268a4 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceSubject.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAceSubject.java @@ -22,14 +22,14 @@ package org.openconnectivity.otgc.domain.model.resource.secure.acl; -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCAceConnectionType; +import org.iotivity.OCAceSubject; +import org.iotivity.OCAceSubjectType; +import org.iotivity.OCUuidUtil; public class OcAceSubject { - private OcAceSubjectType type; + private String type; private String connType; private String uuid; private String roleId; @@ -39,11 +39,11 @@ public class OcAceSubject { } - public OcAceSubjectType getType() { + public String getType() { return type; } - public void setType(OcAceSubjectType type) { + public void setType(String type) { this.type = type; } @@ -79,42 +79,21 @@ public class OcAceSubject { this.authority = authority; } - public void parseOCRepresentation(OCRepresentation rep) { - while (rep != null) { - switch (rep.getType()) { - case OC_REP_STRING: - if (rep.getName().equals(OcfResourceAttributeKey.UUID_TYPE_KEY)) { - this.setType(OcAceSubjectType.UUID_TYPE); - this.setUuid(rep.getValue().getString()); - } else if (rep.getName().equals(OcfResourceAttributeKey.CONN_TYPE_KEY)) { - this.setType(OcAceSubjectType.CONN_TYPE); - this.setConnType(rep.getValue().getString()); - } else if (rep.getName().equals(OcfResourceAttributeKey.ROLE_AUTHORITY_KEY) || rep.getName().equals(OcfResourceAttributeKey.ROLE_KEY)) { - this.setType(OcAceSubjectType.ROLE_TYPE); - if (rep.getName().equals(OcfResourceAttributeKey.ROLE_KEY)) { - this.setRoleId(rep.getValue().getString()); - } else { - this.setAuthority(rep.getValue().getString()); - } - } - break; - default: - break; + public void parseOCRepresentation(OCAceSubjectType subjectType, OCAceSubject subject) { + this.setType(subjectType.toString()); + if (subjectType == OCAceSubjectType.OC_SUBJECT_UUID) { + this.setUuid(OCUuidUtil.uuidToString(subject.getUuid())); + } else if (subjectType == OCAceSubjectType.OC_SUBJECT_ROLE) { + this.setRoleId(subject.getRole()); + if (subject.getAuthority() != null && !subject.getAuthority().isEmpty()) { + this.setAuthority(subject.getAuthority()); + } + } else if (subjectType == OCAceSubjectType.OC_SUBJECT_CONN) { + if (subject.getConn() == OCAceConnectionType.OC_CONN_AUTH_CRYPT) { + this.setConnType("auth-crypt"); + } else { + this.setConnType("anon-clear"); } - - rep = rep.getNext(); - } - } - - public void parseToCbor(CborEncoder parent) { - /* subject */ - if (this.getType().equals(OcAceSubjectType.UUID_TYPE)) { - OCRep.setTextString(parent, OcfResourceAttributeKey.UUID_TYPE_KEY, this.getUuid()); - } else if (this.getType().equals(OcAceSubjectType.CONN_TYPE)) { - OCRep.setTextString(parent, OcfResourceAttributeKey.CONN_TYPE_KEY, this.getConnType()); - } else if (this.getType().equals(OcAceSubjectType.ROLE_TYPE)) { - OCRep.setTextString(parent, OcfResourceAttributeKey.ROLE_KEY, this.getRoleId()); - OCRep.setTextString(parent, OcfResourceAttributeKey.ROLE_AUTHORITY_KEY, this.getAuthority()); } } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAcl.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAcl.java index 7dec271376b7f2435779f37eaf30a1f991e86db5..eba02760b65fb67388e1c6e4783fc366a3d99c6f 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAcl.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/acl/OcAcl.java @@ -22,14 +22,12 @@ package org.openconnectivity.otgc.domain.model.resource.secure.acl; -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; +import org.iotivity.OCSecurityAce; +import org.iotivity.OCSecurityAcl; +import org.iotivity.OCUuidUtil; import org.openconnectivity.otgc.domain.model.resource.OcResourceBase; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class OcAcl extends OcResourceBase { @@ -57,63 +55,20 @@ public class OcAcl extends OcResourceBase { this.rownerUuid = rownerUuid; } - public void parseOCRepresentation(OCRepresentation rep) { + public void parseOCRepresentation(OCSecurityAcl acl) { /* aclist2 */ - OCRepresentation aclist2Obj = OCRep.getObjectArray(rep, OcfResourceAttributeKey.ACE_LIST_KEY); + OCSecurityAce ac = acl.getSubjectsListHead(); List aceList = new ArrayList<>(); - while (aclist2Obj != null) { + while (ac != null) { OcAce ace = new OcAce(); - ace.parseOCRepresentation(aclist2Obj.getValue().getObject()); + ace.parseOCRepresentation(ac); aceList.add(ace); - aclist2Obj = aclist2Obj.getNext(); + + ac = ac.getNext(); } this.setAceList(aceList); /* rowneruuid */ - String rowneruuid = OCRep.getString(rep, OcfResourceAttributeKey.ROWNER_UUID_KEY); + String rowneruuid = OCUuidUtil.uuidToString(acl.getRowneruuid()); this.setRownerUuid(rowneruuid); - /* rt */ - String[] resourceTypes = OCRep.getStringArray(rep, OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - this.setResourceTypes(Arrays.asList(resourceTypes)); - /* if */ - String[] interfaces = OCRep.getStringArray(rep, OcfResourceAttributeKey.INTERFACES_KEY); - this.setInterfaces(Arrays.asList(interfaces)); } - - public CborEncoder parseToCbor() { - CborEncoder root = OCRep.beginRootObject(); - - /* aclist2 */ - if (this.getAceList() != null && !this.getAceList().isEmpty()) { - CborEncoder aclist2 = OCRep.openArray(root, OcfResourceAttributeKey.ACE_LIST_KEY); - for (OcAce ace : this.getAceList()) { - ace.parseToCbor(aclist2); - } - OCRep.closeArray(root, aclist2); - } - - if (this.getRownerUuid() != null && !this.getRownerUuid().isEmpty()) { - OCRep.setTextString(root, OcfResourceAttributeKey.ROWNER_UUID_KEY, this.getRownerUuid()); - } - - if (this.getResourceTypes() != null && !this.getResourceTypes().isEmpty()) { - CborEncoder resourceType = OCRep.openArray(root, OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - for (String rtStr : this.getResourceTypes()) { - OCRep.addTextString(resourceType, rtStr); - } - OCRep.closeArray(root, resourceType); - } - - if (this.getInterfaces() != null && !this.getInterfaces().isEmpty()) { - CborEncoder interfaces = OCRep.openArray(root, OcfResourceAttributeKey.INTERFACES_KEY); - for (String ifStr : this.getInterfaces()) { - OCRep.addTextString(interfaces, ifStr); - } - OCRep.closeArray(root, interfaces); - } - - OCRep.endRootObject(); - - return root; - } - } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPrivateData.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPrivateData.java index 9e3de679259e75b163ec10e480aea682293908fd..adaf43687059e46d383cbf30134c1f8ffb37c919 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPrivateData.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPrivateData.java @@ -22,17 +22,14 @@ package org.openconnectivity.otgc.domain.model.resource.secure.cred; -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfEncoding; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCCredData; +import org.iotivity.OCCredUtil; public class OcCredPrivateData { private byte[] dataDer; private String dataPem; - private OcfEncoding encoding; + private String encoding; public OcCredPrivateData() { @@ -54,37 +51,20 @@ public class OcCredPrivateData { this.dataPem = dataPem; } - public OcfEncoding getEncoding() { + public String getEncoding() { return encoding; } - public void setEncoding(OcfEncoding encoding) { + public void setEncoding(String encoding) { this.encoding = encoding; } - public void parseOCRepresentation(OCRepresentation rep) { - /* data DER format */ - byte[] dataDer = OCRep.getByteString(rep, OcfResourceAttributeKey.DATA_KEY); - this.setDataDer(dataDer); + public void parseOCRepresentation(OCCredData data) { /* data PEM format */ - String dataPem = OCRep.getString(rep, OcfResourceAttributeKey.DATA_KEY); + String dataPem = data.getData(); this.setDataPem(dataPem); /* encoding */ - String encoding = OCRep.getString(rep, OcfResourceAttributeKey.ENCODING_KEY); - this.setEncoding(OcfEncoding.valueToEnum(encoding)); - } - - public void parseToCbor(CborEncoder parent) { - if (this.getEncoding() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.ENCODING_KEY, this.getEncoding().getValue()); - } - - if (this.getDataPem() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.DATA_KEY, this.getDataPem()); - } - - if (this.getDataDer() != null) { - OCRep.setByteString(parent, OcfResourceAttributeKey.DATA_KEY, this.getDataDer()); - } + String encoding = OCCredUtil.readEncoding(data.getEncoding()); + this.setEncoding(encoding); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPublicData.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPublicData.java index b3625b0b12a71b4f28d90c514f074274c33b860c..aaf28fb1798ba9eee9c85096acf7f86ffa9ab399 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPublicData.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredPublicData.java @@ -22,17 +22,12 @@ package org.openconnectivity.otgc.domain.model.resource.secure.cred; -import com.upokecenter.cbor.CBORObject; - -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfEncoding; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCCredData; +import org.iotivity.OCCredUtil; public class OcCredPublicData { - private OcfEncoding encoding; + private String encoding; private String pemData; private byte[] derData; @@ -40,11 +35,11 @@ public class OcCredPublicData { } - public OcfEncoding getEncoding() { + public String getEncoding() { return encoding; } - public void setEncoding(OcfEncoding encoding) { + public void setEncoding(String encoding) { this.encoding = encoding; } @@ -64,51 +59,12 @@ public class OcCredPublicData { this.derData = derData; } - public void parseCbor(CBORObject cbor) { - /* encoding */ - CBORObject encodingObj = cbor.get(OcfResourceAttributeKey.ENCODING_KEY); - if (encodingObj != null) { - String encoding = encodingObj.AsString(); - this.setEncoding(OcfEncoding.valueToEnum(encoding)); - } - /* data */ - CBORObject dataObj = cbor.get(OcfResourceAttributeKey.DATA_KEY); - if (dataObj != null) { - if (encodingObj.AsString().equals(OcfEncoding.OC_ENCODING_DER.getValue())) { - /* data DER format */ - byte[] dataDer = dataObj.GetByteString(); - this.setDerData(dataDer); - } else if (encodingObj.AsString().equals(OcfEncoding.OC_ENCODING_PEM.getValue())) { - /* data PEM format */ - String dataPem = dataObj.AsString(); - this.setPemData(dataPem); - } - } - } - - public void parseOCRepresentation(OCRepresentation rep) { - /* data DER format */ - byte[] dataDer = OCRep.getByteString(rep, OcfResourceAttributeKey.DATA_KEY); - this.setDerData(dataDer); + public void parseOCRepresentation(OCCredData data) { /* data PEM format */ - String dataPem = OCRep.getString(rep, OcfResourceAttributeKey.DATA_KEY); + String dataPem = data.getData(); this.setPemData(dataPem); /* encoding */ - String encoding = OCRep.getString(rep, OcfResourceAttributeKey.ENCODING_KEY); - this.setEncoding(OcfEncoding.valueToEnum(encoding)); - } - - public void parseToCbor(CborEncoder parent) { - if (this.getEncoding() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.ENCODING_KEY, this.getEncoding().getValue()); - } - - if (this.getPemData() != null && !this.getPemData().isEmpty()) { - OCRep.setTextString(parent, OcfResourceAttributeKey.DATA_KEY, this.getPemData()); - } - - if (this.getDerData() != null) { - OCRep.setByteString(parent, OcfResourceAttributeKey.DATA_KEY, this.getDerData()); - } + String encoding = OCCredUtil.readEncoding(data.getEncoding()); + this.setEncoding(encoding); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredRole.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredRole.java index 35130555059c80734f578ded83968445dcda5d14..cd30959ffc6ff3ee91634406058be90e821bd278 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredRole.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredRole.java @@ -22,9 +22,6 @@ package org.openconnectivity.otgc.domain.model.resource.secure.cred; -import com.upokecenter.cbor.CBORObject; - -import org.iotivity.CborEncoder; import org.iotivity.OCRep; import org.iotivity.OCRepresentation; import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; @@ -53,21 +50,6 @@ public class OcCredRole { this.role = role; } - public void parseCbor(CBORObject cbor) { - /* role */ - CBORObject roleObj = cbor.get(OcfResourceAttributeKey.ROLE_KEY); - if (roleObj != null) { - String role = roleObj.AsString(); - this.setRole(role); - } - /* authority */ - CBORObject authorityObj = cbor.get(OcfResourceAttributeKey.ROLE_AUTHORITY_KEY); - if (authorityObj != null) { - String authority = authorityObj.AsString(); - this.setAuthority(authority); - } - } - public void parseOCRepresentation(OCRepresentation rep) { /* role */ String role = OCRep.getString(rep, OcfResourceAttributeKey.ROLE_KEY); @@ -76,15 +58,4 @@ public class OcCredRole { String authority = OCRep.getString(rep, OcfResourceAttributeKey.ROLE_AUTHORITY_KEY); this.setAuthority(authority); } - - public void parseToCbor(CborEncoder parent) { - /* role */ - if (this.getRole() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.ROLE_KEY, this.getRole()); - } - /* authority */ - if (this.getAuthority() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.ROLE_AUTHORITY_KEY, this.getAuthority()); - } - } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredential.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredential.java index a08508d57c313cd2a8e616902fbd99498b7259ed..cd257155e043a52b6aa7b4b95aeb95cc178fea9c 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredential.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredential.java @@ -22,22 +22,17 @@ package org.openconnectivity.otgc.domain.model.resource.secure.cred; -import com.upokecenter.cbor.CBORObject; - -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; -import org.openconnectivity.otgc.utils.constant.OcfCredType; -import org.openconnectivity.otgc.utils.constant.OcfCredUsage; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; +import org.iotivity.OCCred; +import org.iotivity.OCCredUtil; +import org.iotivity.OCUuidUtil; public class OcCredential { - private Long credid; + private Integer credid; private String subjectuuid; private OcCredRole roleid; - private OcfCredType credtype; - private OcfCredUsage credusage; + private String credtype; + private String credusage; private OcCredPublicData publicData; private OcCredPrivateData privateData; private OcCredOptionalData optionalData; @@ -45,11 +40,11 @@ public class OcCredential { public OcCredential() {} - public Long getCredid() { + public Integer getCredid() { return credid; } - public void setCredid(Long credid) { + public void setCredid(Integer credid) { this.credid = credid; } @@ -69,19 +64,19 @@ public class OcCredential { this.roleid = roleid; } - public OcfCredType getCredtype() { + public String getCredtype() { return credtype; } - public void setCredtype(OcfCredType credtype) { + public void setCredtype(String credtype) { this.credtype = credtype; } - public OcfCredUsage getCredusage() { + public String getCredusage() { return credusage; } - public void setCredusage(OcfCredUsage credusage) { + public void setCredusage(String credusage) { this.credusage = credusage; } @@ -117,136 +112,42 @@ public class OcCredential { this.period = period; } - public void parseCbor(CBORObject cbor) { - /* credid */ - CBORObject credidObj = cbor.get(OcfResourceAttributeKey.CRED_ID_KEY); - if (credidObj != null) { - Long credid = credidObj.AsInt64(); - this.setCredid(credid); - } - /* credtype */ - CBORObject credtypeObj = cbor.get(OcfResourceAttributeKey.CRED_TYPE_KEY); - if (credtypeObj != null) { - Long credtype = credtypeObj.AsInt64(); - this.setCredtype(OcfCredType.valueToEnum(credtype.intValue())); - } - /* credusage */ - CBORObject credUsageObj = cbor.get(OcfResourceAttributeKey.CRED_USAGE_KEY); - if (credUsageObj != null) { - String credusage = credUsageObj.AsString(); - this.setCredusage(credusage != null ? OcfCredUsage.valueToEnum(credusage) : null); - } - /* subjectuuid */ - CBORObject subjectuuidObj = cbor.get(OcfResourceAttributeKey.SUBJECTUUID_KEY); - if (subjectuuidObj != null) { - String subjectuuid = subjectuuidObj.AsString(); - this.setSubjectuuid(subjectuuid); - } - /* period */ - CBORObject periodObj = cbor.get(OcfResourceAttributeKey.PERIOD_KEY); - if (periodObj != null) { - String period = periodObj.AsString(); - this.setPeriod(period); - } - /* publicdata */ - CBORObject publicdataObj = cbor.get(OcfResourceAttributeKey.PUBLIC_DATA_KEY); - if (publicdataObj != null) { - OcCredPublicData publicData = new OcCredPublicData(); - publicData.parseCbor(publicdataObj); - this.setPublicData(publicData); - } - /* optionaldata */ - // TODO: - - /* roleid */ - CBORObject roleidObj = cbor.get(OcfResourceAttributeKey.ROLE_ID_KEY); - if (roleidObj != null) { - OcCredRole roleid = new OcCredRole(); - roleid.parseCbor(roleidObj); - this.setRoleid(roleid); - } - } - - public void parseOCRepresentation(OCRepresentation rep) { + public void parseOCRepresentation(OCCred cred) { /* credid */ - Long credid = OCRep.getLong(rep, OcfResourceAttributeKey.CRED_ID_KEY); + Integer credid = cred.getCredId(); this.setCredid(credid); /* credtype */ - Long credtype = OCRep.getLong(rep, OcfResourceAttributeKey.CRED_TYPE_KEY); - this.setCredtype(OcfCredType.valueToEnum(credtype.intValue())); + String credtype = OCCredUtil.credTypeString(cred.getCredType()); + this.setCredtype(credtype); /* credusage */ - String credusage = OCRep.getString(rep, OcfResourceAttributeKey.CRED_USAGE_KEY); - this.setCredusage(credusage != null ? OcfCredUsage.valueToEnum(credusage) : null); + String credusage = OCCredUtil.readCredUsage(cred.getCredUsage()); + this.setCredusage(credusage); /* subjectuuid */ - String subjectuuid = OCRep.getString(rep, OcfResourceAttributeKey.SUBJECTUUID_KEY); + String subjectuuid = OCUuidUtil.uuidToString(cred.getSubjectUuid()); this.setSubjectuuid(subjectuuid); - /* period */ - String period = OCRep.getString(rep, OcfResourceAttributeKey.PERIOD_KEY); - this.setPeriod(period); /* publicdata */ - OCRepresentation publicdataObj = OCRep.getObject(rep, OcfResourceAttributeKey.PUBLIC_DATA_KEY); - if (publicData != null) { + if (cred.getPublicData() != null && + cred.getPublicData().getData() != null && + !cred.getPublicData().getData().isEmpty()) { OcCredPublicData publicData = new OcCredPublicData(); - publicData.parseOCRepresentation(publicdataObj); + publicData.parseOCRepresentation(cred.getPublicData()); this.setPublicData(publicData); } - /* optionaldata */ - OCRepresentation optionaldataObj = OCRep.getObject(rep, OcfResourceAttributeKey.OPTIONAL_DATA_KEY); - if (optionalData != null) { - OcCredOptionalData optionalData = new OcCredOptionalData(); - optionalData.parseOCRepresentation(optionaldataObj); - this.setOptionalData(optionalData); - } + /* privatedata */ + OcCredPrivateData privateData = new OcCredPrivateData(); + privateData.parseOCRepresentation(cred.getPrivateData()); + this.setPrivateData(privateData); /* roleid */ - OCRepresentation roleidObj = OCRep.getObject(rep, OcfResourceAttributeKey.ROLE_ID_KEY); - if (roleidObj != null) { + if (cred.getRole() != null) { OcCredRole roleid = new OcCredRole(); - roleid.parseOCRepresentation(roleidObj); - this.setRoleid(roleid); - } - } - - public void parseToCbor(CborEncoder parent) { - if (this.getCredid() != null) { - OCRep.setLong(parent, OcfResourceAttributeKey.CRED_ID_KEY, this.getCredid()); - } + if (!cred.getRole().isEmpty()) { + roleid.setRole(cred.getRole()); + } - if (this.getSubjectuuid() != null && !this.getSubjectuuid().isEmpty()) { - OCRep.setTextString(parent, OcfResourceAttributeKey.SUBJECTUUID_KEY, this.getSubjectuuid()); - } - - if (this.getRoleid() != null) { - CborEncoder roleId = OCRep.openObject(parent, OcfResourceAttributeKey.ROLE_ID_KEY); - this.getRoleid().parseToCbor(roleId); - OCRep.closeObject(parent, roleId); - } - - if (this.getCredtype() != null) { - OCRep.setLong(parent, OcfResourceAttributeKey.CRED_TYPE_KEY, this.getCredtype().getValue()); - } - - if (this.getCredusage() != null) { - OCRep.setTextString(parent, OcfResourceAttributeKey.CRED_USAGE_KEY, this.getCredusage().getValue()); - } - - if (this.getPublicData() != null) { - CborEncoder publicObj = OCRep.openObject(parent, OcfResourceAttributeKey.PUBLIC_DATA_KEY); - this.getPublicData().parseToCbor(publicObj); - OCRep.closeObject(parent, publicObj); - } - - if (this.getPrivateData() != null) { - CborEncoder privateObj = OCRep.openObject(parent, OcfResourceAttributeKey.PRIVATE_DATA_KEY); - this.getPrivateData().parseToCbor(privateObj); - OCRep.closeObject(parent, privateObj); - } - - if (this.getOptionalData() != null) { - // TODO - } - - if (this.getPeriod() != null && !this.getPeriod().isEmpty()) { - // TODO + if (cred.getAuthority() != null && !cred.getAuthority().isEmpty()) { + roleid.setAuthority(cred.getAuthority()); + } + this.setRoleid(roleid); } } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredentials.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredentials.java index a3b20c3bc8dc8876bf9e6f7ce9b1588479fba1a4..88720bccef0b74cdda47481a22d0a512f09b7e37 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredentials.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredentials.java @@ -22,16 +22,12 @@ package org.openconnectivity.otgc.domain.model.resource.secure.cred; -import com.upokecenter.cbor.CBORObject; - -import org.iotivity.CborEncoder; -import org.iotivity.OCRep; -import org.iotivity.OCRepresentation; +import org.iotivity.OCCred; +import org.iotivity.OCCreds; +import org.iotivity.OCUuidUtil; import org.openconnectivity.otgc.domain.model.resource.OcResourceBase; -import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class OcCredentials extends OcResourceBase { @@ -59,87 +55,20 @@ public class OcCredentials extends OcResourceBase { this.rowneruuid = rowneruuid; } - public void parseCbor(CBORObject cbor) { - /* creds */ - CBORObject credsObj = cbor.get(OcfResourceAttributeKey.CREDENTIALS_KEY); - if (credsObj != null) { - List credList = new ArrayList<>(); - for (CBORObject credObj : credsObj.getValues()) { - OcCredential cred = new OcCredential(); - cred.parseCbor(credObj); - credList.add(cred); - } - this.setCredList(credList); - } - /* rowneruuid */ - CBORObject rowneruuidObj = cbor.get(OcfResourceAttributeKey.ROWNER_UUID_KEY); - if (rowneruuidObj != null) { - String rowneruuid = rowneruuidObj.AsString(); - this.setRowneruuid(rowneruuid); - } - /* rt */ - CBORObject rtsObj = cbor.get(OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - if (rtsObj != null) { - List resourceTypes = new ArrayList<>(); - for (CBORObject rtObj : rtsObj.getValues()){ - resourceTypes.add(rtObj.AsString()); - } - this.setResourceTypes(resourceTypes); - } - /* if */ - CBORObject ifsObj = cbor.get(OcfResourceAttributeKey.INTERFACES_KEY); - if (ifsObj != null) { - List interfaces = new ArrayList<>(); - for (CBORObject ifObj : ifsObj.getValues()){ - interfaces.add(ifObj.AsString()); - } - this.setInterfaces(interfaces); - } - } - - public void parseOCRepresentation(OCRepresentation rep) { + public void parseOCRepresentation(OCCreds creds) { /* creds */ - OCRepresentation credsObj = OCRep.getObjectArray(rep, OcfResourceAttributeKey.CREDENTIALS_KEY); List credList = new ArrayList<>(); - while (credsObj != null) { + OCCred cr = creds.getCredsListHead(); + while (cr != null) { OcCredential cred = new OcCredential(); - cred.parseOCRepresentation(credsObj.getValue().getObject()); + cred.parseOCRepresentation(cr); credList.add(cred); - credsObj = credsObj.getNext(); + cr = cr.getNext(); } this.setCredList(credList); /* rowneruuid */ - String rowneruuid = OCRep.getString(rep, OcfResourceAttributeKey.ROWNER_UUID_KEY); + String rowneruuid = OCUuidUtil.uuidToString(creds.getRowneruuid()); this.setRowneruuid(rowneruuid); - /* rt */ - String[] resourceTypes = OCRep.getStringArray(rep, OcfResourceAttributeKey.RESOURCE_TYPES_KEY); - this.setResourceTypes(resourceTypes != null ? Arrays.asList(resourceTypes) : null); - /* if */ - String[] interfaces = OCRep.getStringArray(rep, OcfResourceAttributeKey.INTERFACES_KEY); - this.setInterfaces(interfaces != null ? Arrays.asList(interfaces) : null); - } - - public CborEncoder parseToCbor() { - CborEncoder root = OCRep.beginRootObject(); - - if (this.getCredList() != null && !this.getCredList().isEmpty()) { - CborEncoder credsArray = OCRep.openArray(root, OcfResourceAttributeKey.CREDENTIALS_KEY); - for (OcCredential cred : this.getCredList()) { - CborEncoder credObj = OCRep.beginObject(credsArray); - cred.parseToCbor(credObj); - OCRep.closeObject(credsArray, credObj); - } - - OCRep.closeArray(root, credsArray); - } - - if (this.getRowneruuid() != null && !this.getRowneruuid().isEmpty()) { - OCRep.setTextString(root, OcfResourceAttributeKey.ROWNER_UUID_KEY, this.getRowneruuid()); - } - - OCRep.endRootObject(); - - return root; } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetResourcesUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetResourcesUseCase.java index 445dc05005a57b652435ed86090c276797bb0080..1246183d1ee7b4dc4c276220739345e85ca5fddf 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetResourcesUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetResourcesUseCase.java @@ -45,8 +45,7 @@ public class GetResourcesUseCase { } public Single> execute(Device device) { - return iotivityRepository.getNonSecureEndpoint(device) - .flatMap(iotivityRepository::findVerticalResources) + return iotivityRepository.discoverVerticalResources(device.getDeviceId()) .map(ocResources -> { List serializableResources = new ArrayList<>(); for (OcResource resource : ocResources) { diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/DeleteAclUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/DeleteAclUseCase.java index 5e0995b38a016e3f3217e3378f11104712d96135..4039376695e2ca51084af5f484bb4f96e217ed53 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/DeleteAclUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/DeleteAclUseCase.java @@ -23,34 +23,21 @@ package org.openconnectivity.otgc.domain.usecase.accesscontrol; import org.openconnectivity.otgc.data.repository.AmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; -import org.openconnectivity.otgc.data.repository.PstatRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; -import org.openconnectivity.otgc.utils.constant.OcfDosType; import javax.inject.Inject; import io.reactivex.Completable; public class DeleteAclUseCase { - private final IotivityRepository iotivityRepository; private final AmsRepository amsRepository; - private final PstatRepository pstatRepository; @Inject - DeleteAclUseCase(IotivityRepository iotivityRepository, - AmsRepository amsRepository, - PstatRepository pstatRepository) { - this.iotivityRepository = iotivityRepository; + DeleteAclUseCase(AmsRepository amsRepository) { this.amsRepository = amsRepository; - this.pstatRepository = pstatRepository; } public Completable execute(Device device, long aceId) { - return iotivityRepository.getSecureEndpoint(device) - .flatMapCompletable(endpoint -> - pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(amsRepository.deleteAcl(endpoint, device.getDeviceId(), aceId)) - .andThen(pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP))); + return amsRepository.deleteAcl(device.getDeviceId(), aceId); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/RetrieveAclUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/RetrieveAclUseCase.java index 6c06c6da39826e4b9b29477f9c284931d28dcea2..a6f17ae587d623d97678c72b4ea816e1be890521 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/RetrieveAclUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/accesscontrol/RetrieveAclUseCase.java @@ -23,7 +23,6 @@ package org.openconnectivity.otgc.domain.usecase.accesscontrol; import org.openconnectivity.otgc.data.repository.AmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAcl; @@ -32,18 +31,14 @@ import javax.inject.Inject; import io.reactivex.Single; public class RetrieveAclUseCase { - private final IotivityRepository iotivityRepository; private final AmsRepository amsRepository; @Inject - public RetrieveAclUseCase(IotivityRepository iotivityRepository, - AmsRepository amsReporitory) { - this.iotivityRepository = iotivityRepository; + public RetrieveAclUseCase(AmsRepository amsReporitory) { this.amsRepository = amsReporitory; } public Single execute(Device device) { - return iotivityRepository.getSecureEndpoint(device) - .flatMap(endpoint -> amsRepository.getAcl(endpoint, device.getDeviceId())); + return amsRepository.getAcl(device.getDeviceId()); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/DeleteCredentialUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/DeleteCredentialUseCase.java index 3451254724f80f874591e4a2a8f16f3947fa4f37..9bb72438d1d73db3b9fe616177270a848c6e433a 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/DeleteCredentialUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/DeleteCredentialUseCase.java @@ -22,28 +22,19 @@ package org.openconnectivity.otgc.domain.usecase.credential; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.data.repository.CmsRepository; -import org.openconnectivity.otgc.data.repository.PstatRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; -import org.openconnectivity.otgc.utils.constant.OcfDosType; import javax.inject.Inject; import io.reactivex.Completable; public class DeleteCredentialUseCase { - private final IotivityRepository iotivityRepository; private final CmsRepository mCmsRepository; - private final PstatRepository mPstatRepository; @Inject - public DeleteCredentialUseCase(IotivityRepository iotivityRepository, - CmsRepository cmsRepository, - PstatRepository pstatRepository) { - this.iotivityRepository = iotivityRepository; + public DeleteCredentialUseCase(CmsRepository cmsRepository) { this.mCmsRepository = cmsRepository; - this.mPstatRepository = pstatRepository; } /** @@ -54,10 +45,6 @@ public class DeleteCredentialUseCase { */ public Completable execute(Device device, long credId) { - return iotivityRepository.getSecureEndpoint(device) - .flatMapCompletable(endpoint -> - mPstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(mCmsRepository.deleteCredential(endpoint, device.getDeviceId(), credId)) - .andThen(mPstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP))); + return mCmsRepository.deleteCredential(device.getDeviceId(), credId); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/RetrieveCredentialsUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/RetrieveCredentialsUseCase.java index 17922b649535ab84c672b28375636e4c8ecacd63..76f31667305ae81e69729f5a995f11d7f6b02b02 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/RetrieveCredentialsUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/credential/RetrieveCredentialsUseCase.java @@ -22,7 +22,6 @@ package org.openconnectivity.otgc.domain.usecase.credential; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.data.repository.CmsRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredentials; @@ -32,18 +31,14 @@ import javax.inject.Inject; import io.reactivex.Single; public class RetrieveCredentialsUseCase { - private final IotivityRepository iotivityRepository; private final CmsRepository cmsRepository; @Inject - public RetrieveCredentialsUseCase(IotivityRepository iotivityRepository, - CmsRepository cmsRepository) { - this.iotivityRepository = iotivityRepository; + public RetrieveCredentialsUseCase(CmsRepository cmsRepository) { this.cmsRepository = cmsRepository; } public Single execute(Device targetDevice) { - return iotivityRepository.getSecureEndpoint(targetDevice) - .flatMap(endpoint -> cmsRepository.getCredentials(endpoint, targetDevice.getDeviceId())); + return cmsRepository.getCredentials(targetDevice.getDeviceId()); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedDevicesUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedDevicesUseCase.java index 75d78138bb0cd425e0d2d333ac4c275da5d2ea8d..1df06679d3716a8b0f185b7c958be643c34e3d10 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedDevicesUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedDevicesUseCase.java @@ -22,11 +22,10 @@ package org.openconnectivity.otgc.domain.usecase.link; +import org.iotivity.OCCredType; import org.openconnectivity.otgc.data.repository.CmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; -import org.openconnectivity.otgc.utils.constant.OcfCredType; import java.util.ArrayList; import java.util.List; @@ -36,26 +35,22 @@ import javax.inject.Inject; import io.reactivex.Single; public class RetrieveLinkedDevicesUseCase { - private final IotivityRepository iotivityRepository; private final CmsRepository cmsRepository; @Inject - public RetrieveLinkedDevicesUseCase(IotivityRepository iotivityRepository, - CmsRepository cmsRepository) + public RetrieveLinkedDevicesUseCase(CmsRepository cmsRepository) { - this.iotivityRepository = iotivityRepository; this.cmsRepository = cmsRepository; } public Single> execute(Device device) { - return iotivityRepository.getSecureEndpoint(device) - .flatMap(endpoint -> cmsRepository.getCredentials(endpoint, device.getDeviceId())) + return cmsRepository.getCredentials(device.getDeviceId()) .map(ocCredentials -> { List creds = new ArrayList<>(); for (OcCredential cred : ocCredentials.getCredList()) { if (cred.getSubjectuuid() != null - && cred.getCredtype() == OcfCredType.OC_CREDTYPE_PSK) { + && OCCredType.valueOf(cred.getCredtype()) == OCCredType.OC_CREDTYPE_PSK) { creds.add(cred.getSubjectuuid()); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForClientUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForClientUseCase.java index 6d5e5d10b17fa063e8d03da5285c3a671c5a046e..f22622cbbbd1c08d193667ea737eae5e4492d746 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForClientUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForClientUseCase.java @@ -22,7 +22,6 @@ package org.openconnectivity.otgc.domain.usecase.link; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.data.repository.CmsRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; @@ -35,21 +34,17 @@ import javax.inject.Inject; import io.reactivex.Single; public class RetrieveLinkedRolesForClientUseCase { - private final IotivityRepository iotivityRepository; private final CmsRepository cmsRepository; @Inject - public RetrieveLinkedRolesForClientUseCase(IotivityRepository iotivityRepository, - CmsRepository cmsRepository) + public RetrieveLinkedRolesForClientUseCase(CmsRepository cmsRepository) { - this.iotivityRepository = iotivityRepository; this.cmsRepository = cmsRepository; } public Single> execute(Device device) { - return iotivityRepository.getSecureEndpoint(device) - .flatMap(endpoint -> cmsRepository.getCredentials(endpoint, device.getDeviceId())) + return cmsRepository.getCredentials(device.getDeviceId()) .map(credentials -> { List roles = new ArrayList<>(); diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForServerUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForServerUseCase.java index 263043193a3dc7c32b67b77bbb66eca530b6e22e..e713e1960289ae1ce089c016cd4df6dda0e2779c 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForServerUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/RetrieveLinkedRolesForServerUseCase.java @@ -22,11 +22,10 @@ package org.openconnectivity.otgc.domain.usecase.link; +import org.iotivity.OCAceSubjectType; import org.openconnectivity.otgc.data.repository.AmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAce; -import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAceSubjectType; import java.util.ArrayList; import java.util.List; @@ -36,26 +35,22 @@ import javax.inject.Inject; import io.reactivex.Single; public class RetrieveLinkedRolesForServerUseCase { - private final IotivityRepository iotivityRepository; private final AmsRepository amsRepository; @Inject - public RetrieveLinkedRolesForServerUseCase(IotivityRepository iotivityRepository, - AmsRepository amsRepository) + public RetrieveLinkedRolesForServerUseCase(AmsRepository amsRepository) { - this.iotivityRepository = iotivityRepository; this.amsRepository = amsRepository; } public Single> execute(Device device) { - return iotivityRepository.getSecureEndpoint(device) - .flatMap(endpoint -> amsRepository.getAcl(endpoint, device.getDeviceId())) + return amsRepository.getAcl(device.getDeviceId()) .map(acl -> { List roles = new ArrayList<>(); for (OcAce ace : acl.getAceList()) { - if (ace.getSubject().getType() == OcAceSubjectType.ROLE_TYPE + if (OCAceSubjectType.valueOf(ace.getSubject().getType()) == OCAceSubjectType.OC_SUBJECT_ROLE && ace.getSubject().getRoleId() != null) { roles.add(ace.getSubject().getRoleId()); } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkDevicesUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkDevicesUseCase.java index 8197734fc2fdc5bae7ce3ce732bb0f57cfd63cc5..1023597966e8c6416ebe37ec12b2b2a210f15438 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkDevicesUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkDevicesUseCase.java @@ -22,13 +22,10 @@ package org.openconnectivity.otgc.domain.usecase.link; +import org.iotivity.OCCredType; import org.openconnectivity.otgc.data.repository.CmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; -import org.openconnectivity.otgc.data.repository.PstatRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; -import org.openconnectivity.otgc.utils.constant.OcfCredType; -import org.openconnectivity.otgc.utils.constant.OcfDosType; import java.util.ArrayList; import java.util.List; @@ -38,53 +35,41 @@ import javax.inject.Inject; import io.reactivex.Completable; public class UnlinkDevicesUseCase { - private final IotivityRepository iotivityRepository; - private final PstatRepository pstatRepository; private final CmsRepository cmsRepository; @Inject - public UnlinkDevicesUseCase(IotivityRepository iotivityRepository, - PstatRepository pstatRepository, - CmsRepository cmsRepository) + public UnlinkDevicesUseCase(CmsRepository cmsRepository) { - this.iotivityRepository = iotivityRepository; - this.pstatRepository = pstatRepository; this.cmsRepository = cmsRepository; } public Completable execute(Device client, Device server) { - Completable deleteClientPairwise = iotivityRepository.getSecureEndpoint(client) - .flatMapCompletable(endpoint -> cmsRepository.getCredentials(endpoint, client.getDeviceId()) - .flatMapCompletable(ocCredentials -> { - List deleteCredList = new ArrayList<>(); - for(OcCredential cred : ocCredentials.getCredList()) { - if (cred.getSubjectuuid() != null && cred.getSubjectuuid().equals(server.getDeviceId()) - && cred.getCredtype() == OcfCredType.OC_CREDTYPE_PSK) { - Completable deleteCred = pstatRepository.changeDeviceStatus(endpoint, client.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(cmsRepository.deleteCredential(endpoint, client.getDeviceId(), cred.getCredid())) - .andThen(pstatRepository.changeDeviceStatus(endpoint, client.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP)); - deleteCredList.add(deleteCred); - } - } - return Completable.merge(deleteCredList); - })); + Completable deleteClientPairwise = cmsRepository.getCredentials(client.getDeviceId()) + .flatMapCompletable(ocCredentials -> { + List deleteCredList = new ArrayList<>(); + for(OcCredential cred : ocCredentials.getCredList()) { + if (cred.getSubjectuuid() != null && cred.getSubjectuuid().equals(server.getDeviceId()) + && OCCredType.valueOf(cred.getCredtype()) == OCCredType.OC_CREDTYPE_PSK) { + Completable deleteCred = cmsRepository.deleteCredential(client.getDeviceId(), cred.getCredid()); + deleteCredList.add(deleteCred); + } + } + return Completable.merge(deleteCredList); + }); - Completable deleteServerPairwise = iotivityRepository.getSecureEndpoint(server) - .flatMapCompletable(endpoint -> cmsRepository.getCredentials(endpoint, server.getDeviceId()) - .flatMapCompletable(ocCredentials -> { - List deleteCredList = new ArrayList<>(); - for(OcCredential cred : ocCredentials.getCredList()) { - if (cred.getSubjectuuid() != null && cred.getSubjectuuid().equals(client.getDeviceId()) - && cred.getCredtype() == OcfCredType.OC_CREDTYPE_PSK) { - Completable deleteCred = pstatRepository.changeDeviceStatus(endpoint, server.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(cmsRepository.deleteCredential(endpoint, server.getDeviceId(), cred.getCredid())) - .andThen(pstatRepository.changeDeviceStatus(endpoint, server.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP)); - deleteCredList.add(deleteCred); - } - } - return Completable.merge(deleteCredList); - })); + Completable deleteServerPairwise = cmsRepository.getCredentials(server.getDeviceId()) + .flatMapCompletable(ocCredentials -> { + List deleteCredList = new ArrayList<>(); + for(OcCredential cred : ocCredentials.getCredList()) { + if (cred.getSubjectuuid() != null && cred.getSubjectuuid().equals(client.getDeviceId()) + && OCCredType.valueOf(cred.getCredtype()) == OCCredType.OC_CREDTYPE_PSK) { + Completable deleteCred = cmsRepository.deleteCredential(server.getDeviceId(), cred.getCredid()); + deleteCredList.add(deleteCred); + } + } + return Completable.merge(deleteCredList); + }); return deleteClientPairwise .andThen(deleteServerPairwise); diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForClientUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForClientUseCase.java index 13e6c67e2bb314edc15be368a08e29d1d4296f9b..f49fa0b921c9fec4e74b05603acfb797369505ff 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForClientUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForClientUseCase.java @@ -22,12 +22,9 @@ package org.openconnectivity.otgc.domain.usecase.link; -import org.openconnectivity.otgc.data.repository.IotivityRepository; import org.openconnectivity.otgc.data.repository.CmsRepository; -import org.openconnectivity.otgc.data.repository.PstatRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; -import org.openconnectivity.otgc.utils.constant.OcfDosType; import java.util.ArrayList; import java.util.List; @@ -37,34 +34,25 @@ import javax.inject.Inject; import io.reactivex.Completable; public class UnlinkRoleForClientUseCase { - private final IotivityRepository iotivityRepository; - private final PstatRepository pstatRepository; private final CmsRepository cmsRepository; @Inject - public UnlinkRoleForClientUseCase(IotivityRepository iotivityRepository, - PstatRepository pstatRepository, - CmsRepository cmsRepository) + public UnlinkRoleForClientUseCase(CmsRepository cmsRepository) { - this.iotivityRepository = iotivityRepository; - this.pstatRepository = pstatRepository; this.cmsRepository = cmsRepository; } public Completable execute(Device device, String roleId) { - return iotivityRepository.getSecureEndpoint(device) - .flatMapCompletable(endpoint -> cmsRepository.getCredentials(endpoint, device.getDeviceId()) - .flatMapCompletable(ocCredentials -> { - List deleteCredList = new ArrayList<>(); - for(OcCredential cred : ocCredentials.getCredList()) { - if (cred.getRoleid() != null && cred.getRoleid().getRole().equals(roleId)) { - Completable deleteCred = pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(cmsRepository.deleteCredential(endpoint, device.getDeviceId(), cred.getCredid())) - .andThen(pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP)); - deleteCredList.add(deleteCred); - } - } - return Completable.merge(deleteCredList); - })); + return cmsRepository.getCredentials(device.getDeviceId()) + .flatMapCompletable(ocCredentials -> { + List deleteCredList = new ArrayList<>(); + for(OcCredential cred : ocCredentials.getCredList()) { + if (cred.getRoleid() != null && cred.getRoleid().getRole().equals(roleId)) { + Completable deleteCred = cmsRepository.deleteCredential(device.getDeviceId(), cred.getCredid()); + deleteCredList.add(deleteCred); + } + } + return Completable.merge(deleteCredList); + }); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForServerUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForServerUseCase.java index 49e62354ab418c92dde9d69b4f6788ec70b8a503..d4d1c2dd8e8fa763ebbe91f1000368b1a4707f13 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForServerUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/link/UnlinkRoleForServerUseCase.java @@ -23,11 +23,8 @@ package org.openconnectivity.otgc.domain.usecase.link; import org.openconnectivity.otgc.data.repository.AmsRepository; -import org.openconnectivity.otgc.data.repository.IotivityRepository; -import org.openconnectivity.otgc.data.repository.PstatRepository; import org.openconnectivity.otgc.domain.model.devicelist.Device; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAce; -import org.openconnectivity.otgc.utils.constant.OcfDosType; import java.util.ArrayList; import java.util.List; @@ -37,34 +34,25 @@ import javax.inject.Inject; import io.reactivex.Completable; public class UnlinkRoleForServerUseCase { - private final IotivityRepository iotivityRepository; - private final PstatRepository pstatRepository; private final AmsRepository amsRepository; @Inject - public UnlinkRoleForServerUseCase(IotivityRepository iotivityRepository, - PstatRepository pstatRepository, - AmsRepository amsRepository) + public UnlinkRoleForServerUseCase(AmsRepository amsRepository) { - this.iotivityRepository = iotivityRepository; - this.pstatRepository = pstatRepository; this.amsRepository = amsRepository; } public Completable execute(Device device, String roleId) { - return iotivityRepository.getSecureEndpoint(device) - .flatMapCompletable(endpoint -> amsRepository.getAcl(endpoint, device.getDeviceId()) - .flatMapCompletable(ocAcl -> { - List deleteAceList = new ArrayList<>(); - for (OcAce ace : ocAcl.getAceList()) { - if (ace.getSubject().getRoleId() != null && ace.getSubject().getRoleId().equals(roleId)) { - Completable deleteAce = pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFPRO) - .andThen(amsRepository.deleteAcl(endpoint, device.getDeviceId(), ace.getAceid())) - .andThen(pstatRepository.changeDeviceStatus(endpoint, device.getDeviceId(), OcfDosType.OC_DOSTYPE_RFNOP)); - deleteAceList.add(deleteAce); - } - } - return Completable.merge(deleteAceList); - })); + return amsRepository.getAcl(device.getDeviceId()) + .flatMapCompletable(ocAcl -> { + List deleteAceList = new ArrayList<>(); + for (OcAce ace : ocAcl.getAceList()) { + if (ace.getSubject().getRoleId() != null && ace.getSubject().getRoleId().equals(roleId)) { + Completable deleteAce = amsRepository.deleteAcl(device.getDeviceId(), ace.getAceid()); + deleteAceList.add(deleteAce); + } + } + return Completable.merge(deleteAceList); + }); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/GetTrustAnchorUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/GetTrustAnchorUseCase.java index 160b37b50d3f59dba33ea7d0b13ed51fc2a49421..4c25eb54b7547e9b967cff1444248170a74c9a16 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/GetTrustAnchorUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/GetTrustAnchorUseCase.java @@ -19,34 +19,33 @@ package org.openconnectivity.otgc.domain.usecase.trustanchor; import io.reactivex.Single; -import org.openconnectivity.otgc.data.repository.IORepository; + +import org.iotivity.OCCredUsage; +import org.iotivity.OCCredUtil; +import org.openconnectivity.otgc.data.repository.CmsRepository; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; -import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredentials; -import org.openconnectivity.otgc.utils.constant.OcfCredUsage; import javax.inject.Inject; import java.util.ArrayList; import java.util.List; public class GetTrustAnchorUseCase { - private final IORepository ioRepository; + private final CmsRepository cmsRepository; @Inject - public GetTrustAnchorUseCase(IORepository ioRepository) { - this.ioRepository = ioRepository; + public GetTrustAnchorUseCase(CmsRepository cmsRepository) { + this.cmsRepository = cmsRepository; } public Single> execute() { - return ioRepository.getAssetSvrAsCbor("cred", 0 /* First device */) - .flatMap(cbor -> Single.create(emitter -> { - OcCredentials credentials = new OcCredentials(); - credentials.parseCbor(cbor); + return cmsRepository.retrieveOwnCredentials() + .flatMap(creds -> Single.create(emitter -> { List trustAnchorList = new ArrayList<>(); - for (OcCredential cred : credentials.getCredList()) { - if (cred.getCredusage() != null - && (cred.getCredusage() == OcfCredUsage.OC_CREDUSAGE_MFGTRUSTCA - || cred.getCredusage() == OcfCredUsage.OC_CREDUSAGE_TRUSTCA)) { + for (OcCredential cred : creds.getCredList()) { + if (cred.getCredusage() != null && !cred.getCredusage().isEmpty() + && (OCCredUtil.parseCredUsage(cred.getCredusage()) == OCCredUsage.OC_CREDUSAGE_MFG_TRUSTCA + || OCCredUtil.parseCredUsage(cred.getCredusage()) == OCCredUsage.OC_CREDUSAGE_TRUSTCA)) { trustAnchorList.add(cred); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/RemoveTrustAnchorByCredidUseCase.java b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/RemoveTrustAnchorByCredidUseCase.java index 6da2b9937b07adecbaf259627f0d6b80b4226095..8938b75fa557a15cf0fe954ab0c2f050cc95b6d5 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/RemoveTrustAnchorByCredidUseCase.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/trustanchor/RemoveTrustAnchorByCredidUseCase.java @@ -33,6 +33,6 @@ public class RemoveTrustAnchorByCredidUseCase { } public Completable execute(long credid) { - return cmsRepository.removeTrustAnchor(0 /* First device */, credid); + return cmsRepository.removeTrustAnchor(credid); } } diff --git a/otgc/src/main/java/org/openconnectivity/otgc/view/accesscontrol/AccessControlAdapter.java b/otgc/src/main/java/org/openconnectivity/otgc/view/accesscontrol/AccessControlAdapter.java index 9b17a378c8a0fee759195fa0e65c5ecb4e1f6bc1..88283b79341b397f696cc6c1551f70801e37acb1 100644 --- a/otgc/src/main/java/org/openconnectivity/otgc/view/accesscontrol/AccessControlAdapter.java +++ b/otgc/src/main/java/org/openconnectivity/otgc/view/accesscontrol/AccessControlAdapter.java @@ -35,6 +35,7 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; +import org.iotivity.OCAceSubjectType; import org.openconnectivity.otgc.R; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAce; import org.openconnectivity.otgc.domain.model.resource.secure.acl.OcAceResource; @@ -140,9 +141,9 @@ public class AccessControlAdapter extends RecyclerView.Adapter