merged back to parent ENGINE-553
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 15 May 2019 16:02:11 +0200
branchENGINE-553
changeset 3709c560e8fd8246
parent 3706 3bcb75b270ed
parent 3708 42c376229484
child 3710 d7c1395f473c
merged back to parent
     1.1 --- a/src/message.h	Wed May 15 14:35:22 2019 +0200
     1.2 +++ b/src/message.h	Wed May 15 16:02:11 2019 +0200
     1.3 @@ -70,6 +70,9 @@
     1.4      char *comments;                         // UTF-8 string with comments
     1.5      stringpair_list_t *opt_fields;          // optional fields
     1.6      PEP_enc_format enc_format;              // format of encrypted data
     1.7 +    char* _sender_fpr;                      // INTERNAL USE ONLY - fingerprint of 
     1.8 +                                            // sending signer.
     1.9 +                                            // (read_only to the outside)
    1.10  } message;
    1.11  
    1.12  typedef struct _message_ref_list {
     2.1 --- a/src/message_api.c	Wed May 15 14:35:22 2019 +0200
     2.2 +++ b/src/message_api.c	Wed May 15 16:02:11 2019 +0200
     2.3 @@ -947,6 +947,12 @@
     2.4          if (!attachment->shortmsg)
     2.5              goto enomem;
     2.6      }
     2.7 +    
     2.8 +    /* add sender fpr to inner message */
     2.9 +    add_opt_field(attachment, 
    2.10 +                  "X-pEp-Sender-FPR", 
    2.11 +                  (attachment->_sender_fpr ? attachment->_sender_fpr : "")
    2.12 +              );
    2.13              
    2.14      /* Turn message into a MIME-blob */
    2.15      status = _mime_encode_message_internal(attachment, false, &message_text, true);
    2.16 @@ -1703,7 +1709,10 @@
    2.17      if (status != PEP_STATUS_OK)
    2.18          goto pEp_error;
    2.19  
    2.20 -    keys = new_stringlist(src->from->fpr);
    2.21 +    char* send_fpr = strdup(src->from->fpr ? src->from->fpr : "");
    2.22 +    src->_sender_fpr = send_fpr;
    2.23 +    
    2.24 +    keys = new_stringlist(send_fpr);
    2.25      if (keys == NULL)
    2.26          goto enomem;
    2.27  
    2.28 @@ -3557,9 +3566,27 @@
    2.29                                      // Since we capture the information, this is ok.
    2.30                                      wrap_info = NULL;
    2.31                                      inner_message->enc_format = src->enc_format;
    2.32 -                                    // FIXME
    2.33 +
    2.34 +                                    const stringpair_list_t* pEp_protocol_version = NULL;
    2.35 +                                    const stringpair_list_t* sender_fpr = NULL;
    2.36 +                                    pEp_protocol_version = stringpair_list_find(inner_message->opt_fields, "X-pEp-Version");
    2.37 +                                    unsigned int pEp_v_major = 0;
    2.38 +                                    unsigned int pEp_v_minor = 0;
    2.39 +                                    if (pEp_protocol_version && !EMPTYSTR(pEp_protocol_version->value->value)) {
    2.40 +                                        // Roker is of course right. Meh :)
    2.41 +                                        if (sscanf(pEp_protocol_version->value->value, "%u.%u", &pEp_v_major, &pEp_v_minor) != 2) {
    2.42 +                                            pEp_v_major = 0;
    2.43 +                                            pEp_v_minor = 0;
    2.44 +                                        }
    2.45 +                                    }
    2.46 +                                    
    2.47 +                                    if (((pEp_v_major == 2) && (pEp_v_minor > 0)) || (pEp_v_major > 2))                              
    2.48 +                                        sender_fpr = stringpair_list_find(inner_message->opt_fields, "X-pEp-Sender-FPR");
    2.49 +
    2.50 +                                    // FIXME - Message 2.1                                    
    2.51                                      status = unencapsulate_hidden_fields(inner_message, NULL, &wrap_info);
    2.52                                      
    2.53 +                                    
    2.54                                      // ?
    2.55                                      if (status != PEP_STATUS_OK) {
    2.56                                          free_message(inner_message);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/include/SenderFPRTests.h	Wed May 15 16:02:11 2019 +0200
     3.3 @@ -0,0 +1,19 @@
     3.4 +// This file is under GNU General Public License 3.0
     3.5 +// see LICENSE.txt
     3.6 +
     3.7 +#ifndef SENDER_F_P_R_H
     3.8 +#define SENDER_F_P_R_H
     3.9 +
    3.10 +#include <string>
    3.11 +#include "EngineTestIndividualSuite.h"
    3.12 +
    3.13 +using namespace std;
    3.14 +
    3.15 +class SenderFPRTests : public EngineTestIndividualSuite {
    3.16 +    public:
    3.17 +        SenderFPRTests(string test_suite, string test_home_dir);
    3.18 +    private:
    3.19 +        void check_sender_f_p_r();
    3.20 +};
    3.21 +
    3.22 +#endif
     4.1 --- a/test/src/SuiteMaker.cc	Wed May 15 14:35:22 2019 +0200
     4.2 +++ b/test/src/SuiteMaker.cc	Wed May 15 16:02:11 2019 +0200
     4.3 @@ -69,6 +69,7 @@
     4.4  #include "OwnKeysRetrieveTests.h"
     4.5  #include "TrustManipulationTests.h"
     4.6  #include "SyncTests.h"
     4.7 +#include "SenderFPRTests.h"
     4.8  #include "RevocationTests.h"
     4.9  #include "AppleMailTests.h"
    4.10  
    4.11 @@ -131,12 +132,13 @@
    4.12      "OwnKeysRetrieveTests",
    4.13      "TrustManipulationTests",
    4.14      "SyncTests",
    4.15 +    "SenderFPRTests",
    4.16      "RevocationTests",
    4.17      "AppleMailTests",
    4.18  };
    4.19  
    4.20  // This file is generated, so magic constants are ok.
    4.21 -int SuiteMaker::num_suites = 59;
    4.22 +int SuiteMaker::num_suites = 60;
    4.23  
    4.24  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    4.25      if (strcmp(test_class_name, "URIAddressTests") == 0)
    4.26 @@ -253,6 +255,8 @@
    4.27          *test_suite = new TrustManipulationTests(test_class_name, test_home);
    4.28      else if (strcmp(test_class_name, "SyncTests") == 0)
    4.29          *test_suite = new SyncTests(test_class_name, test_home);
    4.30 +    else if (strcmp(test_class_name, "SenderFPRTests") == 0)
    4.31 +        *test_suite = new SenderFPRTests(test_class_name, test_home);
    4.32      else if (strcmp(test_class_name, "RevocationTests") == 0)
    4.33          *test_suite = new RevocationTests(test_class_name, test_home);
    4.34      else if (strcmp(test_class_name, "AppleMailTests") == 0)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/src/engine_tests/SenderFPRTests.cc	Wed May 15 16:02:11 2019 +0200
     5.3 @@ -0,0 +1,79 @@
     5.4 +// This file is under GNU General Public License 3.0
     5.5 +// see LICENSE.txt
     5.6 +
     5.7 +#include <stdlib.h>
     5.8 +#include <cstring>
     5.9 +#include <string>
    5.10 +
    5.11 +#include <cpptest.h>
    5.12 +#include "test_util.h"
    5.13 +
    5.14 +#include "pEpEngine.h"
    5.15 +#include "mime.h"
    5.16 +
    5.17 +#include "EngineTestIndividualSuite.h"
    5.18 +#include "SenderFPRTests.h"
    5.19 +
    5.20 +using namespace std;
    5.21 +
    5.22 +SenderFPRTests::SenderFPRTests(string suitename, string test_home_dir) :
    5.23 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    5.24 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SenderFPRTests::check_sender_f_p_r"),
    5.25 +                                                                      static_cast<Func>(&SenderFPRTests::check_sender_f_p_r)));
    5.26 +}
    5.27 +
    5.28 +void SenderFPRTests::check_sender_f_p_r() {
    5.29 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    5.30 +    const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
    5.31 +    PEP_STATUS status = read_file_and_import_key(session,
    5.32 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    5.33 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    5.34 +    status = set_up_ident_from_scratch(session,
    5.35 +                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    5.36 +                "pep.test.alice@pep-project.org", alice_fpr,
    5.37 +                PEP_OWN_USERID, "Alice in Wonderland", NULL, true
    5.38 +            );
    5.39 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.40 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"),
    5.41 +                    "Unable to import test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    5.42 +                    
    5.43 +
    5.44 +    message* msg = new_message(PEP_dir_outgoing);
    5.45 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);                
    5.46 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "Bob", NULL);
    5.47 +    status = myself(session, alice);
    5.48 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.49 +    status = update_identity(session, bob);
    5.50 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.51 +    
    5.52 +    status = set_as_pEp_user(session, bob);
    5.53 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.54 +
    5.55 +    msg->to = new_identity_list(bob);
    5.56 +    msg->from = alice;
    5.57 +    msg->shortmsg = strdup("Yo Bob!");
    5.58 +    msg->longmsg = strdup("Look at my hot new sender fpr field!");
    5.59 +
    5.60 +    message* enc_msg = NULL;
    5.61 +    
    5.62 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    5.63 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.64 +    TEST_ASSERT(stringpair_list_find(enc_msg->opt_fields, "X-pEp-Sender-FPR") == NULL);
    5.65 +    
    5.66 +    message* dec_msg = NULL;
    5.67 +
    5.68 +    stringlist_t* keylist = NULL;
    5.69 +    PEP_rating rating;
    5.70 +    PEP_decrypt_flags_t flags = 0;
    5.71 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
    5.72 +    TEST_ASSERT(status == PEP_STATUS_OK);
    5.73 +
    5.74 +    char* text = NULL;
    5.75 +    mime_encode_message(dec_msg, false, &text);
    5.76 +    cout << text << endl;
    5.77 +    free(text);
    5.78 +    
    5.79 +    stringpair_list_t* fpr_node = stringpair_list_find(dec_msg->opt_fields, "X-pEp-Sender-FPR");
    5.80 +    TEST_ASSERT(fpr_node);
    5.81 +    TEST_ASSERT(strcmp(fpr_node->value->value, alice_fpr) == 0);
    5.82 +}