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