...
 
Commits (7)
[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
......@@ -64,10 +64,8 @@ git checkout swig
```
2. Apply all patchs of the OTGC in IoTivity-lite
```
git apply <otgc-linux>/extlibs/patchs/remove_cred_by_credid.patch
git apply <otgc-linux>/extlibs/patchs/fix_config.patch
git apply <otgc-linux>/extlibs/patchs/bwt_fix.patch
git apply <otgc-linux>/extlibs/patchs/timeout_fix.patch
git apply <otgc-linux>/extlibs/patchs/fix_swig_flags.patch
git apply <otgc-linux>/extlibs/patchs/ignore_cloud_discover_resources.patch
```
3. Go to the linux directory.
```
......
......@@ -11,7 +11,7 @@
# Constants
PROJECT_NAME="otgc"
VERSION="2.9.0"
VERSION="2.10.0"
program=$0
......
Subproject commit 66a2d08784903110b7dead5b9a518933a355e1e6
Subproject commit 89a79af890df2084d7ae1e33522b6d0e24a3e9a3
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/port/linux/oc_config.h b/port/linux/oc_config.h
index 8e801156..7c8fbd78 100644
--- a/port/linux/oc_config.h
+++ b/port/linux/oc_config.h
@@ -34,7 +34,7 @@ typedef uint64_t oc_clock_time_t;
/* Add support for the oic.if.create interface in Collections */
#define OC_COLLECTIONS_IF_CREATE
/* Add support for the maintenance resource */
-#define OC_MNT
+//#define OC_MNT
/* If we selected support for dynamic memory allocation */
#ifdef OC_DYNAMIC_ALLOCATION
#define OC_COLLECTIONS
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/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/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/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;
......@@ -6,7 +6,7 @@
<groupId>otgc</groupId>
<artifactId>otgc</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -24,7 +24,6 @@ import io.reactivex.Single;
import org.apache.log4j.Logger;
import org.iotivity.*;
import org.openconnectivity.otgc.domain.model.resource.secure.acl.*;
import org.openconnectivity.otgc.utils.constant.OcfResourceUri;
import org.openconnectivity.otgc.utils.constant.OcfWildcard;
import javax.inject.Inject;
......@@ -41,64 +40,33 @@ public class AmsRepository {
@Inject
public AmsRepository(){}
public Single<OcAcl> getAcl(String endpoint, String deviceId) {
public Single<OcAcl> 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 {
LOG.debug("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)) {
LOG.debug("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";
LOG.debug(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()) {
LOG.debug("Sent POST request to /oic/sec/acl2");
} else {
String error = "Could not send POST request to /oic/sec/acl2";
LOG.error(error);
emitter.onError(new Exception(error));
}
int ret = OCObt.retrieveAcl(uuid, handler);
if (ret >= 0) {
LOG.debug("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";
LOG.error(error);
emitter.onError(new Exception(error));
}
OCEndpointUtil.freeEndpoint(ep);
});
}
......@@ -138,22 +106,6 @@ public class AmsRepository {
});
}
public Completable provisionUuidAcl(String endpoint, String deviceId, String subjectId, List<String> 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<OcAce> 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<String> verticalResources, long permission) {
OCUuid di = OCUuidUtil.stringToUuid(subjectId);
......@@ -167,23 +119,6 @@ public class AmsRepository {
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionRoleAcl(String endpoint, String deviceId, String roleId, String roleAuthority, List<String> 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<OcAce> 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<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForRole(roleId, roleAuthority);
if (ace == null) {
......@@ -195,22 +130,6 @@ public class AmsRepository {
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionConntypeAcl(String endpoint, String deviceId, boolean isAuthCrypt, List<String> 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<OcAce> 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<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForConnection(isAuthCrypt ? OCAceConnectionType.OC_CONN_AUTH_CRYPT : OCAceConnectionType.OC_CONN_ANON_CLEAR);
if (ace == null) {
......@@ -274,29 +193,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) {
LOG.debug("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) {
LOG.debug("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;
LOG.error(error);
emitter.onError(new Exception(error));
}
OCEndpointUtil.freeEndpoint(ep);
});
}
......
......@@ -95,8 +95,10 @@ public class IORepository {
return Single.fromCallable(() -> {
byte[] fileBytes;
try (InputStream inputStream = new FileInputStream(OtgcConstant.DATA_PATH + path)) {
fileBytes = new byte[inputStream.available()];
int numBytes = inputStream.available() + 1;
fileBytes = new byte[numBytes];
inputStream.read(fileBytes);
fileBytes[numBytes - 1] = '\0';
}
return fileBytes;
......
......@@ -20,7 +20,6 @@
package org.openconnectivity.otgc.data.repository;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.Single;
import org.apache.log4j.Logger;
......@@ -488,9 +487,74 @@ public class IotivityRepository {
Thread.currentThread().interrupt();
LOG.error(ex.getMessage());
}
// Free endpoint
OCEndpointUtil.freeEndpoint(ep);
});
}
public Observable<OcResource> 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<OcEndpoint> 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(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)
{
LOG.debug("Successfully issued resource discovery request");
} else {
String error = "ERROR issuing resource discovery request";
LOG.error(error);
emitter.onError(new Exception(error));
}
});
}
public Single<List<OcResource>> discoverVerticalResources(String deviceId) {
return discoverAllResources(deviceId)
.toList()
.map(resources -> {
List<OcResource> 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<OcRes> findResource(String host, String resourceType) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(host, new String[1]);
......
......@@ -19,18 +19,15 @@
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.*;
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<OcAceResource> resources;
......@@ -38,19 +35,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;
}
......@@ -70,56 +67,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<OcAceResource> 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);
}
}
......@@ -19,13 +19,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 {
......@@ -72,49 +68,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);
}
}
......@@ -19,14 +19,11 @@
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.*;
public class OcAceSubject {
private OcAceSubjectType type;
private String type;
private String connType;
private String uuid;
private String roleId;
......@@ -36,11 +33,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;
}
......@@ -76,42 +73,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());
}
}
}
......@@ -19,14 +19,10 @@
package org.openconnectivity.otgc.domain.model.resource.secure.acl;
import org.iotivity.CborEncoder;
import org.iotivity.OCRep;
import org.iotivity.OCRepresentation;
import org.iotivity.*;
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 {
......@@ -54,63 +50,21 @@ 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<OcAce> 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;
}
}
......@@ -19,17 +19,13 @@
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.*;
public class OcCredPrivateData {
private byte[] dataDer;
private String dataPem;
private OcfEncoding encoding;
private String encoding;
public OcCredPrivateData() {
......@@ -51,37 +47,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);
}
}
......@@ -19,16 +19,11 @@
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.*;
public class OcCredPublicData {
private OcfEncoding encoding;
private String encoding;
private String pemData;
private byte[] derData;
......@@ -36,11 +31,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;
}
......@@ -60,51 +55,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);
}
}
......@@ -19,8 +19,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;
......@@ -49,21 +47,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);
......@@ -72,15 +55,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());
}
}
}
......@@ -19,19 +19,15 @@
package org.openconnectivity.otgc.domain.model.resource.secure.cred;
import com.upokecenter.cbor.CBORObject;
import org.iotivity.*;
import org.openconnectivity.otgc.utils.constant.OcfCredType;
import org.openconnectivity.otgc.utils.constant.OcfCredUsage;
import org.openconnectivity.otgc.utils.constant.OcfResourceAttributeKey;
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;
......@@ -39,11 +35,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;
}
......@@ -63,19 +59,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;
}
......@@ -111,136 +107,42 @@ public class OcCredential {
this.period = period;
}
public void parseCbor(CBORObject cbor) {
public void parseOCRepresentation(OCCred cred) {
/* 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) {
/* 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(