adding flags to keys keysync
authorVolker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 00:06:35 +0200
branchkeysync
changeset 944e97cf5e73b64
parent 943 034486702a07
child 945 4474a1ae092e
adding flags to keys
db/Makefile
src/pEpEngine.c
src/pEpEngine.h
sync/devicegroup.fsm
     1.1 --- a/db/Makefile	Sat Jul 30 10:36:01 2016 +0200
     1.2 +++ b/db/Makefile	Sun Jul 31 00:06:35 2016 +0200
     1.3 @@ -12,6 +12,7 @@
     1.4  .PHONY: clean install
     1.5  
     1.6  install: system.db
     1.7 +	mkdir -p `dirname $(SYSTEM_DB)`
     1.8  	cp system.db $(SYSTEM_DB)
     1.9  
    1.10  clean:
     2.1 --- a/src/pEpEngine.c	Sat Jul 30 10:36:01 2016 +0200
     2.2 +++ b/src/pEpEngine.c	Sun Jul 31 00:06:35 2016 +0200
     2.3 @@ -3,6 +3,7 @@
     2.4  #include "cryptotech.h"
     2.5  #include "transport.h"
     2.6  #include "blacklist.h"
     2.7 +#include "sync_fsm.h"
     2.8  
     2.9  static int init_count = -1;
    2.10  
    2.11 @@ -127,7 +128,7 @@
    2.12      sqlite3_busy_timeout(_session->system_db, 1000);
    2.13  
    2.14  // increment this when patching DDL
    2.15 -#define _DDL_USER_VERSION "1"
    2.16 +#define _DDL_USER_VERSION "2"
    2.17  
    2.18      if (in_first) {
    2.19          int_result = sqlite3_exec(
    2.20 @@ -173,7 +174,8 @@
    2.21                  "   private_id text,\n"
    2.22                  "   created integer,\n"
    2.23                  "   expires integer,\n"
    2.24 -                "   comment text\n"
    2.25 +                "   comment text,\n"
    2.26 +                "   flags integer default (0)\n"
    2.27                  ");\n"
    2.28                  "create index if not exists pgp_keypair_expires on pgp_keypair (\n"
    2.29                  "   expires\n"
    2.30 @@ -255,6 +257,18 @@
    2.31              assert(int_result == SQLITE_OK);
    2.32          }
    2.33  
    2.34 +        if (version < 2) {
    2.35 +            int_result = sqlite3_exec(
    2.36 +                _session->db,
    2.37 +                "alter table pgp_keypair\n"
    2.38 +                "   add column flags integer default (0);",
    2.39 +                NULL,
    2.40 +                NULL,
    2.41 +                NULL
    2.42 +            );
    2.43 +            assert(int_result == SQLITE_OK);
    2.44 +        }
    2.45 +
    2.46          if (version < atoi(_DDL_USER_VERSION)) {
    2.47              int_result = sqlite3_exec(
    2.48                  _session->db,
    2.49 @@ -271,7 +285,7 @@
    2.50          sql_log = "insert into log (title, entity, description, comment)"
    2.51                    "values (?1, ?2, ?3, ?4);";
    2.52  
    2.53 -        sql_get_identity =  "select fpr, username, comm_type, lang, flags"
    2.54 +        sql_get_identity =  "select fpr, username, comm_type, lang, identity.flags"
    2.55                              "   from identity"
    2.56                              "   join person on id = identity.user_id"
    2.57                              "   join pgp_keypair on fpr = identity.main_key_id"
    2.58 @@ -1237,7 +1251,18 @@
    2.59          (identity->fpr == NULL || identity->fpr[0] == 0) && identity->username))
    2.60          return PEP_ILLEGAL_VALUE;
    2.61  
    2.62 -    return session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session, identity);
    2.63 +    PEP_STATUS status =
    2.64 +        session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session,
    2.65 +                identity);
    2.66 +    if (status != PEP_STATUS_OK)
    2.67 +        return status;
    2.68 +
    2.69 +    // if a state machine for keysync is in place, inject notify
    2.70 +    if (session->sync_state != DeviceState_state_NONE)
    2.71 +        status = fsm_DeviceState_inject(session, KeyGen, NULL,
    2.72 +                DeviceState_state_NONE);
    2.73 +
    2.74 +    return status;
    2.75  }
    2.76  
    2.77  DYNAMIC_API PEP_STATUS get_key_rating(
     3.1 --- a/src/pEpEngine.h	Sat Jul 30 10:36:01 2016 +0200
     3.2 +++ b/src/pEpEngine.h	Sun Jul 31 00:06:35 2016 +0200
     3.3 @@ -384,6 +384,8 @@
     3.4      PEP_idf_group = 2           // identity of group of persons
     3.5  } identity_flags;
     3.6  
     3.7 +typedef unsigned int identity_flags_t;
     3.8 +
     3.9  typedef struct _pEp_identity {
    3.10      char *address;              // C string with address UTF-8 encoded
    3.11      char *fpr;                  // C string with fingerprint UTF-8 encoded
    3.12 @@ -393,7 +395,7 @@
    3.13      char lang[3];               // language of conversation
    3.14                                  // ISO 639-1 ALPHA-2, last byte is 0
    3.15      bool me;                    // if this is the local user herself/himself
    3.16 -    unsigned int flags;         // identity_flag1 | identity_flag2 | ...
    3.17 +    identity_flags_t flags;     // identity_flag1 | identity_flag2 | ...
    3.18  } pEp_identity;
    3.19  
    3.20  typedef struct _identity_list {
     4.1 --- a/sync/devicegroup.fsm	Sat Jul 30 10:36:01 2016 +0200
     4.2 +++ b/sync/devicegroup.fsm	Sun Jul 31 00:06:35 2016 +0200
     4.3 @@ -19,7 +19,7 @@
     4.4          }
     4.5  
     4.6          state Sole {
     4.7 -            on KeyGen
     4.8 +            on KeyGen // injected by generate_keypair()
     4.9                  do sendBeacon;
    4.10              on CannotDecrypt
    4.11                  do sendBeacon;  // cry, baby