test.c 3.45 KB
Newer Older
hark's avatar
bla  
hark committed
1 2 3 4
/*
 * test thingie for the pagerlib
 */

hark's avatar
hark committed
5 6 7 8 9 10 11 12 13 14

#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>
hark's avatar
hark committed
15
#include <stdlib.h>
hark's avatar
hark committed
16 17
#include <fcntl.h>

hark's avatar
hark committed
18

hark's avatar
hark committed
19 20
//#include "packets.h"
#include "../libs/pagerlib/pagerlib.h"
hark's avatar
hark committed
21 22 23 24 25
#ifndef uECC_TEST_NUMBER_OF_ITERATIONS
#define uECC_TEST_NUMBER_OF_ITERATIONS   1
#endif

int main() {
hark's avatar
bla  
hark committed
26 27 28 29 30 31 32 33 34
  struct pl_keypair *kp;
  kp = 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 * context;

  context = pl_init();

hark's avatar
hark committed
35
  int  f = 0;
hark's avatar
hark committed
36
  while ( f < 2 ) {
hark's avatar
hark committed
37
    f++;
hark's avatar
bla  
hark committed
38
    /* create keypairs */
hark's avatar
hark committed
39
    kp = pl_create_keypair(context);
hark's avatar
hark committed
40 41 42 43 44 45 46 47 48 49 50 51
    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)) ;


hark's avatar
hark committed
52 53 54
    pl_load_key_in_list(context, kp);
    // set key to use for sending the message (FIXME)
    context->kp = kp;
55

hark's avatar
bla  
hark committed
56
    // load the message to send
hark's avatar
dingen  
hark committed
57
    memcpy(context->msg->msg, clear_message, MSG_SIZE);
hark's avatar
update  
hark committed
58

hark's avatar
bla  
hark committed
59
    //to who to send the message to (get from kp)
hark's avatar
hark committed
60
    memcpy(&context->receiver_compressed_point, &kp->compressed_point, sizeof(context->receiver_compressed_point));
hark's avatar
hark committed
61

hark's avatar
hark committed
62
    pl_send_message(context);
hark's avatar
hark committed
63
    printf("crypted msg: %s",context->msg->msg);
hark's avatar
bla  
hark committed
64 65 66 67 68 69 70 71

    /* receive the msg */
    if ( pl_receive_message(context) ==  1) {
      printf("failed to receive this message ! (exit 1) \n");
    } else  {
      printf("recv success! \n");
      //    printf(" Message! \n to: %u  from: %u \n the decrypted message: %s \n", context->msg->address, compressed_point_to_addr(context->msg->sender_compressed_point), context->msg->msg);
    }
hark's avatar
hark committed
72 73


hark's avatar
bla  
hark committed
74

hark's avatar
hark committed
75
  
hark's avatar
bla  
hark committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89

  /*
     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);

*/

hark's avatar
hark committed
90
     context->kp = kp;
hark's avatar
bla  
hark committed
91

hark's avatar
hark committed
92 93
    if (pl_receive_message(context) == 1) {
      printf("OK: \n");
94
    } else  {
hark's avatar
hark committed
95
      printf("failed to receive this message ! (exit 1)");
96
    }
hark's avatar
hark committed
97

hark's avatar
hark committed
98
//  pl_inbox_display_all(context);
hark's avatar
hark committed
99 100


hark's avatar
hark committed
101 102
  while (pl_inbox_next(context))
  {
hark's avatar
bla  
hark committed
103 104
      pl_inbox_display(context);
  }
hark's avatar
hark committed
105

hark's avatar
hark committed
106 107 108 109 110 111 112
  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);
  }
hark's avatar
hark committed
113

hark's avatar
hark committed
114 115 116 117 118 119
  while (pl_inbox_prev(context)) {
          pl_inbox_display(context);
  }
//  pl_inbox_delete(context); 
  pl_inbox_display(context);
  }
hark's avatar
bla  
hark committed
120
  return 0;
hark's avatar
hark committed
121
}