test/encrypt_missing_private_key_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 2394 88b9027db1bf
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
krista@1377
     4
#include <iostream>
krista@1377
     5
#include <iostream>
krista@1377
     6
#include <fstream>
krista@1377
     7
#include <string>
krista@1377
     8
#include <cstring> // for strcmp()
krista@1377
     9
#include <assert.h>
krista@1377
    10
#include "blacklist.h"
krista@1377
    11
#include "keymanagement.h"
krista@1377
    12
#include "message_api.h"
krista@1377
    13
#include "mime.h"
roker@1660
    14
#include "test_util.h"
krista@1377
    15
krista@1377
    16
using namespace std;
krista@1377
    17
krista@1377
    18
int main() {
krista@1377
    19
    cout << "\n*** encrypt_missing_private_key_test ***\n\n";
krista@1377
    20
krista@1377
    21
    PEP_SESSION session;
krista@1377
    22
    
krista@1377
    23
    cout << "calling init()\n";
krista@1377
    24
    PEP_STATUS status1 = init(&session);   
krista@1377
    25
    assert(status1 == PEP_STATUS_OK);
krista@1377
    26
    assert(session);
krista@1377
    27
    cout << "init() completed.\n";
krista@1377
    28
    
krista@2394
    29
    pEp_identity* no_key_identity = new_identity("blacklistself@kgrothoff.org",
krista@2394
    30
                                                      NULL,
krista@1377
    31
                                                      PEP_OWN_USERID,
krista@1377
    32
                                                      "Blacklist Self");
krista@2394
    33
    no_key_identity->me = true;
krista@2394
    34
    PEP_STATUS status8 = myself(session, no_key_identity);
krista@1925
    35
    assert (status8 == PEP_STATUS_OK);
krista@1377
    36
krista@2394
    37
    /* Now let's try to encrypt a message. */
krista@2394
    38
        
krista@1377
    39
    message* tmp_msg = NULL;
krista@1377
    40
    message* enc_msg = NULL;
krista@1377
    41
    
krista@2394
    42
    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
krista@2394
    43
krista@1377
    44
    PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
krista@1377
    45
    assert(status == PEP_STATUS_OK);
krista@1377
    46
    
krista@2394
    47
    status = update_identity(session, tmp_msg->from);
krista@2394
    48
    identity_list* to_list = tmp_msg->to;
krista@2394
    49
krista@2394
    50
    while (to_list) {
krista@2394
    51
        if (to_list->ident)
krista@2394
    52
            update_identity(session, to_list->ident);
krista@2394
    53
        to_list = to_list->next;
krista@2394
    54
    }
krista@1377
    55
    
krista@1377
    56
    // This isn't incoming, though... so we need to reverse the direction
krista@1377
    57
    tmp_msg->dir = PEP_dir_outgoing;
krista@1377
    58
    status = encrypt_message(session,
krista@1377
    59
                             tmp_msg,
krista@1377
    60
                             NULL,
krista@1377
    61
                             &enc_msg,
krista@1377
    62
                             PEP_enc_PGP_MIME,
krista@1377
    63
                             0);
krista@1377
    64
    assert(status == PEP_STATUS_OK);
krista@1377
    65
    
krista@1377
    66
krista@2394
    67
    char* new_key = enc_msg->from->fpr;
krista@1377
    68
    cout << "Encrypted with key " << new_key << endl;
krista@1377
    69
    
krista@1377
    70
    status = delete_keypair(session, new_key);
krista@2394
    71
    PEP_STATUS status14 = myself(session, no_key_identity);
krista@1377
    72
krista@1377
    73
    free_message(tmp_msg);    
krista@1377
    74
    free_message(enc_msg);
krista@1377
    75
    
krista@1377
    76
    cout << "calling release()\n";
krista@1377
    77
    release(session);
krista@1377
    78
    return 0;
krista@1377
    79
}