patch #4 Add support for Mutual verified JW OTM in android PT.
patch #5 Fix names as per C++
Change-Id: I6be03b4af14645808171d25e92b78ef0382c2e7a
Signed-off-by: Sandeep Sharma <sandeep.s9@samsung.com>
Signed-off-by: Sunil Kumar K R <sunil.k14@samsung.com>
Signed-off-by: Sandeep Sharma <sandeep.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14843
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15235
JniSecureUtils.cpp \\r
JniProvisionResultListner.cpp \\r
JniPinCheckListener.cpp \\r
- JniDisplayPinListener.cpp\r
+ JniDisplayPinListener.cpp \\r
+ JniDisplayVerifyNumListener.cpp \
+ JniConfirmNumListener.cpp
endif\r
\r
ifeq ($(WITH_CLOUD), 1)\r
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 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 "JniConfirmNumListener.h"
+
+JniConfirmNumListener::JniConfirmNumListener(JNIEnv *env, jobject jListener)
+{
+ m_jgListener = env->NewGlobalRef(jListener);
+}
+
+JniConfirmNumListener::~JniConfirmNumListener()
+{
+ LOGI("~JniConfirmNumListener()");
+ if (m_jgListener)
+ {
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (NULL == env) return;
+ env->DeleteGlobalRef(m_jgListener);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ }
+}
+
+OCStackResult JniConfirmNumListener::confirmMutualVerifNumCallback()
+{
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (NULL == env)
+ {
+ return OC_STACK_ERROR;
+ }
+
+ jclass clsL = env->GetObjectClass(m_jgListener);
+
+ if (!clsL)
+ {
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return OC_STACK_ERROR;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "confirmNumListener", "()I");
+ if (!midL)
+ {
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return OC_STACK_ERROR;
+ }
+
+ OCStackResult result = (OCStackResult) env->CallIntMethod(m_jgListener, midL);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ env->ExceptionClear();
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return result;
+}
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 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 <jni.h>
+#include "JniOcStack.h"
+#include "OCProvisioningManager.hpp"
+
+#ifndef _Included_org_iotivity_base_JniConfirmNumListener
+#define _Included_org_iotivity_base_JniConfirmNumListener
+
+class JniConfirmNumListener
+{
+ public:
+ JniConfirmNumListener(JNIEnv *env, jobject jListener);
+ ~JniConfirmNumListener();
+
+ OCStackResult confirmMutualVerifNumCallback();
+
+ private:
+ jobject m_jgListener;
+};
+#endif
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 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 "JniDisplayVerifyNumListener.h"
+#include "oic_malloc.h"
+
+JniDisplayVerifyNumListener::JniDisplayVerifyNumListener(JNIEnv *env, jobject jListener)
+{
+ m_jgListener = env->NewGlobalRef(jListener);
+}
+
+JniDisplayVerifyNumListener::~JniDisplayVerifyNumListener()
+{
+ LOGI("~JniDisplayVerifyNumListener()");
+ if (m_jgListener)
+ {
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (NULL == env) return;
+ env->DeleteGlobalRef(m_jgListener);
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ }
+}
+
+OCStackResult JniDisplayVerifyNumListener::displayMutualVerifNumCallback(uint8_t verifNum[3])
+{
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ char *byteArray;
+
+ if (NULL == env)
+ {
+ return OC_STACK_ERROR;
+ }
+
+ jclass clsL = env->GetObjectClass(m_jgListener);
+
+ if (!clsL)
+ {
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return OC_STACK_ERROR;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "displayNumListener", "(Ljava/lang/String;)I");
+ if (!midL)
+ {
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return OC_STACK_ERROR;
+ }
+
+ byteArray = (char*)OICCalloc(20, sizeof(char));
+
+ if (NULL == byteArray)
+ {
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ return OC_STACK_NO_MEMORY;
+ }
+
+ sprintf(byteArray, "%02X%02X%02X", verifNum[0], verifNum[1], verifNum[2]);
+
+ jstring jStr = env->NewStringUTF(byteArray);
+ if (!jStr)
+ {
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return OC_STACK_ERROR;
+ }
+ OCStackResult result = (OCStackResult)env->CallIntMethod(m_jgListener, midL, jStr);
+
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ env->ExceptionClear();
+ }
+
+ if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+ free(byteArray);
+ return result;
+}
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2016 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 <jni.h>
+#include "JniOcStack.h"
+#include "OCProvisioningManager.hpp"
+
+#ifndef _Included_org_iotivity_base_JniDisplayVerifyNumListener
+#define _Included_org_iotivity_base_JniDisplayVerifyNumListener
+
+class JniDisplayVerifyNumListener
+{
+ public:
+ JniDisplayVerifyNumListener(JNIEnv *env, jobject jListener);
+ ~JniDisplayVerifyNumListener();
+
+ OCStackResult displayMutualVerifNumCallback(uint8_t verfNum[3]);
+
+ private:
+ jobject m_jgListener;
+};
+#endif
#include "JniOcProvisioning.h"
#include "JniPinCheckListener.h"
#include "JniDisplayPinListener.h"
+#include "oxmverifycommon.h"
+#include "JniDisplayVerifyNumListener.h"
+#include "JniConfirmNumListener.h"
using namespace OC;
namespace PH = std::placeholders;
static JniPinCheckListener *jniPinListener = nullptr;
static JniDisplayPinListener *jniDisplayPinListener = nullptr;
+static JniDisplayVerifyNumListener *jniDisplayMutualVerifyNumListener = nullptr;
+static JniConfirmNumListener *jniConfirmMutualVerifyNumListener = nullptr;
void Callback(char *buf, size_t size)
{
}
}
+OCStackResult displayMutualVerifNumCB(uint8_t *verifyNum)
+{
+ OCStackResult res;
+
+ if (jniDisplayMutualVerifyNumListener)
+ {
+ res = jniDisplayMutualVerifyNumListener->displayMutualVerifNumCallback(verifyNum);
+ }
+ else
+ {
+ res = OC_STACK_ERROR;
+ LOGE("DisplayMutualVerifyNumListener is null");
+ }
+ return res;
+}
+
+OCStackResult confirmMutualVerifNumCB()
+{
+ OCStackResult res;
+
+ if (jniConfirmMutualVerifyNumListener)
+ {
+ res = jniConfirmMutualVerifyNumListener->confirmMutualVerifNumCallback();
+ }
+ else
+ {
+ res = OC_STACK_ERROR;
+ LOGE("ConfirmMutualVerifyNumListener is null");
+ }
+ return res;
+}
+
/*
* Class: org_iotivity_base_OcProvisioning
* Method: ownershipTransferCDdata
/*
* Class: org_iotivity_base_OcProvisioning
+ * Method: setDisplayNumListener
+ * Signature: (Lorg/iotivity/base/OcProvisioning/DisplayNumListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayNumListener
+ (JNIEnv *env, jclass clazz, jobject jListener)
+{
+ LOGI("OcProvisioning_setDisplayNumListener");
+
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listner can't be null");
+ return;
+ }
+ delete jniDisplayMutualVerifyNumListener;
+ jniDisplayMutualVerifyNumListener = new JniDisplayVerifyNumListener(env, jListener);
+
+ try
+ {
+ OCStackResult result = OCSecure::registerDisplayNumCallback(displayMutualVerifNumCB);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to set Listner");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ return;
+ }
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: unsetDisplayNumListener
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetDisplayNumListener
+ (JNIEnv * env, jclass clazz)
+{
+ LOGI("OcProvisioning_unsetDisplayNumListener");
+
+ OCStackResult result = OCSecure::deregisterDisplayNumCallback();
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "Failed to unset Listener");
+ }
+
+ return result;
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: setConfirmNumListener
+ * Signature: (Lorg/iotivity/base/OcProvisioning/ConfirmNumListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setConfirmNumListener
+ (JNIEnv *env, jclass clazz, jobject jListener)
+{
+ LOGI("OcProvisioning_setConfirmNumListener");
+
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listner can't be null");
+ return;
+ }
+ delete jniConfirmMutualVerifyNumListener;
+ jniConfirmMutualVerifyNumListener = new JniConfirmNumListener(env, jListener);
+
+ try
+ {
+ OCStackResult result = OCSecure::registerUserConfirmCallback(confirmMutualVerifNumCB);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to set Listner");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ return;
+ }
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: unsetConfirmNumListener
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetConfirmNumListener
+ (JNIEnv *env, jclass clazz)
+{
+ LOGI("OcProvisioning_unsetConfirmNumListener");
+
+ OCStackResult result = OCSecure::deregisterUserConfirmCallback();
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "Failed to unser Listener");
+ }
+
+ return result;
+}
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: setMVJustWorksOptions0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setMVJustWorksOptions0
+ (JNIEnv *env, jclass clazz, jint options)
+{
+ LOGI("OcProvisioning_setMVJustWorksOptions0");
+
+ OCStackResult result = OCSecure::setVerifyOptionMask((VerifyOptionBitmask_t)options);
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "setMVJustWorksOptions Failed");
+ }
+
+ return result;
+}
+
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
* Method: setDisplayPinListener
* Signature: (Lorg/iotivity/base/OcProvisioning/DisplayPinListener;)V
*/
/*
* Class: org_iotivity_base_OcProvisioning
+ * Method: setDisplayNumListener
+ * Signature: (Lorg/iotivity/base/OcProvisioning/DisplayNumListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayNumListener
+ (JNIEnv *, jclass, jobject);
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: unsetDisplayNumListener
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetDisplayNumListener
+ (JNIEnv *, jclass);
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: setConfirmNumListener
+ * Signature: (Lorg/iotivity/base/OcProvisioning/ConfirmNumListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setConfirmNumListener
+ (JNIEnv *, jclass, jobject);
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: unsetConfirmNumListener
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetConfirmNumListener
+ (JNIEnv *, jclass);
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: setMVJustWorksOptions0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setMVJustWorksOptions0
+ (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);
+
/*
* Class: org_iotivity_base_OcProvisioning
* Method: saveTrustCertChain1
--- /dev/null
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 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 MVJustWorksOptionMask {
+ NOT_APPLICABLE (0x0),
+ DISPLAY_MUTUAL_VERIF_NUM (0x1 << 0),
+ CONFIRM_MUTUAL_VERIF_NUM (0x1 << 1),
+ ;
+
+ private int value;
+
+ private MVJustWorksOptionMask(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return this.value;
+ }
+
+ public static EnumSet<MVJustWorksOptionMask> convertToEnumSet(int value) {
+ EnumSet<MVJustWorksOptionMask> typeSet = null;
+
+ for (MVJustWorksOptionMask 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 MVJustWorksOptionMask value:" + value);
+ }
+
+ return typeSet;
+ }
+
+}
import java.util.List;
import java.util.Arrays;
import java.util.Map;
+import java.util.EnumSet;
/**
* OcProvisionig represents functions corresponding to the provisioing of
}
/**
+ * API to Set callback for displaying verifNum in verified Just-Works.
+ *
+ *@param DisplayNumListener callback Listener to be registered for
+ displaying VerifyNUm.
+ *@throws OcException
+ */
+ public static native void setDisplayNumListener(
+ DisplayNumListener displayNumListener) throws OcException;
+
+ public static interface DisplayNumListener {
+ public int displayNumListener(String verifyNum);
+ }
+
+ /**
+ * API to unregister DisplayNumListener Listener
+ *
+ *@return 0 on success, 1 on failure
+ *@throws OcException
+ */
+ public static native int unsetDisplayNumListener() throws OcException;
+
+ /**
+ * API to Set callback for getting user confirmation in verified
+ * Just-Works
+ *
+ *@param ConfirmNumListener callback Listener to be registered for getting user confirmation.
+ *@throws OcException
+ */
+ public static native void setConfirmNumListener(ConfirmNumListener
+ confirmNumListener) throws OcException;
+
+ public static interface ConfirmNumListener {
+ public int confirmNumListener();
+ }
+
+ /**
+ * API to unregister ConfirmMutualVerifyNum Listener
+ *
+ *@return 0 on success, 1 on failure
+ *@throws OcException
+ */
+ public static native int unsetConfirmNumListener() throws OcException;
+
+ /**
+ * API to set options for Mutual Verified Just-works
+ * Default is for both screen PIN display and get user confirmation.
+ *
+ */
+ public static int setMVJustWorksOptions(EnumSet<MVJustWorksOptionMask> optionMask) throws OcException {
+
+ int optionMaskInt = 0;
+
+ for (MVJustWorksOptionMask ops : MVJustWorksOptionMask.values()) {
+ if (optionMask.contains(ops))
+ optionMaskInt |= ops.getValue();
+ }
+ return setMVJustWorksOptions0(optionMaskInt);
+ }
+
+ private static native int setMVJustWorksOptions0(int optionsMask) throws OcException;
+
+ /**
* Method to get Array of owned and un-owned devices in the current subnet.
*
* @param timeout timeout in sec for the API to return.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.iotivity.base.examples.provisioningclient" >
-
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
package org.iotivity.base.examples.provisioningclient;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.os.Environment;
+import android.widget.Toast;
import org.iotivity.base.CredType;
import org.iotivity.base.EncodingType;
import org.iotivity.base.OcException;
import org.iotivity.base.OcPlatform;
import org.iotivity.base.OcProvisioning;
+import org.iotivity.base.MVJustWorksOptionMask;
import org.iotivity.base.OcSecureResource;
import org.iotivity.base.OicSecAcl;
import org.iotivity.base.OicSecAce;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import java.nio.channels.FileChannel;
import org.iotivity.ca.OicCipher;
import org.iotivity.base.OcConnectivityType;
private static final String TAG = "Provisioning Client: ";
private static final int BUFFER_SIZE = 1024;
private int credId=0;
+ private int verifyVal=1;
+ private String verifyNumber;
int unownedDevCount = StringConstants.NUMBER_ZERO;
OcProvisioning.PinCallbackListener pinCallbackListener =
new OcProvisioning.PinCallbackListener() {
}
};
+ OcProvisioning.DisplayNumListener displayNumListener = new OcProvisioning.DisplayNumListener() {
+ @Override
+ public int displayNumListener(String verifyNum) {
+ Log.d(TAG, "Inside verifySecretListener ");
+ logMessage(TAG + "DisplayMutualVerifyNumListener verify Number = " + verifyNum);
+ verifyNumber = verifyNum;
+ return 0;
+ }
+ };
+
+ OcProvisioning.ConfirmNumListener confirmNumListener = new OcProvisioning.ConfirmNumListener() {
+ @Override
+ public int confirmNumListener() {
+ Log.d(TAG, "Inside confirmMutualVerifyNumListener ");
+ final String message = "Is number matches with " + verifyNumber;
+ final Object lock = new Object();
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+
+ AlertDialog.Builder alertDialog = new AlertDialog.Builder(ProvisioningClient.this);
+ alertDialog.setTitle("Confirm Number");
+ alertDialog.setMessage(message);
+ alertDialog.setCancelable(false);
+ alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ try {
+ synchronized (lock) {
+ verifyVal = 0;
+ lock.notifyAll();
+ }
+ } catch (Exception e) {
+ Log.d(TAG, e + "");
+ }
+ }
+ });
+ alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ try {
+ synchronized (lock) {
+ lock.notifyAll();
+ }
+ } catch (Exception e) {
+ Log.d(TAG, e + "");
+ }
+ }
+ }).show();
+ }
+ });
+ synchronized (lock) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ Log.d(TAG, e + "");
+ }
+ }
+ Log.d(TAG, "VerifyVal after submit =" + verifyVal);
+ logMessage(TAG + " confirmMutualVerifyNumListener " + verifyVal);
+ return verifyVal;
+ }
+ };
+
OcSecureResource.ProvisionAclListener provisionAclListener =
new OcSecureResource.ProvisionAclListener() {
@Override
OcPlatform.Configure(cfg);
//Get deviceId
- byte [] deviceIdBytes= OcPlatform.getDeviceId();
- String devId = new String(deviceIdBytes);
- Log.d(TAG, "Get Device Id "+devId);
+ /*byte [] deviceIdBytes= OcPlatform.getDeviceId();
+ String devId = new String(deviceIdBytes);
+ Log.d(TAG, "Get Device Id "+devId);
//Set deviceId
try {
- String setId = "adminDeviceUuid1";
- OcPlatform.setDeviceId(setId.getBytes());
- Log.d(TAG, "Set Device Id done");
+ String setId = "adminDeviceUuid1";
+ OcPlatform.setDeviceId(setId.getBytes());
+ Log.d(TAG, "Set Device Id done");
+ setId = "adminDeviceUuid0";
+ OcPlatform.setDeviceId(setId.getBytes());
+ Log.d(TAG, "Set Device Id Reverted");
}
catch (OcException e) {
- Log.d(TAG, e.getMessage());
- }
+ Log.d(TAG, e.getMessage());
+ }*/
try {
/*
}
Log.d(TAG, "Sql db directory exists at " + sqlDbPath);
OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE);
+
+ try {
+ OcProvisioning.setMVJustWorksOptions(EnumSet.of(MVJustWorksOptionMask.DISPLAY_MUTUAL_VERIF_NUM,
+ MVJustWorksOptionMask.CONFIRM_MUTUAL_VERIF_NUM));
+ OcProvisioning.setDisplayNumListener(displayNumListener);
+ OcProvisioning.setConfirmNumListener(confirmNumListener);
+ } catch (OcException e) {
+ e.printStackTrace();
+ }
} catch (OcException e) {
logMessage(TAG + "provisionInit error: " + e.getMessage());
Log.e(TAG, e.getMessage());
}
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_secure_provision_client, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+
+
+ if (id == R.id.export_dat) {
+ try {
+ File sd = Environment.getExternalStorageDirectory();
+ File data = Environment.getDataDirectory();
+ if (sd.canWrite()) {
+ String currentDBPath = "/data/data/" + getPackageName() + "/files/" + StringConstants.OIC_CLIENT_CBOR_DB_FILE;
+
+ File currentDB = new File(currentDBPath);
+ File backupDB = new File(sd, StringConstants.OIC_CLIENT_CBOR_DB_FILE);
+ if (currentDB.exists()) {
+ FileChannel src = new FileInputStream(currentDB).getChannel();
+ FileChannel dst = new FileOutputStream(backupDB).getChannel();
+ dst.transferFrom(src, 0, src.size());
+ src.close();
+ dst.close();
+ }
+ }
+ } catch (Exception e) {
+ Toast.makeText(ProvisioningClient.this, e.getMessage(), Toast.LENGTH_SHORT).show();
+ }
+
+ Toast.makeText(ProvisioningClient.this, StringConstants.OIC_CLIENT_CBOR_DB_FILE + " File export to sdcard", Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
/**
* to display on Server Message on Client screen
*/
<menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" tools:context=".SecureProvisionClientActivity">
- <item android:id="@+id/action_settings" android:title="@string/action_settings"
- android:orderInCategory="100" android:showAsAction="never" />
+ xmlns:tools="http://schemas.android.com/tools" tools:context=".ProvisioningClient">
+ <item android:id="@+id/export_dat"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="Export dat"/>
</menu>