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