From 2fb4e1c948236c524e4900971980370762130124 Mon Sep 17 00:00:00 2001 From: Sandeep Sharma Date: Tue, 1 Sep 2015 17:04:51 +0530 Subject: [PATCH] Added Android support for Provisioning APIs - Unowned/Owned device discovery, ACL, Credential provisioning - Ownership transfer [Patch #2] fixed wrong code comment. [Patch #3] Added JNI and Java Interface for Unlink, revocation and Dashboard. Added Android Provisioning sample app. [Patch #4] Revert Sconscript Changes with causes failure for automatic rebase. [Patch #5] Addressed Ashwini's review commnets. [Patch #6] Few fixes and addressed Randeep's review comments. [Patch #7] Renamed sample app and more memory fixes. [Patch #8] Addressed Tim's review comments. [Patch #13] Addresses review comments. NOTE: This change set won't build. It depends upon change set #2320 Change-Id: I41a29c0467976ea2b8439d8f85926b0a0ae6d79f Signed-off-by: Sandeep Sharma Signed-off-by: Sunil Kumar K R Reviewed-on: https://gerrit.iotivity.org/gerrit/2334 Tested-by: jenkins-iotivity Reviewed-by: Sachin Agrawal --- android/android_api/SConscript | 3 +- android/android_api/base/build.gradle | 2 +- android/android_api/base/jni/Android.mk | 31 + android/android_api/base/jni/JniOcProvisioning.cpp | 223 +++++++ android/android_api/base/jni/JniOcProvisioning.h | 84 +++ .../android_api/base/jni/JniOcSecureResource.cpp | 653 +++++++++++++++++++ android/android_api/base/jni/JniOcSecureResource.h | 171 +++++ android/android_api/base/jni/JniOcStack.cpp | 69 ++ android/android_api/base/jni/JniOcStack.h | 14 + .../android_api/base/jni/JniPinCheckListener.cpp | 77 +++ android/android_api/base/jni/JniPinCheckListener.h | 40 ++ .../base/jni/JniProvisionResultListner.cpp | 150 +++++ .../base/jni/JniProvisionResultListner.h | 55 ++ android/android_api/base/jni/JniSecureUtils.cpp | 240 +++++++ android/android_api/base/jni/JniSecureUtils.h | 38 ++ .../src/main/java/org/iotivity/base/CredType.java | 74 +++ .../main/java/org/iotivity/base/DeviceStatus.java | 55 ++ .../src/main/java/org/iotivity/base/KeySize.java | 38 ++ .../java/org/iotivity/base/OcProvisioning.java | 102 +++ .../java/org/iotivity/base/OcSecureResource.java | 240 +++++++ .../src/main/java/org/iotivity/base/OicSecAcl.java | 123 ++++ .../main/java/org/iotivity/base/OwnedStatus.java | 55 ++ .../src/main/java/org/iotivity/base/OxmType.java | 42 ++ .../java/org/iotivity/base/ProvisionResult.java | 41 ++ android/examples/provisioningclient/build.gradle | 24 + .../examples/provisioningclient/proguard-rules.pro | 17 + .../provisioningclient/provisioningclient.iml | 95 +++ .../src/main/AndroidManifest.xml | 21 + .../src/main/assets/oic_svr_db_client.json | 49 ++ .../provisioningclient/ProvisioningClient.java | 711 +++++++++++++++++++++ .../provisioningclient/StringConstants.java | 12 + .../layout/activity_secure_provision_client.xml | 16 + .../main/res/menu/menu_secure_provision_client.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../src/main/res/values-v21/styles.xml | 5 + .../src/main/res/values-w820dp/dimens.xml | 6 + .../src/main/res/values/dimens.xml | 5 + .../src/main/res/values/strings.xml | 6 + .../src/main/res/values/styles.xml | 8 + android/examples/settings.gradle | 2 +- resource/csdk/security/SConscript | 2 +- 44 files changed, 3600 insertions(+), 4 deletions(-) create mode 100644 android/android_api/base/jni/JniOcProvisioning.cpp create mode 100644 android/android_api/base/jni/JniOcProvisioning.h create mode 100644 android/android_api/base/jni/JniOcSecureResource.cpp create mode 100644 android/android_api/base/jni/JniOcSecureResource.h create mode 100644 android/android_api/base/jni/JniPinCheckListener.cpp create mode 100644 android/android_api/base/jni/JniPinCheckListener.h create mode 100644 android/android_api/base/jni/JniProvisionResultListner.cpp create mode 100644 android/android_api/base/jni/JniProvisionResultListner.h create mode 100644 android/android_api/base/jni/JniSecureUtils.cpp create mode 100644 android/android_api/base/jni/JniSecureUtils.h create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/CredType.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/KeySize.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OxmType.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java create mode 100644 android/examples/provisioningclient/build.gradle create mode 100644 android/examples/provisioningclient/proguard-rules.pro create mode 100644 android/examples/provisioningclient/provisioningclient.iml create mode 100644 android/examples/provisioningclient/src/main/AndroidManifest.xml create mode 100644 android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json create mode 100644 android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java create mode 100644 android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java create mode 100644 android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml create mode 100644 android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml create mode 100644 android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 android/examples/provisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 android/examples/provisioningclient/src/main/res/values-v21/styles.xml create mode 100644 android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml create mode 100644 android/examples/provisioningclient/src/main/res/values/dimens.xml create mode 100644 android/examples/provisioningclient/src/main/res/values/strings.xml create mode 100644 android/examples/provisioningclient/src/main/res/values/styles.xml diff --git a/android/android_api/SConscript b/android/android_api/SConscript index f2bc851..0f27318 100644 --- a/android/android_api/SConscript +++ b/android/android_api/SConscript @@ -9,6 +9,7 @@ if env.get('RELEASE'): ANDROID_RELEASE="release" else: ANDROID_RELEASE="debug" +ANDROID_SECURED = env.get('SECURED') os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME') os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK') @@ -46,6 +47,6 @@ def ensure_libs(target, source, env): return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so'] jdk_env = Environment(ENV=os.environ) -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE), emitter = ensure_libs) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PSECURED=%s -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_SECURED, ANDROID_TARGET_ARCH, ANDROID_RELEASE), emitter = ensure_libs) jdk_env['BUILD_DIR'] = env.get('BUILD_DIR') jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java") diff --git a/android/android_api/base/build.gradle b/android/android_api/base/build.gradle index 9cbdaf8..afeb10d 100755 --- a/android/android_api/base/build.gradle +++ b/android/android_api/base/build.gradle @@ -94,7 +94,7 @@ task buildNative(type: Exec) { //for windows use 'ndk-build.cmd' //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd') def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') - commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE" + commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED" } else { println '##################' println 'Skipping NDK build' diff --git a/android/android_api/base/jni/Android.mk b/android/android_api/base/jni/Android.mk index f29d75a..05172ee 100644 --- a/android/android_api/base/jni/Android.mk +++ b/android/android_api/base/jni/Android.mk @@ -1,5 +1,6 @@ LOCAL_PATH := $(call my-dir) TARGET_ARCH_ABI := $(APP_ABI) +SECURED := $(SECURE) include $(CLEAR_VARS) OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM) @@ -25,6 +26,20 @@ LOCAL_MODULE := libandroid-ca LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so include $(PREBUILT_SHARED_LIBRARY) +ifeq ($(SECURED), 1) +include $(CLEAR_VARS) +OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM) +LOCAL_MODULE := libandroid-ocprovision +LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libocprovision.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM) +LOCAL_MODULE := libandroid-ocpmapi +LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libocpmapi.a +include $(PREBUILT_STATIC_LIBRARY) +endif + include $(CLEAR_VARS) OIC_SRC_PATH := ../../../resource LOCAL_MODULE := libca-interface @@ -60,6 +75,13 @@ LOCAL_SRC_FILES := JniOcStack.cpp \ JniOcResource.cpp \ JniOcResourceIdentifier.cpp \ JniOcSecurity.cpp +ifeq ($(SECURED), 1) +LOCAL_SRC_FILES += JniOcSecureResource.cpp \ + JniOcProvisioning.cpp \ + JniSecureUtils.cpp \ + JniProvisionResultListner.cpp \ + JniPinCheckListener.cpp +endif LOCAL_LDLIBS := -llog LOCAL_STATIC_LIBRARIES := android-oc @@ -68,14 +90,23 @@ LOCAL_STATIC_LIBRARIES += android-coap LOCAL_STATIC_LIBRARIES += android-oc_logger LOCAL_STATIC_LIBRARIES += android-ca LOCAL_STATIC_LIBRARIES += android_cpp11_compat +ifeq ($(SECURED), 1) +LOCAL_STATIC_LIBRARIES += android-ocprovision +LOCAL_STATIC_LIBRARIES += android-ocpmapi +endif LOCAL_CPPFLAGS += -std=c++0x LOCAL_CPP_FEATURES := rtti exceptions LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common/oic_string/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/stack/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/ +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include include $(BUILD_SHARED_LIBRARY) diff --git a/android/android_api/base/jni/JniOcProvisioning.cpp b/android/android_api/base/jni/JniOcProvisioning.cpp new file mode 100644 index 0000000..7813169 --- /dev/null +++ b/android/android_api/base/jni/JniOcProvisioning.cpp @@ -0,0 +1,223 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcProvisioning.h" +#include "JniPinCheckListener.h" + +using namespace OC; +namespace PH = std::placeholders; + +static JniPinCheckListener *PinListener = nullptr; + +void Callback(char *buf, size_t size) +{ + if (PinListener) + { + PinListener->PinCallback(buf, size); + } + else + { + LOGE("PinListener is null"); + } +} + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: ownershipTransferCDdata + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCBdata + (JNIEnv *env, jobject thiz, jint OxmType, jobject jListener) +{ + LOGD("OcProvisioning_ownershipTransferCBdata"); + OCStackResult result = OC_STACK_ERROR; + + try + { + OTMCallbackData_t CBData = {0}; + if (OIC_JUST_WORKS == (OicSecOxm_t)OxmType) + { + CBData.loadSecretCB = LoadSecretJustWorksCallback; + CBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback; + CBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload; + CBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload; + + result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType, + &CBData, NULL); + } + if (OIC_RANDOM_DEVICE_PIN == (OicSecOxm_t)OxmType) + { + if (jListener) + { + delete PinListener; + PinListener = new JniPinCheckListener(env, jListener); + CBData.loadSecretCB = InputPinCodeCallback; + CBData.createSecureSessionCB = CreateSecureSessionRandomPinCallbak; + CBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload; + CBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload; + result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType, + &CBData, Callback); + } + else + { + result = OC_STACK_ERROR; + } + } + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcProvisioning_ownershipTransferCDdata"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcProvisioning +* Method: discoverUnownedDevices +* Signature: (I)[Lorg/iotivity/base/OcSecureResource; +*/ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverUnownedDevices1 + (JNIEnv *env, jclass clazz, jint timeout) +{ + LOGI("OcProvisioning_discoverUnownedDevices"); + DeviceList_t list; + + try + { + OCStackResult result = OCSecure::discoverUnownedDevices((unsigned short)timeout, list); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to discover Unowned devices"); + return nullptr; + } + + return JniSecureUtils::convertDeviceVectorToJavaArray(env, list); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: provisionInit + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_provisionInit + (JNIEnv *env, jclass calzz, jstring jdbPath) +{ + LOGI("OcProvisioning_provisionInit"); + char *dbpath; + + if (!jdbPath) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "SVR db path cannot be null"); + return; + } + + try + { + dbpath = (char*)env->GetStringUTFChars(jdbPath, NULL); + OCStackResult result = OCSecure::provisionInit(env->GetStringUTFChars(jdbPath, NULL)); + + if (OC_STACK_OK != result) + { + env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath); + ThrowOcException(result, "Failed to Init Provisioning Manager"); + return; + } + env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverOwnedDevices + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverOwnedDevices1 + (JNIEnv *env, jclass clazz , jint timeout) +{ + LOGI("OcProvisioning_discoverOwnedDevices"); + DeviceList_t list; + + try + { + OCStackResult result = OCSecure::discoverOwnedDevices((unsigned short)timeout, list); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to discover Owned devices"); + return nullptr; + } + + return JniSecureUtils::convertDeviceVectorToJavaArray(env, list); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: getDevicestatusLists + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1 + (JNIEnv *env, jclass clazz, jint timeout) +{ + LOGI("OcProvisioning_getDeviceStatusList"); + DeviceList_t ownedDevList, unownedDevList; + + try + { + OCStackResult result = OCSecure::getDevInfoFromNetwork((unsigned short)timeout, + ownedDevList, unownedDevList); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to get Device Status List"); + return nullptr; + } + ownedDevList.insert(ownedDevList.end(), unownedDevList.begin(), unownedDevList.end()); + return JniSecureUtils::convertDeviceVectorToJavaArray(env, ownedDevList); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} diff --git a/android/android_api/base/jni/JniOcProvisioning.h b/android/android_api/base/jni/JniOcProvisioning.h new file mode 100644 index 0000000..fe5bd9a --- /dev/null +++ b/android/android_api/base/jni/JniOcProvisioning.h @@ -0,0 +1,84 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniOcStack.h" +#include "OCProvisioningManager.h" +#include "JniSecureUtils.h" +#include "oxmjustworks.h" +#include "oxmrandompin.h" +#include +#include + +#ifndef _Included_org_iotivity_base_OcProvisioning +#define _Included_org_iotivity_base_OcProvisioning + +using namespace OC; + +/* DO NOT EDIT THIS FILE - it is machine generated */ +/* Header for class org_iotivity_base_OcProvisioning */ + +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_iotivity_base_OcProvisioning + * Method: ownershipTransferCDdata + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCBdata + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverUnownedDevices + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverUnownedDevices1 + (JNIEnv *, jclass, jint); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: provisionInit + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_provisionInit + (JNIEnv *, jclass, jstring); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverOwnedDevices + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverOwnedDevices1 + (JNIEnv *, jclass, jint); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: getDevicestatusLists + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1 + (JNIEnv *, jclass, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/android_api/base/jni/JniOcSecureResource.cpp b/android/android_api/base/jni/JniOcSecureResource.cpp new file mode 100644 index 0000000..d2929de --- /dev/null +++ b/android/android_api/base/jni/JniOcSecureResource.cpp @@ -0,0 +1,653 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcSecureResource.h" +#include "JniSecureUtils.h" +namespace PH = std::placeholders; + +JniOcSecureResource::JniOcSecureResource(std::shared_ptr device) + : m_sharedSecureResource(device) +{} + +JniOcSecureResource::~JniOcSecureResource() +{ + LOGD("~JniOcSecureResource()"); + m_sharedSecureResource = nullptr; +} + +std::string JniOcSecureResource::getIpAddr() +{ + return m_sharedSecureResource->getDevAddr(); +} + +std::string JniOcSecureResource::getDeviceID() +{ + return m_sharedSecureResource->getDeviceID(); +} + +int JniOcSecureResource::getDeviceStatus() +{ + return m_sharedSecureResource->getDeviceStatus(); +} + +bool JniOcSecureResource::getOwnedStatus() +{ + return m_sharedSecureResource->getOwnedStatus(); +} + +OCSecureResource* JniOcSecureResource::getDevicePtr() +{ + return m_sharedSecureResource.get(); +} + +JniOcSecureResource* JniOcSecureResource::getJniOcSecureResourcePtr(JNIEnv *env, jobject thiz) +{ + JniOcSecureResource *secureResource = GetHandle(env, thiz); + if (env->ExceptionCheck()) + { + LOGE("Failed to get native handle from OcSecureResource"); + } + if (!secureResource) + { + ThrowOcException(JNI_NO_NATIVE_POINTER, ""); + } + return secureResource; +} + +JniProvisionResultListner* JniOcSecureResource::AddProvisionResultListener(JNIEnv* env, + jobject jListener) +{ + JniProvisionResultListner *resultListener = NULL; + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + resultListener = refPair.first; + refPair.second++; + it->second = refPair; + resultMap.insert(*it); + LOGD("Provision resultListener: ref. count incremented"); + break; + } + } + if (!resultListener) + { + resultListener = new JniProvisionResultListner(env, jListener, + RemoveCallback(std::bind(&JniOcSecureResource::RemoveProvisionResultListener, + this, PH::_1, PH::_2))); + jobject jgListener = env->NewGlobalRef(jListener); + + resultMap.insert(std::pair < jobject, std::pair < JniProvisionResultListner*, + int >> (jgListener, std::pair(resultListener, 1))); + LOGD("Provision resultListener: new listener"); + } + resultMapLock.unlock(); + return resultListener; +} + +void JniOcSecureResource::RemoveProvisionResultListener(JNIEnv* env, jobject jListener) +{ + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + resultMap.insert(*it); + LOGI("Provision resultListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniProvisionResultListner* listener = refPair.first; + delete listener; + resultMap.erase(it); + LOGI("Provision resultListener removed"); + } + break; + } + } + resultMapLock.unlock(); +} + +OCStackResult JniOcSecureResource::doOwnershipTransfer(JNIEnv* env, jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::OWNERSHIPTRANSFER); + }; + + return m_sharedSecureResource->doOwnershipTransfer(resultCallback); +} + +OCStackResult JniOcSecureResource::getLinkedDevices(JNIEnv *env, UuidList_t &uuidList) +{ + return m_sharedSecureResource->getLinkedDevices(uuidList); +} + +OCStackResult JniOcSecureResource::removeDevice(JNIEnv* env, jint timeout, jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::REMOVEDEVICE); + }; + + return m_sharedSecureResource->removeDevice((int)timeout, resultCallback); +} + +OCStackResult JniOcSecureResource::unlinkDevices(JNIEnv* env, jobject _device2, jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::UNLINKDEVICES); + }; + + JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2); + if (!device2) + { + return OC_STACK_ERROR; + } + + return m_sharedSecureResource->unlinkDevices(*device2->getDevicePtr(), resultCallback); +} + +OCStackResult JniOcSecureResource::provisionCredentials(JNIEnv* env, jint type, jint keySize, + jobject _device2, jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONCREDENTIALS); + }; + + JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2); + if (!device2) + { + return OC_STACK_ERROR; + } + + Credential cred((OicSecCredType_t)type, keySize); + + return m_sharedSecureResource->provisionCredentials(cred, *device2->getDevicePtr(), + resultCallback); +} + +OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobject jListener) +{ + OCStackResult ret; + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + OicSecAcl_t *acl = new OicSecAcl_t; + acl->next = nullptr; + if (!acl) + { + return OC_STACK_NO_MEMORY; + } + + if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl, acl)) + { + delete acl; + return OC_STACK_ERROR; + } + + ResultCallBack resultCallback = [acl, resultListener](PMResultList_t *result, int hasError) + { + delete acl; + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONACL); + }; + ret = m_sharedSecureResource->provisionACL(acl, resultCallback); + + if (ret != OC_STACK_OK) + { + delete acl; + + } + return ret; +} + +OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint type, jint keySize, + jobject _acl1, jobject _device2, jobject _acl2, jobject jListener) +{ + OCStackResult ret; + + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2); + if (!device2) + { + return OC_STACK_ERROR; + } + + Credential cred((OicSecCredType_t)type, keySize); + + OicSecAcl_t *acl1 = nullptr; + OicSecAcl_t *acl2 = nullptr; + + if (_acl1) + { + acl1 = new OicSecAcl_t; + if (!acl1) + { + return OC_STACK_NO_MEMORY; + } + + if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl1, acl1)) + { + delete acl1; + return OC_STACK_ERROR; + } + acl1->next = nullptr; + } + + if (_acl2) + { + acl2 = new OicSecAcl_t; + if (!acl2) + { + delete acl1; + return OC_STACK_NO_MEMORY; + } + + if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl2, acl2)) + { + delete acl2; + return OC_STACK_ERROR; + } + acl2->next = nullptr; + } + + ResultCallBack resultCallback = [acl1, acl2, resultListener](PMResultList_t *result, + int hasError) + { + delete acl1; + delete acl2; + resultListener->ProvisionResultCallback(result, hasError, + ListenerFunc::PROVISIONPAIRWISEDEVICES); + }; + + + ret = m_sharedSecureResource->provisionPairwiseDevices(cred, acl1, + *device2->getDevicePtr(), acl2, resultCallback); + if (ret != OC_STACK_OK) + { + delete acl1; + delete acl2; + } + return ret; +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: doOwnershipTransfer + * Signature: (Lorg/iotivity/base/OcSecureResource/doOwnershipTransferListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransfer +(JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcSecureResource_doOwnershipTransfer"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->doOwnershipTransfer(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_doOwnershipTransfer"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: removeDevice + * Signature: (ILorg/iotivity/base/OcSecureResource/removeDevice;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice +(JNIEnv *env, jobject thiz, jint timeout, jobject jListener) +{ + LOGD("OcSecureResource_removeDevice"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->removeDevice(env, timeout, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_removeDevice"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: unlinkDevices + * Signature: (Lorg/iotivity/base/OcSecureResource/unlinkDevices;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices +(JNIEnv *env, jobject thiz, jobject device2, jobject jListener) +{ + LOGD("OcSecureResource_unlinkDevices"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->unlinkDevices(env, device2, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_unlinkDevices"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionCredentials1 + * Signature: (Lorg/iotivity/base/OcSecureResource/provisionCredentials;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 +(JNIEnv *env, jobject thiz, jint type, jint keySize, jobject device2, jobject jListener) +{ + LOGD("OcSecureResource_provisionCredentials"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->provisionCredentials(env, type, keySize, device2, + jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionCredentials"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionACL + * Signature: (Lorg/iotivity/base/OcSecureResource/provisionACL;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL +(JNIEnv *env, jobject thiz, jobject acl, jobject jListener) +{ + LOGD("OcSecureResource_provisionACL"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->provisionACL(env, acl, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionACL"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionPairwiseDevices1 + * Signature: (Lorg/iotivity/base/OcSecureResource/provisionPairwiseDevices;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwiseDevices1 +(JNIEnv *env, jobject thiz, jint type, jint keySize, jobject acl1, jobject device2, + jobject acl2, jobject jListener) +{ + LOGD("OcSecureResource_provisionPairwiseDevices"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->provisionPairwiseDevices(env, type, keySize, + acl1, device2, acl2, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionPairwiseDevices"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getLinkedDevices + * Signature: ()Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevices +(JNIEnv *env, jobject thiz) +{ + LOGD("OcSecureResource_getLinkedDevices"); + UuidList_t uuidList; + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return nullptr; + } + + try + { + OCStackResult result = secureResource->getLinkedDevices(env, uuidList); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_getLinkedDevices"); + return nullptr; + } + return JniSecureUtils::convertUUIDVectorToJavaStrList(env, uuidList); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getIpAddr + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr + (JNIEnv *env, jobject thiz) +{ + LOGD("OcSecureResource_getIpAddr"); + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return nullptr; + } + + return env->NewStringUTF(secureResource->getIpAddr().c_str()); +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getDeviceID + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID + (JNIEnv *env , jobject thiz) +{ + LOGD("OcSecureResource_getDeviceID"); + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return nullptr; + } + + return env->NewStringUTF(secureResource->getDeviceID().c_str()); +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: deviceStatus + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus + (JNIEnv *env, jobject thiz) +{ + LOGD("OcSecureResource_deviceStatus"); + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return -1; + } + + return secureResource->getDeviceStatus(); +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: ownedStatus + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus + (JNIEnv *env, jobject thiz) +{ + LOGD("OcSecureResource_ownedStatus"); + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return -1; + } + + return secureResource->getOwnedStatus(); +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: dispose + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_dispose + (JNIEnv *env, jobject thiz) +{ + LOGD("OcSecureResource_dispose"); + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + delete secureResource; +} diff --git a/android/android_api/base/jni/JniOcSecureResource.h b/android/android_api/base/jni/JniOcSecureResource.h new file mode 100644 index 0000000..0b98f75 --- /dev/null +++ b/android/android_api/base/jni/JniOcSecureResource.h @@ -0,0 +1,171 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcStack.h" +#include "JniProvisionResultListner.h" +#include "OCProvisioningManager.h" +#include + +#ifndef _Included_org_iotivity_base_OcSecureResource +#define _Included_org_iotivity_base_OcSecureResource + +using namespace OC; + +class JniOcSecureResource +{ + public: + JniOcSecureResource(std::shared_ptr secureresource); + ~JniOcSecureResource(); + + static JniOcSecureResource* getJniOcSecureResourcePtr(JNIEnv *env, jobject thiz); + std::string getDeviceID(void); + std::string getIpAddr(void); + int getDeviceStatus(void); + bool getOwnedStatus(void); + OCSecureResource* getDevicePtr(); + + JniProvisionResultListner* AddProvisionResultListener(JNIEnv* env, jobject jListener); + void RemoveProvisionResultListener(JNIEnv* env, jobject jListener); + + OCStackResult doOwnershipTransfer(JNIEnv* env, jobject jListener); + OCStackResult getLinkedDevices(JNIEnv *env, UuidList_t &uuidList); + OCStackResult provisionACL(JNIEnv* env, jobject acl, jobject jListener); + OCStackResult provisionPairwiseDevices(JNIEnv* env, jint type, jint keySize, + jobject acl1, jobject device2, jobject acl2, jobject jListener); + OCStackResult provisionCredentials(JNIEnv* env, jint type, jint keySize, + jobject device2, jobject jListener); + OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener); + OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener); + + private: + + std::map> resultMap; + std::mutex resultMapLock; + std::shared_ptr m_sharedSecureResource; +}; + +/* DO NOT EDIT THIS FILE BEYOND THIS LINE - it is machine generated */ + +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_iotivity_base_OcSecureResource + * Method: doOwnershipTransfer + * Signature: (Lorg/iotivity/base/OcSecureResource/DoOwnershipTransferListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransfer + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: removeDevice + * Signature: (ILorg/iotivity/base/OcSecureResource/RemoveDeviceListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: unlinkDevices + * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/UnlinkDevicesListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionCredentials1 + * Signature: (IILjava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionCredentialsListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 + (JNIEnv *, jobject, jint, jint, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionACL + * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionAclListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionPairwiseDevices1 + * Signature: (IILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionPairwiseDevicesListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwiseDevices1 + (JNIEnv *, jobject, jint, jint, jobject, jobject, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getLinkedDevices + * Signature: ()Ljava/util/List; + */ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevices + (JNIEnv *, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getIpAddr + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr + (JNIEnv *, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: getDeviceID + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID + (JNIEnv *, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: deviceStatus + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus + (JNIEnv *, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: ownedStatus + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus + (JNIEnv *, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: dispose + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_dispose + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/android/android_api/base/jni/JniOcStack.cpp b/android/android_api/base/jni/JniOcStack.cpp index bb9868c..9884732 100644 --- a/android/android_api/base/jni/JniOcStack.cpp +++ b/android/android_api/base/jni/JniOcStack.cpp @@ -60,6 +60,10 @@ jclass g_cls_OcHeaderOption = NULL; jclass g_cls_ObservationInfo = NULL; jclass g_cls_OcResourceIdentifier = NULL; +jclass g_cls_OcProvisionResult = NULL; +jclass g_cls_OcSecureResource = NULL; +jclass g_cls_OcOicSecAcl = NULL; + jmethodID g_mid_Integer_ctor = NULL; jmethodID g_mid_Double_ctor = NULL; jmethodID g_mid_Boolean_ctor = NULL; @@ -90,6 +94,19 @@ jmethodID g_mid_ObservationInfo_N_ctor = NULL; jmethodID g_mid_OcPresenceStatus_get = NULL; jmethodID g_mid_OcResourceIdentifier_N_ctor = NULL; +jmethodID g_mid_OcProvisionResult_ctor = NULL; +jmethodID g_mid_OcSecureResource_ctor = NULL; + +jmethodID g_mid_OcOicSecAcl_get_subject = NULL; +jmethodID g_mid_OcOicSecAcl_get_resources_cnt = NULL; +jmethodID g_mid_OcOicSecAcl_get_resources = NULL; +jmethodID g_mid_OcOicSecAcl_get_permission = NULL; +jmethodID g_mid_OcOicSecAcl_get_periods_cnt = NULL; +jmethodID g_mid_OcOicSecAcl_get_periods = NULL; +jmethodID g_mid_OcOicSecAcl_get_recurrences = NULL; +jmethodID g_mid_OcOicSecAcl_get_owners_cnt = NULL; +jmethodID g_mid_OcOicSecAcl_get_owners = NULL; + jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line, const int code, const char* message) { @@ -400,6 +417,55 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) g_mid_OcResourceIdentifier_N_ctor = env->GetMethodID(g_cls_OcResourceIdentifier, "", "(J)V"); if (!g_mid_OcResourceIdentifier_N_ctor) return JNI_ERR; + //OcSecureResource + clazz = env->FindClass("org/iotivity/base/OcSecureResource"); + if (!clazz) return JNI_ERR; + g_cls_OcSecureResource = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + g_mid_OcSecureResource_ctor = env->GetMethodID(g_cls_OcSecureResource, "", "(J)V"); + if (!g_mid_OcSecureResource_ctor) return JNI_ERR; + + //ProvisionResult + clazz = env->FindClass("org/iotivity/base/ProvisionResult"); + if (!clazz) return JNI_ERR; + g_cls_OcProvisionResult = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + g_mid_OcProvisionResult_ctor = env->GetMethodID(g_cls_OcProvisionResult, "", "(Ljava/lang/String;I)V"); + if (!g_mid_OcProvisionResult_ctor) return JNI_ERR; + + //OicSecAcl + clazz = env->FindClass("org/iotivity/base/OicSecAcl"); + if (!clazz) return JNI_ERR; + g_cls_OcOicSecAcl = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_OcOicSecAcl_get_subject = env->GetMethodID(g_cls_OcOicSecAcl, "getSubject", "()Ljava/lang/String;"); + if (!g_mid_OcOicSecAcl_get_subject) return JNI_ERR; + + g_mid_OcOicSecAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getResourcesCount", "()I"); + if (!g_mid_OcOicSecAcl_get_resources_cnt) return JNI_ERR; + + g_mid_OcOicSecAcl_get_resources = env->GetMethodID(g_cls_OcOicSecAcl, "getResources", "(I)Ljava/lang/String;"); + if (!g_mid_OcOicSecAcl_get_resources) return JNI_ERR; + + g_mid_OcOicSecAcl_get_permission = env->GetMethodID(g_cls_OcOicSecAcl, "getPermission", "()I"); + if (!g_mid_OcOicSecAcl_get_permission) return JNI_ERR; + + g_mid_OcOicSecAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriodsCount", "()I"); + if (!g_mid_OcOicSecAcl_get_periods_cnt) return JNI_ERR; + + g_mid_OcOicSecAcl_get_periods = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriods", "(I)Ljava/lang/String;"); + if (!g_mid_OcOicSecAcl_get_periods) return JNI_ERR; + + g_mid_OcOicSecAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl, "getRecurrences", "(I)Ljava/lang/String;"); + if (!g_mid_OcOicSecAcl_get_recurrences) return JNI_ERR; + + g_mid_OcOicSecAcl_get_owners_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getOwnersCount", "()I"); + if (!g_mid_OcOicSecAcl_get_owners_cnt) return JNI_ERR; + + g_mid_OcOicSecAcl_get_owners = env->GetMethodID(g_cls_OcOicSecAcl, "getOwners", "(I)Ljava/lang/String;"); + if (!g_mid_OcOicSecAcl_get_owners) return JNI_ERR; + return JNI_CURRENT_VERSION; } @@ -446,4 +512,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) env->DeleteGlobalRef(g_cls_OcHeaderOption); env->DeleteGlobalRef(g_cls_ObservationInfo); env->DeleteGlobalRef(g_cls_OcResourceIdentifier); + env->DeleteGlobalRef(g_cls_OcSecureResource); + env->DeleteGlobalRef(g_cls_OcProvisionResult); + env->DeleteGlobalRef(g_cls_OcOicSecAcl); } \ No newline at end of file diff --git a/android/android_api/base/jni/JniOcStack.h b/android/android_api/base/jni/JniOcStack.h index f6b1ee0..1bb7fae 100644 --- a/android/android_api/base/jni/JniOcStack.h +++ b/android/android_api/base/jni/JniOcStack.h @@ -79,6 +79,9 @@ extern jclass g_cls_OcPresenceStatus; extern jclass g_cls_OcHeaderOption; extern jclass g_cls_ObservationInfo; extern jclass g_cls_OcResourceIdentifier; +extern jclass g_cls_OcProvisionResult; +extern jclass g_cls_OcSecureResource; +extern jclass g_cls_OcOicSecAcl; extern jmethodID g_mid_Integer_ctor; extern jmethodID g_mid_Double_ctor; @@ -109,6 +112,17 @@ extern jmethodID g_mid_OcHeaderOption_get_data; extern jmethodID g_mid_ObservationInfo_N_ctor; extern jmethodID g_mid_OcPresenceStatus_get; extern jmethodID g_mid_OcResourceIdentifier_N_ctor; +extern jmethodID g_mid_OcProvisionResult_ctor; +extern jmethodID g_mid_OcSecureResource_ctor; +extern jmethodID g_mid_OcOicSecAcl_get_subject; +extern jmethodID g_mid_OcOicSecAcl_get_resources_cnt; +extern jmethodID g_mid_OcOicSecAcl_get_resources; +extern jmethodID g_mid_OcOicSecAcl_get_permission; +extern jmethodID g_mid_OcOicSecAcl_get_periods_cnt; +extern jmethodID g_mid_OcOicSecAcl_get_periods; +extern jmethodID g_mid_OcOicSecAcl_get_recurrences; +extern jmethodID g_mid_OcOicSecAcl_get_owners_cnt; +extern jmethodID g_mid_OcOicSecAcl_get_owners; typedef void(*RemoveListenerCallback)(JNIEnv* env, jobject jListener); diff --git a/android/android_api/base/jni/JniPinCheckListener.cpp b/android/android_api/base/jni/JniPinCheckListener.cpp new file mode 100644 index 0000000..9a5e35a --- /dev/null +++ b/android/android_api/base/jni/JniPinCheckListener.cpp @@ -0,0 +1,77 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniPinCheckListener.h" +#include "oic_string.h" + +JniPinCheckListener::JniPinCheckListener(JNIEnv *env, jobject jListener) +{ + m_jListener = env->NewGlobalRef(jListener); +} + +JniPinCheckListener::~JniPinCheckListener() +{ + LOGI("~JniPinCheckListener()"); + if (m_jListener) + { + jint ret; + JNIEnv *env = GetJNIEnv(ret); + if (NULL == env) return; + env->DeleteWeakGlobalRef(m_jListener); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + } +} + +void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize) +{ + jint ret; + + JNIEnv *env = GetJNIEnv(ret); + if (NULL == env) return; + + jclass clsL = env->GetObjectClass(m_jListener); + + if (!clsL) + { + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;"); + if (!midL) + { + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + char *str = (char*)env->GetStringUTFChars(jpin, NULL); + OICStrcpy(pinBuf, bufSize, str); + env->ReleaseStringUTFChars(jpin, str); + + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); +} diff --git a/android/android_api/base/jni/JniPinCheckListener.h b/android/android_api/base/jni/JniPinCheckListener.h new file mode 100644 index 0000000..74d150d --- /dev/null +++ b/android/android_api/base/jni/JniPinCheckListener.h @@ -0,0 +1,40 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcStack.h" +#include "OCProvisioningManager.h" + +#ifndef _Included_org_iotivity_base_PinCheckListener +#define _Included_org_iotivity_base_PinCheckListener + +typedef std::function RemoveCallback; +class JniPinCheckListener +{ + public: + JniPinCheckListener(JNIEnv *, jobject); + ~JniPinCheckListener(); + + void PinCallback(char*, size_t); + private: + jobject m_jListener; +}; +#endif diff --git a/android/android_api/base/jni/JniProvisionResultListner.cpp b/android/android_api/base/jni/JniProvisionResultListner.cpp new file mode 100644 index 0000000..6b9fd04 --- /dev/null +++ b/android/android_api/base/jni/JniProvisionResultListner.cpp @@ -0,0 +1,150 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniProvisionResultListner.h" +#include "JniOcSecureResource.h" +#include "JniSecureUtils.h" + +JniProvisionResultListner::JniProvisionResultListner(JNIEnv *env, jobject jListener, + RemoveCallback removeProvisionResultListener) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeProvisionResultListener = removeProvisionResultListener; +} + +JniProvisionResultListner::~JniProvisionResultListner() +{ + LOGI("~JniProvisionResultListner()"); + if (m_jwListener) + { + jint ret; + JNIEnv *env = GetJNIEnv(ret); + if (NULL == env) return; + env->DeleteWeakGlobalRef(m_jwListener); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + } +} + +void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError, + ListenerFunc func) +{ + jint ret; + JNIEnv *env = GetJNIEnv(ret); + if (NULL == env) return; + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + + jobject jResultList = JniSecureUtils::convertProvisionresultVectorToJavaList(env, result); + if (!jResultList) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + + std::string calledFunc; + switch (func) + { + case ListenerFunc::OWNERSHIPTRANSFER: + { + calledFunc = "doOwnershipTransferListener"; + } + break; + case ListenerFunc::PROVISIONACL: + { + calledFunc = "provisionAclListener"; + } + break; + case ListenerFunc::PROVISIONCREDENTIALS: + { + calledFunc = "provisionCredentialsListener"; + } + break; + case ListenerFunc::UNLINKDEVICES: + { + calledFunc = "unlinkDevicesListener"; + } + break; + case ListenerFunc::REMOVEDEVICE: + { + calledFunc = "removeDeviceListener"; + } + break; + case ListenerFunc::PROVISIONPAIRWISEDEVICES: + { + calledFunc = "provisionPairwiseDevicesListener"; + } + break; + default: + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + } + return; + } + + jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Ljava/util/List;I)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + return; + } + env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + } + + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); +} + +void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeProvisionResultListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeProvisionResultListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniProvisionResultListner.h b/android/android_api/base/jni/JniProvisionResultListner.h new file mode 100644 index 0000000..6df56d7 --- /dev/null +++ b/android/android_api/base/jni/JniProvisionResultListner.h @@ -0,0 +1,55 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include +#include "JniOcStack.h" +#include "OCProvisioningManager.h" + +#ifndef _Included_org_iotivity_base_OcProvisioning_JniProvisionResultListner +#define _Included_org_iotivity_base_OcProvisioning_JniProvisionResultListner + +typedef std::function RemoveCallback; + +enum class ListenerFunc +{ + OWNERSHIPTRANSFER = 1, + PROVISIONACL, + PROVISIONCREDENTIALS, + UNLINKDEVICES, + REMOVEDEVICE, + PROVISIONPAIRWISEDEVICES +}; + +class JniProvisionResultListner +{ + public: + JniProvisionResultListner(JNIEnv *env, jobject jListener, + RemoveCallback removeProvisionResultListener); + ~JniProvisionResultListner(); + + void ProvisionResultCallback(OC::PMResultList_t *result, int hasError, ListenerFunc func); + + private: + RemoveCallback m_removeProvisionResultListener; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; +#endif diff --git a/android/android_api/base/jni/JniSecureUtils.cpp b/android/android_api/base/jni/JniSecureUtils.cpp new file mode 100644 index 0000000..2fb507f --- /dev/null +++ b/android/android_api/base/jni/JniSecureUtils.cpp @@ -0,0 +1,240 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniSecureUtils.h" +#include "JniOcSecureResource.h" +#include "base64.h" + +jobject JniSecureUtils::convertProvisionresultVectorToJavaList(JNIEnv *env, const OC::PMResultList_t *result) +{ + jobject jResultList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor); + if (!jResultList) + { + return nullptr; + } + + for (size_t i = 0; i < result->size(); ++i) + { + jobject jresult = env->NewObject( + g_cls_OcProvisionResult, + g_mid_OcProvisionResult_ctor, + env->NewStringUTF((char*)result->at(i).deviceId.id), + static_cast(result->at(i).res) + ); + if (!jresult) + { + return nullptr; + } + + env->CallBooleanMethod(jResultList, g_mid_LinkedList_add_object, jresult); + if (env->ExceptionCheck()) + { + return nullptr; + } + env->DeleteLocalRef(jresult); + } + return jResultList; +} + +jobjectArray JniSecureUtils::convertDeviceVectorToJavaArray(JNIEnv *env, + std::vector> &deviceListVector) +{ + jsize len = static_cast(deviceListVector.size()); + jobjectArray devArr = env->NewObjectArray(len, g_cls_OcSecureResource, NULL); + + if (!devArr) + { + return nullptr; + } + + for (jsize i = 0; i < len; ++i) + { + JniOcSecureResource *device = new JniOcSecureResource(deviceListVector[i]); + jobject jDevice = env->NewObject(g_cls_OcSecureResource, g_mid_OcSecureResource_ctor); + + SetHandle(env, jDevice, device); + if (!jDevice) + { + return nullptr; + } + + env->SetObjectArrayElement(devArr, i, jDevice); + if (env->ExceptionCheck()) + { + return nullptr; + } + env->DeleteLocalRef(jDevice); + } + return devArr; +} + +std::string JniSecureUtils::convertUUIDtoStr(OicUuid_t uuid) +{ + std::ostringstream deviceId(""); + char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*)0)->id)) + 1] = {0,}; + uint32_t outLen = 0; + B64Result b64Ret = B64_OK; + + b64Ret = b64Encode(uuid.id, sizeof(uuid.id), base64Buff, + sizeof(base64Buff), &outLen); + + deviceId << base64Buff; + return deviceId.str(); +} + +void JniSecureUtils::convertStrToUUID(char *str, OicUuid_t &uuid) +{ + unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {}; + uint32_t outLen = 0; + B64Result b64Ret = B64_OK; + + b64Ret = b64Decode(str, strlen(str), base64Buff, sizeof(base64Buff), &outLen); + memcpy(uuid.id, base64Buff, outLen); +} + +jobject JniSecureUtils::convertUUIDVectorToJavaStrList(JNIEnv *env, UuidList_t &vector) +{ + jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor); + if (!jList) + { + return nullptr; + } + for (size_t i = 0; i < vector.size(); ++i) + { + jstring jStr = env->NewStringUTF((convertUUIDtoStr(vector[i])).c_str()); + if (!jStr) + { + return nullptr; + } + env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, jStr); + if (env->ExceptionCheck()) + { + return nullptr; + } + env->DeleteLocalRef(jStr); + } + return jList; +} + +OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *acl) +{ + jstring jData; + jvalue args[1]; + + jData = (jstring) env->CallObjectMethod(in, g_mid_OcOicSecAcl_get_subject); + if (!jData || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + char *str = (char*) env->GetStringUTFChars(jData, 0); + convertStrToUUID(str, acl->subject); + env->ReleaseStringUTFChars(jData, str); + + jint jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_resources_cnt); + if (!jCount || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->resourcesLen = jCount; + acl->resources = new char*[jCount]; + for (jint i = 0; i < jCount; ++i) + { + args[0].i = i; + jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_resources, args); + if (!jData || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->resources[i] = (char*) env->GetStringUTFChars(jData, 0); + } + + jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_permission); + if (env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->permission = jCount; + jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_periods_cnt); + if (env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->prdRecrLen = jCount; + acl->periods = new char*[jCount]; + for (jint i = 0; i < jCount; ++i) + { + args[0].i = i; + jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_periods, args); + if (!jData || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->periods[i] = (char*) env->GetStringUTFChars(jData, 0); + } + + acl->recurrences = new char*[jCount]; //TODO:Period Len and Reccurence len is same + for (jint i = 0; i < jCount; ++i) + { + args[0].i = i; + jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_recurrences, args); + if (!jData || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->recurrences[i] = (char*) env->GetStringUTFChars(jData, 0); + } + + jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_owners_cnt); + if (!jCount || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + acl->ownersLen = jCount; + acl->owners = new OicUuid_t[acl->ownersLen]; + if (!acl->owners) + { + return OC_STACK_ERROR; + } + + for (jint i = 0; i < jCount; ++i) + { + args[0].i = i; + jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_owners, args); + if (!jData || env->ExceptionCheck()) + { + return OC_STACK_ERROR; + } + + str = (char*) env->GetStringUTFChars(jData, 0); + convertStrToUUID(str, acl->owners[i]); + env->ReleaseStringUTFChars(jData, str); + } + return OC_STACK_OK; +} diff --git a/android/android_api/base/jni/JniSecureUtils.h b/android/android_api/base/jni/JniSecureUtils.h new file mode 100644 index 0000000..c239c44 --- /dev/null +++ b/android/android_api/base/jni/JniSecureUtils.h @@ -0,0 +1,38 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcStack.h" +#include "OCProvisioningManager.h" + +class JniSecureUtils +{ + private: + static std::string convertUUIDtoStr(OicUuid_t uuid); + static void convertStrToUUID(char *str, OicUuid_t &uuid); + public: + static jobject convertProvisionresultVectorToJavaList(JNIEnv *, + const OC::PMResultList_t *); + static jobjectArray convertDeviceVectorToJavaArray(JNIEnv *env, + std::vector>& deviceListVector); + static jobject convertUUIDVectorToJavaStrList(JNIEnv *env, OC::UuidList_t &vector); + static OCStackResult convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *out); +}; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java new file mode 100644 index 0000000..bbaeda7 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java @@ -0,0 +1,74 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.security.InvalidParameterException; +import java.util.EnumSet; + +public enum CredType { + + NO_SECURITY_MODE (0), + + SYMMETRIC_PAIR_WISE_KEY (1 << 0), + + SYMMETRIC_GROUP_KEY (1 << 1), + + ASYMMETRIC_KEY (1 << 2), + + SIGNED_ASYMMETRIC_KEY (1 << 3), + + PIN_PASSWORD (1 << 4), + + ASYMMETRIC_ENCRYPTION_KEY (1 << 5), + + ; + private int value; + + private CredType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + public static EnumSet convertToEnumSet(int value) { + EnumSet typeSet = null; + + for (CredType v : values()) { + if (0 != (value & v.getValue())) { + if (null == typeSet) { + typeSet = EnumSet.of(v); + } else { + typeSet.add(v); + } + } + } + + if (null == typeSet || typeSet.isEmpty()) { + throw new InvalidParameterException("Unexpected CredType value:" + value); + } + + return typeSet; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java new file mode 100644 index 0000000..4bc2e6f --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java @@ -0,0 +1,55 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum DeviceStatus { + ON(0), + OFF(1), + INVALID(-1); + + private int value; + + private DeviceStatus(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + public static DeviceStatus convertDeviceStatus(int value) { + + if (0 == value) + { + return DeviceStatus.ON; + } + else if (1 == value) + { + return DeviceStatus.OFF; + } + else + { + return DeviceStatus.INVALID; + } + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java new file mode 100644 index 0000000..6243db6 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java @@ -0,0 +1,38 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum KeySize { + OWNER_PSK_LENGTH_128 (128/8), + OWNER_PSK_LENGTH_256 (256/8),; + + private int value; + + private KeySize(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java new file mode 100644 index 0000000..636e590 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java @@ -0,0 +1,102 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.List; +import java.util.Arrays; +import java.util.Map; + +/** + * OcProvisionig represents functions corresponding to the provisioing of + * resources. + */ +public class OcProvisioning { + + /** + * Method to Intialize Provisioning Manager.This will load the provisioning + * Manager's persistent database. + * + * @param dbPath dbPath file path of the sqlite3 db. + * @throws OcException + */ + public static native void provisionInit(String dbPath) throws OcException; + + /** + * Method to Discover un-owned devices in its subnet.Un-owned devices need + * to be owned by calling ownershipTransferCBdata. + * + * @param timeout Timeout in sec.Time to listen for responses before + * returining the Array. + * @return Array of OcSecureResource class objects. + * @throws OcException + */ + public static List discoverUnownedDevices(int timeout) throws OcException { + return Arrays.asList(OcProvisioning.discoverUnownedDevices1(timeout)); + } + private static native OcSecureResource[] discoverUnownedDevices1(int timeout) throws OcException; + + /** + * Method to Discover owned devices in its subnet. + * + * @param timeout Timeout in sec.Time to listen for responses before + * returining the Array. + * @return Array of OcSecureResource class objects. + * @throws OcException + */ + public static List discoverOwnedDevices(int timeout) throws OcException { + return Arrays.asList(OcProvisioning.discoverOwnedDevices1(timeout)); + } + private static native OcSecureResource[] discoverOwnedDevices1(int timeout) throws OcException; + + /** + * API for registering Ownership transfer methods for a particular + * transfer Type + * + * @param type OxmType ownership transfer type. + * @throws OcException + */ + public static void SetownershipTransferCBdata(OxmType type, + PinCallbackListener pinCallbackListener) throws OcException + { + OcProvisioning.ownershipTransferCBdata(type.getValue(), pinCallbackListener); + } + + private static native void ownershipTransferCBdata(int oxmType, PinCallbackListener pinCallbackListener); + + public static interface PinCallbackListener { + public String pinCallbackListener(); + } + + /** + * Method to get Array of owned and un-owned devices in the current subnet. + * + * @param timeout timeout in sec for the API to return. + * @retrun Array of OcSecureResource class objects. + * be provisioned. + * @throws OcException + */ + public static List getDeviceStatusList(int timeout) throws OcException { + return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout)); + } + private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException; +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java new file mode 100644 index 0000000..218b9e2 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java @@ -0,0 +1,240 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.List; +import java.util.EnumSet; +import java.util.Map; + +public class OcSecureResource { + + private OcSecureResource(long nativeHandle) { + this.mNativeHandle = nativeHandle; + } + + /** + * Method to Start Ownership Transfer of an un-owned device. + * + * @param DoOwnershipTransferListener Callback function, which will be called after + * completion of ownership Transfer. + * @throws OcException + */ + public native void doOwnershipTransfer(DoOwnershipTransferListener doOwnershipTransferListener) + throws OcException; + + /** + * Method removes device credential from all devices in subnet + * + * @param timeout + * @param RemoveDeviceListener Callback function, which will be called after + * completion of removing device. + * @throws OcException + */ + public native void removeDevice(int timeout, RemoveDeviceListener removeDeviceListener) + throws OcException; + + /** + * Method removes the credential & relationship between the two devices. + * + * @param jobject Second device + * @param UnlinkDevicesListener Callback function, which will be called after + * completion of removing device. + * @throws OcException + */ + public native void unlinkDevices(Object device2, UnlinkDevicesListener unlinkDevicesListener) + throws OcException; + + /** + * Method removes the credential & relationship between the two devices. + * + * @param EnumSet OR'ed Cred Types + * @param KeySize keySize + * @param Object Second device + * @param ProvisionCredentialsListener Callback function, which will be called after + * completion of removing device. + * @throws OcException + */ + public void provisionCredentials(EnumSet credTypeSet, KeySize keysize, Object device2, + ProvisionCredentialsListener provisionCredentialsListener) throws OcException { + int credTypeInt = 0; + + for (CredType credType : CredType.values()) { + if (credTypeSet.contains(credType)) + credTypeInt |= credType.getValue(); + } + this.provisionCredentials1(credTypeInt, keysize.getValue(), + device2, provisionCredentialsListener); + } + private native void provisionCredentials1(int type, int keySize, Object device2, + ProvisionCredentialsListener provisionCredentialsListener) + throws OcException; + + /** + * Method send ACL information to resource. + * + * @param jobject Acl + * @param ProvisionAclListener Callback function, which will be called after + * completion of removing device. + * @throws OcException + */ + public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener) + throws OcException; + + + /** + * Method provisions credentials between two devices and ACLs for the devices who + * act as a server. + * + * @param EnumSet OR'ed Cred Types + * @param KeySize keySize + * @param Object First acl + * @param Object Second device + * @param Object Second acl + * @param ProvisionPairwiseDevicesListener Callback function, which will be called after + * completion of removing device. + * @throws OcException + */ + public void provisionPairwiseDevices(EnumSet credTypeSet, KeySize keysize, Object acl1, + Object device2, Object acl2, + ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException { + int credTypeInt = 0; + + for (CredType credType : CredType.values()) { + if (credTypeSet.contains(credType)) + credTypeInt |= credType.getValue(); + } + this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2, + acl2, provisionPairwiseDevicesListener); + } + private native void provisionPairwiseDevices1(int type, int keySize, Object acl1, + Object device2, Object acl2, + ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException; + + /** + * doOwnershipTransferListener can be registered with doOwnershipTransfer + * call. + * Listener notified asynchronously. + */ + public interface DoOwnershipTransferListener { + public void doOwnershipTransferListener(List provisionResultList, + int hasError); + } + + /** + * removeDeviceListener can be registered with removeDeviceListener + * call. + * Listener notified asynchronously. + */ + public interface RemoveDeviceListener { + public void removeDeviceListener(List provisionResultList, + int hasError); + } + + /** + * unlinkDevicesListener can be registered with unlinkDevicesListener + * call. + * Listener notified asynchronously. + */ + public interface UnlinkDevicesListener { + public void unlinkDevicesListener(List provisionResultList, + int hasError); + } + + /** + * provisionCredentialsListener can be registered with provisionCredentialsListener + * call. + * Listener notified asynchronously. + */ + public interface ProvisionCredentialsListener { + public void provisionCredentialsListener(List provisionResultList, + int hasError); + } + + /** + * provisionAclListener can be registered with provisionAclListener + * call. + * Listener notified asynchronously. + */ + public interface ProvisionAclListener { + public void provisionAclListener(List provisionResultList, + int hasError); + } + + /** + * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener + * call. + * Listener notified asynchronously. + */ + public interface ProvisionPairwiseDevicesListener { + public void provisionPairwiseDevicesListener(List provisionResultList, + int hasError); + } + + /** Method to get List of device ID of devices linked with invoking device. + * + * @return Sring List List of device id's of linked devices. + */ + public native List getLinkedDevices(); + + /** + * Method to get IP address of sercure discovered device. + * @return Stringified IP address. + */ + public native String getIpAddr(); + + /** + * Method to get device id of a device. + * @return Device ID of the selected device. + */ + public native String getDeviceID(); + + /** + * Method to get device status (ON/OFF) of a device. + * @return ON/OFF + */ + + public DeviceStatus getDeviceStatus() throws OcException { + return DeviceStatus.convertDeviceStatus(this.deviceStatus()); + } + public native int deviceStatus() throws OcException; + + /** + * Method to get device ownership (OWNED/UNOWNED) status. + * @return OWNED/UNOWNED + */ + + public OwnedStatus getOwnedStatus() throws OcException { + return OwnedStatus.convertOwnedStatus(this.ownedStatus()); + } + public native int ownedStatus() throws OcException; + + @Override + protected void finalize() throws Throwable { + super.finalize(); + dispose(); + } + + private native void dispose(); + + private long mNativeHandle; +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java b/android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java new file mode 100644 index 0000000..5ca6d96 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java @@ -0,0 +1,123 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.io.Serializable; +import java.util.List; +import java.util.Arrays; + +public class OicSecAcl implements Serializable { + + private String subject; + private int permission; + private List resources; + private List periods; + private List recurrences; + private List owners; + + public OicSecAcl(String subject, List recurrences, List periods, int permission, + List resources, List owners) { + this.subject = subject; + this.recurrences = recurrences; + this.periods = periods; + this.permission = permission; + this.resources = resources; + this.owners = owners; + } + + public String getSubject() { + return this.subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public List getOwners() { + return owners; + } + + public void setOwners(List owners) { + this.owners = owners; + } + + public List getRecurrences() { + return recurrences; + } + + public void setRecurrences(List recurrences) { + this.recurrences = recurrences; + } + + public List getPeriods() { + return periods; + } + + public void setPeriods(List periods) { + this.periods = periods; + } + + public int getPermission() { + return this.permission; + } + + public void setPermission(int permission) { + this.permission = permission; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } + + public int getResourcesCount() { + return this.resources.size(); + } + + public String getResources(int i) { + return this.resources.get(i); + } + + public int getPeriodsCount() { + return this.periods.size(); + } + + public String getPeriods(int i) { + return this.periods.get(i); + } + + public String getRecurrences(int i) { + return this.recurrences.get(i); + } + + public int getOwnersCount() { + return this.owners.size(); + } + + public String getOwners(int i) { + return this.owners.get(i); + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java new file mode 100644 index 0000000..1c90578 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java @@ -0,0 +1,55 @@ +/* + * //****************************************************************** + * // + * // Copyright Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum OwnedStatus { + OWNED(0), + UNOWNED(1), + INVALID(-1); + + private int value; + + private OwnedStatus(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + public static OwnedStatus convertOwnedStatus(int value) { + + if (0 == value) + { + return OwnedStatus.UNOWNED; + } + else if (1 == value) + { + return OwnedStatus.OWNED; + } + else + { + return OwnedStatus.INVALID; + } + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java new file mode 100644 index 0000000..f336076 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java @@ -0,0 +1,42 @@ +/* + * //****************************************************************** + * // + * // Copyright 2015 Samsung Electronics All Rights Reserved. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // http://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + * // + * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum OxmType { + OIC_JUST_WORKS(0), + OIC_MODE_SWITCH(1), + OIC_RANDOM_DEVICE_PIN(2), + OIC_PRE_PROVISIONED_DEVICE_PIN(3), + OIC_PRE_PROVISION_STRONG_CREDENTIAL(4), + OIC_OXM_COUNT(5); + + private int value; + + private OxmType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java b/android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java new file mode 100644 index 0000000..5d46b8f --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java @@ -0,0 +1,41 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * *****************************************************************/ +package org.iotivity.base; + +public class ProvisionResult { + + private String mDeviceId; + private int mResult; + + public ProvisionResult(String deviceId, int result) + { + this.mDeviceId = deviceId; + this.mResult = result; + } + + public String getDevId() + { + return this.mDeviceId; + } + public int getResult() + { + return this.mResult; + } +} diff --git a/android/examples/provisioningclient/build.gradle b/android/examples/provisioningclient/build.gradle new file mode 100644 index 0000000..252b151 --- /dev/null +++ b/android/examples/provisioningclient/build.gradle @@ -0,0 +1,24 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "org.iotivity.base.examples.provisioningclient" + minSdkVersion 19 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/android/examples/provisioningclient/proguard-rules.pro b/android/examples/provisioningclient/proguard-rules.pro new file mode 100644 index 0000000..8a79c59 --- /dev/null +++ b/android/examples/provisioningclient/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/sri/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android/examples/provisioningclient/provisioningclient.iml b/android/examples/provisioningclient/provisioningclient.iml new file mode 100644 index 0000000..c44426e --- /dev/null +++ b/android/examples/provisioningclient/provisioningclient.iml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/provisioningclient/src/main/AndroidManifest.xml b/android/examples/provisioningclient/src/main/AndroidManifest.xml new file mode 100644 index 0000000..93a375b --- /dev/null +++ b/android/examples/provisioningclient/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json b/android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json new file mode 100644 index 0000000..17dc43f --- /dev/null +++ b/android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json @@ -0,0 +1,49 @@ +{ + "acl": [ + { + "sub": "Kg==", + "rsrc": [ + "/oic/res", + "/oic/d", + "/oic/p", + "/oic/res/types/d", + "/oic/ad", + "/oic/sec/acl" + ], + "perms": 2, + "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="] + }, + { + "sub": "Kg==", + "rsrc": [ + "/oic/sec/doxm", + "/oic/sec/pstat" + ], + "perms": 2, + "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="] + } + ], + "pstat": { + "isop": true, + "deviceid": "ZGV2aWNlaWQAAAAAABhanw==", + "ch": 0, + "cm": 0, + "tm": 0, + "om": 3, + "sm": [3] + }, + "doxm": { + "oxm": [0], + "oxmsel": 0, + "owned": true, + "deviceid": "MjIyMjIyMjIyMjIyMjIyMg==", + "ownr": "MjIyMjIyMjIyMjIyMjIyMg==" + }, + "cred": [{ + "credid": 1, + "sub": "MTExMTExMTExMTExMTExMQ==", + "credtyp": 1, + "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==", + "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="] + }] +} diff --git a/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java new file mode 100644 index 0000000..b9758af --- /dev/null +++ b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java @@ -0,0 +1,711 @@ + +package org.iotivity.base.examples.provisioningclient; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Message; +import android.preference.PreferenceManager; +import android.text.method.ScrollingMovementMethod; +import android.util.Log; +import android.view.Gravity; +import android.widget.LinearLayout; +import android.widget.TextView; + + +import org.iotivity.base.ModeType; + +import org.iotivity.base.OcException; + +import org.iotivity.base.OcPlatform; + + +import org.iotivity.base.PlatformConfig; +import org.iotivity.base.QualityOfService; +import org.iotivity.base.ServiceType; +import org.iotivity.base.OcProvisioning; +import org.iotivity.base.OcSecureResource; +import org.iotivity.base.ProvisionResult; +import org.iotivity.base.OxmType; +import org.iotivity.base.OicSecAcl; +import org.iotivity.base.CredType; +import org.iotivity.base.KeySize; +import org.iotivity.base.DeviceStatus; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.EnumSet; + + +import java.util.List; + + +public class ProvisioningClient extends Activity implements + OcSecureResource.DoOwnershipTransferListener, + OcSecureResource.ProvisionPairwiseDevicesListener { + private static final String TAG = "Provisioning Client: "; + OcProvisioning.PinCallbackListener pinCallbackListener = + new OcProvisioning.PinCallbackListener() { + @Override + public String pinCallbackListener() { + + Log.d(TAG, "Inside Pin Callback "); + return ""; + + } + }; + OcSecureResource.ProvisionAclListener provisionAclListener = + new OcSecureResource.ProvisionAclListener() { + @Override + public void provisionAclListener(List provisionResults, + int hasError) { + + Log.d(TAG, "Inside ProvisionAclListener "); + + if (hasError == StringConstants.ERROR_CODE) { + logMessage("Error: ACL Provision failed !!"); + } else { + logMessage("ACL Provision Done !!"); + new DeviceRevocationAsyncTask().execute(); + } + + } + }; + OcSecureResource.ProvisionCredentialsListener provisionCredentialsListener = + new OcSecureResource.ProvisionCredentialsListener() { + @Override + public void provisionCredentialsListener(List provisionResults, + int hasError) { + + Log.d(TAG, "Inside ProvisionCredentialsListener "); + if (hasError == StringConstants.ERROR_CODE) { + logMessage("Error: Provision Credentials failed !!"); + } else { + logMessage("Provision Credentials Done !!"); + new ProvisionACLAsyncTask().execute(); + } + + + } + }; + OcSecureResource.UnlinkDevicesListener unlinkDevicesListener = + new OcSecureResource.UnlinkDevicesListener() { + @Override + public void unlinkDevicesListener(List provisionResults, + int hasError) { + Log.d(TAG, "Inside unlinkDevicesListener "); + + if (hasError == StringConstants.ERROR_CODE) { + logMessage("Error: UnLinking device !!"); + } else { + logMessage("Unlink Done !!"); + new ProvisionCredentialAsyncTask().execute(); + } + + } + }; + + OcSecureResource.RemoveDeviceListener removeDeviceListener = + new OcSecureResource.RemoveDeviceListener() { + @Override + public void removeDeviceListener(List provisionResults, + int hasError) { + if (hasError == StringConstants.ERROR_CODE) { + logMessage("Error: Remove Fail !!"); + } else { + logMessage("Remove Device done !!"); + } + } + }; + private static final int BUFFER_SIZE = 1024; + int unownedDevCount = StringConstants.NUMBER_ZERO; + private String filePath = ""; + private OcSecureResource newSecureResource; + private List deviceList; + private List ownedDeviceList; + //for display + private TextView mEventsTextView; + + /** + * configure OIC platform and call findResource + */ + private void initOICStack() { + + //create platform config + PlatformConfig cfg = new PlatformConfig( + this, + ServiceType.IN_PROC, + ModeType.CLIENT_SERVER, + "0.0.0.0", // bind to all available interfaces + 0, + QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE); + OcPlatform.Configure(cfg); + + try { + /* + * Initialize DataBase + */ + + String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") + + File.separator; + + File file = new File(sqlDbPath); + //check files directory exists + if (!(file.isDirectory())) { + file.mkdirs(); + Log.d(TAG, "Sql db directory created at " + sqlDbPath); + } + Log.d(TAG, "Sql db directory exists at " + sqlDbPath); + + OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE); + } catch (OcException e) { + logMessage(TAG + "provisionInit error: " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } + + new DiscoveryOTTransferAsyncTask().execute(); + } + + @Override + synchronized public void doOwnershipTransferListener(List ProvisionResultList, + int hasError) { + + ProvisionResult pResult = ProvisionResultList.get(0); + if (hasError == StringConstants.ERROR_CODE) { + logMessage(TAG + "Ownership Transfer Failed for " + pResult.getDevId()); + } else { + logMessage(TAG + "Ownership Transfer Successful for " + + pResult.getDevId()); + unownedDevCount--; + } + + if (unownedDevCount == 0) { //When done with Ownership Transfer + new OwnedDiscoveryAsyncTask().execute(); + } + } + + private void doPairwiseProvisioning() { + try { + logMessage(TAG + "Pairwise Provisioning b/w " + ownedDeviceList.get(0).getDeviceID() + + " and " + ownedDeviceList.get(1).getDeviceID()); + newSecureResource = ownedDeviceList.get(0); + OcSecureResource newSecureResource2 = ownedDeviceList.get(1); + List resources = new ArrayList(); + List owners = new ArrayList(); + List periods = new ArrayList(); + List recurrences = new ArrayList(); + recurrences.add("Daily"); + resources.add("*"); + owners.add("adminDeviceUUID0"); + periods.add("01-01-15"); + OicSecAcl acl1 = new OicSecAcl(newSecureResource.getDeviceID(), recurrences, periods, + 31, resources, owners); + OicSecAcl acl2 = new OicSecAcl(newSecureResource2.getDeviceID(), recurrences, periods, + 31, resources, owners); + newSecureResource.provisionPairwiseDevices(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY), + KeySize.OWNER_PSK_LENGTH_128, acl1, newSecureResource2, acl2, this); + + } catch (Exception e) { + logMessage(TAG + "Pairwise Provisioning error: " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } + } + + @Override + public void provisionPairwiseDevicesListener(List ProvisionResultList, + int hasError) { + if (hasError == StringConstants.ERROR_CODE) { + logMessage(TAG + "provisionPairwiseDevices Failed"); + } else { + for (int i = 0; i < ProvisionResultList.size(); i++) { + ProvisionResult pResult = ProvisionResultList.get(i); + logMessage(TAG + "provisionPairwiseDevices Result for " + + pResult.getDevId() + "is " + pResult.getResult()); + } + new GetLinkedDevicesAsyncTask().execute(); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_secure_provision_client); + mEventsTextView = new TextView(this); + mEventsTextView.setGravity(Gravity.BOTTOM); + mEventsTextView.setMovementMethod(new ScrollingMovementMethod()); + LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout); + layout.addView(mEventsTextView, new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f) + ); + + filePath = getFilesDir().getPath() + "/"; // data/data//files/ + //copy json when application runs first time + SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this); + boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true); + if (isFirstRun) { + copyJsonFromAsset(); + SharedPreferences.Editor editor = wmbPreference.edit(); + editor.putBoolean("FIRSTRUN", false); + editor.commit(); + } + initOICStack(); + } + + /** + * Copy svr db json file from assets folder to app data files dir + */ + private void copyJsonFromAsset() { + InputStream inputStream = null; + OutputStream outputStream = null; + int length; + byte[] buffer = new byte[BUFFER_SIZE]; + + try { + inputStream = getAssets().open(StringConstants.OIC_CLIENT_JSON_DB_FILE); + File file = new File(filePath); + //check files directory exists + if (!(file.exists() && file.isDirectory())) { + file.mkdirs(); + } + outputStream = new FileOutputStream(filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE); + + while ((length = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, length); + } + + + } catch (NullPointerException e) { + logMessage(TAG + "Null pointer exception " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (FileNotFoundException e) { + logMessage(TAG + "Json svr db file not found " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (IOException e) { + logMessage(TAG + StringConstants.OIC_CLIENT_JSON_DB_FILE + " file copy failed"); + Log.e(TAG, e.getMessage()); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + } + } + + public void logMessage(String text) { + logMsg(text); + } + + public void logMsg(final String text) { + runOnUiThread(new Runnable() { + public void run() { + Message msg = new Message(); + msg.obj = text; + mEventsTextView.append(text); + mEventsTextView.append("\n\n"); + } + }); + Log.i(TAG, text); + + Intent intent = new Intent(getPackageName()); + intent.putExtra(StringConstants.MESSAGE, text); + sendBroadcast(intent); + } + + private class DiscoveryOTTransferAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected String doInBackground(Void... params) { + try { + /** + * Discover Un-owned devices + */ + + publishProgress(TAG + "Discovering Unowned Devices"); + deviceList = new ArrayList(); + deviceList = OcProvisioning.discoverUnownedDevices(5); + + + if (deviceList.size() > 0) { + unownedDevCount = deviceList.size(); + for (int i = 0; i < deviceList.size(); i++) { + publishProgress(TAG + "Un-owned Discovered Device " + (i + 1) + "= " + + deviceList.get(i).getDeviceID()); + } + + + try { + + OcProvisioning.SetownershipTransferCBdata(OxmType.OIC_JUST_WORKS, + pinCallbackListener); + + for (int i = 0; i < deviceList.size(); i++) { + publishProgress(TAG + "Doing Ownership Transfer for " + + deviceList.get(i).getDeviceID()); + deviceList.get(i).doOwnershipTransfer(ProvisioningClient.this); + } + } catch (OcException e) { + publishProgress(TAG + "Ownership Transfer error: " + e.getMessage()); + return "Ownership Transfer error: " + e.getMessage(); + + } + + + } else { + publishProgress(TAG + "No un-owned devices present"); + } + + } catch (OcException e) { + publishProgress(TAG + "Un-owned discovery error: " + e.getMessage()); + return "Un-owned discovery error: " + e.getMessage(); + + } + return "success"; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + @Override + protected void onPostExecute(String s) { + super.onPostExecute(s); + } + } + + private class ProvisionACLAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected Void doInBackground(Void... params) { + try { + + + if (ownedDeviceList.size() > 1) { + OcSecureResource ocSecureResource = ownedDeviceList.get(0); + + OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1); + + publishProgress(TAG + "ACL Provision for " + ocSecureResource.getDeviceID()); + + List resources = new ArrayList(); + List owners = new ArrayList(); + List periods = new ArrayList(); + List recurrences = new ArrayList(); + recurrences.add("Daily"); + resources.add("*"); + owners.add("adminDeviceUUID0"); + periods.add("01-01-15"); + + OicSecAcl aclObject = new OicSecAcl(ocSecureResourceDest.getDeviceID(), + recurrences, periods, 31, resources, owners); + + + ocSecureResource.provisionACL(aclObject, provisionAclListener); + + } else { + publishProgress(TAG + "No Owned devices present"); + } + + } catch (Exception e) { + publishProgress(TAG + "ProvisionACL error: " + e.getMessage()); + + + } + return null; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + + } + + private class ProvisionCredentialAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected Void doInBackground(Void... params) { + try { + + if (ownedDeviceList.size() > 1) { + + OcSecureResource ocSecureResource = ownedDeviceList.get(0); + OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1); + publishProgress(TAG + "ProvisionCredential for " + + ocSecureResource.getDeviceID() + " with " + + ocSecureResourceDest.getDeviceID()); + + + int credential_type = StringConstants.CREDENTIAL_TYPE; //symmetrical + int psk_length = StringConstants.OWNER_PSK_LENGTH_128; + + ocSecureResource.provisionCredentials(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY), + KeySize.OWNER_PSK_LENGTH_128, + ocSecureResourceDest, provisionCredentialsListener); + + + } else { + publishProgress(TAG + "Cannot perform credentials between devices"); + } + + } catch (Exception e) { + publishProgress(TAG + "ProvisionACL error: " + e.getMessage()); + + + } + return null; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + + } + + private class GetLinkedDevicesAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected String doInBackground(Void... params) { + try { + + if (ownedDeviceList.size() > 1) { + + OcSecureResource ocSecureResource = ownedDeviceList.get(0); + publishProgress(TAG + "Get linked devices of " + ocSecureResource.getDeviceID()); + + + List linkedDevices= ocSecureResource.getLinkedDevices(); + if(linkedDevices.size() >0 ) + { + for (int i = 0; i < linkedDevices.size(); i++) { + publishProgress(TAG + "Linked Devices "+ + + (i + 1) + "= " + linkedDevices.get(i) + ); + } + } + else + { + publishProgress(TAG + "No linked Devices found"); + } + } else { + publishProgress(TAG + "Cannot perform linked devices"); + } + + } catch (Exception e) { + publishProgress(TAG + "getLinked device error: " + e.getMessage()); + return "failed"; + + + } + return "success"; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + + @Override + protected void onPostExecute(String s) { + + if ("success".equals(s)) { + new ProvisionUnlinkAsyncTask().execute(); + + } + + + } + + } + + + private class ProvisionUnlinkAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected Void doInBackground(Void... params) { + try { + + if (ownedDeviceList.size() > 1) { + + OcSecureResource ocSecureResource = ownedDeviceList.get(0); + OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1); + publishProgress(TAG + "Un linking " + ocSecureResource.getDeviceID() + + " with " + ocSecureResourceDest.getDeviceID()); + + ocSecureResource.unlinkDevices(ocSecureResourceDest, unlinkDevicesListener); + + + } else { + publishProgress(TAG + "Cannot perform unlink devices"); + } + + } catch (Exception e) { + publishProgress(TAG + "Unlink error: " + e.getMessage()); + + + } + return null; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + + } + + + private class DeviceRevocationAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected Void doInBackground(Void... params) { + try { + + if (ownedDeviceList.size() > 0) { + + OcSecureResource ocSecureResource = ownedDeviceList.get(0); + + publishProgress(TAG + "Removing " + ocSecureResource.getDeviceID()); + + ocSecureResource.removeDevice(20, removeDeviceListener); + + + } else { + publishProgress(TAG + "Cannot remove"); + } + + } catch (Exception e) { + publishProgress(TAG + "Remove Device error: " + e.getMessage()); + + + } + return null; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + + } + + private class OwnedDiscoveryAsyncTask extends AsyncTask { + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected String doInBackground(Void... params) { + try { + publishProgress(TAG + "Initiate Owned device Discovery"); + + ownedDeviceList = OcProvisioning.discoverOwnedDevices(10); + + if (ownedDeviceList.size() > 0) { + for (int i = 0; i < ownedDeviceList.size(); i++) { + publishProgress(TAG + "Owned Discovered Device " + (i + 1) + "= " + + ownedDeviceList.get(i).getDeviceID() + + "\nIP Address= " + ownedDeviceList.get(i).getIpAddr() + + "\nOwned Status= " + ownedDeviceList.get(i).getOwnedStatus() + + "\nDevice Status= " + ((ownedDeviceList.get(i). + getDeviceStatus() == DeviceStatus.ON) ? "ON" : "OFF") + ); + } + } else { + publishProgress(TAG + "No Owned devices present"); + } + + } catch (OcException e) { + publishProgress(TAG + "Owned device Discovery error: " + e.getMessage()); + return "Owned device Discovery error: " + e.getMessage(); + + } + return "success"; + } + + @Override + protected void onProgressUpdate(String... values) { + logMessage(values[0]); + } + + @Override + protected void onPostExecute(String s) { + + if (ownedDeviceList.size() > 1 && "success".equals(s)) { + doPairwiseProvisioning(); + + } + + + } + + } + + /** + * to display on Server Message on Client screen + */ + public class MessageReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + final String message = intent.getStringExtra(StringConstants.MESSAGE); + logMessage(message); + } + } +} diff --git a/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java new file mode 100644 index 0000000..0854861 --- /dev/null +++ b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java @@ -0,0 +1,12 @@ +package org.iotivity.base.examples.provisioningclient; + +public interface StringConstants { + + public static final int NUMBER_ZERO = 0; + public static final int ERROR_CODE = 1; + public static final String OIC_CLIENT_JSON_DB_FILE = "oic_svr_db_client.json"; + public static final String MESSAGE = "message"; + public static final String OIC_SQL_DB_FILE = "Pdm.db"; + public static final int CREDENTIAL_TYPE=1; + public static final int OWNER_PSK_LENGTH_128=128/8; +} diff --git a/android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml b/android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml new file mode 100644 index 0000000..596ac98 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml b/android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml new file mode 100644 index 0000000..dd57e4d --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml @@ -0,0 +1,5 @@ + + + diff --git a/android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..cde69bcccec65160d92116f20ffce4fce0b5245c GIT binary patch literal 3418 zcmZ{nX*|@A^T0p5j$I+^%FVhdvMbgt%d+mG98ubwNv_tpITppba^GiieBBZGI>I89 zGgm8TA>_)DlEu&W;s3#ZUNiH4&CF{a%siTjzG;eOzQB6{003qKeT?}z_5U*{{kgZ; zdV@U&tqa-&4FGisjMN8o=P}$t-`oTM2oeB5d9mHPgTYJx4jup)+5a;Tke$m708DocFzDL>U$$}s6FGiy_I1?O zHXq`q884|^O4Q*%V#vwxqCz-#8i`Gu)2LeB0{%%VKunOF%9~JcFB9MM>N00M`E~;o zBU%)O5u-D6NF~OQV7TV#JAN;=Lylgxy0kncoQpGq<<_gxw`FC=C-cV#$L|(47Hatl ztq3Jngq00x#}HGW@_tj{&A?lwOwrVX4@d66vLVyj1H@i}VD2YXd)n03?U5?cKtFz4 zW#@+MLeDVP>fY0F2IzT;r5*MAJ2}P8Z{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fE5^;R!~}H4C?q{1AG?O$5kGp)G$f%VML%aPD?{ zG6)*KodSZRXbl8OD=ETxQLJz)KMI7xjArKUNh3@0f|T|75?Yy=pD7056ja0W)O;Td zCEJ=7q?d|$3rZb+8Cvt6mybV-#1B2}Jai^DOjM2<90tpql|M5tmheg){2NyZR}x3w zL6u}F+C-PIzZ56q0x$;mVJXM1V0;F}y9F29ob51f;;+)t&7l30gloMMHPTuod530FC}j^4#qOJV%5!&e!H9#!N&XQvs5{R zD_FOomd-uk@?_JiWP%&nQ_myBlM6so1Ffa1aaL7B`!ZTXPg_S%TUS*>M^8iJRj1*~ e{{%>Z1YfTk|3C04d;8A^0$7;Zm{b|L#{L(;l>}-4 literal 0 HcmV?d00001 diff --git a/android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..bfa42f0e7b91d006d22352c9ff2f134e504e3c1d GIT binary patch literal 4842 zcmZ{oXE5C1x5t0WvTCfdv7&7fy$d2l*k#q|U5FAbL??P!61}%ovaIM)mL!5G(V|6J zAtDH(OY|Du^}l!K&fFLG%sJ2JIp@rG=9y>Ci)Wq~U2RobsvA@Q0MM$dq4lq5{hy#9 zzgp+B{O(-=?1<7r0l>Q?>N6X%s~lmgrmqD6fjj_!c?AF`S0&6U06Z51fWOuNAe#jM z%pSN#J-Mp}`ICpL=qp~?u~Jj$6(~K_%)9}Bn(;pY0&;M00H9x2N23h=CpR7kr8A9X zU%oh4-E@i!Ac}P+&%vOPQ3warO9l!SCN)ixGW54Jsh!`>*aU)#&Mg7;#O_6xd5%I6 zneGSZL3Kn-4B^>#T7pVaIHs3^PY-N^v1!W=%gzfioIWosZ!BN?_M)OOux&6HCyyMf z3ToZ@_h75A33KyC!T)-zYC-bp`@^1n;w3~N+vQ0#4V7!f|JPMlWWJ@+Tg~8>1$GzLlHGuxS)w&NAF*&Y;ef`T^w4HP7GK%6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R#q6F($w>kmKK`x21VmX=9kb^+cPdBY2l zGkIZSf%C+`2nj^)j zo}g}v;5{nk<>%xj-2OqDbJ3S`7|tQWqdvJdgiL{1=w0!qS9$A`w9Qm7>N0Y*Ma%P_ zr@fR4>5u{mKwgZ33Xs$RD6(tcVH~Mas-87Fd^6M6iuV^_o$~ql+!eBIw$U)lzl`q9 z=L6zVsZzi0IIW=DT&ES9HajKhb5lz4yQxT-NRBLv_=2sn7WFX&Wp6Y!&}P+%`!A;s zrCwXO3}jrdA7mB`h~N~HT64TM{R$lNj*~ekqSP^n9P~z;P zWPlRPz0h6za8-P>!ARb+A1-r>8VF*xhrGa8W6J$p*wy`ULrD$CmYV7Gt^scLydQWbo7XN-o9X1i7;l+J_8Ncu zc=EX&dg`GRo4==cz2d_Rz28oLS`Suf6OCp~f{0-aQ`t5YZ=!CAMc6-RZw#}A%;s44 znf2`6gcgm=0SezTH9h+JzeR3Lcm;8?*@+?FDfguK^9)z(Z`I!RKrSAI?H~4et6GTkz07Qgq4B6%Q*8Y0yPc4x z8(^YwtZjYIeOvVLey#>@$UzIciJ#x0pJLFg=8UaZv%-&?Yzp7gWNIo_x^(d75=x2c zv|LQ`HrKP(8TqFxTiP5gdT2>aTN0S7XW*pilASS$UkJ2*n+==D)0mgTGxv43t61fr z47GkfMnD-zSH@|mZ26r*d3WEtr+l-xH@L}BM)~ThoMvKqGw=Ifc}BdkL$^wC}=(XSf4YpG;sA9#OSJf)V=rs#Wq$?Wj+nTlu$YXn yn3SQon5>kvtkl(BT2@T#Mvca!|08g9w{vm``2PjZHg=b<1c17-HkzPl9sXa)&-Ts$ literal 0 HcmV?d00001 diff --git a/android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..324e72cdd7480cb983fa1bcc7ce686e51ef87fe7 GIT binary patch literal 7718 zcmZ{JWl)?=u?hpbj?h-6mfK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3f` zT5-g`z5|%qOa!WTBed-8`#AQ~wb9TrUZKU)H*O7!LtNnEd!r8!Oda)u!Gb5P`9(`b z`lMP6CLh4OzvXC#CR|@uo$EcHAyGr=)LB7)>=s3 zvU;aR#cN3<5&CLMFU@keW^R-Tqyf4fdkOnwI(H$x#@I1D6#dkUo@YW#7MU0@=NV-4 zEh2K?O@+2e{qW^7r?B~QTO)j}>hR$q9*n$8M(4+DOZ00WXFonLlk^;os8*zI>YG#? z9oq$CD~byz>;`--_NMy|iJRALZ#+qV8OXn=AmL^GL&|q1Qw-^*#~;WNNNbk(96Tnw zGjjscNyIyM2CYwiJ2l-}u_7mUGcvM+puPF^F89eIBx27&$|p_NG)fOaafGv|_b9G$;1LzZ-1aIE?*R6kHg}dy%~K(Q5S2O6086 z{lN&8;0>!pq^f*Jlh=J%Rmaoed<=uf@$iKl+bieC83IT!09J&IF)9H)C?d!eW1UQ}BQwxaqQY47DpOk@`zZ zo>#SM@oI^|nrWm~Ol7=r`!Bp9lQNbBCeHcfN&X$kjj0R(@?f$OHHt|fWe6jDrYg3(mdEd$8P2Yzjt9*EM zLE|cp-Tzsdyt(dvLhU8}_IX&I?B=|yoZ!&<`9&H5PtApt=VUIB4l0a1NH v0SQqt3DM`an1p};^>=lX|A*k@Y-MNT^ZzF}9G-1G696?OEyXH%^Pv9$0dR%J literal 0 HcmV?d00001 diff --git a/android/examples/provisioningclient/src/main/res/values-v21/styles.xml b/android/examples/provisioningclient/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..dba3c41 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/values-v21/styles.xml @@ -0,0 +1,5 @@ + + + + diff --git a/android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml b/android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/android/examples/provisioningclient/src/main/res/values/dimens.xml b/android/examples/provisioningclient/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/android/examples/provisioningclient/src/main/res/values/strings.xml b/android/examples/provisioningclient/src/main/res/values/strings.xml new file mode 100644 index 0000000..fafb434 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/values/strings.xml @@ -0,0 +1,6 @@ + + Provisioning Client + + Hello world! + Settings + diff --git a/android/examples/provisioningclient/src/main/res/values/styles.xml b/android/examples/provisioningclient/src/main/res/values/styles.xml new file mode 100644 index 0000000..ff6c9d2 --- /dev/null +++ b/android/examples/provisioningclient/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/android/examples/settings.gradle b/android/examples/settings.gradle index 4cd41ac..fa802b9 100755 --- a/android/examples/settings.gradle +++ b/android/examples/settings.gradle @@ -1 +1 @@ -include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient' +include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':secureprovisionclient' diff --git a/resource/csdk/security/SConscript b/resource/csdk/security/SConscript index 0266046..cf7ad92 100755 --- a/resource/csdk/security/SConscript +++ b/resource/csdk/security/SConscript @@ -126,6 +126,6 @@ libocsrm = libocsrm_env.StaticLibrary('libocsrm', libocsrm_src) libocsrm_env.InstallTarget(libocsrm, 'libocsrm') libocsrm_env.UserInstallTargetLib(libocsrm, 'libocsrm') -if target_os == 'linux' and env.get('SECURED') == '1': +if target_os in ['linux', 'android'] and env.get('SECURED') == '1': SConscript('provisioning/SConscript') -- 2.7.4