ENGINE-289: tested adn tests up to key election - that comes next. Minor bug fixes in update_identity ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 17 Jan 2018 22:49:46 +0100
branchENGINE-289
changeset 2405f723208869f7
parent 2404 ba45f3303e5f
child 2406 be9932cba368
ENGINE-289: tested adn tests up to key election - that comes next. Minor bug fixes in update_identity
default.conf
src/keymanagement.c
src/keymanagement.h
test/external_revoke_test.cc
test/userid_alias_test.cc
     1.1 --- a/default.conf	Wed Jan 17 12:39:10 2018 +0100
     1.2 +++ b/default.conf	Wed Jan 17 22:49:46 2018 +0100
     1.3 @@ -99,7 +99,7 @@
     1.4          CFLAGS+= -w
     1.5      endif
     1.6      ifdef DEBUG
     1.7 -        CFLAGS+= -Og -ggdb -DDEBUG_ERRORSTACK
     1.8 +        CFLAGS+= -g -ggdb -DDEBUG_ERRORSTACK
     1.9      else
    1.10          CFLAGS+= -O3 -DNDEBUG
    1.11      endif
    1.12 @@ -148,7 +148,7 @@
    1.13          CXXFLAGS+= -w
    1.14      endif
    1.15      ifdef DEBUG
    1.16 -        CXXFLAGS+= -Og -ggdb
    1.17 +        CXXFLAGS+= -g -ggdb
    1.18      else
    1.19          CXXFLAGS+= -O3 -DNDEBUG
    1.20      endif
     2.1 --- a/src/keymanagement.c	Wed Jan 17 12:39:10 2018 +0100
     2.2 +++ b/src/keymanagement.c	Wed Jan 17 22:49:46 2018 +0100
     2.3 @@ -350,7 +350,7 @@
     2.4      if (status == PEP_STATUS_OK && stored_ident->fpr && *(stored_ident->fpr) != '\0') {
     2.5      // set identity comm_type from trust db (user_id, FPR)
     2.6          status = get_trust(session, stored_ident);
     2.7 -        if (status == PEP_CANNOT_FIND_IDENTITY) {
     2.8 +        if (status == PEP_CANNOT_FIND_IDENTITY || stored_ident->comm_type == PEP_ct_unknown) {
     2.9              // This is OK - there is no trust DB entry, but we
    2.10              // found a key. We won't store this, but we'll
    2.11              // use it.
    2.12 @@ -826,7 +826,7 @@
    2.13      // input.
    2.14      if (EMPTYSTR(identity->username)) {
    2.15          bool stored_uname = (stored_identity && stored_identity->username);
    2.16 -        char* uname = (stored_uname ? "Anonymous" : stored_identity->username);
    2.17 +        char* uname = (stored_uname ? stored_identity->username : "Anonymous");
    2.18          free(identity->username);
    2.19          identity->username = strdup(uname);
    2.20          if (identity->username == NULL)
    2.21 @@ -930,42 +930,21 @@
    2.22          
    2.23      if (!my_idents)
    2.24          return PEP_STATUS_OK;
    2.25 -        
    2.26 -    char* default_own_userid = NULL;
    2.27 -    get_default_own_userid(session, &default_own_userid);
    2.28 -    
    2.29 +            
    2.30      identity_list* ident_curr = my_idents;
    2.31      while (ident_curr) {
    2.32          pEp_identity* ident = ident_curr->ident;
    2.33 -        if (!ident)
    2.34 -            return PEP_ILLEGAL_VALUE;
    2.35 -            
    2.36 -        if (default_own_userid) {
    2.37 -            if (ident->user_id && strcmp(default_own_userid, ident->user_id) != 0) {
    2.38 -                status = set_userid_alias(session, default_own_userid, ident->user_id);
    2.39 -                if (status != PEP_STATUS_OK)
    2.40 -                    goto pep_free;
    2.41 -                free(ident->user_id);
    2.42 -            }
    2.43 -            ident->user_id = strdup(default_own_userid);        
    2.44 +        if (!ident || !ident->address) {
    2.45 +            status = PEP_ILLEGAL_VALUE;
    2.46 +            goto pep_error;
    2.47          }
    2.48 -        else if (!ident->user_id) {
    2.49 -            default_own_userid = PEP_OWN_USERID;
    2.50 -            ident->user_id = strdup(PEP_OWN_USERID);
    2.51 -        }
    2.52 -        
    2.53 -        ident->me = true;
    2.54 -        
    2.55 -        // Ok, do it...
    2.56 -        status = set_identity(session, ident);
    2.57 -        if (status != PEP_STATUS_OK)
    2.58 -            goto pep_free;
    2.59 +
    2.60 +        status = _myself(session, ident, false, false);
    2.61          
    2.62          ident_curr = ident_curr->next;
    2.63      }
    2.64      
    2.65 -pep_free:
    2.66 -    free(default_own_userid);
    2.67 +pep_error:
    2.68      return status;
    2.69  }
    2.70  
     3.1 --- a/src/keymanagement.h	Wed Jan 17 12:39:10 2018 +0100
     3.2 +++ b/src/keymanagement.h	Wed Jan 17 22:49:46 2018 +0100
     3.3 @@ -34,6 +34,27 @@
     3.4          PEP_SESSION session, pEp_identity * identity
     3.5      );
     3.6  
     3.7 +// initialise_own_identities () - ensures that an own identity is complete
     3.8 +//
     3.9 +//  parameters:
    3.10 +//      session (in)        session to use
    3.11 +//      my_idents (inout)   identities of local user to quick-set
    3.12 +//                          For these, at least .address must be set.
    3.13 +//                          if no .user_id is set, AND the DB doesn't contain
    3.14 +//                          a default user_id, PEP_OWN_USERID will be used and
    3.15 +//                          become the perennial default for the DB.
    3.16 +//
    3.17 +//  return value:
    3.18 +//      PEP_STATUS_OK if identity could be set,
    3.19 +//      any other value on error
    3.20 +//
    3.21 +//  caveat:
    3.22 +//      this function does NOT generate keypairs. It is intended to
    3.23 +//      precede running of the engine on actual messages. It effectively
    3.24 +//      behaves like myself(), but when there would normally be key generation
    3.25 +//      (when there is no valid key, for example),
    3.26 +//      it instead stores an identity without keys.
    3.27 +//
    3.28  DYNAMIC_API PEP_STATUS initialise_own_identities(PEP_SESSION session,
    3.29                                                   identity_list* my_idents);
    3.30  
     4.1 --- a/test/external_revoke_test.cc	Wed Jan 17 12:39:10 2018 +0100
     4.2 +++ b/test/external_revoke_test.cc	Wed Jan 17 22:49:46 2018 +0100
     4.3 @@ -45,7 +45,6 @@
     4.4      status = myself(session, me);
     4.5      
     4.6      // Create key
     4.7 -
     4.8      cout << "Creating new id for : ";
     4.9      char *uniqname = strdup("AAAAtestuser@testdomain.org");
    4.10      srandom(time(NULL));
     5.1 --- a/test/userid_alias_test.cc	Wed Jan 17 12:39:10 2018 +0100
     5.2 +++ b/test/userid_alias_test.cc	Wed Jan 17 22:49:46 2018 +0100
     5.3 @@ -15,7 +15,7 @@
     5.4  using namespace std;
     5.5  
     5.6  int main() {
     5.7 -    cout << "\n*** test user_id aliases ***\n\n";
     5.8 +    cout << "\n*** userid_alias_test ***\n\n";
     5.9  
    5.10      PEP_SESSION session;
    5.11      
    5.12 @@ -38,11 +38,16 @@
    5.13      const char* alias1 = "TheBigCheese";
    5.14      const char* alias2 = "PEBKAC";
    5.15  
    5.16 +    char* own_id = NULL;
    5.17 +    status = get_default_own_userid(session, &own_id);
    5.18 +    if (!own_id)
    5.19 +        own_id = strdup(PEP_OWN_USERID);
    5.20 +    
    5.21      cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
    5.22      status = myself(session, alice);
    5.23      assert(status == PEP_STATUS_OK);
    5.24      cout << "After myself, user_id is " << alice->user_id << endl;
    5.25 -    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);
    5.26 +    assert(strcmp(alice->user_id, own_id) == 0);
    5.27      
    5.28      cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
    5.29      free(alice->user_id);
    5.30 @@ -51,7 +56,7 @@
    5.31      status = myself(session, alice);
    5.32      assert(status == PEP_STATUS_OK);
    5.33      cout << "After myself, user_id is " << alice->user_id << endl;
    5.34 -    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);
    5.35 +    assert(strcmp(alice->user_id, own_id) == 0);
    5.36  
    5.37      cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
    5.38      free(alice->user_id);
    5.39 @@ -60,20 +65,20 @@
    5.40      status = myself(session, alice);
    5.41      assert(status == PEP_STATUS_OK);
    5.42      cout << "After myself, user_id is " << alice->user_id << endl;
    5.43 -    assert(strcmp(alice->user_id, PEP_OWN_USERID) == 0);    
    5.44 +    assert(strcmp(alice->user_id, own_id) == 0);    
    5.45  
    5.46      char* default_id = NULL;
    5.47      status = get_userid_alias_default(session, alias1, &default_id);
    5.48      assert(status == PEP_STATUS_OK);
    5.49      cout << "Default user_id for " << alias1 << " is " << default_id << endl;
    5.50 -    assert(strcmp(default_id, PEP_OWN_USERID) == 0);
    5.51 +    assert(strcmp(default_id, own_id) == 0);
    5.52      
    5.53      free(default_id);
    5.54      default_id = NULL;
    5.55      status = get_userid_alias_default(session, alias2, &default_id);
    5.56      assert(status == PEP_STATUS_OK);
    5.57      cout << "Default user_id for " << alias2 << " is " << default_id << endl;
    5.58 -    assert(strcmp(default_id, PEP_OWN_USERID) == 0);
    5.59 +    assert(strcmp(default_id, own_id) == 0);
    5.60      
    5.61      
    5.62      return 0;