- PBEKeySpec keyspec = new PBEKeySpec(password->internalBytes(),
- salt,
- 65536,
- 128);
- SecretKey tmpkey = SecretKeyFactory_getInstance("PBKDF2WithHmacSHA256")->generateSecret(keyspec);
+ PBEKeySpec *keyspec = new PBEKeySpec(password->internalBytes(),
+ salt,
+ 65536,
+ 128);
+ SecretKey *tmpkey = SecretKeyFactory_getInstance("PBKDF2WithHmacSHA256")->generateSecret(keyspec);
return new SecretKeySpec(tmpkey->getEncoded(), "AES");
} catch (Exception *e) {
throw new Error("Failed generating key.");
return new SecretKeySpec(tmpkey->getEncoded(), "AES");
} catch (Exception *e) {
throw new Error("Failed generating key.");
http->setRequestMethod("POST");
http->setFixedLengthStreamingMode(saltTmp->length());
http->setDoOutput(true);
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setRequestMethod("POST");
http->setFixedLengthStreamingMode(saltTmp->length());
http->setDoOutput(true);
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setRequestMethod("POST");
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
http->setRequestMethod("POST");
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
-
- int responsecode = http.getResponseCode();
- if (responsecode != HttpURLConnection.HTTP_OK) {
- // TODO: Remove this print
- // System.out.println(responsecode);
+ int responsecode = http->getResponseCode();
+ if (responsecode != HttpURLConnection_HTTP_OK) {
if (is->available() > 0) {
DataInputStream *dis = new DataInputStream(is);
int salt_length = dis->readInt();
if (is->available() > 0) {
DataInputStream *dis = new DataInputStream(is);
int salt_length = dis->readInt();
} catch (Exception *e) {
throw new Error("getSlot failed");
}
}
Array<char> *CloudComm::createIV(int64_t machineId, int64_t localSequenceNumber) {
} catch (Exception *e) {
throw new Error("getSlot failed");
}
}
Array<char> *CloudComm::createIV(int64_t machineId, int64_t localSequenceNumber) {
buffer->putLong(machineId);
int64_t localSequenceNumberShifted = localSequenceNumber << 16;
buffer->putLong(localSequenceNumberShifted);
buffer->putLong(machineId);
int64_t localSequenceNumberShifted = localSequenceNumber << 16;
buffer->putLong(localSequenceNumberShifted);
- IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
- Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
- cipher->init(Cipher.ENCRYPT_MODE, key, ivSpec);
+ IvParameterSpec *ivSpec = new IvParameterSpec(ivBytes);
+ Cipher *cipher = Cipher_getInstance("AES/CTR/NoPadding");
+ cipher->init(Cipher_ENCRYPT_MODE, key, ivSpec);
Array<char> *encryptedBytes = cipher->doFinal(rawData);
Array<char> *chars = new Array<char>(encryptedBytes->length() + CloudComm_IV_SIZE);
Array<char> *encryptedBytes = cipher->doFinal(rawData);
Array<char> *chars = new Array<char>(encryptedBytes->length() + CloudComm_IV_SIZE);
- System_arraycopy(ivBytes, 0, chars, 0, ivBytes.length());
- System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes.length);
+ System_arraycopy(ivBytes, 0, chars, 0, ivBytes->length());
+ System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes->length());
Array<char> *CloudComm::stripIVAndDecryptSlot(Array<char> *rawData) {
try {
Array<char> *ivBytes = new Array<char>(CloudComm_IV_SIZE);
Array<char> *CloudComm::stripIVAndDecryptSlot(Array<char> *rawData) {
try {
Array<char> *ivBytes = new Array<char>(CloudComm_IV_SIZE);
System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length);
IvParameterSpec *ivSpec = new IvParameterSpec(ivBytes);
System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length);
IvParameterSpec *ivSpec = new IvParameterSpec(ivBytes);
Cipher *cipher = Cipher_getInstance("AES/CTR/NoPadding");
cipher->init(Cipher_DECRYPT_MODE, key, ivSpec);
return cipher->doFinal(encryptedBytes);
Cipher *cipher = Cipher_getInstance("AES/CTR/NoPadding");
cipher->init(Cipher_DECRYPT_MODE, key, ivSpec);
return cipher->doFinal(encryptedBytes);
/*
* API for putting a slot into the queue. Returns NULL on success.
* On failure, the server will send slots with newer sequence
/*
* API for putting a slot into the queue. Returns NULL on success.
* On failure, the server will send slots with newer sequence
http->setRequestMethod("POST");
http->setFixedLengthStreamingMode(chars->length);
http->setDoOutput(true);
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
http->connect();
http->setRequestMethod("POST");
http->setFixedLengthStreamingMode(chars->length);
http->setDoOutput(true);
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
http->connect();
DataInputStream *dis = new DataInputStream(is);
Array<char> *resptype = new Array<char>(7);
dis->readFully(resptype);
DataInputStream *dis = new DataInputStream(is);
Array<char> *resptype = new Array<char>(7);
dis->readFully(resptype);
} catch (SocketTimeoutException *e) {
timer->endTime();
throw new ServerException("putSlot failed", ServerException->TypeInputTimeout);
} catch (SocketTimeoutException *e) {
timer->endTime();
throw new ServerException("putSlot failed", ServerException->TypeInputTimeout);
URL *url = buildRequest(false, sequencenumber, 0);
timer->startTime();
URLConnection *con = url->openConnection();
URL *url = buildRequest(false, sequencenumber, 0);
timer->startTime();
URLConnection *con = url->openConnection();
http->setRequestMethod("POST");
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
http->setRequestMethod("POST");
http->setConnectTimeout(CloudComm_TIMEOUT_MILLIS);
http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
timer->startTime();
InputStream *is = http->getInputStream();
DataInputStream *dis = new DataInputStream(is);
Array<char> *resptype = new Array<char>(7);
timer->startTime();
InputStream *is = http->getInputStream();
DataInputStream *dis = new DataInputStream(is);
Array<char> *resptype = new Array<char>(7);
throw new Error("Bad Response: " + new String(resptype));
return processSlots(dis);
} catch (SocketTimeoutException *e) {
timer->endTime();
throw new Error("Bad Response: " + new String(resptype));
return processSlots(dis);
} catch (SocketTimeoutException *e) {
timer->endTime();
Array<Slot *> *CloudComm::processSlots(DataInputStream *dis) {
int numberofslots = dis->readInt();
Array<int> *sizesofslots = new Array<int>(numberofslots);
Array<Slot *> *CloudComm::processSlots(DataInputStream *dis) {
int numberofslots = dis->readInt();
Array<int> *sizesofslots = new Array<int>(numberofslots);
for (int i = 0; i < numberofslots; i++)
sizesofslots->set(i, dis->readInt());
for (int i = 0; i < numberofslots; i++)
sizesofslots->set(i, dis->readInt());
for (int i = 0; i < numberofslots; i++) {
Array<char> *rawData = new Array<char>(sizesofslots->get(i));
dis->readFully(rawData);
for (int i = 0; i < numberofslots; i++) {
Array<char> *rawData = new Array<char>(sizesofslots->get(i));
dis->readFully(rawData);
Array<char> *data = stripIVAndDecryptSlot(rawData);
slots->set(i, Slot_decode(table, data, mac));
}
Array<char> *data = stripIVAndDecryptSlot(rawData);
slots->set(i, Slot_decode(table, data, mac));
}
}
Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, String host, int port) {
}
Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, String host, int port) {
mac->update(sendData);
Array<char> *genmac = mac->doFinal();
Array<char> *totalData = new Array<char>(sendData->length() + genmac->length());
mac->update(sendData);
Array<char> *genmac = mac->doFinal();
Array<char> *totalData = new Array<char>(sendData->length() + genmac->length());
- System_arraycopy(sendData, 0, totalData, 0, sendData.length());
- System - arraycopy(genmac, 0, totalData, sendData.length, genmac->length());
+ System_arraycopy(sendData, 0, totalData, 0, sendData->length());
+ System_arraycopy(genmac, 0, totalData, sendData->length(), genmac->length());
// Encrypt the data for sending
Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
// Encrypt the data for sending
Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
int lengthOfReturnData = input->readInt();
Array<char> *returnData = new Array<char>(lengthOfReturnData);
input->readFully(returnData);
int lengthOfReturnData = input->readInt();
Array<char> *returnData = new Array<char>(lengthOfReturnData);
input->readFully(returnData);
mac->update(returnData, 0, returnData->length - HMAC_SIZE);
Array<char> *realmac = mac->doFinal();
Array<char> *recmac = new Array<char>(HMAC_SIZE);
System_arraycopy(returnData, returnData->length - realmac->length, recmac, 0, realmac->length);
mac->update(returnData, 0, returnData->length - HMAC_SIZE);
Array<char> *realmac = mac->doFinal();
Array<char> *recmac = new Array<char>(HMAC_SIZE);
System_arraycopy(returnData, returnData->length - realmac->length, recmac, 0, realmac->length);
throw new Error("Local Error: Invalid HMAC! Potential Attack!");
Array<char> *returnData2 = new Array<char>(lengthOfReturnData - recmac->length());
throw new Error("Local Error: Invalid HMAC! Potential Attack!");
Array<char> *returnData2 = new Array<char>(lengthOfReturnData - recmac->length());
DataInputStream *input = new DataInputStream(socket->getInputStream());
DataOutputStream *output = new DataOutputStream(socket->getOutputStream());
DataInputStream *input = new DataInputStream(socket->getInputStream());
DataOutputStream *output = new DataOutputStream(socket->getOutputStream());
int dataSize = input->readInt();
Array<char> *readData = new Array<char>(dataSize);
input->readFully(readData);
int dataSize = input->readInt();
Array<char> *readData = new Array<char>(dataSize);
input->readFully(readData);
mac->update(readData, 0, readData->length - HMAC_SIZE);
Array<char> *genmac = mac->doFinal();
Array<char> *recmac = new Array<char>(HMAC_SIZE);
mac->update(readData, 0, readData->length - HMAC_SIZE);
Array<char> *genmac = mac->doFinal();
Array<char> *recmac = new Array<char>(HMAC_SIZE);
mac->update(sendData);
Array<char> *realmac = mac->doFinal();
Array<char> *totalData = new Array<char>(sendData->length() + realmac->length());
mac->update(sendData);
Array<char> *realmac = mac->doFinal();
Array<char> *totalData = new Array<char>(sendData->length() + realmac->length());
Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
timer->startTime();
// Send data to output (length of data, the data)
output->writeInt(encryptedData->length());
timer->startTime();
// Send data to output (length of data, the data)
output->writeInt(encryptedData->length());