test/apple_mail_test.cc
author Krista Bennett <krista@pep-project.org>
Mon, 05 Feb 2018 10:58:03 +0100
branchENGINE-250
changeset 2477 45e8ed722fec
parent 2462 48b526a0daac
child 2496 389abc0e9b54
permissions -rw-r--r--
Intermittent commit
krista@1543
     1
#include <iostream>
krista@1543
     2
#include <iostream>
krista@1543
     3
#include <fstream>
krista@1543
     4
#include <string>
krista@1543
     5
#include <cstring> // for strcmp()
krista@1543
     6
#include <assert.h>
krista@1543
     7
#include "blacklist.h"
krista@1543
     8
#include "keymanagement.h"
krista@1543
     9
#include "message_api.h"
krista@1543
    10
#include "mime.h"
roker@1660
    11
#include "test_util.h" // for slurp()
krista@1543
    12
krista@1543
    13
using namespace std;
krista@1543
    14
krista@1543
    15
int main(int argc, char** argv) {
krista@1545
    16
krista@1543
    17
    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
krista@1543
    18
    
krista@1543
    19
    PEP_SESSION session;
krista@1543
    20
    
krista@1543
    21
    cout << "calling init()\n";
krista@1543
    22
    PEP_STATUS status1 = init(&session);   
krista@1543
    23
    assert(status1 == PEP_STATUS_OK);
krista@1543
    24
    assert(session);
krista@1543
    25
    cout << "init() completed.\n";
krista@1543
    26
roker@1660
    27
    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
roker@1660
    28
    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
krista@1839
    29
    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
krista@1545
    30
krista@1545
    31
    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
krista@1545
    32
    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
krista@1839
    33
    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
krista@1543
    34
        
roker@1660
    35
    const string mailtext = slurp(mailfile);
krista@1839
    36
    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
krista@2461
    37
    me->me = true;    
krista@1839
    38
    PEP_STATUS status = myself(session, me);
krista@1638
    39
    
krista@1543
    40
    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");    
krista@2461
    41
    you->me = false;    
krista@1543
    42
    status = update_identity(session, you);
krista@1543
    43
krista@1543
    44
    trust_personal_key(session, you);
krista@1543
    45
    
krista@1543
    46
    status = update_identity(session, you);
krista@1543
    47
    
krista@1543
    48
    message* msg_ptr = nullptr;
krista@1543
    49
    message* dest_msg = nullptr;
krista@1543
    50
    message* final_ptr = nullptr;
krista@1543
    51
    stringlist_t* keylist = nullptr;
krista@1543
    52
    PEP_rating rating;
krista@1543
    53
    PEP_decrypt_flags_t flags;
krista@1543
    54
    
krista@1543
    55
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1543
    56
    assert(status == PEP_STATUS_OK);
krista@1543
    57
    assert(msg_ptr);
krista@2461
    58
    
krista@2461
    59
    update_identity(session, msg_ptr->from);
krista@2461
    60
    update_identity(session, msg_ptr->to->ident);
krista@2461
    61
    
krista@1543
    62
    final_ptr = msg_ptr;
krista@2461
    63
    
krista@1543
    64
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1543
    65
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1543
    66
  
krista@1543
    67
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1543
    68
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1543
    69
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1543
    70
krista@1543
    71
    assert(color_from_rating(rating) == PEP_color_green);
krista@1543
    72
krista@1543
    73
    if (final_ptr == dest_msg)
krista@1543
    74
    	free_message(dest_msg);
krista@1543
    75
    free_message(msg_ptr);
krista@1543
    76
    free_stringlist(keylist);
krista@1543
    77
krista@1543
    78
    msg_ptr = nullptr;
krista@1543
    79
    dest_msg = nullptr;
krista@1543
    80
    final_ptr = nullptr;
krista@1543
    81
    keylist = nullptr;
krista@1543
    82
    rating = PEP_rating_unreliable;
krista@1543
    83
    
krista@1543
    84
    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
roker@1660
    85
    const string mailtext2 = slurp(mailfile2);
krista@1543
    86
    
krista@1543
    87
    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
krista@1543
    88
    assert(status == PEP_STATUS_OK);
krista@1543
    89
    assert(msg_ptr);
krista@1543
    90
    final_ptr = msg_ptr;
krista@1543
    91
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1543
    92
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1543
    93
  
krista@1543
    94
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1543
    95
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1543
    96
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1543
    97
krista@1543
    98
    assert(color_from_rating(rating) == PEP_color_green);
krista@1543
    99
krista@1543
   100
    if (final_ptr == dest_msg)
krista@1543
   101
    	free_message(dest_msg);
krista@1543
   102
    free_message(msg_ptr);
krista@1543
   103
    free_stringlist(keylist);
krista@1543
   104
krista@1545
   105
    msg_ptr = nullptr;
krista@1545
   106
    dest_msg = nullptr;
krista@1545
   107
    final_ptr = nullptr;
krista@1545
   108
    keylist = nullptr;
krista@1545
   109
    rating = PEP_rating_unreliable;
krista@1545
   110
        
krista@1543
   111
    cout << "calling release()\n";
krista@1543
   112
    release(session);
krista@1543
   113
    return 0;
krista@1543
   114
}