test/revoke_regen_attach_test.cc
author Edouard Tisserant
Thu, 09 Jun 2016 19:19:46 +0200
branchimport_own_key
changeset 727 382718692559
parent 700 5d543921a9c6
child 940 5f0a9d0f0ecd
permissions -rw-r--r--
branched
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include <time.h>
     4 #include "platform.h"
     5 #include <iostream>
     6 #include <fstream>
     7 #include <assert.h>
     8 #include "mime.h"
     9 #include "message_api.h"
    10 
    11 using namespace std;
    12 
    13 int main() {
    14     cout << "\n*** revoke_regen_attach_test ***\n\n";
    15 
    16     PEP_SESSION session;
    17     
    18     cout << "calling init()\n";
    19     PEP_STATUS status = init(&session);   
    20     assert(status == PEP_STATUS_OK);
    21     assert(session);
    22     cout << "init() completed.\n";
    23 
    24     cout << "creating own id for : ";
    25     char *uniqname = strdup("AAAAtestuser@testdomain.org");
    26     srandom(time(NULL));
    27     for(int i=0; i < 4;i++)
    28         uniqname[i] += random() & 0xf;
    29     
    30     cout << uniqname << "\n";
    31     pEp_identity * me = new_identity(uniqname, NULL, PEP_OWN_USERID, "Test User");
    32     free(uniqname);
    33     myself(session, me);
    34 
    35     cout << "generated fingerprint \n";
    36     cout << me->fpr << "\n";
    37 
    38     const char *prev_fpr = strdup(me->fpr);
    39     
    40     cout << "revoke \n";
    41     
    42     key_compromized(session, me);
    43 
    44     cout << "re-generated fingerprint \n";
    45     cout << me->fpr << "\n";
    46     
    47     assert(strcmp(me->fpr, prev_fpr));
    48 
    49     identity_list *to = new_identity_list(new_identity("vb@dingens.org", NULL, "42", "Volker Birk"));
    50     message *msg = new_message(PEP_dir_outgoing);
    51     assert(msg);
    52     msg->from = me;
    53     msg->to = to;
    54     msg->shortmsg = strdup("hello, world");
    55     cout << "message created.\n";
    56 
    57     cout << "encrypting message as MIME multipart…\n";
    58     message *enc_msg;
    59     cout << "calling encrypt_message()\n";
    60     status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME);
    61     cout << status;
    62     assert(status == PEP_STATUS_OK);
    63     assert(enc_msg);
    64     cout << "message encrypted.\n";
    65 
    66     cout << msg->attachments->filename;
    67     assert(bloblist_length(msg->attachments) == 2);
    68     assert(strcmp(msg->attachments->filename, "pEpkey.asc") == 0);
    69     assert(strcmp(msg->attachments->next->filename, "pEpkey.asc") == 0);
    70 
    71     cout << "message contains 2 key attachements.\n";
    72 
    73     free_message(msg);
    74     free_message(enc_msg);
    75    
    76     // TODO: check that revoked key isn't sent after some time.
    77 
    78     release(session);
    79 
    80     return 0;
    81 }
    82