test/revoke_regen_attach_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:27:30 +0200
branchENGINE-135
changeset 2708 11e836fe7f0a
parent 1513 e7f7e42385b5
child 1873 2da96adc534e
permissions -rw-r--r--
close branch
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string.h>
     6 #include <time.h>
     7 #include "platform.h"
     8 #include <iostream>
     9 #include <fstream>
    10 #include <assert.h>
    11 #include "mime.h"
    12 #include "message_api.h"
    13 
    14 using namespace std;
    15 
    16 int main() {
    17     cout << "\n*** revoke_regen_attach_test ***\n\n";
    18 
    19     PEP_SESSION session;
    20     
    21     cout << "calling init()\n";
    22     PEP_STATUS status = init(&session);   
    23     assert(status == PEP_STATUS_OK);
    24     assert(session);
    25     cout << "init() completed.\n";
    26 
    27     cout << "creating own id for : ";
    28     char *uniqname = strdup("AAAAtestuser@testdomain.org");
    29     srandom(time(NULL));
    30     for(int i=0; i < 4;i++)
    31         uniqname[i] += random() & 0xf;
    32     
    33     cout << uniqname << "\n";
    34     pEp_identity * me = new_identity(uniqname, NULL, PEP_OWN_USERID, "Test User");
    35     free(uniqname);
    36     myself(session, me);
    37 
    38     cout << "generated fingerprint \n";
    39     cout << me->fpr << "\n";
    40 
    41     const char *prev_fpr = strdup(me->fpr);
    42     
    43     cout << "revoke \n";
    44     
    45     key_mistrusted(session, me);
    46 
    47     cout << "re-generated fingerprint \n";
    48     cout << me->fpr << "\n";
    49     
    50     assert(strcmp(me->fpr, prev_fpr));
    51 
    52     identity_list *to = new_identity_list(new_identity("pep.test.alice@pep-project.org", NULL, "42", "pEp Test Alice (test key don't use)"));
    53     message *msg = new_message(PEP_dir_outgoing);
    54     assert(msg);
    55     msg->from = me;
    56     msg->to = to;
    57     msg->shortmsg = strdup("hello, world");
    58     cout << "message created.\n";
    59 
    60     cout << "encrypting message as MIME multipart…\n";
    61     message *enc_msg;
    62     cout << "calling encrypt_message()\n";
    63     status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    64     cout << status;
    65     assert(status == PEP_STATUS_OK);
    66     assert(enc_msg);
    67     cout << "message encrypted.\n";
    68 
    69     cout << msg->attachments->filename;
    70     assert(bloblist_length(msg->attachments) == 2);
    71     assert(strcmp(msg->attachments->filename, "pEpkey.asc") == 0);
    72     assert(strcmp(msg->attachments->next->filename, "pEpkey.asc") == 0);
    73 
    74     cout << "message contains 2 key attachements.\n";
    75 
    76     free_message(msg);
    77     free_message(enc_msg);
    78    
    79     // TODO: check that revoked key isn't sent after some time.
    80 
    81     release(session);
    82 
    83     return 0;
    84 }
    85