Adding Android wrapper to set a seed value for UUID generation
authorsaurabh.s9 <saurabh.s9@samsung.com>
Tue, 17 Jan 2017 11:33:51 +0000 (17:03 +0530)
committerRick Bell <richard.s.bell@intel.com>
Tue, 7 Mar 2017 07:25:31 +0000 (07:25 +0000)
Change-Id: Id123f745b4409bebbd5cccf9b0d7d8b7e3b7a08d
Signed-off-by: saurabh.s9 <saurabh.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16493
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16875
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/common/src/main/java/org/iotivity/base/OcProvisioning.java
java/jni/JniOcProvisioning.cpp
java/jni/JniOcProvisioning.h

index 31642f9..e02755c 100644 (file)
@@ -287,4 +287,16 @@ public class OcProvisioning {
      *@throws OcException
      */
     public static native void doSelfOwnershiptransfer() throws OcException;
+    
+    /**
+     *  Method to save the seed value to generate device UUID
+     *
+     *  @param seed   buffer of seed value
+     *  @throws OcException
+     */
+    public static int setDeviceIdSeed(byte[] seed) throws OcException {
+        return setDeviceIdSeed1(seed);
+    }
+    private static native int setDeviceIdSeed1(byte[] seed)
+        throws OcException;
 }
index ec995c3..abd358e 100644 (file)
@@ -666,3 +666,37 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_doSelfOwnershiptran
         ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
     }
 }
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    setDeviceIdSeed1
+ * Signature: (Lorg/iotivity/base/OcProvisioning/provisionTrustCertChain1;)V
+ */
+    JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setDeviceIdSeed1
+(JNIEnv *env, jobject thiz, jbyteArray seed)
+{
+    LOGD("OcProvisioning_setDeviceIdSeed1");
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+    jbyte* byteSeed = env->GetByteArrayElements(seed, 0);
+    jsize arrayLength = env->GetArrayLength(seed);
+    try
+    {
+        env->GetByteArrayRegion (seed, 0, arrayLength, byteSeed);
+        OCStackResult result = OCSecure::setDeviceIdSeed((uint8_t*)byteSeed, arrayLength);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcProvisioning_setDeviceIdSeed");
+            return -1;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+    return 0;
+#else
+    ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled");
+    return -1;
+#endif // __WITH_DTLS__ || __WITH_TLS__
+}
index a8b8733..8fe7347 100644 (file)
@@ -156,6 +156,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1
 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setPinType0
   (JNIEnv *, jclass, jint, jint);
 
+
 /*
  * Class:     org_iotivity_base_OcProvisioning
  * Method:    saveACL
@@ -171,6 +172,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_saveACL
  */
 JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_doSelfOwnershiptransfer
   (JNIEnv *, jclass);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    setDeviceIdSeed1
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setDeviceIdSeed1
+  (JNIEnv *, jobject, jbyteArray);
 #ifdef __cplusplus
 }
 #endif