Merge with sync sequoia_windows
authorThomas
Wed, 29 May 2019 08:07:53 +0200
branchsequoia_windows
changeset 3761c8b94d6bd3b4
parent 3748 2626a1c321ff
parent 3760 0fb3c0079c5a
child 3766 dffc8ed6625a
Merge with sync
src/pgp_sequoia.c
     1.1 --- a/src/message_api.c	Tue May 28 12:16:02 2019 +0200
     1.2 +++ b/src/message_api.c	Wed May 29 08:07:53 2019 +0200
     1.3 @@ -1572,7 +1572,7 @@
     1.4  PEP_STATUS _attach_key(PEP_SESSION session, const char* fpr, message *msg)
     1.5  {
     1.6      char *keydata = NULL;
     1.7 -    size_t size;
     1.8 +    size_t size = 0;
     1.9  
    1.10      PEP_STATUS status = export_key(session, fpr, &keydata, &size);
    1.11      assert(status == PEP_STATUS_OK);
    1.12 @@ -1580,7 +1580,7 @@
    1.13          return status;
    1.14      assert(size);
    1.15  
    1.16 -     bloblist_t *bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
    1.17 +    bloblist_t *bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
    1.18                        "file://pEpkey.asc");
    1.19  
    1.20      if (msg->attachments == NULL && bl)
     2.1 --- a/src/pgp_sequoia.c	Tue May 28 12:16:02 2019 +0200
     2.2 +++ b/src/pgp_sequoia.c	Wed May 29 08:07:53 2019 +0200
     2.3 @@ -812,8 +812,11 @@
     2.4                   
     2.5              }
     2.6              else {
     2.7 -                const char* split = strstr(uid_value, "<");
     2.8 -                if (split != uid_value) {       
     2.9 +                // Ok, asan gets really pissed at us using this string directly, SO...
    2.10 +                char* uid_copy = calloc(uid_value_len + 1, 1);
    2.11 +                strlcpy(uid_copy, uid_value, uid_value_len);
    2.12 +                const char* split = strstr(uid_copy, "<");
    2.13 +                if (split != uid_copy) {       
    2.14                      while (split) {
    2.15                          if (isspace(*(split - 1)))
    2.16                              break;
    2.17 @@ -840,9 +843,10 @@
    2.18                      else  
    2.19                          split = NULL;
    2.20                  }
    2.21 -                if (split == NULL) {
    2.22 -                    email = strdup(uid_value);
    2.23 -                }
    2.24 +                if (split == NULL)
    2.25 +                    email = uid_copy;
    2.26 +                else 
    2.27 +                    free(uid_copy);
    2.28              }
    2.29          }
    2.30          
    2.31 @@ -1652,6 +1656,11 @@
    2.32      if (write_status != 0)
    2.33          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Encrypting message");
    2.34  
    2.35 +    pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    2.36 +    ws = NULL;
    2.37 +    if (pgp_status != 0)
    2.38 +        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    2.39 +
    2.40      // Add a terminating NUL for naive users
    2.41      void *t = realloc(*stext, *ssize + 1);
    2.42      if (! t)
    2.43 @@ -1660,13 +1669,6 @@
    2.44      (*stext)[*ssize] = 0;
    2.45  
    2.46   out:
    2.47 -    if (ws) {
    2.48 -        pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    2.49 -        ws = NULL;
    2.50 -        if (pgp_status != 0)
    2.51 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    2.52 -    }
    2.53 -
    2.54      if (signer)
    2.55          pgp_signer_free (signer);
    2.56      if (signing_keypair)
    2.57 @@ -1772,21 +1774,22 @@
    2.58      if (write_status != 0)
    2.59          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Encrypting message");
    2.60  
    2.61 +    pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    2.62 +    ws = NULL;
    2.63 +    if (pgp_status != 0)
    2.64 +        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    2.65 +
    2.66      // Add a terminating NUL for naive users
    2.67      void *t = realloc(*ctext, *csize + 1);
    2.68 -    if (! t)
    2.69 +    if (! t) {
    2.70 +        free(*ctext);
    2.71 +        *ctext = NULL;
    2.72          ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
    2.73 +    }
    2.74      *ctext = t;
    2.75      (*ctext)[*csize] = 0;
    2.76  
    2.77   out:
    2.78 -    if (ws) {
    2.79 -        pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    2.80 -        ws = NULL;
    2.81 -        if (pgp_status != 0)
    2.82 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    2.83 -    }
    2.84 -
    2.85      if (signer)
    2.86          pgp_signer_free (signer);
    2.87      if (signing_keypair)
    2.88 @@ -2050,6 +2053,7 @@
    2.89      pgp_error_t err = NULL;
    2.90      pgp_tpk_t tpk = NULL;
    2.91      pgp_writer_t armor_writer = NULL;
    2.92 +    pgp_writer_t memory_writer = NULL;
    2.93  
    2.94      assert(session);
    2.95      assert(fpr);
    2.96 @@ -2066,13 +2070,12 @@
    2.97      status = tpk_find_by_fpr_hex(session, fpr, secret, &tpk, NULL);
    2.98      ERROR_OUT(NULL, status, "Looking up TSK for %s", fpr);
    2.99  
   2.100 -    pgp_writer_t memory_writer = pgp_writer_alloc((void **) key_data, size);
   2.101 +    memory_writer = pgp_writer_alloc((void **) key_data, size);
   2.102      if (! memory_writer)
   2.103          ERROR_OUT(NULL, PEP_UNKNOWN_ERROR, "creating memory writer");
   2.104      armor_writer = pgp_armor_writer_new(&err, memory_writer,
   2.105                                          PGP_ARMOR_KIND_PUBLICKEY, NULL, 0);
   2.106      if (! armor_writer) {
   2.107 -        pgp_writer_free(memory_writer);
   2.108          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "creating armored writer");
   2.109      }
   2.110  
   2.111 @@ -2090,9 +2093,20 @@
   2.112      if (armor_writer)
   2.113          pgp_writer_free(armor_writer);
   2.114  
   2.115 +    if (memory_writer) {
   2.116 +        if (status == PEP_STATUS_OK) {
   2.117 +            // Add a trailing NUL.
   2.118 +            pgp_writer_write(NULL, memory_writer, (const uint8_t *) "", 1);
   2.119 +        }
   2.120 +
   2.121 +        pgp_writer_free(memory_writer);
   2.122 +    }
   2.123 +
   2.124      if (tpk)
   2.125          pgp_tpk_free(tpk);
   2.126  
   2.127 +    (*size)--;  // Sequoia is delivering the 0 byte at the end with size, but
   2.128 +                // pEp is expecting it without
   2.129      T("(%s) -> %s", fpr, pEp_status_to_string(status));
   2.130      return status;
   2.131  }
   2.132 @@ -2402,7 +2416,7 @@
   2.133      if (tpk)
   2.134          pgp_tpk_free(tpk);
   2.135  
   2.136 -    T("(%s) -> %s", fpr, pep_comm_type_to_string(*comm_type));
   2.137 +    T("(%s) -> %s", fpr, pEp_comm_type_to_string(*comm_type));
   2.138      return status;
   2.139  }
   2.140  
   2.141 @@ -2664,4 +2678,3 @@
   2.142        fpr, *has_private ? "priv" : "pub", pEp_status_to_string(status));
   2.143      return status;
   2.144  }
   2.145 -
     3.1 --- a/src/status_to_string.h	Tue May 28 12:16:02 2019 +0200
     3.2 +++ b/src/status_to_string.h	Wed May 29 08:07:53 2019 +0200
     3.3 @@ -78,6 +78,7 @@
     3.4      case PEP_SYNC_NO_CHANNEL: return "PEP_SYNC_NO_CHANNEL";
     3.5      case PEP_SYNC_CANNOT_ENCRYPT: return "PEP_SYNC_CANNOT_ENCRYPT";
     3.6      case PEP_SYNC_NO_MESSAGE_SEND_CALLBACK: return "PEP_SYNC_NO_MESSAGE_SEND_CALLBACK";
     3.7 +    case PEP_SYNC_CANNOT_START: return "PEP_SYNC_CANNOT_START";
     3.8  
     3.9      case PEP_CANNOT_INCREASE_SEQUENCE: return "PEP_CANNOT_INCREASE_SEQUENCE";
    3.10  
     4.1 --- a/sync/cond_act_sync.yml2	Tue May 28 12:16:02 2019 +0200
     4.2 +++ b/sync/cond_act_sync.yml2	Wed May 29 08:07:53 2019 +0200
     4.3 @@ -416,18 +416,25 @@
     4.4      if (!(session->sync_state.common.from && session->sync_state.common.signature_fpr))
     4.5          return PEP_ILLEGAL_VALUE;
     4.6  
     4.7 -    pEp_identity *ident = session->sync_state.common.from;
     4.8 +    pEp_identity *ident = identity_dup(session->sync_state.common.from);
     4.9 +    if (!ident)
    4.10 +        return PEP_OUT_OF_MEMORY;
    4.11      free(ident->fpr);
    4.12      ident->fpr = strdup(session->sync_state.common.signature_fpr);
    4.13      assert(ident->fpr);
    4.14 -    if (!ident->fpr)
    4.15 +    if (!ident->fpr) {
    4.16 +        free_identity(ident);
    4.17          return PEP_OUT_OF_MEMORY;
    4.18 +    }
    4.19  
    4.20      PEP_STATUS status = trust_own_key(session, ident);
    4.21 -    if (status)
    4.22 +    if (status) {
    4.23 +        free_identity(ident);
    4.24          return status;
    4.25 +    }
    4.26  
    4.27      OCTET_STRING_fromBuf(&session->sync_state.keysync.key, ident->fpr, strlen(ident->fpr));
    4.28 +    free_identity(ident);
    4.29  ||
    4.30  
    4.31  action untrustThisKey
     5.1 --- a/sync/gen_statemachine.ysl2	Tue May 28 12:16:02 2019 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Wed May 29 08:07:53 2019 +0200
     5.3 @@ -335,6 +335,13 @@
     5.4                  if (!(session && data && size))
     5.5                      return PEP_ILLEGAL_VALUE;
     5.6  
     5.7 +                // FIXME: this will go wrong if MAC is used instead of Signature
     5.8 +                if (from && from->fpr && signature_fpr) {
     5.9 +                    // ignore own messages
    5.10 +                    if (strcmp(from->fpr, signature_fpr) == 0)
    5.11 +                        return PEP_STATUS_OK;
    5.12 +                }
    5.13 +
    5.14                  if (!session->inject_«yml:lcase(@name)»_event)
    5.15                     return PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
    5.16