Browse Source

read files for pki certs and idd was modified to add 0x00 at the end of byte array.

Trishia 4 năm trước cách đây
mục cha
commit
d8a6f4bbf7

BIN
app/libs/iotivity-lite.jar


+ 24 - 16
app/src/main/java/org/iotivity/bridge/homeserver/BridgeServer.java

@@ -42,6 +42,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Properties;
 
 public class BridgeServer {
@@ -168,18 +169,18 @@ public class BridgeServer {
 
     public void resetVirtualOCFDevices() {
 
-        int dev_count = OCBridge.getVirtualDeviceCount();
-        Log.d(TAG, "VOD Nums = ["+dev_count+"], Core Res Nums = ["+OCCoreRes.getNumDevices()+"]");
+        int dev_count = (int)OCCoreRes.getNumDevices();
+        Log.d(TAG, "VOD Nums = ["+OCBridge.getVirtualDeviceCount()+"], Core Res Nums = ["+OCCoreRes.getNumDevices()+"]");
         for (int index = 1 ; index <= dev_count; index++) {
-            OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
+            /*OCVirtualDevice vod = OCBridge.getVirtualDeviceInfo(index);
             if(vod!=null) continue;
             Log.d(TAG, "VODs Device [" + index + ", "+vod.getIndex()+", vod_id="+OCUuidUtil.bytesToString(vod.getId())+ "]");
-
-            OCDeviceInfo info = OCCoreRes.getDeviceInfo(index);
-            if(info != null) {
-                Log.d(TAG, "Core Device [" + index + ", "+vod.getIndex()+" piid="+OCUuidUtil.uuidToString(info.getPiid())+ "]");
-                if(info.getName() != null) {
-                    Log.d(TAG, "VODs Device [" + index + ", " + vod.getIndex() + "], " + vod.getEconame() + ", " + info.getName() + " will be reset!");
+*/
+            OCDeviceInfo dev = OCCoreRes.getDeviceInfo(index);
+            if(dev != null) {
+                Log.d(TAG, "Core OCF Device [" + index +" piid="+OCUuidUtil.uuidToString(dev.getPiid())+ "]");
+                if(dev.getName() != null) {
+                    Log.d(TAG, "Core OCF Device [" + index + "] "+dev.getName()+" was reset!");
                     this.resetDevice(index);
                 }
             }
@@ -189,7 +190,7 @@ public class BridgeServer {
     public void resetVirtualOCFDevice(OCUuid device_uuid) {
         int dev_count = (int)OCCoreRes.getNumDevices();
         Log.d(TAG, "Core Device Nums = ["+dev_count+"] ");
-        for (int index = 1; index < dev_count; index++) {
+        for (int index = 1; index <= dev_count; index++) {
             OCDeviceInfo dev = OCCoreRes.getDeviceInfo(index);
             if (dev != null && OCUuidUtil.isEqual(dev.getDi(),device_uuid)) {
                 this.resetDevice(index);
@@ -201,7 +202,7 @@ public class BridgeServer {
     public void resetVirtualOCFDevice(String device_uuid) {
         int dev_count = (int)OCCoreRes.getNumDevices();
         Log.d(TAG, "Core Device Nums = ["+dev_count+"] ");
-        for (int index = 1; index < dev_count; index++) {
+        for (int index = 1; index <= dev_count; index++) {
             OCDeviceInfo dev = OCCoreRes.getDeviceInfo(index);
             if (dev != null && OCUuidUtil.uuidToString(dev.getDi()).equalsIgnoreCase(device_uuid)) {
                 this.resetDevice(index);
@@ -213,7 +214,7 @@ public class BridgeServer {
     public void resetVirtualOCFDeviceByDevicePiid(String device_sn) {
         int dev_count = (int)OCCoreRes.getNumDevices();
         Log.d(TAG, "Core Device Nums = ["+dev_count+"] ");
-        for (int index = 1; index < dev_count; index++) {
+        for (int index = 1; index <= dev_count; index++) {
             OCDeviceInfo dev = OCCoreRes.getDeviceInfo(index);
             if (dev != null && OCUuidUtil.uuidToString(dev.getPiid()).equalsIgnoreCase(device_sn)) {
                 this.resetDevice(index);
@@ -406,8 +407,8 @@ public class BridgeServer {
                         + ", Device Piid = " + OCUuidUtil.uuidToString(dev_info.getPiid()));
 
                 // Add Light OCF Device IDD
-                //byte[] idd_bytes = getFileBytes("idds/virtual_ocf_device_light_IDD.cbor"); // example : "virtual_ocf_device_light_IDD.cbor"
-                //OCIntrospection.setIntrospectionData(vod_index, idd_bytes);
+                byte[] idd_bytes = getFileBytes("idds/virtual_ocf_device_light_IDD.cbor"); // example : "virtual_ocf_device_light_IDD.cbor"
+                OCIntrospection.setIntrospectionData(vod_index, idd_bytes);
             }
         }
     }
@@ -653,7 +654,7 @@ public class BridgeServer {
                 baos = new ByteArrayOutputStream();
                 int length = 0;
                 while ((length = is.read(buffer)) != -1) {
-                    Log.d(TAG, "bytes read = " + length);
+                    //Log.d(TAG, "bytes read = " + length);
                     baos.write(buffer, 0, length);
                 }
             } catch (IOException e) {
@@ -679,7 +680,14 @@ public class BridgeServer {
             Log.e(TAG, "Failed to read " + filepath);
         }
 
-        return ((baos != null) ? baos.toByteArray() : null);
+        if(baos!=null) {
+            int len = baos.toByteArray().length ;
+            byte[] result = Arrays.copyOf(baos.toByteArray(), len + 1);
+            result[len] = (byte)0x00;
+            Log.d(TAG, "bytes length = " + result.length);
+            return result ;
+        }
+        return null;
     }
 }
 

+ 9 - 1
app/src/main/java/org/iotivity/bridge/homeserver/handler/BridgeInitHandler.java

@@ -21,6 +21,7 @@ import org.iotivity.oc.OcUtils;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 
 public class BridgeInitHandler implements OCMainInitHandler {
 
@@ -118,6 +119,13 @@ public class BridgeInitHandler implements OCMainInitHandler {
             Log.e(TAG, "Failed to read " + filepath);
         }
 
-        return ((baos != null) ? baos.toByteArray() : null);
+        if(baos!=null) {
+            int len = baos.toByteArray().length ;
+            byte[] result = Arrays.copyOf(baos.toByteArray(), len + 1);
+            result[len] = (byte)0x00;
+            Log.d(TAG, "bytes length = " + result.length);
+            return result ;
+        }
+        return null;
     }
 }

+ 12 - 3
app/src/main/java/org/iotivity/bridge/homeserver/handler/FactoryPresetsHandler.java

@@ -13,6 +13,7 @@ import org.iotivity.bridge.homeserver.utils.Utils;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 
 public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
 
@@ -29,12 +30,13 @@ public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
         Log.d(TAG, "inside the FactoryPresetsHandler, deviceIndex  = " + deviceIndex);
 
         // TODO : when attempting to add an identity certificate chain, could not parse identity cert's private key
+        setPKISecurityMfgCert(deviceIndex);
 
+        /*
         boolean isMfgCertSupport = true;
         if (isMfgCertSupport && deviceIndex != 0)
             return; // TODO : Only Bridge will use pki certs in this case
-
-        setPKISecurityMfgCert(deviceIndex);
+        */
     }
 
     private void setPKISecurityMfgCert(long deviceIndex) {
@@ -146,6 +148,13 @@ public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
             Log.e(TAG, "Failed to read " + filepath);
         }
 
-        return ((baos != null) ? baos.toByteArray() : null);
+        if(baos!=null) {
+            int len = baos.toByteArray().length ;
+            byte[] result = Arrays.copyOf(baos.toByteArray(), len + 1);
+            result[len] = (byte)0x00;
+            Log.d(TAG, "bytes length = " + result.length);
+            return result ;
+        }
+        return null;
     }
 }