private String password;
private SecureRandom random;
private byte salt[];
+ private byte iv[] = null;
private Table table;
private int listeningPort = -1;
private Thread localServerThread = null;
}
}
+ /**
+ * Generate random numbers for IV from machine ID and local sequence number
+ */
private byte[] createIV(long machineId, long localSequenceNumber) {
ByteBuffer buffer = ByteBuffer.allocate(IV_SIZE);
buffer.putLong(machineId);
return buffer.array();
}
+
+ /**
+ * Generate random numbers for IV from random bits
+ */
+ private byte[] createIV() {
+ if (iv == null) {
+ iv = new byte[IV_SIZE];
+ random.nextBytes(iv);
+ }
+ return iv;
+ }
private byte[] encryptSlotAndPrependIV(byte[] rawData, byte[] ivBytes) {
try {
// byte[] bytes = new byte[slotBytes.length + IV_SIZE];
// System.arraycopy(iVBytes, 0, bytes, 0, iVBytes.length);
// System.arraycopy(slotBytes, 0, bytes, IV_SIZE, slotBytes.length);
-
-
- byte[] bytes = encryptSlotAndPrependIV(slotBytes, slot.getSlotCryptIV());
+ byte[] bytes = encryptSlotAndPrependIV(slotBytes, createIV());
url = buildRequest(true, sequencenumber, max);
}
initCrypt();
}
-
url = buildRequest(false, sequencenumber, 0);
timer.startTime();
con = url.openConnection();
http.setReadTimeout(TIMEOUT_MILLIS);
-
http.connect();
timer.endTime();
throw new ServerException("getSlots failed", ServerException.TypeConnectTimeout);
} catch (ServerException e) {
timer.endTime();
-
throw e;
} catch (Exception e) {
// e.printStackTrace();
}
try {
-
timer.startTime();
InputStream is = http.getInputStream();
DataInputStream dis = new DataInputStream(is);
// Encrypt the data for sending
// byte[] encryptedData = encryptCipher.doFinal(totalData);
// byte[] encryptedData = encryptCipher.doFinal(totalData);
- byte[] iv = createIV(table.getMachineId(), table.getLocalSequenceNumber());
+ byte[] iv = createIV();
byte[] encryptedData = encryptSlotAndPrependIV(totalData, iv);
// Open a TCP socket connection to a local device
// Encrypt the data for sending
// byte[] encryptedData = encryptCipher.doFinal(totalData);
- byte[] iv = createIV(table.getMachineId(), table.getLocalSequenceNumber());
+ byte[] iv = createIV();
byte[] encryptedData = encryptSlotAndPrependIV(totalData, iv);