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");
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());
}
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() {
//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;
return machineid;
}
- byte[] getBytes() {
- return null;
- }
-
void setDead() {
decrementLiveCount();
seqnumlive=false;
}
public String toString() {
- return "<"+getSequenceNumber()+", "+new String(getBytes())+">";
+ return "<"+getSequenceNumber()+">";
}
}
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);
}
}
}