From 57f0a878de30fb3afc7e84fc085ce149eeb6af41 Mon Sep 17 00:00:00 2001 From: Brian Demsky Date: Sun, 24 Jul 2016 01:10:08 -0700 Subject: [PATCH] edits --- src/java/iotcloud/CloudComm.java | 5 +---- src/java/iotcloud/Slot.java | 11 ++++------- src/java/iotcloud/Table.java | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/java/iotcloud/CloudComm.java b/src/java/iotcloud/CloudComm.java index 85c95bb..2c9e0c7 100644 --- a/src/java/iotcloud/CloudComm.java +++ b/src/java/iotcloud/CloudComm.java @@ -27,8 +27,6 @@ class CloudComm { private void initKey(String password) { try { salt=new byte[SALT_SIZE]; - SecureRandom random = new SecureRandom(); - random.nextBytes(salt); PBEKeySpec keyspec = new PBEKeySpec(password.toCharArray(), salt, 65536, 128); SecretKey tmpkey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(keyspec); this.key = new SecretKeySpec(tmpkey.getEncoded(), "AES"); @@ -66,11 +64,10 @@ class CloudComm { URLConnection con=url.openConnection(); HttpURLConnection http = (HttpURLConnection) con; http.setRequestMethod("POST"); - http.setFixedLengthStreamingMode(bytes.length + SALT_SIZE); + http.setFixedLengthStreamingMode(bytes.length); http.setDoOutput(true); http.connect(); OutputStream os=http.getOutputStream(); - os.write(salt); os.write(bytes); System.out.println(http.getResponseMessage()); diff --git a/src/java/iotcloud/Slot.java b/src/java/iotcloud/Slot.java index ea30ddb..9de69db 100644 --- a/src/java/iotcloud/Slot.java +++ b/src/java/iotcloud/Slot.java @@ -30,11 +30,11 @@ class Slot implements Liveness { } Slot(long _seqnum, long _machineid, byte[] _prevhmac) { - this(_seqnum, _machineid, _prevhmac, new byte[HMAC_SIZE]); + this(_seqnum, _machineid, _prevhmac, null); } Slot(long _seqnum, long _machineid) { - this(_seqnum, _machineid, new byte[HMAC_SIZE], new byte[HMAC_SIZE]); + this(_seqnum, _machineid, new byte[HMAC_SIZE], null); } byte[] getHMAC() { @@ -103,6 +103,7 @@ class Slot implements Liveness { //Compute our HMAC mac.update(array, HMAC_SIZE, array.length-HMAC_SIZE); byte[] realmac=mac.doFinal(); + hmac = realmac; bb.position(0); bb.put(realmac); return array; @@ -132,10 +133,6 @@ class Slot implements Liveness { return machineid; } - byte[] getBytes() { - return null; - } - void setDead() { decrementLiveCount(); seqnumlive=false; @@ -150,6 +147,6 @@ class Slot implements Liveness { } public String toString() { - return "<"+getSequenceNumber()+", "+new String(getBytes())+">"; + return "<"+getSequenceNumber()+">"; } } diff --git a/src/java/iotcloud/Table.java b/src/java/iotcloud/Table.java index 1d27932..d4a62c6 100644 --- a/src/java/iotcloud/Table.java +++ b/src/java/iotcloud/Table.java @@ -306,7 +306,7 @@ search: Slot prevslot=indexer.getSlot(currslot.getSequenceNumber()-1); if (prevslot != null && !Arrays.equals(prevslot.getHMAC(), currslot.getPrevHMAC())) - throw new Error("Server Error: Invalid HMAC Chain"); + throw new Error("Server Error: Invalid HMAC Chain"+currslot+" "+prevslot); } } } -- 2.34.1