Commit 2c26fd3f authored by hark's avatar hark

more test in test.c

parent e08ce40b
......@@ -2,25 +2,13 @@
* test thingie for the pagerlib
*/
#include "../libs/micro-ecc/uECC.h"
//#include "../include/oaes_lib.h"
//#include "mbedtls_config.h"
//#include "../libs/mbedtls-2.2.0/include/mbedtls/config.h"
//#include "../libs/mbedtls-2.2.0/include/mbedtls/aes.h"
//#include "../libs/mbedtls-2.2.0/library/aes.c"
//#include <gnutls/gnutls.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
//#include "packets.h"
#include "../libs/pagerlib/pagerlib.h"
#ifndef uECC_TEST_NUMBER_OF_ITERATIONS
#define uECC_TEST_NUMBER_OF_ITERATIONS 1
#endif
int main() {
struct pl_keypair *receiver, *sender;
......@@ -28,48 +16,38 @@ int main() {
sender = NULL;
char clear_message[] = "Blaat blaat, dit is een test berichtje :), en nog meer en meer en meer 123456744555 blablablablablablabal jajajajaj hee blaat ";
// initialise the pager
struct pl_ctx *sender_ctx, *rcv_ctx;
// initialise the pagers
struct pl_ctx *sender_ctx, *rcv_ctx, *context;
rcv_ctx = pl_init();
sender_ctx = pl_init();
/* create keypairs */
receiver = pl_create_keypair(rcv_ctx);
pl_load_key_in_list(rcv_ctx, receiver);
pl_load_key_in_list(sender_ctx, receiver);
rcv_ctx->kp = receiver;
sender = pl_create_keypair(sender_ctx);
pl_load_key_in_list(sender_ctx, sender);
pl_load_key_in_list(rcv_ctx, sender);
sender_ctx->kp = sender;
/*
char *kp_b64, *decoded;
// 4*(n/3)
kp_b64 = malloc(4*(sizeof(struct pl_keypair) / 3));
decoded = malloc(sizeof(struct pl_keypair));
base64_encode(kp_b64, kp, sizeof(struct pl_keypair));
printf("base64 keypair: %s \n", kp_b64);
/* create keypairs */
receiver = pl_create_keypair(rcv_ctx);
pl_load_key_in_list(rcv_ctx, receiver);
pl_load_key_in_list(sender_ctx, receiver);
rcv_ctx->kp = receiver;
base64_decode(decoded , kp_b64, (4*sizeof(struct pl_keypair) / 3)) ;
sender = pl_create_keypair(sender_ctx);
pl_load_key_in_list(sender_ctx, sender);
pl_load_key_in_list(rcv_ctx, sender);
sender_ctx->kp = sender;
*/
// set key to use for sending the message (FIXME)
/*
char *kp_b64, *decoded;
// 4*(n/3)
kp_b64 = malloc(4*(sizeof(struct pl_keypair) / 3));
decoded = malloc(sizeof(struct pl_keypair));
base64_encode(kp_b64, kp, sizeof(struct pl_keypair));
printf("base64 keypair: %s \n", kp_b64);
base64_decode(decoded , kp_b64, (4*sizeof(struct pl_keypair) / 3)) ;
*/
int f = 0;
while ( f < 10 ) {
f++;
// load the message to send
memcpy(sender_ctx->msg->msg, clear_message, MSG_SIZE);
......@@ -78,28 +56,24 @@ int main() {
memcpy(&sender_ctx->receiver_public_key, &receiver->public_key, sizeof(sender_ctx->receiver_public_key));
int r;
switch(pl_send_message(sender_ctx)) {
case 0:
printf("SEND: OK! \n");
break;
case -1:
printf("SEND: -1 \n");
break;
case -2:
printf("SEND: -2 \n");
break;
case -3:
printf("SEND: -3 \n");
break;
default:
printf("SEND: unknown error \n");
break;
case 0:
printf("SEND: OK! \n");
break;
case -1:
printf("SEND: -1 \n");
break;
case -2:
printf("SEND: -2 \n");
break;
case -3:
printf("SEND: -3 \n");
break;
default:
printf("SEND: unknown error \n");
break;
}
// printf("crypted msg: %s",sender_ctx->msg->msg);
// printf("crypted msg: %s",sender_ctx->msg->msg);
/* copy the message to receiver */
struct pl_pagermessage * message = NULL;
......@@ -111,79 +85,68 @@ break;
printf("\n encrypted message: \n %s \n END encrypted message \n", rcv_ctx->msg->msg );
switch(pl_receive_message(sender_ctx)) {
case 0:
printf("RCV: OK! \n");
printf(" Message! \n to: %u from: %u \n the decrypted message: %s \n", rcv_ctx->msg->address, compressed_point_to_addr(rcv_ctx->msg->sender_public_key), rcv_ctx->msg->msg);
break;
case -1:
printf("RCV: -1 (box open error)\n");
break;
case -2:
printf("RCV: -2 \n");
break;
case -3:
printf("RCV: -3 (zerobytes not zero)\n");
break;
case -4:
printf("RCV: -4 (key not found) \n");
break;
default:
printf("RCV: unknown error \n");
break;
}
}
} // main
/*
DBG("\n sender.keypair");
DBM("sender", sizeof(struct pl_keypair), sender);
DBM("receiver", sizeof(struct pl_keypair), receiver);
DBM("context->kp (sender)", sizeof(struct pl_keypair), context->kp);
DBM("context->kp->private_key (sender)", sizeof(context->kp->private_key), &context->kp->private_key);
DBM("receiver->compressed",sizeof(receiver->compressed_point) , &receiver->compressed_point);
DBM("context->receiver_compressed_point",sizeof(context->receiver_compressed_point) , &context->receiver_compressed_point);
DBM("context->kp (receiver)", sizeof(struct pl_keypair), context->kp);
DBM("context->kp->private_key (receiver)", sizeof(context->kp->private_key), &context->kp->private_key);
case 0:
printf("RCV: OK! \n");
printf(" Message! \n to: %u from: %u \n the decrypted message: %s \n", rcv_ctx->msg->address, compressed_point_to_addr(rcv_ctx->msg->sender_public_key), rcv_ctx->msg->msg);
break;
case -1:
printf("RCV: -1 (box open error)\n");
break;
case -2:
printf("RCV: -2 \n");
break;
case -3:
printf("RCV: -3 (zerobytes not zero)\n");
break;
case -4:
printf("RCV: -4 (key not found) \n");
break;
default:
printf("RCV: unknown error \n");
break;
}
}
/*
DBG("\n sender.keypair");
DBM("sender", sizeof(struct pl_keypair), sender);
DBM("receiver", sizeof(struct pl_keypair), receiver);
DBM("context->kp (sender)", sizeof(struct pl_keypair), context->kp);
DBM("context->kp->private_key (sender)", sizeof(context->kp->private_key), &context->kp->private_key);
DBM("receiver->compressed",sizeof(receiver->compressed_point) , &receiver->compressed_point);
DBM("context->receiver_compressed_point",sizeof(context->receiver_compressed_point) , &context->receiver_compressed_point);
DBM("context->kp (receiver)", sizeof(struct pl_keypair), context->kp);
DBM("context->kp->private_key (receiver)", sizeof(context->kp->private_key), &context->kp->private_key);
*/
/*
context->kp = kp;
context = rcv_ctx;
if (pl_receive_message(context) == 1) {
printf("OK: \n");
} else {
printf("failed to receive this message ! (exit 1)");
}
// pl_inbox_display_all(context);
pl_inbox_display_all(context);
while (pl_inbox_next(context))
{
pl_inbox_display(context);
}
while (pl_inbox_next(context))
{
pl_inbox_display(context);
}
while (pl_inbox_prev(context)) {
pl_inbox_display(context);
}
while (pl_inbox_next(context) && context->inbox->prev != NULL && context->inbox->prev->id > 9)
{
pl_inbox_delete(context);
}
while (pl_inbox_prev(context)) {
pl_inbox_display(context);
}
while (pl_inbox_next(context) && context->inbox->prev != NULL && context->inbox->prev->id > 9)
{
pl_inbox_delete(context);
}
while (pl_inbox_prev(context)) {
pl_inbox_display(context);
}
while (pl_inbox_prev(context)) {
pl_inbox_display(context);
}
// pl_inbox_delete(context);
pl_inbox_display(context);
}
return 0;
*/
pl_inbox_display(context);
return 0;
//}
} // main
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment