test/revoke_regen_attach_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 2414 71de06af5121
child 2462 48b526a0daac
permissions -rw-r--r--
fixed update_identity call that could be called on a myself value in outgoing_message_rating
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";
krista@2414
    48
    free(me->fpr);
krista@2414
    49
    status = myself(session, me);
krista@2414
    50
    assert(status == PEP_STATUS_OK);
Edouard@699
    51
    cout << me->fpr << "\n";
Edouard@699
    52
    
krista@2414
    53
    assert(me->fpr);
krista@2414
    54
    assert(strcmp(me->fpr, prev_fpr) != 0);
krista@2386
    55
    cout << "New fpr is: " << me->fpr;
krista@2386
    56
    
krista@2386
    57
    me->fpr = NULL;
krista@2386
    58
    me->comm_type = PEP_ct_unknown;
krista@2386
    59
    myself(session, me);
krista@2386
    60
    
vb@1424
    61
    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
    62
    message *msg = new_message(PEP_dir_outgoing);
Edouard@700
    63
    assert(msg);
Edouard@700
    64
    msg->from = me;
Edouard@700
    65
    msg->to = to;
Edouard@700
    66
    msg->shortmsg = strdup("hello, world");
Edouard@700
    67
    cout << "message created.\n";
Edouard@699
    68
Edouard@700
    69
    cout << "encrypting message as MIME multipart…\n";
Edouard@700
    70
    message *enc_msg;
Edouard@700
    71
    cout << "calling encrypt_message()\n";
krista@2035
    72
    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
Edouard@700
    73
    assert(status == PEP_STATUS_OK);
Edouard@700
    74
    assert(enc_msg);
Edouard@700
    75
    cout << "message encrypted.\n";
Edouard@700
    76
krista@2386
    77
    // cout << msg->attachments->filename;
krista@2386
    78
    // int bl_len = bloblist_length(msg->attachments);
krista@2386
    79
    // cout << "Message contains " << bloblist_length(msg->attachments) << " attachments." << endl;
krista@2386
    80
    // assert(bloblist_length(msg->attachments) == 2);
krista@2386
    81
    // assert(strcmp(msg->attachments->filename, "file://pEpkey.asc") == 0);
krista@2386
    82
    // assert(strcmp(msg->attachments->next->filename, "file://pEpkey.asc") == 0);
krista@2386
    83
    // 
krista@2386
    84
    // cout << "message contains 2 key attachments.\n";
Edouard@700
    85
Edouard@700
    86
    free_message(msg);
Edouard@700
    87
    free_message(enc_msg);
Edouard@700
    88
   
Edouard@700
    89
    // TODO: check that revoked key isn't sent after some time.
Edouard@700
    90
Edouard@700
    91
    release(session);
Edouard@699
    92
Edouard@699
    93
    return 0;
Edouard@699
    94
}