src/pEpEngine.c
branchkeysync
changeset 951 dec407deb10e
parent 948 2c689b7707a9
child 955 060272dfaaeb
     1.1 --- a/src/pEpEngine.c	Sun Jul 31 09:04:42 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Sun Jul 31 19:38:23 2016 +0200
     1.3 @@ -188,7 +188,8 @@
     1.4                  "       references pgp_keypair (fpr)\n"
     1.5                  "       on delete set null,\n"
     1.6                  "   lang text,\n"
     1.7 -                "   comment text\n"
     1.8 +                "   comment text,\n"
     1.9 +                "   device_group text\n"
    1.10                  ");\n"
    1.11                  "create table if not exists identity (\n"
    1.12                  "   address text,\n"
    1.13 @@ -250,7 +251,7 @@
    1.14              int_result = sqlite3_exec(
    1.15                  _session->db,
    1.16                  "alter table identity\n"
    1.17 -                "   add column flags integer default (0);",
    1.18 +                "   add column flags integer default (0);\n",
    1.19                  NULL,
    1.20                  NULL,
    1.21                  NULL
    1.22 @@ -261,9 +262,10 @@
    1.23          if (version < 2) {
    1.24              int_result = sqlite3_exec(
    1.25                  _session->db,
    1.26 -                "PRAGMA application_id = 0x23423423;\n"
    1.27                  "alter table pgp_keypair\n"
    1.28 -                "   add column flags integer default (0);",
    1.29 +                "   add column flags integer default (0);\n"
    1.30 +                "alter table person\n"
    1.31 +                "   add column device_group text;\n",
    1.32                  NULL,
    1.33                  NULL,
    1.34                  NULL
    1.35 @@ -382,8 +384,8 @@
    1.36                                "    where replacement_fpr = upper(replace(?1,' ','')) ;";
    1.37      }
    1.38  
    1.39 -    int_result = sqlite3_prepare_v2(_session->db, sql_log, (int)strlen(sql_log),
    1.40 -            &_session->log, NULL);
    1.41 +    int_result = sqlite3_prepare_v2(_session->db, sql_log,
    1.42 +            (int)strlen(sql_log), &_session->log, NULL);
    1.43      assert(int_result == SQLITE_OK);
    1.44  
    1.45      int_result = sqlite3_prepare_v2(_session->system_db, sql_trustword,
    1.46 @@ -399,7 +401,8 @@
    1.47      assert(int_result == SQLITE_OK);
    1.48  
    1.49      int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
    1.50 -            (int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair, NULL);
    1.51 +            (int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair,
    1.52 +            NULL);
    1.53      assert(int_result == SQLITE_OK);
    1.54  
    1.55      int_result = sqlite3_prepare_v2(_session->db, sql_set_identity,
    1.56 @@ -407,7 +410,8 @@
    1.57      assert(int_result == SQLITE_OK);
    1.58  
    1.59      int_result = sqlite3_prepare_v2(_session->db, sql_set_identity_flags,
    1.60 -            (int)strlen(sql_set_identity_flags), &_session->set_identity_flags, NULL);
    1.61 +            (int)strlen(sql_set_identity_flags), &_session->set_identity_flags,
    1.62 +            NULL);
    1.63      assert(int_result == SQLITE_OK);
    1.64  
    1.65      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    1.66 @@ -423,7 +427,8 @@
    1.67      assert(int_result == SQLITE_OK);
    1.68  
    1.69      int_result = sqlite3_prepare_v2(_session->db, sql_mark_as_compromized,
    1.70 -            (int)strlen(sql_mark_as_compromized), &_session->mark_compromized, NULL);
    1.71 +            (int)strlen(sql_mark_as_compromized), &_session->mark_compromized,
    1.72 +            NULL);
    1.73      assert(int_result == SQLITE_OK);
    1.74  
    1.75      int_result = sqlite3_prepare_v2(_session->db, sql_crashdump,
    1.76 @@ -445,45 +450,52 @@
    1.77      assert(int_result == SQLITE_OK);
    1.78  
    1.79      int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_delete,
    1.80 -            (int)strlen(sql_blacklist_delete), &_session->blacklist_delete, NULL);
    1.81 +            (int)strlen(sql_blacklist_delete), &_session->blacklist_delete,
    1.82 +            NULL);
    1.83      assert(int_result == SQLITE_OK);
    1.84  
    1.85      int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_is_listed,
    1.86 -            (int)strlen(sql_blacklist_is_listed), &_session->blacklist_is_listed, NULL);
    1.87 +            (int)strlen(sql_blacklist_is_listed),
    1.88 +            &_session->blacklist_is_listed, NULL);
    1.89      assert(int_result == SQLITE_OK);
    1.90  
    1.91      int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_retrieve,
    1.92 -            (int)strlen(sql_blacklist_retrieve), &_session->blacklist_retrieve, NULL);
    1.93 +            (int)strlen(sql_blacklist_retrieve), &_session->blacklist_retrieve,
    1.94 +            NULL);
    1.95      assert(int_result == SQLITE_OK);
    1.96  
    1.97      // Own keys
    1.98      
    1.99      int_result = sqlite3_prepare_v2(_session->db, sql_own_key_is_listed,
   1.100 -            (int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed, NULL);
   1.101 +            (int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed,
   1.102 +            NULL);
   1.103      assert(int_result == SQLITE_OK);
   1.104      
   1.105      int_result = sqlite3_prepare_v2(_session->db, sql_own_key_retrieve,
   1.106 -            (int)strlen(sql_own_key_retrieve), &_session->own_key_retrieve, NULL);
   1.107 +            (int)strlen(sql_own_key_retrieve), &_session->own_key_retrieve,
   1.108 +            NULL);
   1.109      assert(int_result == SQLITE_OK);
   1.110   
   1.111      // Sequence
   1.112  
   1.113      int_result = sqlite3_prepare_v2(_session->db, sql_sequence_value1,
   1.114 -            (int)strlen(sql_sequence_value1), &_session->sequence_value1, NULL);
   1.115 +            (int)strlen(sql_sequence_value1), &_session->sequence_value1,
   1.116 +            NULL);
   1.117      assert(int_result == SQLITE_OK);
   1.118  
   1.119      int_result = sqlite3_prepare_v2(_session->db, sql_sequence_value2,
   1.120 -            (int)strlen(sql_sequence_value2), &_session->sequence_value2, NULL);
   1.121 +            (int)strlen(sql_sequence_value2), &_session->sequence_value2,
   1.122 +            NULL);
   1.123      assert(int_result == SQLITE_OK);
   1.124  
   1.125      // Revocation tracking
   1.126      
   1.127      int_result = sqlite3_prepare_v2(_session->db, sql_set_revoked,
   1.128 -                                    (int)strlen(sql_set_revoked), &_session->set_revoked, NULL);
   1.129 +            (int)strlen(sql_set_revoked), &_session->set_revoked, NULL);
   1.130      assert(int_result == SQLITE_OK);
   1.131      
   1.132      int_result = sqlite3_prepare_v2(_session->db, sql_get_revoked,
   1.133 -                                    (int)strlen(sql_get_revoked), &_session->get_revoked, NULL);
   1.134 +            (int)strlen(sql_get_revoked), &_session->get_revoked, NULL);
   1.135      assert(int_result == SQLITE_OK);
   1.136      
   1.137      status = init_cryptotech(_session, in_first);
   1.138 @@ -602,7 +614,8 @@
   1.139      session->unencrypted_subject = enable;
   1.140  }
   1.141  
   1.142 -DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable)
   1.143 +DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session,
   1.144 +        bool enable)
   1.145  {
   1.146      assert(session);
   1.147      session->use_only_own_private_keys = enable;
   1.148 @@ -833,7 +846,8 @@
   1.149  {
   1.150      assert(src);
   1.151  
   1.152 -    pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id, src->username);
   1.153 +    pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id,
   1.154 +            src->username);
   1.155      assert(dup);
   1.156      if (dup == NULL)
   1.157          return NULL;
   1.158 @@ -896,8 +910,10 @@
   1.159          if (_identity == NULL)
   1.160              return PEP_OUT_OF_MEMORY;
   1.161  
   1.162 -        _identity->comm_type = (PEP_comm_type) sqlite3_column_int(session->get_identity, 2);
   1.163 -        const char* const _lang = (const char *) sqlite3_column_text(session->get_identity, 3);
   1.164 +        _identity->comm_type = (PEP_comm_type)
   1.165 +            sqlite3_column_int(session->get_identity, 2);
   1.166 +        const char* const _lang = (const char *)
   1.167 +            sqlite3_column_text(session->get_identity, 3);
   1.168          if (_lang && _lang[0]) {
   1.169              assert(_lang[0] >= 'a' && _lang[0] <= 'z');
   1.170              assert(_lang[1] >= 'a' && _lang[1] <= 'z');
   1.171 @@ -906,7 +922,8 @@
   1.172              _identity->lang[1] = _lang[1];
   1.173              _identity->lang[2] = 0;
   1.174          }
   1.175 -        _identity->flags = (unsigned int) sqlite3_column_int(session->get_identity, 4);
   1.176 +        _identity->flags = (unsigned int)
   1.177 +            sqlite3_column_int(session->get_identity, 4);
   1.178          *identity = _identity;
   1.179          break;
   1.180      default:
   1.181 @@ -1090,13 +1107,15 @@
   1.182      identity->comm_type = PEP_ct_unknown;
   1.183  
   1.184      sqlite3_reset(session->get_trust);
   1.185 -    sqlite3_bind_text(session->get_trust, 1, identity->user_id, -1, SQLITE_STATIC);
   1.186 +    sqlite3_bind_text(session->get_trust, 1, identity->user_id, -1,
   1.187 +            SQLITE_STATIC);
   1.188      sqlite3_bind_text(session->get_trust, 2, identity->fpr, -1, SQLITE_STATIC);
   1.189  
   1.190      result = sqlite3_step(session->get_trust);
   1.191      switch (result) {
   1.192      case SQLITE_ROW: {
   1.193 -        int comm_type = (PEP_comm_type) sqlite3_column_int(session->get_trust, 0);
   1.194 +        int comm_type = (PEP_comm_type) sqlite3_column_int(session->get_trust,
   1.195 +                0);
   1.196          identity->comm_type = comm_type;
   1.197          break;
   1.198      }
   1.199 @@ -1179,7 +1198,8 @@
   1.200      if (!(session && keylist && ptext && psize && ctext && csize))
   1.201          return PEP_ILLEGAL_VALUE;
   1.202  
   1.203 -    return session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
   1.204 +    return session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session,
   1.205 +            keylist, ptext, psize, ctext, csize);
   1.206  }
   1.207  
   1.208  DYNAMIC_API PEP_STATUS verify_text(
   1.209 @@ -1197,7 +1217,8 @@
   1.210      if (!(session && text && size && signature && sig_size && keylist))
   1.211          return PEP_ILLEGAL_VALUE;
   1.212  
   1.213 -    return session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text, size, signature, sig_size, keylist);
   1.214 +    return session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text,
   1.215 +            size, signature, sig_size, keylist);
   1.216  }
   1.217  
   1.218  DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
   1.219 @@ -1223,7 +1244,8 @@
   1.220      if (!(session && fpr && key_data && size))
   1.221          return PEP_ILLEGAL_VALUE;
   1.222  
   1.223 -    return session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr, key_data, size);
   1.224 +    return session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr,
   1.225 +            key_data, size);
   1.226  }
   1.227  
   1.228  DYNAMIC_API PEP_STATUS find_keys(
   1.229 @@ -1237,7 +1259,8 @@
   1.230      if (!(session && pattern && keylist))
   1.231          return PEP_ILLEGAL_VALUE;
   1.232  
   1.233 -    return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
   1.234 +    return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern,
   1.235 +            keylist);
   1.236  }
   1.237  
   1.238  DYNAMIC_API PEP_STATUS generate_keypair(
   1.239 @@ -1251,7 +1274,8 @@
   1.240      assert(identity->username);
   1.241  
   1.242      if (!(session && identity && identity->address &&
   1.243 -        (identity->fpr == NULL || identity->fpr[0] == 0) && identity->username))
   1.244 +            (identity->fpr == NULL || identity->fpr[0] == 0) &&
   1.245 +            identity->username))
   1.246          return PEP_ILLEGAL_VALUE;
   1.247  
   1.248      PEP_STATUS status =
   1.249 @@ -1262,8 +1286,7 @@
   1.250  
   1.251      // if a state machine for keysync is in place, inject notify
   1.252      if (session->sync_state != DeviceState_state_NONE)
   1.253 -        status = fsm_DeviceState_inject(session, KeyGen, NULL,
   1.254 -                DeviceState_state_NONE);
   1.255 +        status = fsm_DeviceState_inject(session, KeyGen, NULL, NULL);
   1.256  
   1.257      return status;
   1.258  }
   1.259 @@ -1281,7 +1304,8 @@
   1.260      if (!(session && fpr && comm_type))
   1.261          return PEP_ILLEGAL_VALUE;
   1.262  
   1.263 -    return session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
   1.264 +    return session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr,
   1.265 +            comm_type);
   1.266  }
   1.267  
   1.268  DYNAMIC_API PEP_STATUS import_key(
   1.269 @@ -1297,7 +1321,8 @@
   1.270      if (!(session && key_data))
   1.271          return PEP_ILLEGAL_VALUE;
   1.272  
   1.273 -    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size, private_keys);
   1.274 +    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data,
   1.275 +            size, private_keys);
   1.276  }
   1.277  
   1.278  DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
   1.279 @@ -1372,10 +1397,10 @@
   1.280  }
   1.281  
   1.282  DYNAMIC_API PEP_STATUS key_revoked(
   1.283 -                                   PEP_SESSION session,
   1.284 -                                   const char *fpr,
   1.285 -                                   bool *revoked
   1.286 -                                   )
   1.287 +       PEP_SESSION session,
   1.288 +       const char *fpr,
   1.289 +       bool *revoked
   1.290 +   )
   1.291  {
   1.292      assert(session);
   1.293      assert(fpr);
   1.294 @@ -1385,7 +1410,7 @@
   1.295          return PEP_ILLEGAL_VALUE;
   1.296      
   1.297      return session->cryptotech[PEP_crypt_OpenPGP].key_revoked(session, fpr,
   1.298 -                                                              revoked);
   1.299 +            revoked);
   1.300  }
   1.301  
   1.302  static void _clean_log_value(char *text)
   1.303 @@ -1457,11 +1482,16 @@
   1.304          result = sqlite3_step(session->crashdump);
   1.305          switch (result) {
   1.306          case SQLITE_ROW:
   1.307 -            timestamp = (const char *) sqlite3_column_text(session->crashdump, 0);
   1.308 -            title   = (const char *) sqlite3_column_text(session->crashdump, 1);
   1.309 -            entity  = (const char *) sqlite3_column_text(session->crashdump, 2);
   1.310 -            desc    = (const char *) sqlite3_column_text(session->crashdump, 3);
   1.311 -            comment = (const char *) sqlite3_column_text(session->crashdump, 4);
   1.312 +            timestamp = (const char *) sqlite3_column_text(session->crashdump,
   1.313 +                    0);
   1.314 +            title   = (const char *) sqlite3_column_text(session->crashdump,
   1.315 +                    1);
   1.316 +            entity  = (const char *) sqlite3_column_text(session->crashdump,
   1.317 +                    2);
   1.318 +            desc    = (const char *) sqlite3_column_text(session->crashdump,
   1.319 +                    3);
   1.320 +            comment = (const char *) sqlite3_column_text(session->crashdump,
   1.321 +                    4);
   1.322  
   1.323              _logdata = _concat_string(_logdata, timestamp, ',');
   1.324              if (_logdata == NULL)
   1.325 @@ -1536,9 +1566,12 @@
   1.326          result = sqlite3_step(session->languagelist);
   1.327          switch (result) {
   1.328          case SQLITE_ROW:
   1.329 -            lang = (const char *) sqlite3_column_text(session->languagelist, 0);
   1.330 -            name = (const char *) sqlite3_column_text(session->languagelist, 1);
   1.331 -            phrase = (const char *) sqlite3_column_text(session->languagelist, 2);
   1.332 +            lang = (const char *) sqlite3_column_text(session->languagelist,
   1.333 +                    0);
   1.334 +            name = (const char *) sqlite3_column_text(session->languagelist,
   1.335 +                    1);
   1.336 +            phrase = (const char *) sqlite3_column_text(session->languagelist,
   1.337 +                    2);
   1.338  
   1.339              _languages = _concat_string(_languages, lang, ',');
   1.340              if (_languages == NULL)
   1.341 @@ -1656,7 +1689,8 @@
   1.342      }
   1.343      else {
   1.344          sqlite3_reset(session->sequence_value2);
   1.345 -        sqlite3_bind_text(session->sequence_value2, 1, name, -1, SQLITE_STATIC);
   1.346 +        sqlite3_bind_text(session->sequence_value2, 1, name, -1,
   1.347 +                SQLITE_STATIC);
   1.348          result = sqlite3_step(session->sequence_value2);
   1.349          switch (result) {
   1.350              case SQLITE_ROW: {
   1.351 @@ -1695,7 +1729,8 @@
   1.352      
   1.353      sqlite3_reset(session->set_revoked);
   1.354      sqlite3_bind_text(session->set_revoked, 1, revoked_fpr, -1, SQLITE_STATIC);
   1.355 -    sqlite3_bind_text(session->set_revoked, 2, replacement_fpr, -1, SQLITE_STATIC);
   1.356 +    sqlite3_bind_text(session->set_revoked, 2, replacement_fpr, -1,
   1.357 +            SQLITE_STATIC);
   1.358      sqlite3_bind_int64(session->set_revoked, 3, revocation_date);
   1.359  
   1.360      int result;
   1.361 @@ -1745,9 +1780,11 @@
   1.362      result = sqlite3_step(session->get_revoked);
   1.363      switch (result) {
   1.364          case SQLITE_ROW: {
   1.365 -            *revoked_fpr = strdup((const char *) sqlite3_column_text(session->get_revoked, 0));
   1.366 +            *revoked_fpr = strdup((const char *)
   1.367 +                    sqlite3_column_text(session->get_revoked, 0));
   1.368              if(*revoked_fpr)
   1.369 -                *revocation_date = sqlite3_column_int64(session->get_revoked, 1);
   1.370 +                *revocation_date = sqlite3_column_int64(session->get_revoked,
   1.371 +                        1);
   1.372              else
   1.373                  status = PEP_OUT_OF_MEMORY;
   1.374