ENGINE_214: intermittent commit ENGINE-214
authorKrista Bennett <krista@pep-project.org>
Wed, 27 Sep 2017 18:28:42 +0200
branchENGINE-214
changeset 2120b99308bd100a
parent 2119 c4e078c65941
child 2121 3e2d2c40c229
ENGINE_214: intermittent commit
src/message_api.c
src/pEp_internal.h
     1.1 --- a/src/message_api.c	Wed Sep 27 11:29:43 2017 +0200
     1.2 +++ b/src/message_api.c	Wed Sep 27 18:28:42 2017 +0200
     1.3 @@ -100,11 +100,11 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -static char * encapsulate_message_version(const char *msg_version, const char *longmsg)
     1.8 +static char * encapsulate_message_wrap_info(const char *msg_wrap_info, const char *longmsg)
     1.9  {
    1.10 -    assert(msg_version);
    1.11 +    assert(msg_wrap_info);
    1.12      
    1.13 -    if (!msg_version) {
    1.14 +    if (!msg_wrap_info) {
    1.15          if (!longmsg)
    1.16              return NULL;
    1.17          else {
    1.18 @@ -120,14 +120,14 @@
    1.19      const char * const newlines = "\n\n";
    1.20      const size_t NL_LEN = 2;
    1.21          
    1.22 -    const size_t bufsize = PEP_MSG_VERSION_KEY_LEN + strlen(msg_version) + NL_LEN + strlen(longmsg) + 1;
    1.23 +    const size_t bufsize = PEP_MSG_WRAP_KEY_LEN + strlen(msg_wrap_info) + NL_LEN + strlen(longmsg) + 1;
    1.24      char * ptext = calloc(1, bufsize);
    1.25      assert(ptext);
    1.26      if (ptext == NULL)
    1.27          return NULL;
    1.28  
    1.29 -    strlcpy(ptext, PEP_MSG_VERSION_KEY, bufsize);
    1.30 -    strlcat(ptext, msg_version, bufsize);
    1.31 +    strlcpy(ptext, PEP_MSG_WRAP_KEY, bufsize);
    1.32 +    strlcat(ptext, msg_wrap_info, bufsize);
    1.33      strlcat(ptext, newlines, bufsize);
    1.34      strlcat(ptext, longmsg, bufsize);
    1.35  
    1.36 @@ -225,29 +225,29 @@
    1.37  }
    1.38  
    1.39  
    1.40 -static int separate_short_and_long(const char *src, char **shortmsg, char** msg_version, char **longmsg)
    1.41 +static int separate_short_and_long(const char *src, char **shortmsg, char** msg_wrap_info, char **longmsg)
    1.42  {
    1.43      char *_shortmsg = NULL;
    1.44 -    char *_msg_version = NULL;
    1.45 +    char *_msg_wrap_info = NULL;
    1.46      char *_longmsg = NULL;
    1.47  
    1.48      assert(src);
    1.49      assert(shortmsg);
    1.50 -    assert(msg_version);
    1.51 +    assert(msg_wrap_info);
    1.52      assert(longmsg);
    1.53  
    1.54 -    if (src == NULL || shortmsg == NULL || msg_version == NULL || longmsg == NULL)
    1.55 +    if (src == NULL || shortmsg == NULL || msg_wrap_info == NULL || longmsg == NULL)
    1.56          return -1;
    1.57  
    1.58      *shortmsg = NULL;
    1.59      *longmsg = NULL;
    1.60 -    *msg_version = NULL;
    1.61 +    *msg_wrap_info = NULL;
    1.62  
    1.63      // We generated the input here. If we ever need more than one header value to be
    1.64      // encapsulated and hidden in the encrypted text, we will have to modify this.
    1.65      // As is, we're either doing this with a version 1.0 client, in which case
    1.66      // the only encapsulated header value is subject, or 2.0+, in which the
    1.67 -    // message version is the only encapsulated header value. If we need this
    1.68 +    // message wrap info is the only encapsulated header value. If we need this
    1.69      // to be more complex, we're going to have to do something more elegant
    1.70      // and efficient.    
    1.71      PEP_STATUS status = get_data_from_encapsulated_line(src, PEP_SUBJ_KEY_LC, 
    1.72 @@ -261,19 +261,19 @@
    1.73              goto enomem;
    1.74      }
    1.75      else {
    1.76 -        status = get_data_from_encapsulated_line(src, PEP_MSG_VERSION_KEY_LC, 
    1.77 -                                                 PEP_MSG_VERSION_KEY_LEN, 
    1.78 -                                                 &_msg_version, &_longmsg);
    1.79 -        if (_msg_version) {
    1.80 +        status = get_data_from_encapsulated_line(src, PEP_MSG_WRAP_KEY_LC, 
    1.81 +                                                 PEP_MSG_WRAP_KEY_LEN, 
    1.82 +                                                 &_msg_wrap_info, &_longmsg);
    1.83 +        if (_msg_wrap_info) {
    1.84              if (status == PEP_STATUS_OK)
    1.85 -                *msg_version = _msg_version;
    1.86 +                *msg_wrap_info = _msg_wrap_info;
    1.87              else
    1.88                  goto enomem;
    1.89          }
    1.90      }
    1.91      
    1.92      // If there was no secret data hiding in the first line...
    1.93 -    if (!_shortmsg && !_msg_version) {
    1.94 +    if (!_shortmsg && !_msg_wrap_info) {
    1.95          _longmsg = strdup(src);
    1.96          assert(_longmsg);
    1.97          if (_longmsg == NULL)
    1.98 @@ -286,7 +286,7 @@
    1.99  
   1.100  enomem:
   1.101      free(_shortmsg);
   1.102 -    free(_msg_version);
   1.103 +    free(_msg_wrap_info);
   1.104      free(_longmsg);
   1.105  
   1.106      return -1;
   1.107 @@ -453,29 +453,16 @@
   1.108      dst->enc_format = PEP_enc_PGP_MIME;
   1.109      unsigned char pepstr[] = PEP_SUBJ_STRING;
   1.110  
   1.111 -    if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0 
   1.112 -                      && _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0) {
   1.113 -        if (session->unencrypted_subject) {
   1.114 -            dst->shortmsg = strdup(src->shortmsg);
   1.115 -            assert(dst->shortmsg);
   1.116 -            if (dst->shortmsg == NULL)
   1.117 -                goto enomem;
   1.118 -            ptext = src->longmsg;
   1.119 -        }
   1.120 -        else {
   1.121 -            ptext = combine_short_and_long(src->shortmsg, src->longmsg);
   1.122 -            if (ptext == NULL)
   1.123 -                goto enomem;
   1.124 -            free_ptext = true;
   1.125 -        }
   1.126 -    }
   1.127 -    else if (src->longmsg) {
   1.128 -        ptext = src->longmsg;
   1.129 -    }
   1.130 -    else {
   1.131 -        ptext = (char*)pepstr;
   1.132 -    }
   1.133 -
   1.134 +    if (src->shortmsg)
   1.135 +        dst->shortmsg = strdup(src->shortmsg);
   1.136 +
   1.137 +    // Right now, we only encrypt inner messages or outer messages. There
   1.138 +    // is no in-between. All messages are to be wrapped or are a wrapper.
   1.139 +    const char* msg_wrap_info = (flags & PEP_encrypt_flag_wrap_message ? 
   1.140 +                                 "INNER" : "OUTER");
   1.141 +    
   1.142 +    ptext = encapsulate_message_wrap_info(const char *msg_wrap_info, src->longmsg);
   1.143 +        
   1.144      message *_src = calloc(1, sizeof(message));
   1.145      assert(_src);
   1.146      if (_src == NULL)
   1.147 @@ -1833,8 +1820,8 @@
   1.148              {
   1.149                  char * shortmsg;
   1.150                  char * longmsg;
   1.151 -                char * msg_version; // This is incorrect, but just here to get things compiling for the moment
   1.152 -                int r = separate_short_and_long(msg->longmsg, &shortmsg, &msg_version,
   1.153 +                char * msg_wrap_info; // This is incorrect, but just here to get things compiling for the moment
   1.154 +                int r = separate_short_and_long(msg->longmsg, &shortmsg, &msg_wrap_info,
   1.155                          &longmsg);
   1.156                  
   1.157                  if (r == -1)
     2.1 --- a/src/pEp_internal.h	Wed Sep 27 11:29:43 2017 +0200
     2.2 +++ b/src/pEp_internal.h	Wed Sep 27 18:28:42 2017 +0200
     2.3 @@ -43,10 +43,10 @@
     2.4  #define PEP_SUBJ_KEY_LEN 9
     2.5  #endif
     2.6  
     2.7 -#ifndef PEP_MSG_VERSION_KEY
     2.8 -#define PEP_MSG_VERSION_KEY "pEp-Message-Version: "
     2.9 -#define PEP_MSG_VERSION_KEY_LC "pep-message-version: "
    2.10 -#define PEP_MSG_VERSION_KEY_LEN 21
    2.11 +#ifndef PEP_MSG_WRAP_KEY
    2.12 +#define PEP_MSG_WRAP_KEY "pEp-Wrapped-Message-Info: "
    2.13 +#define PEP_MSG_WRAP_KEY_LC "pep-wrapped-message-info: "
    2.14 +#define PEP_MSG_WRAP_KEY_LEN 26
    2.15  #endif
    2.16  
    2.17