Added CASelectCipherSuite for android
authorRandeep Singh <randeep.s@samsung.com>
Thu, 8 Sep 2016 13:06:02 +0000 (18:36 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 28 Sep 2016 03:42:45 +0000 (03:42 +0000)
Change-Id: I073d1191e6a114c3c34f67f48d1ab7c7443bf1d6
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11605
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashwini Kumar <k.ashwini@samsung.com>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
(cherry picked from commit 7c4dd58b07c1b0f5c349bab2b6e8e93eb8fef543)
Reviewed-on: https://gerrit.iotivity.org/gerrit/12327

android/android_api/base/jni/Android.mk
android/android_api/base/jni/JniCaInterface.c
android/android_api/base/jni/JniCaInterface.h
android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java
android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java [new file with mode: 0644]
android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java
resource/csdk/connectivity/src/caconnectivitymanager.c

index 1c432943f4cb3715e3cdfe6ec4f0a329b26da0d7..7039ac301bcacab81331ccd5fe0c288a402bd0c5 100644 (file)
@@ -47,6 +47,9 @@ include $(PREBUILT_SHARED_LIBRARY)
 endif\r
 \r
 include $(CLEAR_VARS)\r
+ifeq ($(SECURE), 1)\r
+    LOCAL_CFLAGS += -D__WITH_DTLS__\r
+endif\r
 OIC_SRC_PATH := ../../../resource\r
 LOCAL_MODULE := libca-interface\r
 LOCAL_SRC_FILES := JniCaInterface.c\r
@@ -70,6 +73,10 @@ ifeq ($(WITH_TCP), 1)
     LOCAL_CPPFLAGS += -D__WITH_TLS__\r
 endif\r
 \r
+ifeq ($(SECURED), 1)\r
+    LOCAL_CPPFLAGS += -D__WITH_DTLS__\r
+endif\r
+\r
 MQ_FLAG = 0\r
 ifeq ($(WITH_MQ_PUB), 1)\r
 LOCAL_CFLAGS += -DWITH_MQ -DMQ_PUBLISHER\r
index 06ff75bc299bef20f3ef7fb9cc51c4c92d0c6740..9499b5596b4c749610de0c5cb69f995be1236db8 100644 (file)
@@ -356,3 +356,18 @@ Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass c
     CAUtilSetLEScanInterval(intervalTime, workignCount);
 }
 
+JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl
+  (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter)
+{
+    LOGI("setCipherSuiteImpl");
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+    (void)env;
+    (void)clazz;
+    CAResult_t ret = CASelectCipherSuite(cipherSuite, (CATransportAdapter_t) adapter);
+    return ret;
+#else
+    LOGE("Method not supported");
+    return -1;
+#endif //  __WITH_DTLS__ || __WITH_TLS__
+}
+
index 2e8ba5bea7d683103786984727c070ccdfb323b5..663aef33e038321c42035aa0a3ab1517d9835000 100644 (file)
@@ -128,6 +128,14 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl
         (JNIEnv *, jclass, jint, jint);
 
+    /*
+     * Class:     org_iotivity_ca_CaInterface
+     * Method:    setCipherSuiteImpl
+     * Signature: (Lorg/iotivity/ca/OicCipher;Lorg/iotivity/ca/CATransportAdapter;)I
+     */
+    JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl
+     (JNIEnv *, jclass, jint, jint);
+
 #ifdef __cplusplus
 }
 #endif
index 3d62800793bc9e076a2acf2a7249118a24e58a93..6924eb417b53d256a08acf6ea8b956dcdb8ce2cb 100644 (file)
@@ -192,4 +192,11 @@ public class CaInterface {
     }
 
     private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount);
+
+
+    public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){
+        return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue());
+    }
+    private static native int setCipherSuiteImpl(int cipher, int adapter);
+
 }
diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java b/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java
new file mode 100644 (file)
index 0000000..60f9f16
--- /dev/null
@@ -0,0 +1,38 @@
+/* ****************************************************************\r
+ *\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+package org.iotivity.ca;\r
+\r
+public enum OicCipher {\r
+    TLS_ECDH_anon_WITH_AES_128_CBC_SHA(0xC018),\r
+    TLS_PSK_WITH_AES_128_CCM_8(0xC0A8),\r
+    TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8(0xC0AE),\r
+    TLS_RSA_WITH_AES_256_CBC_SHA(0x35);\r
+\r
+    private int cipher;\r
+\r
+    private OicCipher(int cipher) {\r
+        this.cipher = cipher;\r
+    }\r
+\r
+    public int getValue(){\r
+        return cipher;\r
+    }\r
+}\r
index dbd6a187e4447f0c3ec539a61a5fcb1366e74cc1..07ae29b61663b7ffa233dec68bde2aa7375df16f 100644 (file)
@@ -46,6 +46,11 @@ import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
 
+import org.iotivity.ca.OicCipher;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.ca.CaInterface;
+
+
 public class ProvisioningClient extends Activity implements
 OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwiseDevicesListener {
 
@@ -182,6 +187,9 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
             }
             initOICStack();
             saveCertChain();
+            int ret = CaInterface.setCipherSuite(OicCipher.TLS_ECDH_anon_WITH_AES_128_CBC_SHA,
+                                                    OcConnectivityType.CT_ADAPTER_IP);
+            Log.e(TAG,"CaInterface.setCipherSuite returned = "+ret);
         }
 
     /**
index a2876083121b545b173b4a1874ca9869416d4901..0dc5a521eb47e57e17abdb7df64e9d59990aacdc 100644 (file)
@@ -534,11 +534,13 @@ CAResult_t CAHandleRequestResponse()
 #if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
 CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
 {
-    OIC_LOG_V(DEBUG, TAG, "CASelectCipherSuite");
+    OIC_LOG_V(DEBUG, TAG, "IN CASelectCipherSuite");
+    OIC_LOG_V(DEBUG, TAG, "cipher : %d , CATransportAdapter : %d",cipher, adapter);
     if(CA_ADAPTER_IP == adapter)
     {
         if (CA_STATUS_OK != CADtlsSelectCipherSuite(cipher))
         {
+            OIC_LOG_V(DEBUG, TAG, "CADtlsSelectCipherSuite failed");
             return CA_STATUS_FAILED;
         }
     }
@@ -547,10 +549,12 @@ CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapt
     {
         if (CA_STATUS_OK != CAsetTlsCipherSuite(cipher))
         {
+            OIC_LOG_V(DEBUG, TAG, "CAsetTlsCipherSuite failed");
             return CA_STATUS_FAILED;
         }
     }
 #endif
+    OIC_LOG_V(DEBUG, TAG, "CASelectCipherSuite OK");
     return CA_STATUS_OK;
 }