ENGINE-129: merge into default
authorKrista Grothoff <krista@pep-project.org>
Thu, 27 Oct 2016 21:58:13 +0200
changeset 13453c27d945fe92
parent 1340 276625d4f083
parent 1344 bdde3e670d9d
child 1347 0786e2cb42eb
ENGINE-129: merge into default
     1.1 --- a/src/keymanagement.c	Thu Oct 27 17:01:20 2016 +0200
     1.2 +++ b/src/keymanagement.c	Thu Oct 27 21:58:13 2016 +0200
     1.3 @@ -24,7 +24,7 @@
     1.4  {
     1.5      PEP_STATUS status;
     1.6      stringlist_t *keylist;
     1.7 -    char *_fpr = NULL;
     1.8 +    char *_fpr = "";
     1.9      identity->comm_type = PEP_ct_unknown;
    1.10  
    1.11      status = find_keys(session, identity->address, &keylist);
    1.12 @@ -59,15 +59,16 @@
    1.13          }
    1.14      }
    1.15  
    1.16 -    if (_fpr) {
    1.17 -        free(identity->fpr);
    1.18 +    
    1.19 +//    if (_fpr) {
    1.20 +    free(identity->fpr);
    1.21  
    1.22 -        identity->fpr = strdup(_fpr);
    1.23 -        if (identity->fpr == NULL) {
    1.24 -            free_stringlist(keylist);
    1.25 -            return PEP_OUT_OF_MEMORY;
    1.26 -        }
    1.27 +    identity->fpr = strdup(_fpr);
    1.28 +    if (identity->fpr == NULL) {
    1.29 +        free_stringlist(keylist);
    1.30 +        return PEP_OUT_OF_MEMORY;
    1.31      }
    1.32 +//    }
    1.33      free_stringlist(keylist);
    1.34      return PEP_STATUS_OK;
    1.35  }
    1.36 @@ -137,7 +138,7 @@
    1.37          bool dont_use_fpr = true;
    1.38  
    1.39          /* if we have a stored_identity fpr */
    1.40 -        if (!EMPTYSTR(stored_identity->fpr)) {
    1.41 +        if (!EMPTYSTR(stored_identity->fpr) && !EMPTYSTR(temp_id->fpr)) {
    1.42              status = blacklist_is_listed(session, stored_identity->fpr, &dont_use_fpr);
    1.43              if (status != PEP_STATUS_OK)
    1.44                  dont_use_fpr = true; 
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/blacklist_accept_new_key_test.cc	Thu Oct 27 21:58:13 2016 +0200
     2.3 @@ -0,0 +1,102 @@
     2.4 +#include <iostream>
     2.5 +#include <iostream>
     2.6 +#include <fstream>
     2.7 +#include <string>
     2.8 +#include <cstring> // for strcmp()
     2.9 +#include <assert.h>
    2.10 +#include "blacklist.h"
    2.11 +#include "keymanagement.h"
    2.12 +#include "message_api.h"
    2.13 +#include "mime.h"
    2.14 +
    2.15 +using namespace std;
    2.16 +
    2.17 +int main() {
    2.18 +    cout << "\n*** blacklist_test ***\n\n";
    2.19 +
    2.20 +    PEP_SESSION session;
    2.21 +    
    2.22 +    cout << "calling init()\n";
    2.23 +    PEP_STATUS status1 = init(&session);   
    2.24 +    assert(status1 == PEP_STATUS_OK);
    2.25 +    assert(session);
    2.26 +    cout << "init() completed.\n";
    2.27 +
    2.28 +    // blacklist test code
    2.29 +
    2.30 +    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    2.31 +    
    2.32 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    2.33 +
    2.34 +    /* read the key into memory */
    2.35 +    ifstream infile("blacklisted_pub.asc");
    2.36 +    string keytext;
    2.37 +    while (!infile.eof()) {
    2.38 +        static string line;
    2.39 +        getline(infile, line);
    2.40 +        keytext += line + "\n";
    2.41 +    }
    2.42 +    infile.close(); 
    2.43 +    
    2.44 +    /* import it into pep */
    2.45 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    2.46 +    
    2.47 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
    2.48 +    bool is_blacklisted = false;
    2.49 +    
    2.50 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
    2.51 +                                                      bl_fpr_1,
    2.52 +                                                      NULL,
    2.53 +                                                      "Blacklist Keypair");
    2.54 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    2.55 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    2.56 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    2.57 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    2.58 +
    2.59 +    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
    2.60 +    
    2.61 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";    
    2.62 +    
    2.63 +    ifstream infile2("test_mails/blacklist_new_key_attached.eml");
    2.64 +    string mailtext;
    2.65 +    while (!infile2.eof()) {
    2.66 +        static string line;
    2.67 +        getline(infile2, line);
    2.68 +        mailtext += line + "\n";
    2.69 +    }
    2.70 +    infile2.close(); 
    2.71 +
    2.72 +    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    2.73 +
    2.74 +    PEP_STATUS status = update_identity(session, me1);
    2.75 +    message* msg_ptr = nullptr;
    2.76 +    message* dest_msg = nullptr;
    2.77 +    stringlist_t* keylist = nullptr;
    2.78 +    PEP_rating rating;
    2.79 +    PEP_decrypt_flags_t flags;
    2.80 +    
    2.81 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    2.82 +    assert(status == PEP_STATUS_OK);
    2.83 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    2.84 +
    2.85 +    PEP_STATUS status12 = update_identity(session, blacklisted_identity);
    2.86 +
    2.87 +    assert(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
    2.88 +
    2.89 +    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
    2.90 +    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
    2.91 +
    2.92 +    status = delete_keypair(session, bl_fpr_1);
    2.93 +    update_identity(session, blacklisted_identity);
    2.94 +    status = delete_keypair(session, new_key);
    2.95 +    update_identity(session, blacklisted_identity);
    2.96 +    
    2.97 +    free_message(msg_ptr);
    2.98 +    free_message(dest_msg);
    2.99 +    free_stringlist(keylist);
   2.100 +    
   2.101 +    cout << "calling release()\n";
   2.102 +    release(session);
   2.103 +    return 0;
   2.104 +}
   2.105 +
     3.1 --- a/test/blacklist_test.cc	Thu Oct 27 17:01:20 2016 +0200
     3.2 +++ b/test/blacklist_test.cc	Thu Oct 27 21:58:13 2016 +0200
     3.3 @@ -111,8 +111,14 @@
     3.4      PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
     3.5      PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
     3.6      PEP_STATUS status13 = update_identity(session, blacklisted_identity);
     3.7 -    
     3.8 -    /* FIXME: remove both keys again from everywhere and clean up identities */
     3.9 +            
    3.10 +    PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
    3.11 +    update_identity(session, blacklisted_identity);
    3.12 +    PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
    3.13 +    update_identity(session, blacklisted_identity2);
    3.14 +        
    3.15 +    free_identity(blacklisted_identity);
    3.16 +    free_identity(blacklisted_identity2);
    3.17      
    3.18      cout << "calling release()\n";
    3.19      release(session);