Adding Android Interface API saveACL() and doSelfOwnershiptransfer()
authorRandeep Singh <randeep.s@samsung.com>
Wed, 18 Jan 2017 09:50:56 +0000 (15:20 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 9 Feb 2017 06:47:40 +0000 (06:47 +0000)
Change-Id: Ia19bb669d073868a1ca74b1e98968383256a62aa
Signed-off-by: Sandeep Sharma <sandeep.s9@samsung.com>
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15835
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16873

java/common/src/main/java/org/iotivity/base/OcProvisioning.java
java/jni/JniOcProvisioning.cpp
java/jni/JniOcProvisioning.h

index 51890fa..f1a6946 100644 (file)
@@ -222,7 +222,7 @@ public class OcProvisioning {
     private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType)
         throws OcException;
 
-   /**
+    /**
      *  Method to save pin type.
      *
      *  @param pinSize Byte Len of Random pin.
@@ -240,4 +240,19 @@ public class OcProvisioning {
         return setPinType0(pinSize, pinTypeInt);
     }
     private static native int setPinType0(int pinSize, int pinType) throws OcException;
+
+    /**
+     * API to save ACL, having multiple ACE's
+     *
+     *@param acl object
+     *@throws OcException
+     */
+    public static native void saveACL(Object acl) throws OcException;
+
+    /**
+     * API to do self ownership transfer.
+     *
+     *@throws OcException
+     */
+    public static native void doSelfOwnershiptransfer() throws OcException;
 }
index 94188c1..3fad9bf 100644 (file)
@@ -23,6 +23,8 @@
 #include "JniOcProvisioning.h"
 #include "JniPinCheckListener.h"
 #include "JniDisplayPinListener.h"
+#include "oic_malloc.h"
+#include "aclresource.h"
 #include "oxmverifycommon.h"
 #include "JniDisplayVerifyNumListener.h"
 #include "JniConfirmNumListener.h"
@@ -508,3 +510,74 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen
     return -1;
 #endif // __WITH_DTLS__ || __WITH_TLS__
 }
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    saveACL
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_saveACL
+  (JNIEnv *env , jclass thiz, jobject jacl)
+{
+    LOGD("OcProvisioning_saveACL");
+
+    if (!jacl)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "acl can't be null");
+    }
+
+    OicSecAcl_t *acl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
+    if (!acl)
+    {
+        ThrowOcException(OC_STACK_NO_MEMORY, "acl allocation failed");
+        return;
+    }
+
+    if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, jacl, acl))
+    {
+        DeleteACLList(acl);
+        ThrowOcException(OC_STACK_INVALID_PARAM, "Failed to convert Java acl to OC acl");
+        return ;
+    }
+
+    try
+    {
+        OCStackResult result = OCSecure::saveACL(acl);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OCSecure::saveACL Failed");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    doSelfOwnershiptransfer
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_doSelfOwnershiptransfer
+  (JNIEnv *env, jclass thiz)
+{
+
+    LOGD("OcProvisioning_doSelfOwnershiptransfer");
+    try
+    {
+        OCStackResult result = OCSecure::configSelfOwnership();
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OCSecure::configSelfOwnership Failed");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
index 541b4e0..702bc9e 100644 (file)
@@ -141,6 +141,22 @@ 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
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_saveACL
+  (JNIEnv *, jclass, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    doSelfOwnershiptransfer
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_doSelfOwnershiptransfer
+  (JNIEnv *, jclass);
 #ifdef __cplusplus
 }
 #endif