ENGINE-133 merged default into ENGINE-133 ENGINE-133
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 01 Dec 2016 10:47:28 +0100
branchENGINE-133
changeset 1458443278ea9c47
parent 1447 c5ca494344d9
parent 1457 3efe9ded2561
child 1459 ab329d7db8d7
ENGINE-133 merged default into ENGINE-133
     1.1 --- a/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Mon Nov 28 10:29:07 2016 +0100
     1.2 +++ b/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Thu Dec 01 10:47:28 2016 +0100
     1.3 @@ -14,6 +14,7 @@
     1.4      <ProjectGuid>{F8B454D8-E2DA-455C-AA56-3F076CAA1A6E}</ProjectGuid>
     1.5      <Keyword>Win32Proj</Keyword>
     1.6      <RootNamespace>pEpEngineASN1</RootNamespace>
     1.7 +    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
     1.8    </PropertyGroup>
     1.9    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    1.10    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     2.1 --- a/src/keymanagement.c	Mon Nov 28 10:29:07 2016 +0100
     2.2 +++ b/src/keymanagement.c	Thu Dec 01 10:47:28 2016 +0100
     2.3 @@ -226,13 +226,20 @@
     2.4  
     2.5              if (!dont_use_fpr) {
     2.6                  PEP_comm_type _comm_type_key;
     2.7 +                
     2.8 +                // We don't want to lose a previous trust entry!!!
     2.9 +                status = get_trust(session, temp_id);
    2.10  
    2.11 +                bool has_trust_status = (status == PEP_STATUS_OK);
    2.12 +                
    2.13                  status = get_key_rating(session, temp_id->fpr, &_comm_type_key);
    2.14 +            
    2.15                  assert(status != PEP_OUT_OF_MEMORY);
    2.16                  if (status == PEP_OUT_OF_MEMORY)
    2.17                      goto exit_free;
    2.18  
    2.19 -                temp_id->comm_type = _comm_type_key;
    2.20 +                if (!has_trust_status || _comm_type_key > temp_id->comm_type)
    2.21 +                    temp_id->comm_type = _comm_type_key;
    2.22              }
    2.23              else {
    2.24                  free(temp_id->fpr);
     3.1 --- a/src/message_api.c	Mon Nov 28 10:29:07 2016 +0100
     3.2 +++ b/src/message_api.c	Thu Dec 01 10:47:28 2016 +0100
     3.3 @@ -1477,30 +1477,30 @@
     3.4      // Check for encryption stuck in the first 2 attachments instead of the body
     3.5      // (RFC3156)
     3.6      //
     3.7 -    if (!src->longmsg && !src->longmsg_formatted) {
     3.8 -        bloblist_t* attached_head = src->attachments;
     3.9 -        if (attached_head && 
    3.10 -            strcasecmp(attached_head->mime_type, "application/pgp-encrypted") == 0) {
    3.11 -            bloblist_t* enc_att_txt = attached_head->next;
    3.12 -            if (enc_att_txt && 
    3.13 -                strcasecmp(enc_att_txt->mime_type, "application/octet-stream") == 0) {
    3.14 -                size_t enc_att_len = enc_att_txt->size;
    3.15 -                char* newlongmsg = calloc(1, enc_att_len + 1);
    3.16 -                if (newlongmsg == NULL)
    3.17 -                    goto enomem;
    3.18 -
    3.19 -                memcpy(newlongmsg, enc_att_txt, enc_att_len);
    3.20 -                newlongmsg[enc_att_len] = '\0';
    3.21 -
    3.22 -                src->longmsg = newlongmsg;
    3.23 -
    3.24 -                // delete attachments here
    3.25 -                src->attachments = enc_att_txt->next;
    3.26 -                consume_bloblist_head(attached_head);
    3.27 -                consume_bloblist_head(attached_head);
    3.28 -            }
    3.29 -        }
    3.30 -    }
    3.31 +    // if (!src->longmsg && !src->longmsg_formatted) {
    3.32 +    //     bloblist_t* attached_head = src->attachments;
    3.33 +    //     if (attached_head && 
    3.34 +    //         strcasecmp(attached_head->mime_type, "application/pgp-encrypted") == 0) {
    3.35 +    //         bloblist_t* enc_att_txt = attached_head->next;
    3.36 +    //         if (enc_att_txt && 
    3.37 +    //             strcasecmp(enc_att_txt->mime_type, "application/octet-stream") == 0) {
    3.38 +    //             size_t enc_att_len = enc_att_txt->size;
    3.39 +    //             char* newlongmsg = calloc(1, enc_att_len + 1);
    3.40 +    //             if (newlongmsg == NULL)
    3.41 +    //                 goto enomem;
    3.42 +    // 
    3.43 +    //             memcpy(newlongmsg, enc_att_txt, enc_att_len);
    3.44 +    //             newlongmsg[enc_att_len] = '\0';
    3.45 +    // 
    3.46 +    //             src->longmsg = newlongmsg;
    3.47 +    // 
    3.48 +    //             // delete attachments here
    3.49 +    //             src->attachments = enc_att_txt->next;
    3.50 +    //             consume_bloblist_head(attached_head);
    3.51 +    //             consume_bloblist_head(attached_head);
    3.52 +    //         }
    3.53 +    //     }
    3.54 +    // }
    3.55  
    3.56      // Get detached signature, if any
    3.57      bloblist_t* detached_sig = NULL;
     4.1 --- a/src/pEpEngine.c	Mon Nov 28 10:29:07 2016 +0100
     4.2 +++ b/src/pEpEngine.c	Thu Dec 01 10:47:28 2016 +0100
     4.3 @@ -134,7 +134,7 @@
     4.4      sqlite3_busy_timeout(_session->system_db, 1000);
     4.5  
     4.6  // increment this when patching DDL
     4.7 -#define _DDL_USER_VERSION "4"
     4.8 +#define _DDL_USER_VERSION "5"
     4.9  
    4.10      if (in_first) {
    4.11  
    4.12 @@ -287,6 +287,23 @@
    4.13              );
    4.14          }
    4.15  
    4.16 +        if (version < 5) {
    4.17 +            int_result = sqlite3_exec(
    4.18 +                _session->db,
    4.19 +                "delete from pgp_keypair where fpr = '';",
    4.20 +                NULL,
    4.21 +                NULL,
    4.22 +                NULL
    4.23 +            );
    4.24 +            int_result = sqlite3_exec(
    4.25 +                _session->db,
    4.26 +                "delete from trust where pgp_keypair_fpr = '';",
    4.27 +                NULL,
    4.28 +                NULL,
    4.29 +                NULL
    4.30 +            );
    4.31 +        }
    4.32 +
    4.33          if (version < atoi(_DDL_USER_VERSION)) {
    4.34              int_result = sqlite3_exec(
    4.35                  _session->db,
    4.36 @@ -1065,9 +1082,10 @@
    4.37          return PEP_ILLEGAL_VALUE;
    4.38  
    4.39      bool listed;
    4.40 +
    4.41 +    bool has_fpr = (identity->fpr && identity->fpr[0] != '\0');
    4.42      
    4.43 -    if (identity->fpr && identity->fpr[0] != '\0') {
    4.44 -        
    4.45 +    if (has_fpr) {    
    4.46          // blacklist check
    4.47          PEP_STATUS status = blacklist_is_listed(session, identity->fpr, &listed);
    4.48          assert(status == PEP_STATUS_OK);
    4.49 @@ -1076,7 +1094,6 @@
    4.50  
    4.51          if (listed)
    4.52              return PEP_KEY_BLACKLISTED;
    4.53 -        
    4.54      }
    4.55  
    4.56      sqlite3_exec(session->db, "BEGIN ;", NULL, NULL, NULL);
    4.57 @@ -1106,17 +1123,18 @@
    4.58          return PEP_CANNOT_SET_PERSON;
    4.59      }
    4.60  
    4.61 -    sqlite3_reset(session->set_pgp_keypair);
    4.62 -    sqlite3_bind_text(session->set_pgp_keypair, 1, identity->fpr, -1,
    4.63 -            SQLITE_STATIC);
    4.64 -    result = sqlite3_step(session->set_pgp_keypair);
    4.65 -    sqlite3_reset(session->set_pgp_keypair);
    4.66 -    if (result != SQLITE_DONE) {
    4.67 -        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
    4.68 -        return PEP_CANNOT_SET_PGP_KEYPAIR;
    4.69 +    if (has_fpr) {
    4.70 +        sqlite3_reset(session->set_pgp_keypair);
    4.71 +        sqlite3_bind_text(session->set_pgp_keypair, 1, identity->fpr, -1,
    4.72 +                SQLITE_STATIC);
    4.73 +        result = sqlite3_step(session->set_pgp_keypair);
    4.74 +        sqlite3_reset(session->set_pgp_keypair);
    4.75 +        if (result != SQLITE_DONE) {
    4.76 +            sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
    4.77 +            return PEP_CANNOT_SET_PGP_KEYPAIR;
    4.78 +        }
    4.79      }
    4.80  
    4.81 -
    4.82      sqlite3_reset(session->set_identity);
    4.83      sqlite3_bind_text(session->set_identity, 1, identity->address, -1,
    4.84              SQLITE_STATIC);
    4.85 @@ -1132,34 +1150,35 @@
    4.86          return PEP_CANNOT_SET_IDENTITY;
    4.87      }
    4.88  
    4.89 -    if(strcmp(identity->user_id, PEP_OWN_USERID) == 0 &&
    4.90 -       identity->fpr && identity->fpr[0] != '\0') {
    4.91 -        sqlite3_reset(session->set_own_key);
    4.92 -        sqlite3_bind_text(session->set_own_key, 1, identity->address, -1,
    4.93 -            SQLITE_STATIC);
    4.94 -        sqlite3_bind_text(session->set_own_key, 2, identity->fpr, -1,
    4.95 -            SQLITE_STATIC);
    4.96 -        result = sqlite3_step(session->set_own_key);
    4.97 -        sqlite3_reset(session->set_own_key);
    4.98 +    if (has_fpr) {
    4.99 +        if(strcmp(identity->user_id, PEP_OWN_USERID) == 0) {
   4.100 +            sqlite3_reset(session->set_own_key);
   4.101 +            sqlite3_bind_text(session->set_own_key, 1, identity->address, -1,
   4.102 +                SQLITE_STATIC);
   4.103 +            sqlite3_bind_text(session->set_own_key, 2, identity->fpr, -1,
   4.104 +                SQLITE_STATIC);
   4.105 +            result = sqlite3_step(session->set_own_key);
   4.106 +            sqlite3_reset(session->set_own_key);
   4.107 +            if (result != SQLITE_DONE) {
   4.108 +                sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   4.109 +                return PEP_CANNOT_SET_PGP_KEYPAIR;
   4.110 +            }
   4.111 +        }
   4.112 +
   4.113 +        sqlite3_reset(session->set_trust);
   4.114 +        sqlite3_bind_text(session->set_trust, 1, identity->user_id, -1,
   4.115 +                SQLITE_STATIC);
   4.116 +        sqlite3_bind_text(session->set_trust, 2, identity->fpr, -1,
   4.117 +                SQLITE_STATIC);
   4.118 +        sqlite3_bind_int(session->set_trust, 3, identity->comm_type);
   4.119 +        result = sqlite3_step(session->set_trust);
   4.120 +        sqlite3_reset(session->set_trust);
   4.121          if (result != SQLITE_DONE) {
   4.122              sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   4.123 -            return PEP_CANNOT_SET_PGP_KEYPAIR;
   4.124 +            return PEP_CANNOT_SET_TRUST;
   4.125          }
   4.126      }
   4.127 -
   4.128 -    sqlite3_reset(session->set_trust);
   4.129 -    sqlite3_bind_text(session->set_trust, 1, identity->user_id, -1,
   4.130 -            SQLITE_STATIC);
   4.131 -    sqlite3_bind_text(session->set_trust, 2, identity->fpr, -1,
   4.132 -            SQLITE_STATIC);
   4.133 -    sqlite3_bind_int(session->set_trust, 3, identity->comm_type);
   4.134 -    result = sqlite3_step(session->set_trust);
   4.135 -    sqlite3_reset(session->set_trust);
   4.136 -    if (result != SQLITE_DONE) {
   4.137 -        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   4.138 -        return PEP_CANNOT_SET_TRUST;
   4.139 -    }
   4.140 -
   4.141 +    
   4.142      result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
   4.143      if (result == SQLITE_OK)
   4.144          return PEP_STATUS_OK;
   4.145 @@ -2170,4 +2189,3 @@
   4.146  
   4.147      return PEP_STATUS_OK;
   4.148  }
   4.149 -
     5.1 --- a/test/blacklist_test.cc	Mon Nov 28 10:29:07 2016 +0100
     5.2 +++ b/test/blacklist_test.cc	Thu Dec 01 10:47:28 2016 +0100
     5.3 @@ -86,12 +86,28 @@
     5.4                                                        bl_fpr_1,
     5.5                                                        NULL,
     5.6                                                        "Blacklist Keypair");
     5.7 +
     5.8      PEP_STATUS status8 = update_identity(session, blacklisted_identity);
     5.9 +    
    5.10 +    blacklisted_identity->comm_type = PEP_ct_pEp;
    5.11 +
    5.12 +    PEP_STATUS status99 = set_identity(session, blacklisted_identity);
    5.13 +        
    5.14 +    trust_personal_key(session, blacklisted_identity);
    5.15 +
    5.16 +    PEP_STATUS status999 = update_identity(session, blacklisted_identity);
    5.17 +
    5.18 +    assert(blacklisted_identity->comm_type == PEP_ct_pEp);
    5.19  
    5.20      PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    5.21      PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    5.22      PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    5.23  
    5.24 +    if (strcmp(blacklisted_identity->fpr, ""))
    5.25 +        cout << "blacklisted_identity-> fpr should be empty, but is " << blacklisted_identity->fpr << endl;
    5.26 +    else
    5.27 +        cout << "blacklisted identity's fpr successfully wiped by update_identity" << endl;
    5.28 +
    5.29      /* read the key into memory */
    5.30      ifstream infile2("blacklisted_pub2.asc");
    5.31      string keytext2;
    5.32 @@ -111,7 +127,22 @@
    5.33      PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
    5.34      PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
    5.35      PEP_STATUS status13 = update_identity(session, blacklisted_identity);
    5.36 +
    5.37 +    if (strcmp(blacklisted_identity->fpr, bl_fpr_2))
    5.38 +        cout << "blacklisted identity's fpr successfully replaced by the unblacklisted one" << endl;
    5.39 +    else
    5.40 +        cout << "blacklisted_identity->fpr should be " << bl_fpr_2 << " but is " << blacklisted_identity->fpr << endl;
    5.41              
    5.42 +    pEp_identity* stored_identity = new_identity("blacklistedkeys@kgrothoff.org",
    5.43 +                                                  NULL,
    5.44 +                                                  blacklisted_identity->user_id,
    5.45 +                                                  "Blacklist Keypair");
    5.46 +     
    5.47 +    PEP_STATUS status00 = update_identity(session, stored_identity);
    5.48 +    
    5.49 +    // Following should be true because bl_fpr_1's trust is set higher
    5.50 +    assert(stored_identity->comm_type == PEP_ct_pEp && (strcmp(stored_identity->fpr, bl_fpr_1) == 0));    
    5.51 +    
    5.52      PEP_STATUS status16 = delete_keypair(session, bl_fpr_1);
    5.53      update_identity(session, blacklisted_identity);
    5.54      PEP_STATUS status17 = delete_keypair(session, bl_fpr_2);
    5.55 @@ -124,4 +155,3 @@
    5.56      release(session);
    5.57      return 0;
    5.58  }
    5.59 -