merge from default JNI-26
authorHussein Kasem <huss@pep-project.org>
Thu, 19 Jan 2017 17:15:01 +0100
branchJNI-26
changeset 155019aa77ace10b
parent 1548 a525079dc92e
parent 1547 6c7051a7f0d5
child 1551 78c0e9b079a0
merge from default
     1.1 --- a/src/message_api.c	Wed Jan 18 15:02:25 2017 +0100
     1.2 +++ b/src/message_api.c	Thu Jan 19 17:15:01 2017 +0100
     1.3 @@ -1922,6 +1922,15 @@
     1.4                         status = PEP_STATUS_OK;
     1.5                      if (status != PEP_STATUS_OK)
     1.6                          goto pep_error;
     1.7 +
     1.8 +                    // insert signer's in sender identity so that that new
     1.9 +                    // fpr has a chance to be used for trustwords computation
    1.10 +                    // when hanshaking after receiving message  
    1.11 +                    free(msg->from->fpr);
    1.12 +                    msg->from->fpr = strdup(fpr);
    1.13 +                    assert(msg->from->fpr);
    1.14 +                    if (msg->from->fpr == NULL)
    1.15 +                        goto enomem;
    1.16                  }
    1.17              }
    1.18          }
     2.1 --- a/src/sync.h	Wed Jan 18 15:02:25 2017 +0100
     2.2 +++ b/src/sync.h	Thu Jan 19 17:15:01 2017 +0100
     2.3 @@ -282,6 +282,7 @@
     2.4  //      msg (in)            message to inject
     2.5  //      management (in)     application defined
     2.6  //
     2.7 +//  *** BEWARE: msg is 1st parameter, obj is second!!! ***
     2.8  //  return value:
     2.9  //      0 if msg could be stored successfully or nonzero otherwise
    2.10  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/apple_mail_test.cc	Thu Jan 19 17:15:01 2017 +0100
     3.3 @@ -0,0 +1,138 @@
     3.4 +#include <iostream>
     3.5 +#include <iostream>
     3.6 +#include <fstream>
     3.7 +#include <string>
     3.8 +#include <cstring> // for strcmp()
     3.9 +#include <assert.h>
    3.10 +#include "blacklist.h"
    3.11 +#include "keymanagement.h"
    3.12 +#include "message_api.h"
    3.13 +#include "mime.h"
    3.14 +
    3.15 +using namespace std;
    3.16 +
    3.17 +int main(int argc, char** argv) {
    3.18 +    
    3.19 +
    3.20 +    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    3.21 +    
    3.22 +    PEP_SESSION session;
    3.23 +    
    3.24 +    cout << "calling init()\n";
    3.25 +    PEP_STATUS status1 = init(&session);   
    3.26 +    assert(status1 == PEP_STATUS_OK);
    3.27 +    assert(session);
    3.28 +    cout << "init() completed.\n";
    3.29 +
    3.30 +    ifstream infilekey1("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    3.31 +    string keytextkey1;
    3.32 +    while (!infilekey1.eof()) {
    3.33 +        static string line;
    3.34 +        getline(infilekey1, line);
    3.35 +        keytextkey1 += line + "\n";
    3.36 +    }
    3.37 +    infilekey1.close(); 
    3.38 +    
    3.39 +    ifstream infilekey2("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    3.40 +    string keytextkey2;
    3.41 +    while (!infilekey2.eof()) {
    3.42 +        static string line;
    3.43 +        getline(infilekey2, line);
    3.44 +        keytextkey2 += line + "\n";
    3.45 +    }
    3.46 +    infilekey2.close(); 
    3.47 +
    3.48 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    3.49 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    3.50 +        
    3.51 +    ifstream infile(mailfile);
    3.52 +    string mailtext;
    3.53 +    while (!infile.eof()) {
    3.54 +        static string line;
    3.55 +        getline(infile, line);
    3.56 +        mailtext += line + "\n";
    3.57 +    }
    3.58 +    infile.close(); 
    3.59 +
    3.60 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
    3.61 +    me->me = true;    
    3.62 +    PEP_STATUS status = update_identity(session, me);
    3.63 +
    3.64 +    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");    
    3.65 +    you->me = false;    
    3.66 +    status = update_identity(session, you);
    3.67 +
    3.68 +    trust_personal_key(session, you);
    3.69 +    
    3.70 +    status = update_identity(session, you);
    3.71 +    
    3.72 +    message* msg_ptr = nullptr;
    3.73 +    message* dest_msg = nullptr;
    3.74 +    message* final_ptr = nullptr;
    3.75 +    stringlist_t* keylist = nullptr;
    3.76 +    PEP_rating rating;
    3.77 +    PEP_decrypt_flags_t flags;
    3.78 +    
    3.79 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    3.80 +    assert(status == PEP_STATUS_OK);
    3.81 +    assert(msg_ptr);
    3.82 +    final_ptr = msg_ptr;
    3.83 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    3.84 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
    3.85 +  
    3.86 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    3.87 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    3.88 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    3.89 +
    3.90 +    assert(color_from_rating(rating) == PEP_color_green);
    3.91 +
    3.92 +    if (final_ptr == dest_msg)
    3.93 +    	free_message(dest_msg);
    3.94 +    free_message(msg_ptr);
    3.95 +    free_stringlist(keylist);
    3.96 +
    3.97 +    msg_ptr = nullptr;
    3.98 +    dest_msg = nullptr;
    3.99 +    final_ptr = nullptr;
   3.100 +    keylist = nullptr;
   3.101 +    rating = PEP_rating_unreliable;
   3.102 +    
   3.103 +    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
   3.104 +    
   3.105 +    ifstream infile2(mailfile2);
   3.106 +    string mailtext2;
   3.107 +    while (!infile2.eof()) {
   3.108 +        static string line;
   3.109 +        getline(infile2, line);
   3.110 +        mailtext2 += line + "\n";
   3.111 +    }
   3.112 +    infile2.close(); 
   3.113 +    
   3.114 +    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
   3.115 +    assert(status == PEP_STATUS_OK);
   3.116 +    assert(msg_ptr);
   3.117 +    final_ptr = msg_ptr;
   3.118 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   3.119 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
   3.120 +  
   3.121 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   3.122 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   3.123 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   3.124 +
   3.125 +    assert(color_from_rating(rating) == PEP_color_green);
   3.126 +
   3.127 +    if (final_ptr == dest_msg)
   3.128 +    	free_message(dest_msg);
   3.129 +    free_message(msg_ptr);
   3.130 +    free_stringlist(keylist);
   3.131 +
   3.132 +    msg_ptr = nullptr;
   3.133 +    dest_msg = nullptr;
   3.134 +    final_ptr = nullptr;
   3.135 +    keylist = nullptr;
   3.136 +    rating = PEP_rating_unreliable;
   3.137 +        
   3.138 +    cout << "calling release()\n";
   3.139 +    release(session);
   3.140 +    return 0;
   3.141 +}