ENGINE-172: added no-attached-key flag option and implementation ENGINE-172
authorKrista Grothoff <krista@pep-project.org>
Fri, 10 Mar 2017 17:53:48 +0100
branchENGINE-172
changeset 164052e90165ad0f
parent 1639 be84d676f3ef
child 1641 1c9358f42ce0
child 1642 af07ab39e430
ENGINE-172: added no-attached-key flag option and implementation
src/message_api.c
src/message_api.h
test/encrypt_for_identity_test.cc
     1.1 --- a/src/message_api.c	Fri Mar 10 15:23:31 2017 +0100
     1.2 +++ b/src/message_api.c	Fri Mar 10 17:53:48 2017 +0100
     1.3 @@ -1192,12 +1192,12 @@
     1.4      }
     1.5  
     1.6      if (!dest_keys_found ||
     1.7 -        stringlist_length(keys) == 0 ||
     1.8 +        stringlist_length(keys)  == 0 ||
     1.9          _rating(max_comm_type,
    1.10                  PEP_rating_undefined) < PEP_rating_reliable)
    1.11      {
    1.12          free_stringlist(keys);
    1.13 -        if (!session->passive_mode)
    1.14 +        if (!session->passive_mode && !(flags & PEP_encrypt_flag_force_no_attached_key))
    1.15              attach_own_key(session, src);
    1.16          return PEP_UNENCRYPTED;
    1.17      }
    1.18 @@ -1206,7 +1206,8 @@
    1.19          if (msg == NULL)
    1.20              goto enomem;
    1.21  
    1.22 -        attach_own_key(session, src);
    1.23 +        if (!(flags & PEP_encrypt_flag_force_no_attached_key))
    1.24 +            attach_own_key(session, src);
    1.25  
    1.26          switch (enc_format) {
    1.27          case PEP_enc_PGP_MIME:
    1.28 @@ -1314,6 +1315,9 @@
    1.29  
    1.30      keys = new_stringlist(target_fpr);
    1.31  
    1.32 +    /* KG: did we ever do this??? */
    1.33 +    if (!(flags & PEP_encrypt_flag_force_no_attached_key))
    1.34 +        attach_own_key(session, src);
    1.35  
    1.36      msg = clone_to_empty_message(src);
    1.37      if (msg == NULL)
     2.1 --- a/src/message_api.h	Fri Mar 10 15:23:31 2017 +0100
     2.2 +++ b/src/message_api.h	Fri Mar 10 17:53:48 2017 +0100
     2.3 @@ -29,7 +29,8 @@
     2.4  
     2.5      // This flag is for special use cases and should not be used
     2.6      // by normal pEp clients!
     2.7 -    PEP_encrypt_flag_force_unsigned = 0x2
     2.8 +    PEP_encrypt_flag_force_unsigned = 0x2,
     2.9 +    PEP_encrypt_flag_force_no_attached_key = 0x4
    2.10  } PEP_encrypt_flags; 
    2.11  
    2.12  typedef unsigned int PEP_encrypt_flags_t;
     3.1 --- a/test/encrypt_for_identity_test.cc	Fri Mar 10 15:23:31 2017 +0100
     3.2 +++ b/test/encrypt_for_identity_test.cc	Fri Mar 10 17:53:48 2017 +0100
     3.3 @@ -51,7 +51,7 @@
     3.4      cout << "encrypting message as MIME multipart…\n";
     3.5      message* encrypted_msg = nullptr;
     3.6      cout << "calling encrypt_message_for_identity()\n";
     3.7 -    status = encrypt_message_for_self(session, alice, outgoing_message, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_default);
     3.8 +    status = encrypt_message_for_self(session, alice, outgoing_message, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
     3.9      cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
    3.10      assert(status == PEP_STATUS_OK);
    3.11      assert(encrypted_msg);
    3.12 @@ -81,7 +81,7 @@
    3.13      PEP_decrypt_flags_t flags;
    3.14  
    3.15      status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
    3.16 -    assert(status == PEP_STATUS_OK);
    3.17 +    assert(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
    3.18      assert(decrypted_msg);
    3.19      assert(keylist_used);
    3.20      assert(rating);
    3.21 @@ -90,11 +90,18 @@
    3.22  
    3.23      cout << "keys used:\n";
    3.24  
    3.25 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
    3.26 +    int i = 0;
    3.27 +
    3.28 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
    3.29      {
    3.30 -        cout << "\t " << kl4->value << endl;
    3.31 -        assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    3.32 -        cout << "Encrypted for Alice! Yay! It worked!" << endl;
    3.33 +        if (i == 0)
    3.34 +            assert(strcasecmp("",kl4->value) == 0);
    3.35 +        else {
    3.36 +            cout << "\t " << kl4->value << endl;
    3.37 +            assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    3.38 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
    3.39 +        }
    3.40 +        assert(i < 2);
    3.41      }
    3.42      cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
    3.43