Merge with sync sequoia_windows
authorThomas
Thu, 27 Jun 2019 15:40:53 +0200
branchsequoia_windows
changeset 388899d255a8dc60
parent 3878 37426cf0d1fe
parent 3887 a3f479737dc4
child 3895 eeb2f18965e1
Merge with sync
src/pEpEngine.c
src/pEp_internal.h
src/pgp_sequoia.c
     1.1 --- a/src/keymanagement.c	Thu Jun 27 09:29:20 2019 +0200
     1.2 +++ b/src/keymanagement.c	Thu Jun 27 15:40:53 2019 +0200
     1.3 @@ -470,6 +470,8 @@
     1.4      PEP_STATUS status;
     1.5      
     1.6      bool is_identity_default, is_user_default, is_address_default;
     1.7 +    bool no_stored_default = EMPTYSTR(stored_ident->fpr);
     1.8 +    
     1.9      status = get_valid_pubkey(session, stored_ident,
    1.10                                  &is_identity_default,
    1.11                                  &is_user_default,
    1.12 @@ -488,6 +490,11 @@
    1.13              stored_ident->comm_type = ct;
    1.14          }
    1.15      }
    1.16 +    else if (status != PEP_STATUS_OK) {
    1.17 +        free(stored_ident->fpr);
    1.18 +        stored_ident->fpr = NULL;
    1.19 +        stored_ident->comm_type = PEP_ct_key_not_found;        
    1.20 +    }
    1.21      else {
    1.22          if (stored_ident->comm_type == PEP_ct_unknown)
    1.23              stored_ident->comm_type = PEP_ct_key_not_found;
    1.24 @@ -536,8 +543,17 @@
    1.25           // or identity AND is valid for this address, set in DB
    1.26           // as default
    1.27           status = set_identity(session, return_id);
    1.28 +    } 
    1.29 +    else if (no_stored_default && !EMPTYSTR(return_id->fpr) 
    1.30 +             && return_id->comm_type != PEP_ct_key_revoked
    1.31 +             && return_id->comm_type != PEP_ct_key_expired
    1.32 +             && return_id->comm_type != PEP_ct_key_expired_but_confirmed
    1.33 +             && return_id->comm_type != PEP_ct_mistrusted 
    1.34 +             && return_id->comm_type != PEP_ct_key_b0rken) { 
    1.35 +        // We would have stored this anyway for a first-time elected key. We just have an ident w/ no default already.
    1.36 +        status = set_identity(session, return_id);
    1.37      }
    1.38 -    else {
    1.39 +    else { // this is a key other than the default, but there IS a default (FIXME: fdik, do we really want behaviour below?)
    1.40          // Store without default fpr/ct, but return the fpr and ct 
    1.41          // for current use
    1.42          char* save_fpr = return_id->fpr;
     2.1 --- a/src/message_api.c	Thu Jun 27 09:29:20 2019 +0200
     2.2 +++ b/src/message_api.c	Thu Jun 27 15:40:53 2019 +0200
     2.3 @@ -3126,6 +3126,7 @@
     2.4  }
     2.5  
     2.6  static PEP_STATUS reconcile_sent_and_recv_info(message* src, message* inner_message) {
     2.7 +    PEP_STATUS status = PEP_STATUS_OK;
     2.8      if (!src || !inner_message)
     2.9          return PEP_ILLEGAL_VALUE;
    2.10          
    2.11 @@ -4193,24 +4194,6 @@
    2.12      return PEP_color_no_color;
    2.13  }
    2.14  
    2.15 -DYNAMIC_API PEP_STATUS get_rating_from_bare_key(
    2.16 -        PEP_SESSION session, 
    2.17 -        const char* fpr,
    2.18 -        PEP_rating* rating
    2.19 -    )
    2.20 -{
    2.21 -    if (!rating || !fpr)
    2.22 -        return PEP_ILLEGAL_VALUE;
    2.23 -        
    2.24 -    PEP_comm_type comm_type = PEP_ct_unknown;
    2.25 -    *rating = PEP_rating_undefined;
    2.26 -    PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
    2.27 -    if (status == PEP_STATUS_OK)
    2.28 -        *rating = _rating(comm_type);
    2.29 -    
    2.30 -    return status;    
    2.31 -}
    2.32 -
    2.33  /* [0-9]: 0x30 - 0x39; [A-F] = 0x41 - 0x46; [a-f] = 0x61 - 0x66 */
    2.34  static short asciihex_to_num(char a) {
    2.35      short conv_num = -1;
     3.1 --- a/src/message_api.h	Thu Jun 27 09:29:20 2019 +0200
     3.2 +++ b/src/message_api.h	Thu Jun 27 15:40:53 2019 +0200
     3.3 @@ -507,23 +507,6 @@
     3.4          PEP_rating *rating
     3.5      );
     3.6  
     3.7 -// get_rating_from_bare_key() - get the rating of a certain key (instead of just the comm_type)
     3.8 -//
     3.9 -//  parameters:
    3.10 -//
    3.11 -//      session (in)            session handle
    3.12 -//      fpr (in)                string with fingerprint
    3.13 -//      rating (out)            rating of key for this user
    3.14 -//
    3.15 -//  returns:
    3.16 -//      status from get_key_rating, which only returns comm_type.
    3.17 -
    3.18 -DYNAMIC_API PEP_STATUS get_rating_from_bare_key(
    3.19 -        PEP_SESSION session, 
    3.20 -        const char* fpr,
    3.21 -        PEP_rating* rating
    3.22 -    );
    3.23 -
    3.24  #ifdef __cplusplus
    3.25  }
    3.26  #endif
     4.1 --- a/src/pEpEngine.c	Thu Jun 27 09:29:20 2019 +0200
     4.2 +++ b/src/pEpEngine.c	Thu Jun 27 15:40:53 2019 +0200
     4.3 @@ -4271,8 +4271,8 @@
     4.4              identity->username))
     4.5          return PEP_ILLEGAL_VALUE;
     4.6  
     4.7 -    const char* saved_username = NULL;
     4.8 -    const char* at = NULL;
     4.9 +    char* saved_username = NULL;
    4.10 +    char* at = NULL;
    4.11      size_t uname_len = strlen(identity->username);
    4.12      
    4.13      if (uname_len > 0)
     5.1 --- a/src/pEp_internal.h	Thu Jun 27 09:29:20 2019 +0200
     5.2 +++ b/src/pEp_internal.h	Thu Jun 27 15:40:53 2019 +0200
     5.3 @@ -17,7 +17,7 @@
     5.4  #define PARMS_MAX 32768
     5.5  
     5.6  // maximum busy wait time in ms
     5.7 -#define BUSY_WAIT_TIME 10000
     5.8 +#define BUSY_WAIT_TIME 5000
     5.9  
    5.10  // maximum line length for reading gpg.conf
    5.11  #define MAX_LINELENGTH 1024
    5.12 @@ -132,7 +132,6 @@
    5.13      sqlite3 *key_db;
    5.14      struct {
    5.15          sqlite3_stmt *begin_transaction;
    5.16 -        sqlite3_stmt *begin_transaction_excl;
    5.17          sqlite3_stmt *commit_transaction;
    5.18          sqlite3_stmt *rollback_transaction;
    5.19          sqlite3_stmt *tpk_find;
    5.20 @@ -488,3 +487,4 @@
    5.21      } while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
    5.22      return rc;
    5.23  }
    5.24 +
     6.1 --- a/src/pgp_sequoia.c	Thu Jun 27 09:29:20 2019 +0200
     6.2 +++ b/src/pgp_sequoia.c	Thu Jun 27 15:40:53 2019 +0200
     6.3 @@ -233,8 +233,6 @@
     6.4          ERROR_OUT(NULL, PEP_INIT_CANNOT_OPEN_DB,
     6.5                    "opening keys DB: %s", sqlite3_errmsg(session->key_db));
     6.6  
     6.7 -    sqlite3_busy_timeout(session->key_db, BUSY_WAIT_TIME);
     6.8 -
     6.9      sqlite_result = sqlite3_exec(session->key_db,
    6.10                                   "PRAGMA secure_delete=true;\n"
    6.11                                   "PRAGMA foreign_keys=true;\n"
    6.12 @@ -312,11 +310,6 @@
    6.13      assert(sqlite_result == SQLITE_OK);
    6.14  
    6.15      sqlite_result
    6.16 -        = sqlite3_prepare_v2(session->key_db, "begin transaction exclusive",
    6.17 -                             -1, &session->sq_sql.begin_transaction_excl, NULL);
    6.18 -    assert(sqlite_result == SQLITE_OK);
    6.19 -
    6.20 -    sqlite_result
    6.21          = sqlite3_prepare_v2(session->key_db, "commit transaction",
    6.22                               -1, &session->sq_sql.commit_transaction, NULL);
    6.23      assert(sqlite_result == SQLITE_OK);
    6.24 @@ -718,7 +711,7 @@
    6.25      char *email = NULL;
    6.26      char *name = NULL;
    6.27  
    6.28 -    sqlite3_stmt *stmt = session->sq_sql.begin_transaction_excl;
    6.29 +    sqlite3_stmt *stmt = session->sq_sql.begin_transaction;
    6.30      int sqlite_result = Sqlite3_step(stmt);
    6.31      sqlite3_reset(stmt);
    6.32      if (sqlite_result != SQLITE_DONE)
    6.33 @@ -873,7 +866,6 @@
    6.34                        sqlite3_errmsg(session->key_db));
    6.35      }
    6.36  
    6.37 -
    6.38      T("(%s) -> %s", fpr, pEp_status_to_string(status));
    6.39  
    6.40      free(email);
     7.1 --- a/test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc	Thu Jun 27 09:29:20 2019 +0200
     7.2 +++ b/test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc	Thu Jun 27 15:40:53 2019 +0200
     7.3 @@ -108,6 +108,13 @@
     7.4      status = update_identity(session, expired_inquisitor);
     7.5      TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
     7.6      PEP_comm_type ct = expired_inquisitor->comm_type;    
     7.7 +    TEST_ASSERT_MSG(ct == PEP_ct_key_not_found, tl_ct_string(ct));
     7.8 +    TEST_ASSERT(!expired_inquisitor->fpr);
     7.9 +    
    7.10 +    expired_inquisitor->fpr = strdup(inquisitor_fpr);
    7.11 +    status = get_trust(session, expired_inquisitor);
    7.12 +    ct = expired_inquisitor->comm_type;    
    7.13 +    TEST_ASSERT(status == PEP_STATUS_OK);
    7.14      TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
    7.15      
    7.16      // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
    7.17 @@ -250,6 +257,13 @@
    7.18      status = update_identity(session, expired_inquisitor);
    7.19      TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
    7.20      PEP_comm_type ct = expired_inquisitor->comm_type;    
    7.21 +    TEST_ASSERT_MSG(ct == PEP_ct_key_not_found, tl_ct_string(ct));
    7.22 +    TEST_ASSERT(!expired_inquisitor->fpr);
    7.23 +    
    7.24 +    expired_inquisitor->fpr = strdup(inquisitor_fpr);
    7.25 +    status = get_trust(session, expired_inquisitor);
    7.26 +    ct = expired_inquisitor->comm_type;    
    7.27 +    TEST_ASSERT(status == PEP_STATUS_OK);
    7.28      TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
    7.29      
    7.30      // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
     8.1 --- a/test/src/engine_tests/ExternalRevokeTests.cc	Thu Jun 27 09:29:20 2019 +0200
     8.2 +++ b/test/src/engine_tests/ExternalRevokeTests.cc	Thu Jun 27 15:40:53 2019 +0200
     8.3 @@ -255,8 +255,9 @@
     8.4      
     8.5      status = get_trust(session, recip1);
     8.6  
     8.7 -    cout << "Recip's trust DB comm_type (should be unknown, as we're using a keyring-only key, not in DB) = "  << tl_ct_string(recip1->comm_type) << endl;
     8.8 -    TEST_ASSERT_MSG((recip1->comm_type != PEP_ct_OpenPGP_unconfirmed), "recip1->comm_type != PEP_ct_OpenPGP_unconfirmed");
     8.9 +//    cout << "Recip's trust DB comm_type (should be unknown, as we're using a keyring-only key, not in DB) = "  << tl_ct_string(recip1->comm_type) << endl;
    8.10 +    cout << "Recip's trust DB comm_type (should PEP_ct_OpenPGP_unconfirmed), as we now record this when using update_identity on no-default idents = "  << tl_ct_string(recip1->comm_type) << endl;
    8.11 +    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_OpenPGP_unconfirmed), tl_ct_string(recip1->comm_type));
    8.12  
    8.13      // decrypt message
    8.14  //    free_message(outgoing_msg);
    8.15 @@ -285,8 +286,9 @@
    8.16      
    8.17      status = get_trust(session, recip1);
    8.18      
    8.19 -    cout << "Recip's trust DB comm_type (should be unknown - there's nothing in the DB) = "  << tl_ct_string(recip1->comm_type) << endl;
    8.20 -    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_unknown), "recip1->comm_type == PEP_ct_unknown");
    8.21 +//    cout << "Recip's trust DB comm_type (should be unknown - there's nothing in the DB) = "  << tl_ct_string(recip1->comm_type) << endl;
    8.22 +    cout << "Recip's trust DB comm_type (should be PEP_ct_OpenPGP_unconfirmed, as we now store it.) = "  << tl_ct_string(recip1->comm_type) << endl;
    8.23 +    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_OpenPGP_unconfirmed), tl_ct_string(recip1->comm_type));
    8.24  
    8.25      free_message(encrypted_outgoing_msg);
    8.26      free_message(decrypted_msg);
     9.1 --- a/test/src/engine_tests/NewUpdateIdAndMyselfTests.cc	Thu Jun 27 09:29:20 2019 +0200
     9.2 +++ b/test/src/engine_tests/NewUpdateIdAndMyselfTests.cc	Thu Jun 27 15:40:53 2019 +0200
     9.3 @@ -500,10 +500,10 @@
     9.4      TEST_ASSERT_MSG((bernd->user_id), "bernd->user_id");
     9.5      TEST_ASSERT_MSG((strcmp(bernd->user_id, bernd_userid) == 0), "strcmp(bernd->user_id, bernd_userid) == 0"); // ???
     9.6      TEST_ASSERT_MSG((!bernd->me), "!bernd->me"); 
     9.7 -    TEST_ASSERT_MSG((bernd->comm_type == PEP_ct_key_expired), "bernd->comm_type == PEP_ct_key_expired");
     9.8 +    TEST_ASSERT_MSG((bernd->comm_type == PEP_ct_key_not_found), tl_ct_string(bernd->comm_type));
     9.9      TEST_ASSERT_MSG((strcmp(bernd->address, bernd_address) == 0), "strcmp(bernd->address, bernd_address) == 0");
    9.10  
    9.11 -    cout << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_expired" << endl << endl;
    9.12 +    cout << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_not_found" << endl << endl;
    9.13      free_identity(bernd);
    9.14      
    9.15  }
    10.1 --- a/test/src/engine_tests/RevocationTests.cc	Thu Jun 27 09:29:20 2019 +0200
    10.2 +++ b/test/src/engine_tests/RevocationTests.cc	Thu Jun 27 15:40:53 2019 +0200
    10.3 @@ -52,8 +52,24 @@
    10.4      TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
    10.5  
    10.6      pEp_identity* post = new_identity("linda@example.org", NULL, NULL, NULL);
    10.7 +    
    10.8 +//    string save_fpr = post->fpr;
    10.9 +
   10.10 +    stringlist_t* keylist = NULL;
   10.11 +    
   10.12 +    status = find_keys(session, "linda@example.org", &keylist);
   10.13 +    TEST_ASSERT(status == PEP_STATUS_OK);
   10.14 +    
   10.15      status = update_identity(session, post);
   10.16      // PEP_KEY_UNSUITABLE => revoked (or something similar).
   10.17      TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
   10.18 +    TEST_ASSERT_MSG((post->comm_type == PEP_ct_key_not_found), tl_ct_string(post->comm_type));
   10.19 +    free(post->fpr);
   10.20 +    post->fpr = strdup(keylist->value);
   10.21 +    status = get_trust(session, post);
   10.22 +    TEST_ASSERT(status == PEP_STATUS_OK);
   10.23      TEST_ASSERT_MSG((post->comm_type == PEP_ct_key_revoked), tl_ct_string(post->comm_type));
   10.24 +    free_identity(pre);
   10.25 +    free_identity(post);
   10.26 +    free_stringlist(keylist);    
   10.27  }