explicitly clear trust info out of database ENGINE-654
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 16 Oct 2019 18:10:28 +0200
branchENGINE-654
changeset 41210e3f9c6ce8a9
parent 4120 97a40b9f5026
child 4122 d8d660a8e64e
explicitly clear trust info out of database
src/key_reset.c
src/pEpEngine.c
src/pEp_internal.h
     1.1 --- a/src/key_reset.c	Wed Oct 16 17:39:51 2019 +0200
     1.2 +++ b/src/key_reset.c	Wed Oct 16 18:10:28 2019 +0200
     1.3 @@ -564,13 +564,15 @@
     1.4          } // end is_own_private
     1.5          else {
     1.6              // if it's mistrusted, make it not be so.
     1.7 -            
     1.8              bool mistrusted_key = false;
     1.9              is_mistrusted_key(session, fpr_copy, &mistrusted_key);
    1.10  
    1.11              if (mistrusted_key)
    1.12                  delete_mistrusted_key(session, fpr_copy);
    1.13              
    1.14 +            if (tmp_ident->user_id)
    1.15 +                status = clear_trust_info(session, tmp_ident->user_id, fpr_copy);
    1.16 +
    1.17              // This is a public key (or a private key that isn't ours, which means
    1.18              // we want it gone anyway)
    1.19              //
     2.1 --- a/src/pEpEngine.c	Wed Oct 16 17:39:51 2019 +0200
     2.2 +++ b/src/pEpEngine.c	Wed Oct 16 18:10:28 2019 +0200
     2.3 @@ -336,6 +336,10 @@
     2.4      "update trust set comm_type = ?3 " 
     2.5      "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
     2.6  
     2.7 +static const char *sql_clear_trust_info =
     2.8 +    "delete from trust "
     2.9 +    "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
    2.10 +
    2.11  static const char *sql_update_trust_to_pEp =
    2.12      "update trust set comm_type = comm_type + 71 "
    2.13      "   where (user_id = ?1 "
    2.14 @@ -1760,6 +1764,10 @@
    2.15              NULL);
    2.16      assert(int_result == SQLITE_OK);
    2.17  
    2.18 +    int_result = sqlite3_prepare_v2(_session->db, sql_clear_trust_info,
    2.19 +            (int)strlen(sql_clear_trust_info), &_session->clear_trust_info, NULL);
    2.20 +    assert(int_result == SQLITE_OK);
    2.21 +
    2.22      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    2.23              (int)strlen(sql_set_trust), &_session->set_trust, NULL);
    2.24      assert(int_result == SQLITE_OK);
    2.25 @@ -2034,6 +2042,8 @@
    2.26                  sqlite3_finalize(session->set_pEp_version);                
    2.27              if (session->exists_trust_entry)
    2.28                  sqlite3_finalize(session->exists_trust_entry);                                
    2.29 +            if (session->clear_trust_info)
    2.30 +                sqlite3_finalize(session->clear_trust_info);                
    2.31              if (session->set_trust)
    2.32                  sqlite3_finalize(session->set_trust);
    2.33              if (session->update_trust)
    2.34 @@ -2998,6 +3008,28 @@
    2.35      return PEP_STATUS_OK;
    2.36  }
    2.37  
    2.38 +PEP_STATUS clear_trust_info(PEP_SESSION session,
    2.39 +                            const char* user_id,
    2.40 +                            const char* fpr) {
    2.41 +    if (!session || EMPTYSTR(fpr) || EMPTYSTR(user_id))
    2.42 +        return PEP_ILLEGAL_VALUE;
    2.43 +        
    2.44 +    int result;
    2.45 +    
    2.46 +    sqlite3_reset(session->clear_trust_info);
    2.47 +    sqlite3_bind_text(session->clear_trust_info, 1, user_id, -1,
    2.48 +            SQLITE_STATIC);    
    2.49 +    sqlite3_bind_text(session->clear_trust_info, 2, fpr, -1,
    2.50 +            SQLITE_STATIC);
    2.51 +    result = Sqlite3_step(session->clear_trust_info);
    2.52 +    sqlite3_reset(session->clear_trust_info);
    2.53 +    if (result != SQLITE_DONE) {
    2.54 +        return PEP_UNKNOWN_ERROR;
    2.55 +    }
    2.56 +    
    2.57 +    return PEP_STATUS_OK;
    2.58 +}
    2.59 +
    2.60  static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
    2.61                                         pEp_identity* identity,
    2.62                                         sqlite3_stmt* set_or_update) {
     3.1 --- a/src/pEp_internal.h	Wed Oct 16 17:39:51 2019 +0200
     3.2 +++ b/src/pEp_internal.h	Wed Oct 16 18:10:28 2019 +0200
     3.3 @@ -200,7 +200,8 @@
     3.4      sqlite3_stmt *exists_identity_entry;        
     3.5      sqlite3_stmt *set_identity_flags;
     3.6      sqlite3_stmt *unset_identity_flags;
     3.7 -    sqlite3_stmt *set_pEp_version;    
     3.8 +    sqlite3_stmt *set_pEp_version; 
     3.9 +    sqlite3_stmt *clear_trust_info;   
    3.10      sqlite3_stmt *set_trust;
    3.11      sqlite3_stmt *update_trust;
    3.12      sqlite3_stmt *exists_trust_entry;
    3.13 @@ -566,4 +567,3 @@
    3.14      } while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
    3.15      return rc;
    3.16  }
    3.17 -