shelving mistrust investigation and fixes to fry bigger fish mistrust_fixes
authorKrista Bennett <krista@pep-project.org>
Thu, 01 Feb 2018 13:57:04 +0100
branchmistrust_fixes
changeset 2467ef6bb2e8a84c
parent 2466 339399330a9b
child 2471 4f1c2d62b2dd
shelving mistrust investigation and fixes to fry bigger fish
src/keymanagement.c
src/message_api.c
src/pEpEngine.c
src/pEp_internal.h
test/new_update_id_and_myself_test.cc
     1.1 --- a/src/keymanagement.c	Mon Jan 29 16:52:54 2018 +0100
     1.2 +++ b/src/keymanagement.c	Thu Feb 01 13:57:04 2018 +0100
     1.3 @@ -199,6 +199,7 @@
     1.4              status = update_trust_for_fpr(session, 
     1.5                                            fpr, 
     1.6                                            ct);
     1.7 +        case PEP_ct_mistrusted:                                  
     1.8              free(ident->fpr);
     1.9              ident->fpr = NULL;
    1.10              ident->comm_type = ct;            
     2.1 --- a/src/message_api.c	Mon Jan 29 16:52:54 2018 +0100
     2.2 +++ b/src/message_api.c	Thu Feb 01 13:57:04 2018 +0100
     2.3 @@ -20,6 +20,12 @@
     2.4  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
     2.5  #endif
     2.6  
     2.7 +// These are globals used in generating message IDs and should only be
     2.8 +// computed once, as they're either really constants or OS-dependent
     2.9 +
    2.10 +int _pEp_rand_max_bits;
    2.11 +double _pEp_log2_36;
    2.12 +
    2.13  static bool is_a_pEpmessage(const message *msg)
    2.14  {
    2.15      for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
     3.1 --- a/src/pEpEngine.c	Mon Jan 29 16:52:54 2018 +0100
     3.2 +++ b/src/pEpEngine.c	Thu Feb 01 13:57:04 2018 +0100
     3.3 @@ -468,7 +468,7 @@
     3.4      sqlite3_busy_timeout(_session->system_db, 1000);
     3.5  
     3.6  // increment this when patching DDL
     3.7 -#define _DDL_USER_VERSION "6"
     3.8 +#define _DDL_USER_VERSION "7"
     3.9  
    3.10      if (in_first) {
    3.11  
    3.12 @@ -564,6 +564,10 @@
    3.13                  "       on delete cascade on update cascade,\n"
    3.14                  "    alternate_id text primary key\n"
    3.15                  ");\n"
    3.16 +                // mistrusted keys
    3.17 +                "create table if not exists mistrusted_keys (\n"
    3.18 +                "    fpr text primary key\n"
    3.19 +                ");\n"
    3.20                  ,
    3.21              NULL,
    3.22              NULL,
    3.23 @@ -778,6 +782,17 @@
    3.24                  assert(int_result == SQLITE_OK);    
    3.25              }
    3.26          }
    3.27 +        if (version < 7) {
    3.28 +            int_result = sqlite3_exec(
    3.29 +                _session->db,
    3.30 +                "create table if not exists mistrusted_keys (\n"
    3.31 +                "    fpr text primary key\n"
    3.32 +                ");\n"            
    3.33 +                NULL,
    3.34 +                NULL,
    3.35 +                NULL
    3.36 +            );
    3.37 +        }
    3.38          else { 
    3.39              // Version from DB was 0, it means this is initial setup.
    3.40              // DB has just been created, and all tables are empty.
     4.1 --- a/src/pEp_internal.h	Mon Jan 29 16:52:54 2018 +0100
     4.2 +++ b/src/pEp_internal.h	Thu Feb 01 13:57:04 2018 +0100
     4.3 @@ -405,8 +405,8 @@
     4.4  // These are globals used in generating message IDs and should only be
     4.5  // computed once, as they're either really constants or OS-dependent
     4.6  
     4.7 -int _pEp_rand_max_bits;
     4.8 -double _pEp_log2_36;
     4.9 +extern int _pEp_rand_max_bits;
    4.10 +extern double _pEp_log2_36;
    4.11  
    4.12  static inline void _init_globals() {
    4.13      _pEp_rand_max_bits = ceil(log2(RAND_MAX));
     5.1 --- a/test/new_update_id_and_myself_test.cc	Mon Jan 29 16:52:54 2018 +0100
     5.2 +++ b/test/new_update_id_and_myself_test.cc	Thu Feb 01 13:57:04 2018 +0100
     5.3 @@ -38,7 +38,7 @@
     5.4      
     5.5      cout << uniqname << "\n";
     5.6      
     5.7 -    const char* own_user_id = "FineOwnIdentitiesOfBuckTFerris";
     5.8 +    const char* own_user_id = get_new_uuid();
     5.9      const char* start_username = "Unser Testkandidat";
    5.10  
    5.11      pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
    5.12 @@ -481,28 +481,130 @@
    5.13  
    5.14  
    5.15      cout << "****************************************************************************************" << endl;
    5.16 -    cout << "* III: 2. key election: get identity for user with only revoked keys " << endl;
    5.17 +    cout << "* III: 2. key election: get identity for user with only revoked or mistrusted keys " << endl;
    5.18      cout << "****************************************************************************************" << endl << endl;
    5.19 +
    5.20 +    // Create id with no key
    5.21 +    cout << "Creating new id with no key for : ";
    5.22 +    char *uniqname_10000 = strdup("AAAAtestuser@testdomain.org");
    5.23 +    srandom(time(NULL));
    5.24 +    for(int i=0; i < 4;i++)
    5.25 +        uniqname_10000[i] += random() & 0xf;
    5.26      
    5.27 -    status = revoke_key(session, new_fpr, "Because it's more fun to revoke ALL of someone's keys");
    5.28 +    cout << uniqname_10000 << "\n";
    5.29 +
    5.30 +    char* revoke_uuid = get_new_uuid();
    5.31 +
    5.32 +    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
    5.33 +    
    5.34 +    cout << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl; 
    5.35 +
    5.36 +    char* revoke_fpr_arr[3];
    5.37 +    
    5.38 +    status = generate_keypair(session, revokemaster_3000);
    5.39 +    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
    5.40 +    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
    5.41 +    free(revokemaster_3000->fpr);
    5.42 +    revokemaster_3000->fpr = NULL;
    5.43 +    
    5.44 +    status = generate_keypair(session, revokemaster_3000);
    5.45 +    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
    5.46 +    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
    5.47 +    free(revokemaster_3000->fpr);
    5.48 +    revokemaster_3000->fpr = NULL;
    5.49 +    
    5.50 +    status = generate_keypair(session, revokemaster_3000);
    5.51 +    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
    5.52 +    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
    5.53 +    free(revokemaster_3000->fpr);
    5.54 +    revokemaster_3000->fpr = NULL;
    5.55 +    
    5.56 +    cout << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
    5.57 +    
    5.58 +    free(revokemaster_3000->fpr);
    5.59 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
    5.60 +    status = trust_personal_key(session, revokemaster_3000);
    5.61 +    assert(status == PEP_STATUS_OK); 
    5.62 +    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
    5.63 +
    5.64 +    free(revokemaster_3000->fpr);
    5.65 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
    5.66 +    status = trust_personal_key(session, revokemaster_3000);
    5.67 +    assert(status == PEP_STATUS_OK);
    5.68 +    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
    5.69 +    
    5.70 +    status = update_identity(session, revokemaster_3000);
    5.71 +    assert(status == PEP_STATUS_OK);
    5.72 +    assert(revokemaster_3000->fpr);
    5.73 +    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0);
    5.74 +    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
    5.75 +
    5.76 +    cout << "update_identity returns the correct identity default." << endl;
    5.77 +    
    5.78 +    cout << "Ok, now... we revoke the default..." << endl;
    5.79 +    
    5.80 +    cout << "Revoking " << revoke_fpr_arr[2] << endl;
    5.81 +
    5.82 +    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
    5.83      assert (status == PEP_STATUS_OK);
    5.84 +
    5.85 +    bool is_revoked;
    5.86 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
    5.87 +    assert(status == PEP_STATUS_OK);
    5.88 +    assert(is_revoked);
    5.89 +
    5.90 +    cout << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
    5.91      
    5.92 -    new_me = new_identity(uniqname, NULL, NULL, NULL);
    5.93 +    cout << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
    5.94 +    status = update_identity(session, revokemaster_3000);
    5.95 +    assert(status == PEP_STATUS_OK);
    5.96 +    assert(revokemaster_3000->fpr);
    5.97 +    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0);
    5.98 +    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);    
    5.99      
   5.100 -    status = update_identity(session, new_me);
   5.101 +    cout << "Success! So let's mistrust it, because seriously, that key was so uncool." << endl;
   5.102 +    
   5.103 +    status = key_mistrusted(session, revokemaster_3000);
   5.104 +    assert(status == PEP_STATUS_OK);
   5.105 +
   5.106 +    status = get_trust(session, revokemaster_3000);
   5.107 +    assert(status == PEP_STATUS_OK);
   5.108 +    assert(revokemaster_3000->comm_type == PEP_ct_mistrusted);
   5.109 +    
   5.110 +    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   5.111 +
   5.112 +    cout << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
   5.113 +
   5.114 +    status = update_identity(session, revokemaster_3000);
   5.115 +    assert(status == PEP_STATUS_OK);
   5.116 +    assert(revokemaster_3000->fpr);
   5.117 +    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0);
   5.118 +    assert(!(revokemaster_3000->comm_type & PEP_ct_confirmed));    
   5.119 +
   5.120 +    cout << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
   5.121 +    
   5.122 +    cout << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
   5.123 +
   5.124 +    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
   5.125 +    assert (status == PEP_STATUS_OK);
   5.126 +
   5.127 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
   5.128 +    assert(status == PEP_STATUS_OK);
   5.129 +    assert(is_revoked);
   5.130 +    
   5.131 +    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
   5.132 +
   5.133 +    cout << "Call update_identity - we expect nothing, plus an error comm type." << endl;
   5.134 +
   5.135 +    status = update_identity(session, revokemaster_3000);
   5.136      assert(status != PEP_STATUS_OK);
   5.137 -    assert(!new_me->fpr);
   5.138 -    assert(new_me->username);
   5.139 -    assert(strcmp(new_me->username, start_username) == 0);
   5.140 -    assert(new_me->user_id);
   5.141 -    assert(strcmp(new_me->user_id, default_own_id) == 0);
   5.142 -    assert(new_me->me);
   5.143 -    assert(new_me->comm_type == PEP_ct_key_revoked);
   5.144 -    
   5.145 -    cout << "PASS: update_identity() correctly rejected two revoked keys with PEP_KEY_UNSUITABLE and PEP_ct_key_revoked";
   5.146 -    cout << endl << endl;
   5.147 +    assert(!revokemaster_3000->fpr);
   5.148 +    assert(revokemaster_3000->username);
   5.149 +    assert(strcmp(revokemaster_3000->user_id, revoke_uuid) == 0);
   5.150 +    assert(revokemaster_3000->comm_type == PEP_ct_key_revoked || revokemaster_3000->comm_type == PEP_ct_mistrusted);
   5.151 +    cout << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
   5.152  
   5.153 -    free_identity(new_me);
   5.154 +    free_identity(revokemaster_3000);
   5.155  
   5.156      cout << "****************************************************************************************" << endl;
   5.157      cout << "* III: 100000000. key election: more to come " << endl;