fixes for _own_keys_retrieve sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 30 Apr 2019 15:35:35 +0200
branchsync
changeset 35833c796707c727
parent 3572 b5fab91365e7
child 3584 0a67843c0d27
fixes for _own_keys_retrieve
src/keymanagement.c
src/keymanagement.h
sync/cond_act_sync.yml2
test/gentestshell.py
test/src/SuiteMaker.cc
     1.1 --- a/src/keymanagement.c	Mon Apr 29 12:34:55 2019 +0200
     1.2 +++ b/src/keymanagement.c	Tue Apr 30 15:35:35 2019 +0200
     1.3 @@ -1737,7 +1737,8 @@
     1.4  PEP_STATUS _own_keys_retrieve(
     1.5          PEP_SESSION session,
     1.6          stringlist_t **keylist,
     1.7 -        identity_flags_t excluded_flags
     1.8 +        identity_flags_t excluded_flags,
     1.9 +        bool private_only
    1.10        )
    1.11  {
    1.12      PEP_STATUS status = PEP_STATUS_OK;
    1.13 @@ -1785,8 +1786,31 @@
    1.14      } while (result != SQLITE_DONE);
    1.15      
    1.16      sqlite3_reset(session->own_keys_retrieve);
    1.17 -    if (status == PEP_STATUS_OK)
    1.18 +    if (status == PEP_STATUS_OK) {
    1.19 +        dedup_stringlist(_keylist);
    1.20 +        if (private_only) {
    1.21 +            stringlist_t* _kl = _keylist;
    1.22 +            stringlist_t* _kl_prev = NULL;
    1.23 +            while (_kl) {
    1.24 +                bool has_private = false;
    1.25 +                contains_priv_key(session, _kl->value, &has_private);
    1.26 +                if (!has_private) {
    1.27 +                    stringlist_t* _kl_tmp = _kl;
    1.28 +                    if (_kl_prev) {
    1.29 +                        _kl_prev->next = _kl->next;
    1.30 +                    }
    1.31 +                    _kl = _kl->next;
    1.32 +                    
    1.33 +                    _kl_tmp->next = NULL;
    1.34 +                    free_stringlist(_kl_tmp);
    1.35 +                    continue;
    1.36 +                }
    1.37 +                _kl_prev = _kl;
    1.38 +                _kl = _kl->next;
    1.39 +            }
    1.40 +        }
    1.41          *keylist = _keylist;
    1.42 +    }
    1.43      else
    1.44          free_stringlist(_keylist);
    1.45      
    1.46 @@ -1802,7 +1826,7 @@
    1.47  
    1.48  DYNAMIC_API PEP_STATUS own_keys_retrieve(PEP_SESSION session, stringlist_t **keylist)
    1.49  {
    1.50 -    return _own_keys_retrieve(session, keylist, 0);
    1.51 +    return _own_keys_retrieve(session, keylist, 0, true);
    1.52  }
    1.53  
    1.54  DYNAMIC_API PEP_STATUS set_own_key(
     2.1 --- a/src/keymanagement.h	Mon Apr 29 12:34:55 2019 +0200
     2.2 +++ b/src/keymanagement.h	Tue Apr 30 15:35:35 2019 +0200
     2.3 @@ -330,17 +330,19 @@
     2.4  //  parameters:
     2.5  //      session (in)            session to use
     2.6  //      keylist (out)           list of fingerprints
     2.7 -//      excluded_flags (int)    flags to exclude from results
     2.8 -//
     2.9 +//      excluded_flags (in)     flags to exclude from results
    2.10 +//      private_only (in)       if true, return only fprs for
    2.11 +//                              which we have the secret part
    2.12  //  caveat:
    2.13  //      the ownership of the list goes to the caller
    2.14  DYNAMIC_API PEP_STATUS _own_keys_retrieve(
    2.15          PEP_SESSION session,
    2.16          stringlist_t **keylist,
    2.17 -        identity_flags_t excluded_flags
    2.18 +        identity_flags_t excluded_flags,
    2.19 +        bool private_only
    2.20        );
    2.21  
    2.22 -// own_keys_retrieve() - retrieve all flagged keypair fingerprints 
    2.23 +// own_keys_retrieve() - retrieve all flagged public/private keypair fingerprints 
    2.24  //
    2.25  //  parameters:
    2.26  //      session (in)            session to use
    2.27 @@ -348,6 +350,8 @@
    2.28  //
    2.29  //  caveat:
    2.30  //      the ownership of the list goes to the caller
    2.31 +//      this function does not return keys without a private key part
    2.32 +//
    2.33  DYNAMIC_API PEP_STATUS own_keys_retrieve(
    2.34          PEP_SESSION session,
    2.35          stringlist_t **keylist
     3.1 --- a/sync/cond_act_sync.yml2	Mon Apr 29 12:34:55 2019 +0200
     3.2 +++ b/sync/cond_act_sync.yml2	Tue Apr 30 15:35:35 2019 +0200
     3.3 @@ -233,7 +233,7 @@
     3.4  action prepareOwnKeys
     3.5  ||
     3.6      stringlist_t *own_keys;
     3.7 -    PEP_STATUS status = _own_keys_retrieve(session, &own_keys, PEP_idf_not_for_sync);
     3.8 +    PEP_STATUS status = _own_keys_retrieve(session, &own_keys, PEP_idf_not_for_sync, true);
     3.9      if (status)
    3.10          return status;
    3.11  
     4.1 --- a/test/gentestshell.py	Mon Apr 29 12:34:55 2019 +0200
     4.2 +++ b/test/gentestshell.py	Tue Apr 30 15:35:35 2019 +0200
     4.3 @@ -86,7 +86,10 @@
     4.4  
     4.5  if not args.no_src:
     4.6      src_inc = ('#include <stdlib.h>\n'
     4.7 +               '#include <cstring>\n'
     4.8                 '#include <string>\n\n'
     4.9 +               '#include <cpptest.h>\n'
    4.10 +               '#include "test_util.h"\n\n'
    4.11                 '#include "pEpEngine.h"\n\n'
    4.12                 '#include "' + superclass +'.h"\n'
    4.13                 '#include "' + test_suite + '.h"\n\n')
     5.1 --- a/test/src/SuiteMaker.cc	Mon Apr 29 12:34:55 2019 +0200
     5.2 +++ b/test/src/SuiteMaker.cc	Tue Apr 30 15:35:35 2019 +0200
     5.3 @@ -61,6 +61,7 @@
     5.4  #include "KeyResetMessageTests.h"
     5.5  #include "DeleteKeyTests.h"
     5.6  #include "KeyAttachmentTests.h"
     5.7 +#include "OwnKeysRetrieveTests.h"
     5.8  #include "TrustManipulationTests.h"
     5.9  #include "SyncTests.h"
    5.10  #include "AppleMailTests.h"
    5.11 @@ -116,13 +117,14 @@
    5.12      "KeyResetMessageTests",
    5.13      "DeleteKeyTests",
    5.14      "KeyAttachmentTests",
    5.15 +    "OwnKeysRetrieveTests",
    5.16      "TrustManipulationTests",
    5.17      "SyncTests",
    5.18      "AppleMailTests",
    5.19  };
    5.20  
    5.21  // This file is generated, so magic constants are ok.
    5.22 -int SuiteMaker::num_suites = 52;
    5.23 +int SuiteMaker::num_suites = 53;
    5.24  
    5.25  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    5.26      if (strcmp(test_class_name, "MimeTests") == 0)
    5.27 @@ -223,6 +225,8 @@
    5.28          *test_suite = new DeleteKeyTests(test_class_name, test_home);
    5.29      else if (strcmp(test_class_name, "KeyAttachmentTests") == 0)
    5.30          *test_suite = new KeyAttachmentTests(test_class_name, test_home);
    5.31 +    else if (strcmp(test_class_name, "OwnKeysRetrieveTests") == 0)
    5.32 +        *test_suite = new OwnKeysRetrieveTests(test_class_name, test_home);
    5.33      else if (strcmp(test_class_name, "TrustManipulationTests") == 0)
    5.34          *test_suite = new TrustManipulationTests(test_class_name, test_home);
    5.35      else if (strcmp(test_class_name, "SyncTests") == 0)