merged remove_attached_keys import_own_key
authorEdouard Tisserant
Sun, 12 Jun 2016 20:20:45 +0200
branchimport_own_key
changeset 734bd9a3eb1d707
parent 730 de7942336904
parent 731 6f7c688e0fd4
child 736 496905895282
merged remove_attached_keys
src/message_api.c
src/message_api.h
src/pEpEngine.c
src/pgp_gpg.c
     1.1 --- a/src/map_asn1.h	Thu Jun 09 16:51:44 2016 +0200
     1.2 +++ b/src/map_asn1.h	Sun Jun 12 20:20:45 2016 +0200
     1.3 @@ -1,4 +1,4 @@
     1.4 -#pragma one
     1.5 +#pragma once
     1.6  
     1.7  #include "pEpEngine.h"
     1.8  #include "stringlist.h"
     2.1 --- a/src/message_api.c	Thu Jun 09 16:51:44 2016 +0200
     2.2 +++ b/src/message_api.c	Sun Jun 12 20:20:45 2016 +0200
     2.3 @@ -830,7 +830,17 @@
     2.4      }
     2.5  }
     2.6  
     2.7 -bool _is_pgp_key(bloblist_t *bl)
     2.8 +static void free_bl_entry(bloblist_t *bl)
     2.9 +{
    2.10 +    if (bl) {
    2.11 +        free(bl->value);
    2.12 +        free(bl->mime_type);
    2.13 +        free(bl->filename);
    2.14 +        free(bl);
    2.15 +    }
    2.16 +}
    2.17 +
    2.18 +static bool is_key(const bloblist_t *bl)
    2.19  {
    2.20      return (// workaround for Apple Mail bugs
    2.21              (is_mime_type(bl, "application/x-apple-msg-attachment") &&
    2.22 @@ -849,7 +859,31 @@
    2.23             );
    2.24  }
    2.25  
    2.26 -void import_attached_keys(
    2.27 +static void remove_attached_keys(message *msg)
    2.28 +{
    2.29 +    if (msg) {
    2.30 +        bloblist_t *last = NULL;
    2.31 +        for (bloblist_t *bl = msg->attachments; bl && bl->value; ) {
    2.32 +            bloblist_t *next = bl->next;
    2.33 +
    2.34 +            if (is_key(bl)) {
    2.35 +                if (last) {
    2.36 +                    last->next = next;
    2.37 +                }
    2.38 +                else {
    2.39 +                    msg->attachments = next;
    2.40 +                }
    2.41 +                free_bl_entry(bl);
    2.42 +            }
    2.43 +            else {
    2.44 +                last = bl;
    2.45 +            }
    2.46 +            bl = next;
    2.47 +        }
    2.48 +    }
    2.49 +}
    2.50 +
    2.51 +bool import_attached_keys(
    2.52          PEP_SESSION session, 
    2.53          const message *msg,
    2.54          identity_list **private_idents
    2.55 @@ -858,17 +892,22 @@
    2.56      assert(session);
    2.57      assert(msg);
    2.58  
    2.59 +    bool remove = false;
    2.60 +
    2.61      bloblist_t *bl;
    2.62      for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
    2.63          assert(bl && bl->value && bl->size);
    2.64  
    2.65 -        if (_is_pgp_key(bl))
    2.66 +        if (is_key(bl)) 
    2.67          {
    2.68              import_key(session, bl->value, bl->size, private_idents);
    2.69 +            remove = true;
    2.70          }
    2.71      }
    2.72 +    return remove;
    2.73  }
    2.74  
    2.75 +
    2.76  PEP_STATUS _attach_key(PEP_SESSION session, const char* fpr, message *msg)
    2.77  {
    2.78      char *keydata;
    2.79 @@ -1163,8 +1202,8 @@
    2.80      if (!(session && src && dst && keylist && color))
    2.81          return PEP_ILLEGAL_VALUE;
    2.82  
    2.83 -    // Private key in an unencrypted mail... srsly ? -> NULL
    2.84 -    import_attached_keys(session, src, NULL);
    2.85 +    // Private key in unencrypted mail are ignored -> NULL
    2.86 +    bool imported_keys = import_attached_keys(session, src, NULL);
    2.87  
    2.88      // Update src->from in case we just imported a key
    2.89      // we would need to check signature
    2.90 @@ -1180,6 +1219,8 @@
    2.91      switch (src->enc_format) {
    2.92          case PEP_enc_none:
    2.93              *color = PEP_rating_unencrypted;
    2.94 +            if (imported_keys)
    2.95 +                remove_attached_keys(src);
    2.96              return PEP_UNENCRYPTED;
    2.97  
    2.98          case PEP_enc_PGP_MIME:
    2.99 @@ -1337,10 +1378,9 @@
   2.100                  NOT_IMPLEMENTED
   2.101          }
   2.102         
   2.103 -        // Only check for private key imported if
   2.104 -        // in decrypted message attachement
   2.105 +        // check for private key in decrypted message attachement while inporting
   2.106          identity_list *private_il = NULL;
   2.107 -        import_attached_keys(session, msg, &private_il);
   2.108 +        imported_keys = import_attached_keys(session, msg, &private_il);
   2.109          if (private_il && 
   2.110              identity_list_length(private_il) == 1 &&
   2.111              private_il->ident->address)
   2.112 @@ -1371,7 +1411,7 @@
   2.113              status = cryptotech[crypto].decrypt_and_verify(session, ctext,
   2.114                  csize, &re_ptext, &re_psize, &_keylist);
   2.115              
   2.116 -            if(re_ptext)
   2.117 +            if (re_ptext)
   2.118                  free(re_ptext);
   2.119              
   2.120              if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
   2.121 @@ -1447,6 +1487,8 @@
   2.122  
   2.123      if (msg){
   2.124          decorate_message(msg, *color, _keylist);
   2.125 +        if (imported_keys)
   2.126 +            remove_attached_keys(msg);
   2.127      }
   2.128  
   2.129      *dst = msg;
     3.1 --- a/src/message_api.h	Thu Jun 09 16:51:44 2016 +0200
     3.2 +++ b/src/message_api.h	Sun Jun 12 20:20:45 2016 +0200
     3.3 @@ -10,7 +10,7 @@
     3.4  #endif
     3.5  
     3.6  
     3.7 -void import_attached_keys(
     3.8 +bool import_attached_keys(
     3.9          PEP_SESSION session, 
    3.10          const message *msg,
    3.11          identity_list **private_idents
     4.1 --- a/src/mime.c	Thu Jun 09 16:51:44 2016 +0200
     4.2 +++ b/src/mime.c	Sun Jun 12 20:20:45 2016 +0200
     4.3 @@ -646,14 +646,14 @@
     4.4      struct mailmime * submime = NULL;
     4.5      int r;
     4.6      PEP_STATUS status;
     4.7 -    char *subject;
     4.8 +    //char *subject;
     4.9      char *plaintext;
    4.10      char *htmltext;
    4.11  
    4.12      assert(msg);
    4.13      assert(result);
    4.14  
    4.15 -    subject = (msg->shortmsg) ? msg->shortmsg : "pEp";
    4.16 +    //subject = (msg->shortmsg) ? msg->shortmsg : "pEp";  // not used, yet.
    4.17      plaintext = (msg->longmsg) ? msg->longmsg : "";
    4.18      htmltext = msg->longmsg_formatted;
    4.19  
    4.20 @@ -739,13 +739,13 @@
    4.21  	struct mailmime_parameter * param;
    4.22      int r;
    4.23      PEP_STATUS status;
    4.24 -    char *subject;
    4.25 +    //char *subject;
    4.26      char *plaintext;
    4.27  
    4.28      assert(msg->attachments && msg->attachments->next &&
    4.29              msg->attachments->next->value);
    4.30  
    4.31 -    subject = (msg->shortmsg) ? msg->shortmsg : "pEp";
    4.32 +    //subject = (msg->shortmsg) ? msg->shortmsg : "pEp"; // not used, yet.
    4.33      plaintext = msg->attachments->next->value;
    4.34  
    4.35      mime = part_multiple_new("multipart/encrypted");
     5.1 --- a/src/pEpEngine.c	Thu Jun 09 16:51:44 2016 +0200
     5.2 +++ b/src/pEpEngine.c	Sun Jun 12 20:20:45 2016 +0200
     5.3 @@ -1259,7 +1259,7 @@
     5.4  {
     5.5      if (text) {
     5.6          for (char *c = text; *c; c++) {
     5.7 -            if (*c < 32)
     5.8 +            if (*c < 32 && *c != '\n')
     5.9                  *c = 32;
    5.10              else if (*c == '"')
    5.11                  *c = '\'';
     6.1 --- a/src/pgp_gpg.c	Thu Jun 09 16:51:44 2016 +0200
     6.2 +++ b/src/pgp_gpg.c	Sun Jun 12 20:20:45 2016 +0200
     6.3 @@ -362,7 +362,7 @@
     6.4      gpgme_data_type_t dt;
     6.5  
     6.6      stringlist_t *_keylist = NULL;
     6.7 -    int i_key = 0;
     6.8 +    //int i_key = 0;
     6.9  
    6.10      assert(session);
    6.11      assert(ctext);
    6.12 @@ -543,7 +543,8 @@
    6.13                  break;
    6.14              }
    6.15              case GPG_ERR_BAD_PASSPHRASE:
    6.16 -                NOT_IMPLEMENTED;
    6.17 +                result = PEP_DECRYPT_NO_KEY;
    6.18 +                break;
    6.19              case GPG_ERR_DECRYPT_FAILED:
    6.20              default:
    6.21              {
    6.22 @@ -1677,6 +1678,8 @@
    6.23      const char *reason_ref;
    6.24  } revoke_state;
    6.25  
    6.26 +
    6.27 +/*** unused?
    6.28  static bool isemptystring(const char *str)
    6.29  {
    6.30      if (str == NULL)
    6.31 @@ -1689,6 +1692,8 @@
    6.32  
    6.33      return true;
    6.34  }
    6.35 +***/
    6.36 +
    6.37  
    6.38  static gpgme_error_t revoke_fsm(
    6.39          void *_handle,
     7.1 --- a/sync/Makefile	Thu Jun 09 16:51:44 2016 +0200
     7.2 +++ b/sync/Makefile	Sun Jun 12 20:20:45 2016 +0200
     7.3 @@ -5,10 +5,10 @@
     7.4  skeleton: ../src/sync_actions.c.skeleton
     7.5  
     7.6  ../src/sync_actions.c.skeleton: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
     7.7 -	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
     7.8 +	$(YML2PROC) -I$(YML_PATH) -y gen_actions_skeleton.ysl2 $< -o $@
     7.9  
    7.10  ../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    7.11 -	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
    7.12 +	$(YML2PROC) -I$(YML_PATH) -y gen_statemachine.ysl2 $< -o $@
    7.13  
    7.14  .PHONY: clean
    7.15