ENGINE-172: ENGINE-180: tests check out. Modified MIME_decrypt_message to return decrypt status when MIME successful. ENGINE-172
authorKrista Grothoff <krista@pep-project.org>
Mon, 13 Mar 2017 09:48:14 +0100
branchENGINE-172
changeset 16446b88877f8885
parent 1642 af07ab39e430
child 1645 5f5d81b05b0e
child 1646 8c195fed3e1e
ENGINE-172: ENGINE-180: tests check out. Modified MIME_decrypt_message to return decrypt status when MIME successful.
src/message_api.c
src/message_api.h
test/encrypt_for_identity_test.cc
     1.1 --- a/src/message_api.c	Mon Mar 13 08:46:11 2017 +0100
     1.2 +++ b/src/message_api.c	Mon Mar 13 09:48:14 2017 +0100
     1.3 @@ -2526,17 +2526,18 @@
     1.4      if (status != PEP_STATUS_OK)
     1.5          goto pep_error;
     1.6  
     1.7 -    status = decrypt_message(session,
     1.8 -                             tmp_msg,
     1.9 -                             &dec_msg,
    1.10 -                             keylist,
    1.11 -                             rating,
    1.12 -                             flags);
    1.13 -    if (status != PEP_STATUS_OK)
    1.14 -        goto pep_error;
    1.15 -
    1.16 +    PEP_STATUS decrypt_status = decrypt_message(session,
    1.17 +                                                tmp_msg,
    1.18 +                                                &dec_msg,
    1.19 +                                                keylist,
    1.20 +                                                rating,
    1.21 +                                                flags);
    1.22 +                                                
    1.23      status = mime_encode_message(dec_msg, false, mime_plaintext);
    1.24  
    1.25 +    if (status == PEP_STATUS_OK)
    1.26 +        return decrypt_status;
    1.27 +        
    1.28  pep_error:
    1.29      free_message(tmp_msg);
    1.30      free_message(dec_msg);
    1.31 @@ -2589,7 +2590,6 @@
    1.32      pEp_identity* target_id,
    1.33      const char *mimetext,
    1.34      size_t size,
    1.35 -    stringlist_t* extra,
    1.36      char** mime_ciphertext,
    1.37      PEP_enc_format enc_format,
    1.38      PEP_encrypt_flags_t flags
     2.1 --- a/src/message_api.h	Mon Mar 13 08:46:11 2017 +0100
     2.2 +++ b/src/message_api.h	Mon Mar 13 09:48:14 2017 +0100
     2.3 @@ -140,9 +140,9 @@
     2.4  //                              the message, with MIME output
     2.5  //  parameters:
     2.6  //      session (in)            session handle
     2.7 +//      target_id (in)      self identity this message should be encrypted for
     2.8  //      mimetext (in)           MIME encoded text to encrypt
     2.9  //      size (in)               size of input mime text
    2.10 -//      extra (in)              extra keys for encryption
    2.11  //      mime_ciphertext (out)   encrypted, encoded message
    2.12  //      enc_format (in)         encrypted format
    2.13  //      flags (in)              flags to set special encryption features
    2.14 @@ -165,7 +165,6 @@
    2.15      pEp_identity* target_id,
    2.16      const char *mimetext,
    2.17      size_t size,
    2.18 -    stringlist_t* extra,
    2.19      char** mime_ciphertext,
    2.20      PEP_enc_format enc_format,
    2.21      PEP_encrypt_flags_t flags
    2.22 @@ -255,7 +254,9 @@
    2.23  //      flags (out)             flags to signal special decryption features
    2.24  //
    2.25  //  return value:
    2.26 -//      PEP_STATUS_OK           if everything worked
    2.27 +//      decrypt status          if everything worked with MIME encode/decode, 
    2.28 +//                              the status of the decryption is returned 
    2.29 +//                              (PEP_STATUS_OK or decryption error status)
    2.30  //      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    2.31  //      PEP_CANNOT_CREATE_TEMP_FILE
    2.32  //                              if there are issues with temp files; in
     3.1 --- a/test/encrypt_for_identity_test.cc	Mon Mar 13 08:46:11 2017 +0100
     3.2 +++ b/test/encrypt_for_identity_test.cc	Mon Mar 13 09:48:14 2017 +0100
     3.3 @@ -35,6 +35,7 @@
     3.4      outgoing_message->from = alice;
     3.5      outgoing_message->to = to_list;
     3.6      outgoing_message->shortmsg = strdup("Greetings, humans!");
     3.7 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
     3.8      outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
     3.9      cout << "message created.\n";
    3.10  
    3.11 @@ -81,10 +82,10 @@
    3.12      PEP_decrypt_flags_t flags;
    3.13  
    3.14      status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
    3.15 -    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
    3.16      assert(decrypted_msg);
    3.17      assert(keylist_used);
    3.18      assert(rating);
    3.19 +    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
    3.20      PEP_comm_type ct = encrypted_msg->from->comm_type;
    3.21      assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
    3.22  
    3.23 @@ -111,6 +112,82 @@
    3.24      free_message(outgoing_message);
    3.25      cout << "done.\n";
    3.26  
    3.27 +    cout << "*** Now testing MIME_encrypt_for_self ***" << endl;
    3.28 +
    3.29 +    alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    3.30 +    bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    3.31 +
    3.32 +    cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
    3.33 +    
    3.34 +    ifstream inFile("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
    3.35 +    assert(inFile.is_open());
    3.36 +
    3.37 +    string mimetext;
    3.38 +
    3.39 +    cout << "reading mime mail\n";
    3.40 +    while (!inFile.eof()) {
    3.41 +        static string line;
    3.42 +        getline(inFile, line);
    3.43 +        mimetext += line + "\n";
    3.44 +    }
    3.45 +    inFile.close();
    3.46 +
    3.47 +    cout << "Text read:" << endl;
    3.48 +    cout << mimetext.c_str() << endl;
    3.49 +    char* encrypted_mimetext = nullptr;
    3.50 +    
    3.51 +    cout << "Calling MIME_encrypt_message_for_self" << endl;
    3.52 +    status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(),
    3.53 +                                           mimetext.size(), 
    3.54 +                                           &encrypted_mimetext, 
    3.55 +                                           PEP_enc_PGP_MIME, 
    3.56 +                                           PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
    3.57 +    
    3.58 +    cout << "Encrypted message:" << endl;
    3.59 +    cout << encrypted_mimetext << endl;
    3.60 +
    3.61 +    cout << "Calling MIME_decrypt_message" << endl;
    3.62 +    
    3.63 +    char* decrypted_mimetext = nullptr;
    3.64 +    free_stringlist(keylist_used);
    3.65 +    keylist_used = nullptr;
    3.66 +    PEP_decrypt_flags_t mimeflags;
    3.67 +    PEP_rating mimerating;
    3.68 +
    3.69 +    status = MIME_decrypt_message(session,
    3.70 +                                  encrypted_mimetext,
    3.71 +                                  strlen(encrypted_mimetext),
    3.72 +                                  &decrypted_mimetext,
    3.73 +                                  &keylist_used,
    3.74 +                                  &mimerating,
    3.75 +                                  &mimeflags);
    3.76 +
    3.77 +    assert(decrypted_msg);
    3.78 +    assert(keylist_used);
    3.79 +    assert(mimerating);
    3.80 +                             
    3.81 +    assert(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable);
    3.82 +
    3.83 +    cout << "Decrypted message:" << endl;
    3.84 +    cout << decrypted_mimetext << endl;
    3.85 +
    3.86 +    cout << "keys used:\n";
    3.87 +
    3.88 +    i = 0;
    3.89 +
    3.90 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
    3.91 +    {
    3.92 +        if (i == 0)
    3.93 +            assert(strcasecmp("",kl4->value) == 0);
    3.94 +        else {
    3.95 +            cout << "\t " << kl4->value << endl;
    3.96 +            assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    3.97 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
    3.98 +        }
    3.99 +        assert(i < 2);
   3.100 +    }
   3.101 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
   3.102 +    
   3.103      cout << "calling release()\n";
   3.104      release(session);
   3.105      return 0;