{
}
-void *threadWrapper(void *cloud) {
- CloudComm *c = (CloudComm *) cloud;
- c->localServerWorkerFunction();
- return NULL;
-}
-
/**
* Constructor for actual use. Takes in the url and password.
*/
byteswritten += bytes;
bytestowrite -= bytes;
} else {
- printf("Error in write\n");
+ //printf("Error in write\n");
exit(-1);
}
}
bytesread += bytes;
bytestoread -= bytes;
} else {
- printf("Error in read\n");
+ //printf("Error in read\n");
exit(-1);
}
}
WebConnection openURL(IoTString *url) {
if (url->length() < 7 || memcmp(url->internalBytes()->internalArray(), "http://", 7)) {
- printf("BOGUS URL\n");
+ //printf("BOGUS URL\n");
exit(-1);
}
int i = 7;
break;
if ( i == url->length()) {
- printf("ERROR in openURL\n");
+ //printf("ERROR in openURL\n");
exit(-1);
}
char *host = (char *) malloc(i - 6);
memcpy(host, &url->internalBytes()->internalArray()[7], i - 7);
host[i - 7] = 0;
- printf("%s\n", host);
+ //printf("%s\n", host);
char *message = (char *)malloc(sizeof("POST HTTP/1.1\r\n") + sizeof("Host: \r\n") + 2 * url->length());
char *host = (char *) malloc(name->length() + 1);
memcpy(host, name->internalBytes()->internalArray(), name->length());
host[name->length()] = 0;
- printf("%s\n", host);
- /* How big is the message? */
-
- /* create the socket */
- int sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0) {printf("ERROR opening socket\n"); exit(-1);}
+ //printf("%s\n", host);
/* lookup the ip address */
TCPClient client;
return client;
}
-TCPServer createSocket(int port) {
- int fd;
- TCPServer server = TCPServer(port);
- server.begin();
-
- return server;
-}
-
-
void writeSocketData(TCPClient * fd, Array<char> *data) {
loopWrite(fd, data->internalArray(), data->length());
}
if (bytes <= 0)
break;
if (offset == (numBytes - 1)) {
- printf("Response too long");
+ //printf("Response too long");
exit(-1);
}
response[offset++] = newchar;
readLine(wc, response, sizeof(response));
int ver1 = 0, ver2 = 0, respcode = 0;
sscanf(response, "HTTP/%d.%d %d", &ver1, &ver2, &respcode);
- printf("Response code %d\n", respcode);
+ //printf("Response code %d\n", respcode);
return respcode;
}
if (salt == NULL)
return NULL;
// try {
- printf("Passing Locally\n");
+ //printf("Passing Locally\n");
mac->update(sendData, 0, sendData->length());
Array<char> *genmac = mac->doFinal();
Array<char> *totalData = new Array<char>(sendData->length() + genmac->length());
return NULL;
}
-void CloudComm::localServerWorkerFunction() {
- /* int inputSocket = -1;
-
- try {
- // Local server socket
- inputSocket = createSocket(listeningPort);
- } catch (Exception *e) {
- throw new Error("Local server setup failure...");
- }
-
- while (!doEnd) {
- try {
- // Accept incoming socket
- int socket = acceptSocket(inputSocket);
-
- // Get the encrypted data from the server
- int dataSize = readSocketInt(socket);
- Array<char> *readData = new Array<char>(dataSize);
- readSocketData(socket, readData);
- timer->endTime();
-
- // Decrypt the data
- readData = stripIVAndDecryptSlot(readData);
- mac->update(readData, 0, readData->length() - CloudComm_HMAC_SIZE);
- Array<char> *genmac = mac->doFinal();
- Array<char> *recmac = new Array<char>(CloudComm_HMAC_SIZE);
- System_arraycopy(readData, readData->length() - recmac->length(), recmac, 0, recmac->length());
-
- if (!recmac->equals(genmac))
- // throw new Error("Local Error: Invalid HMAC! Potential Attack!");
- error("Local Error: Invalid HMAC! Potential Attack!\n");
-
- Array<char> *returnData = new Array<char>(readData->length() - recmac->length());
- System_arraycopy(readData, 0, returnData, 0, returnData->length());
-
- // Process the data
- Array<char> *sendData = table->acceptDataFromLocal(returnData);
- mac->update(sendData, 0, sendData->length());
- Array<char> *realmac = mac->doFinal();
- Array<char> *totalData = new Array<char>(sendData->length() + realmac->length());
- System_arraycopy(sendData, 0, totalData, 0, sendData->length());
- System_arraycopy(realmac, 0, totalData, sendData->length(), realmac->length());
-
- // Encrypt the data for sending
- 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)
- writeSocketInt(socket, encryptedData->length());
- writeSocketData(socket, encryptedData);
- close(socket);
- } catch (Exception *e) {
- }
- }
-
- if (inputSocket != -1) {
- try {
- close(inputSocket);
- } catch (Exception *e) {
- throw new Error("Local server close failure...");
- }
- }*/
-}
-
void CloudComm::closeCloud() {
doEnd = true;
#include "SecureRandom.h"
#include <stdlib.h>
+#include "application.h"
//#include <bsd/stdlib.h>
SecureRandom::SecureRandom() {
}
void SecureRandom::nextBytes(Array<char> *array) {
- arc4random_buf(array->internalArray(), array->length());
+ uint len = array->length();
+ for(uint i=0; i<len; i++) {
+ array->internalArray()[i] = (char) random(256);
+ }
}
int32_t SecureRandom::nextInt(int32_t val) {
- return arc4random_uniform(val);
+ return random(val);
}
IoTString * password = new IoTString("reallysecret");
t1 = new Table(baseurl, password, 321, -1);
t1->initTable();
- printf("T1 Ready\n");
t2 = new Table(baseurl, password, 351, -1);
t2->update();
- printf("T2 Ready\n");
delete baseurl; delete password;
// Make the Keys
- printf("Setting up keys\n");
for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- printf("%d\n",i);
char buffer[80];
sprintf(buffer, "a%d", i);
IoTString *ia = new IoTString(buffer);
void loop() {
// Do Updates for the keys
- printf("Setting Key-Values...\n");
for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- printf("%d\n", i);
char buffer[80];
sprintf(buffer, "a%d", i);
IoTString * iKeyA = new IoTString(buffer);
delete iKeyD; delete iValueD;
}
- printf("Updating Clients...\n");
t1->update();
t2->update();
- printf("Checking Key-Values...\n");
for (int i = 0; i < NUMBER_OF_TESTS; i++) {
char buffer[80];
sprintf(buffer, "a%d", i);
IoTString *testValD2 = t2->getCommitted(iKeyD);
if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
- printf("Key-Value t1 incorrect: keyA\n");
+ // printf("Key-Value t1 incorrect: keyA\n");
foundError = true;
}
if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
- printf("Key-Value t1 incorrect: keyB\n");
+ // printf("Key-Value t1 incorrect: keyB\n");
foundError = true;
}
if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
- printf("Key-Value t1 incorrect: keyC\n");
+ // printf("Key-Value t1 incorrect: keyC\n");
foundError = true;
}
if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
- printf("Key-Value t1 incorrect: keyD\n");
+ // printf("Key-Value t1 incorrect: keyD\n");
foundError = true;
}
if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
- printf("Key-Value t2 incorrect: keyA testValA2\n");
+ // printf("Key-Value t2 incorrect: keyA testValA2\n");
foundError = true;
}
if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
- printf("Key-Value t2 incorrect: keyB testValB2\n");
+// printf("Key-Value t2 incorrect: keyB testValB2\n");
foundError = true;
}
if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
- printf("Key-Value t2 incorrect: keyC testValC2\n");
+ // printf("Key-Value t2 incorrect: keyC testValC2\n");
foundError = true;
}
if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
- printf("Key-Value t2 incorrect: keyD testValD2\n");
+// printf("Key-Value t2 incorrect: keyD testValD2\n");
foundError = true;
}
delete iKeyA; delete iValueA;
TransactionStatus * status = transStatusList->get(i);
if (status->getStatus() != TransactionStatus_StatusCommitted) {
foundError = true;
- printf("Status error\n");
+// printf("Status error\n");
}
delete status;
}
if (foundError) {
- printf("Found Errors...\n");
+// printf("Found Errors...\n");
} else {
- printf("No Errors Found...\n");
}
transStatusList->clear();
int64_t nanoTime() {
int64_t time;
struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+ return 0;
}
void startTime() {
}
};
-TimingSingleton t_singleton;
-TimingSingleton *TimingSingleton_getInstance() {
- return &t_singleton;
-}
+TimingSingleton * TimingSingleton_getInstance();
#endif
void Transaction::addPartEncode(TransactionPart *newPart) {
newPart->acquireRef();
- printf("Add part %d\n", newPart->getPartNumber());
+ //printf("Add part %d\n", newPart->getPartNumber());
TransactionPart *old = parts->setExpand(newPart->getPartNumber(), newPart);
if (old == NULL) {
partCount++;
if (kv != NULL) {
- printf("%s %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
+ //printf("%s %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
} else {
- printf("%s null\n", kvGuard->getValue()->internalBytes()->internalArray());
+ //printf("%s null\n", kvGuard->getValue()->internalBytes()->internalArray());
}
delete kvit;
return false;
//typedef uint32_t uint;
#define CMEMALLOC ;
-#define model_print printf
#define ASSERT(expr) \
do { \
if (!(expr)) { \
- fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
- /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
- exit(EXIT_FAILURE); \
+ exit(EXIT_FAILURE); \
} \
} while (0)
#define myerror(msg) \
do { \
- printf(msg); \
exit(-1); \
} while(0)
unsigned int oldcapacity = capacity;
if ((newtable = (struct Hashlistnode<_Key, _Val> *)ourcalloc(newsize, sizeof(struct Hashlistnode<_Key, _Val>))) == NULL) {
- model_print("calloc error %s %d\n", __FILE__, __LINE__);
exit(EXIT_FAILURE);
}
int do_test(testvector *tv)
{
- printf("Started %s\n", tv->t);
fflush(stdout);
char *key = malloc(tv->dkLen);
if (key == 0) {
k = i < 3;
if (verbose != 0)
- printf(" SHA-%d test #%d: ", 256 - k * 32, j + 1);
+ ;
+ // printf(" SHA-%d test #%d: ", 256 - k * 32, j + 1);
sha2_starts(&ctx, k);
if (memcmp(sha2sum, sha2_test_sum[i], 32 - k * 4) != 0) {
if (verbose != 0)
- printf("failed\n");
+ ;
+ //printf("failed\n");
return (1);
}
if (verbose != 0)
- printf("passed\n");
+ ;//printf("passed\n");
}
if (verbose != 0)
- printf("\n");
+ ;//printf("\n");
for (i = 0; i < 14; i++) {
j = i % 7;
k = i < 7;
if (verbose != 0)
- printf(" HMAC-SHA-%d test #%d: ", 256 - k * 32,
- j + 1);
+ ;//printf(" HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1);
if (j == 5 || j == 6) {
memset(buf, '\xAA', buflen = 131);
if (memcmp(sha2sum, sha2_hmac_test_sum[i], buflen) != 0) {
if (verbose != 0)
- printf("failed\n");
+ ;//printf("failed\n");
return (1);
}
if (verbose != 0)
- printf("passed\n");
+ ;//printf("passed\n");
}
if (verbose != 0)
- printf("\n");
+ ;//printf("\n");
testvector *tv = 0;
int res = 0;
tv = &t1;
res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}
tv = &t2;
res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}
tv = &t3;
res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}
tv = &t4;
// res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}
tv = &t5;
res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}
tv = &t6;
res = do_test(tv);
if (res != 0) {
- printf("%s failed\n", tv->t);
+ ;//printf("%s failed\n", tv->t);
return res;
}