ENGINE-539: Removed MIME_encrypt and MIME_decrypt functions from the engine. These now reside in the test utils of the test suite so that current tests don't break, but these should eventually be reworked. sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 09 Apr 2019 10:30:08 +0200
branchsync
changeset 347571e0a8ae558f
parent 3474 b8af3a8121c3
child 3476 7d24e503f976
child 3495 b4d3e47eab14
ENGINE-539: Removed MIME_encrypt and MIME_decrypt functions from the engine. These now reside in the test utils of the test suite so that current tests don't break, but these should eventually be reworked.
src/message_api.c
src/message_api.h
test/include/test_util.h
test/src/util/test_util.cc
     1.1 --- a/src/message_api.c	Tue Apr 09 09:36:39 2019 +0200
     1.2 +++ b/src/message_api.c	Tue Apr 09 10:30:08 2019 +0200
     1.3 @@ -971,39 +971,6 @@
     1.4      return NULL;    
     1.5  }
     1.6  
     1.7 -static PEP_STATUS update_identity_recip_list(PEP_SESSION session,
     1.8 -                                             identity_list* list) {
     1.9 -
    1.10 -    PEP_STATUS status = PEP_STATUS_OK;
    1.11 -
    1.12 -    if (!session)
    1.13 -        return PEP_UNKNOWN_ERROR;
    1.14 -    
    1.15 -    identity_list* id_list_ptr = NULL;
    1.16 -        
    1.17 -    for (id_list_ptr = list; id_list_ptr; id_list_ptr = id_list_ptr->next) {
    1.18 -        pEp_identity* curr_identity = id_list_ptr->ident;
    1.19 -        if (curr_identity) {
    1.20 -            if (!is_me(session, curr_identity)) {
    1.21 -                char* name_bak = curr_identity->username;
    1.22 -                curr_identity->username = NULL;
    1.23 -                status = update_identity(session, curr_identity);
    1.24 -                if (name_bak && 
    1.25 -                    (EMPTYSTR(curr_identity->username) || strcmp(name_bak, curr_identity->username) != 0)) {
    1.26 -                    free(curr_identity->username);
    1.27 -                    curr_identity->username = name_bak;
    1.28 -                }                        
    1.29 -            }
    1.30 -            else
    1.31 -                status = _myself(session, curr_identity, false, false, true);
    1.32 -        if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
    1.33 -            return status;
    1.34 -        }
    1.35 -    }
    1.36 -    
    1.37 -    return PEP_STATUS_OK;                                  
    1.38 -}
    1.39 -
    1.40  static PEP_STATUS encrypt_PGP_MIME(
    1.41      PEP_SESSION session,
    1.42      const message *src,
    1.43 @@ -4452,228 +4419,6 @@
    1.44      return status;
    1.45  }
    1.46  
    1.47 -DYNAMIC_API PEP_STATUS MIME_decrypt_message(
    1.48 -    PEP_SESSION session,
    1.49 -    const char *mimetext,
    1.50 -    size_t size,
    1.51 -    char** mime_plaintext,
    1.52 -    stringlist_t **keylist,
    1.53 -    PEP_rating *rating,
    1.54 -    PEP_decrypt_flags_t *flags,
    1.55 -    char** modified_src
    1.56 -)
    1.57 -{
    1.58 -    assert(mimetext);
    1.59 -    assert(mime_plaintext);
    1.60 -    assert(keylist);
    1.61 -    assert(rating);
    1.62 -    assert(flags);
    1.63 -    assert(modified_src);
    1.64 -
    1.65 -    if (!(mimetext && mime_plaintext && keylist && rating && flags && modified_src))
    1.66 -        return PEP_ILLEGAL_VALUE;
    1.67 -        
    1.68 -    PEP_STATUS status = PEP_STATUS_OK;
    1.69 -    message* tmp_msg = NULL;
    1.70 -    message* dec_msg = NULL;
    1.71 -    *mime_plaintext = NULL;
    1.72 -
    1.73 -    status = mime_decode_message(mimetext, size, &tmp_msg);
    1.74 -    if (status != PEP_STATUS_OK)
    1.75 -        goto pEp_error;
    1.76 -
    1.77 -    tmp_msg->dir = PEP_dir_incoming;
    1.78 -    // MIME decode message delivers only addresses. We need more.
    1.79 -    if (tmp_msg->from) {
    1.80 -        if (!is_me(session, tmp_msg->from))
    1.81 -            status = update_identity(session, (tmp_msg->from));
    1.82 -        else
    1.83 -            status = _myself(session, tmp_msg->from, false, false, true);
    1.84 -
    1.85 -        if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
    1.86 -            goto pEp_error;
    1.87 -    }
    1.88 -
    1.89 -    status = update_identity_recip_list(session, tmp_msg->to);
    1.90 -    if (status != PEP_STATUS_OK)
    1.91 -        goto pEp_error;
    1.92 -
    1.93 -    status = update_identity_recip_list(session, tmp_msg->cc);
    1.94 -    if (status != PEP_STATUS_OK)
    1.95 -        goto pEp_error;
    1.96 -
    1.97 -    status = update_identity_recip_list(session, tmp_msg->bcc);
    1.98 -    if (status != PEP_STATUS_OK)
    1.99 -        goto pEp_error;
   1.100 -
   1.101 -    PEP_STATUS decrypt_status = decrypt_message(session,
   1.102 -                                                tmp_msg,
   1.103 -                                                &dec_msg,
   1.104 -                                                keylist,
   1.105 -                                                rating,
   1.106 -                                                flags);
   1.107 -
   1.108 -
   1.109 -    if (!dec_msg && (decrypt_status == PEP_UNENCRYPTED || decrypt_status == PEP_VERIFIED)) {
   1.110 -        dec_msg = message_dup(tmp_msg);
   1.111 -    }
   1.112 -    
   1.113 -    if (decrypt_status > PEP_CANNOT_DECRYPT_UNKNOWN || !dec_msg)
   1.114 -    {
   1.115 -        status = decrypt_status;
   1.116 -        goto pEp_error;
   1.117 -    }
   1.118 -
   1.119 -    if (*flags & PEP_decrypt_flag_src_modified) {
   1.120 -        _mime_encode_message_internal(tmp_msg, false, modified_src, true);
   1.121 -        if (!modified_src) {
   1.122 -            *flags &= (~PEP_decrypt_flag_src_modified);
   1.123 -            decrypt_status = PEP_CANNOT_REENCRYPT; // Because we couldn't return it, I guess.
   1.124 -        }
   1.125 -    }
   1.126 -
   1.127 -    // FIXME: test with att
   1.128 -    status = _mime_encode_message_internal(dec_msg, false, mime_plaintext, true);
   1.129 -
   1.130 -    if (status == PEP_STATUS_OK)
   1.131 -    {
   1.132 -        free(tmp_msg);
   1.133 -        free(dec_msg);
   1.134 -        return decrypt_status;
   1.135 -    }
   1.136 -    
   1.137 -pEp_error:
   1.138 -    free_message(tmp_msg);
   1.139 -    free_message(dec_msg);
   1.140 -
   1.141 -    return status;
   1.142 -}
   1.143 -
   1.144 -
   1.145 -DYNAMIC_API PEP_STATUS MIME_encrypt_message(
   1.146 -    PEP_SESSION session,
   1.147 -    const char *mimetext,
   1.148 -    size_t size,
   1.149 -    stringlist_t* extra,
   1.150 -    char** mime_ciphertext,
   1.151 -    PEP_enc_format enc_format,
   1.152 -    PEP_encrypt_flags_t flags
   1.153 -)
   1.154 -{
   1.155 -    PEP_STATUS status = PEP_STATUS_OK;
   1.156 -    message* tmp_msg = NULL;
   1.157 -    message* enc_msg = NULL;
   1.158 -
   1.159 -    status = mime_decode_message(mimetext, size, &tmp_msg);
   1.160 -    if (status != PEP_STATUS_OK)
   1.161 -        goto pEp_error;
   1.162 -
   1.163 -    // MIME decode message delivers only addresses. We need more.
   1.164 -    if (tmp_msg->from) {
   1.165 -        char* own_id = NULL;
   1.166 -        status = get_default_own_userid(session, &own_id);
   1.167 -        free(tmp_msg->from->user_id);
   1.168 -        
   1.169 -        if (status != PEP_STATUS_OK || !own_id) {
   1.170 -            tmp_msg->from->user_id = strdup(PEP_OWN_USERID);
   1.171 -        }
   1.172 -        else {
   1.173 -            tmp_msg->from->user_id = own_id; // ownership transfer
   1.174 -        }
   1.175 -            
   1.176 -        status = myself(session, tmp_msg->from);
   1.177 -        if (status != PEP_STATUS_OK)
   1.178 -            goto pEp_error;
   1.179 -    }
   1.180 -    
   1.181 -    // Own identities can be retrieved here where they would otherwise
   1.182 -    // fail because we lack all other information. This is ok and even
   1.183 -    // desired. FIXME: IS it?
   1.184 -    status = update_identity_recip_list(session, tmp_msg->to);
   1.185 -    if (status != PEP_STATUS_OK)
   1.186 -        goto pEp_error;
   1.187 -    
   1.188 -    status = update_identity_recip_list(session, tmp_msg->cc);
   1.189 -    if (status != PEP_STATUS_OK)
   1.190 -        goto pEp_error;
   1.191 -    
   1.192 -    status = update_identity_recip_list(session, tmp_msg->bcc);
   1.193 -    if (status != PEP_STATUS_OK)
   1.194 -        goto pEp_error;
   1.195 -    
   1.196 -    // This isn't incoming, though... so we need to reverse the direction
   1.197 -    tmp_msg->dir = PEP_dir_outgoing;
   1.198 -    status = encrypt_message(session,
   1.199 -                             tmp_msg,
   1.200 -                             extra,
   1.201 -                             &enc_msg,
   1.202 -                             enc_format,
   1.203 -                             flags);
   1.204 -                             
   1.205 -    if (status != PEP_STATUS_OK)
   1.206 -        goto pEp_error;
   1.207 -
   1.208 -
   1.209 -    if (!enc_msg) {
   1.210 -        status = PEP_UNKNOWN_ERROR;
   1.211 -        goto pEp_error;
   1.212 -    }
   1.213 -
   1.214 -    status = _mime_encode_message_internal(enc_msg, false, mime_ciphertext, false);
   1.215 -
   1.216 -pEp_error:
   1.217 -    free_message(tmp_msg);
   1.218 -    free_message(enc_msg);
   1.219 -
   1.220 -    return status;
   1.221 -
   1.222 -}
   1.223 -
   1.224 -DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
   1.225 -    PEP_SESSION session,
   1.226 -    pEp_identity* target_id,
   1.227 -    const char *mimetext,
   1.228 -    size_t size,
   1.229 -    stringlist_t* extra,
   1.230 -    char** mime_ciphertext,
   1.231 -    PEP_enc_format enc_format,
   1.232 -    PEP_encrypt_flags_t flags
   1.233 -)
   1.234 -{
   1.235 -    PEP_STATUS status = PEP_STATUS_OK;
   1.236 -    message* tmp_msg = NULL;
   1.237 -    message* enc_msg = NULL;
   1.238 -
   1.239 -    status = mime_decode_message(mimetext, size, &tmp_msg);
   1.240 -    if (status != PEP_STATUS_OK)
   1.241 -        goto pEp_error;
   1.242 -
   1.243 -    // This isn't incoming, though... so we need to reverse the direction
   1.244 -    tmp_msg->dir = PEP_dir_outgoing;
   1.245 -    status = encrypt_message_for_self(session,
   1.246 -                                      target_id,
   1.247 -                                      tmp_msg,
   1.248 -                                      extra,
   1.249 -                                      &enc_msg,
   1.250 -                                      enc_format,
   1.251 -                                      flags);
   1.252 -    if (status != PEP_STATUS_OK)
   1.253 -        goto pEp_error;
   1.254 - 
   1.255 -    if (!enc_msg) {
   1.256 -        status = PEP_UNKNOWN_ERROR;
   1.257 -        goto pEp_error;
   1.258 -    }
   1.259 -
   1.260 -    status = mime_encode_message(enc_msg, false, mime_ciphertext);
   1.261 -
   1.262 -pEp_error:
   1.263 -    free_message(tmp_msg);
   1.264 -    free_message(enc_msg);
   1.265 -
   1.266 -    return status;
   1.267 -}
   1.268 -
   1.269  static PEP_rating string_to_rating(const char * rating)
   1.270  {
   1.271      if (rating == NULL)
     2.1 --- a/src/message_api.h	Tue Apr 09 09:36:39 2019 +0200
     2.2 +++ b/src/message_api.h	Tue Apr 09 10:30:08 2019 +0200
     2.3 @@ -159,78 +159,6 @@
     2.4          PEP_encrypt_flags_t flags
     2.5      );
     2.6  
     2.7 -
     2.8 -// MIME_encrypt_message() - encrypt a MIME message, with MIME output
     2.9 -//
    2.10 -//  parameters:
    2.11 -//      session (in)            session handle
    2.12 -//      mimetext (in)           MIME encoded text to encrypt
    2.13 -//      size (in)               size of input mime text
    2.14 -//      extra (in)              extra keys for encryption
    2.15 -//      mime_ciphertext (out)   encrypted, encoded message
    2.16 -//      enc_format (in)         encrypted format
    2.17 -//      flags (in)              flags to set special encryption features
    2.18 -//
    2.19 -//  return value:
    2.20 -//      PEP_STATUS_OK           if everything worked
    2.21 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    2.22 -//      PEP_CANNOT_CREATE_TEMP_FILE
    2.23 -//                              if there are issues with temp files; in
    2.24 -//                              this case errno will contain the underlying
    2.25 -//                              error
    2.26 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
    2.27 -//
    2.28 -//  caveat:
    2.29 -//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
    2.30 -//      will remain in the ownership of the caller
    2.31 -DYNAMIC_API PEP_STATUS MIME_encrypt_message(
    2.32 -    PEP_SESSION session,
    2.33 -    const char *mimetext,
    2.34 -    size_t size,
    2.35 -    stringlist_t* extra,
    2.36 -    char** mime_ciphertext,
    2.37 -    PEP_enc_format enc_format,
    2.38 -    PEP_encrypt_flags_t flags
    2.39 -);
    2.40 -
    2.41 -
    2.42 -// MIME_encrypt_message_for_self() - encrypt MIME message for user's identity only,
    2.43 -//                              ignoring recipients and other identities from
    2.44 -//                              the message, with MIME output
    2.45 -//  parameters:
    2.46 -//      session (in)            session handle
    2.47 -//      target_id (in)          self identity this message should be encrypted for
    2.48 -//      mimetext (in)           MIME encoded text to encrypt
    2.49 -//      size (in)               size of input mime text
    2.50 -//      extra (in)              extra keys for encryption
    2.51 -//      mime_ciphertext (out)   encrypted, encoded message
    2.52 -//      enc_format (in)         encrypted format
    2.53 -//      flags (in)              flags to set special encryption features
    2.54 -//
    2.55 -//  return value:
    2.56 -//      PEP_STATUS_OK           if everything worked
    2.57 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    2.58 -//      PEP_CANNOT_CREATE_TEMP_FILE
    2.59 -//                              if there are issues with temp files; in
    2.60 -//                              this case errno will contain the underlying
    2.61 -//                              error
    2.62 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
    2.63 -//
    2.64 -//  caveat:
    2.65 -//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
    2.66 -//      will remain in the ownership of the caller
    2.67 -DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
    2.68 -    PEP_SESSION session,
    2.69 -    pEp_identity* target_id,
    2.70 -    const char *mimetext,
    2.71 -    size_t size,
    2.72 -    stringlist_t* extra,
    2.73 -    char** mime_ciphertext,
    2.74 -    PEP_enc_format enc_format,
    2.75 -    PEP_encrypt_flags_t flags
    2.76 -);
    2.77 -
    2.78 -
    2.79  typedef enum _PEP_rating {
    2.80      PEP_rating_undefined = 0,
    2.81      PEP_rating_cannot_decrypt,
    2.82 @@ -338,65 +266,6 @@
    2.83          PEP_decrypt_flags_t *flags
    2.84  );
    2.85  
    2.86 -
    2.87 -// MIME_decrypt_message() - decrypt a MIME message, with MIME output
    2.88 -//
    2.89 -//  parameters:
    2.90 -//      session (in)            session handle
    2.91 -//      mimetext (in)           MIME encoded text to decrypt
    2.92 -//      size (in)               size of mime text to decode (in order to decrypt)
    2.93 -//      mime_plaintext (out)    decrypted, encoded message
    2.94 -//      keylist (inout)         in: stringlist with additional keyids for reencryption if needed
    2.95 -//                                  (will be freed and replaced with output keylist)
    2.96 -//                              out: stringlist with keyids
    2.97 -//      rating (out)            rating for the message
    2.98 -//      flags (inout)           flags to signal special decryption features (see below)
    2.99 -//      modified_src (out)      modified source string, if decrypt had reason to change it
   2.100 -//
   2.101 -//  return value:
   2.102 -//      decrypt status          if everything worked with MIME encode/decode, 
   2.103 -//                              the status of the decryption is returned 
   2.104 -//                              (PEP_STATUS_OK or decryption error status)
   2.105 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
   2.106 -//      PEP_CANNOT_CREATE_TEMP_FILE
   2.107 -//                              if there are issues with temp files; in
   2.108 -//                              this case errno will contain the underlying
   2.109 -//                              error
   2.110 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
   2.111 -//
   2.112 -//  flag values:
   2.113 -//      in:
   2.114 -//          PEP_decrypt_flag_untrusted_server
   2.115 -//              used to signal that decrypt function should engage in behaviour
   2.116 -//              specified for when the server storing the source is untrusted.
   2.117 -//      out:
   2.118 -//          PEP_decrypt_flag_own_private_key
   2.119 -//              private key was imported for one of our addresses (NOT trusted
   2.120 -//              or set to be used - handshake/trust is required for that)
   2.121 -//          PEP_decrypt_flag_src_modified
   2.122 -//              indicates that the modified_src field should contain a modified
   2.123 -//              version of the source, at the moment always as a result of the
   2.124 -//              input flags. 
   2.125 -//          PEP_decrypt_flag_consume
   2.126 -//              used by sync 
   2.127 -//          PEP_decrypt_flag_ignore
   2.128 -//              used by sync 
   2.129 -// 
   2.130 -//  caveat:
   2.131 -//      the decrypted, encoded mime text will go to the ownership of the caller; mimetext
   2.132 -//      will remain in the ownership of the caller
   2.133 -DYNAMIC_API PEP_STATUS MIME_decrypt_message(
   2.134 -    PEP_SESSION session,
   2.135 -    const char *mimetext,
   2.136 -    size_t size,
   2.137 -    char** mime_plaintext,
   2.138 -    stringlist_t **keylist,
   2.139 -    PEP_rating *rating,
   2.140 -    PEP_decrypt_flags_t *flags,
   2.141 -    char** modified_src
   2.142 -);
   2.143 -
   2.144 -
   2.145  // own_message_private_key_details() - details on own key in own message
   2.146  //
   2.147  //  parameters:
     3.1 --- a/test/include/test_util.h	Tue Apr 09 09:36:39 2019 +0200
     3.2 +++ b/test/include/test_util.h	Tue Apr 09 10:30:08 2019 +0200
     3.3 @@ -58,5 +58,135 @@
     3.4                           int ftw_info, 
     3.5                           struct FTW * ftw_struct);
     3.6                           
     3.7 +// MIME_decrypt_message() - decrypt a MIME message, with MIME output
     3.8 +//
     3.9 +//  parameters:
    3.10 +//      session (in)            session handle
    3.11 +//      mimetext (in)           MIME encoded text to decrypt
    3.12 +//      size (in)               size of mime text to decode (in order to decrypt)
    3.13 +//      mime_plaintext (out)    decrypted, encoded message
    3.14 +//      keylist (inout)         in: stringlist with additional keyids for reencryption if needed
    3.15 +//                                  (will be freed and replaced with output keylist)
    3.16 +//                              out: stringlist with keyids
    3.17 +//      rating (out)            rating for the message
    3.18 +//      flags (inout)           flags to signal special decryption features (see below)
    3.19 +//      modified_src (out)      modified source string, if decrypt had reason to change it
    3.20 +//
    3.21 +//  return value:
    3.22 +//      decrypt status          if everything worked with MIME encode/decode, 
    3.23 +//                              the status of the decryption is returned 
    3.24 +//                              (PEP_STATUS_OK or decryption error status)
    3.25 +//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    3.26 +//      PEP_CANNOT_CREATE_TEMP_FILE
    3.27 +//                              if there are issues with temp files; in
    3.28 +//                              this case errno will contain the underlying
    3.29 +//                              error
    3.30 +//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
    3.31 +//
    3.32 +//  flag values:
    3.33 +//      in:
    3.34 +//          PEP_decrypt_flag_untrusted_server
    3.35 +//              used to signal that decrypt function should engage in behaviour
    3.36 +//              specified for when the server storing the source is untrusted.
    3.37 +//      out:
    3.38 +//          PEP_decrypt_flag_own_private_key
    3.39 +//              private key was imported for one of our addresses (NOT trusted
    3.40 +//              or set to be used - handshake/trust is required for that)
    3.41 +//          PEP_decrypt_flag_src_modified
    3.42 +//              indicates that the modified_src field should contain a modified
    3.43 +//              version of the source, at the moment always as a result of the
    3.44 +//              input flags. 
    3.45 +//          PEP_decrypt_flag_consume
    3.46 +//              used by sync 
    3.47 +//          PEP_decrypt_flag_ignore
    3.48 +//              used by sync 
    3.49 +// 
    3.50 +//  caveat:
    3.51 +//      the decrypted, encoded mime text will go to the ownership of the caller; mimetext
    3.52 +//      will remain in the ownership of the caller
    3.53 +PEP_STATUS MIME_decrypt_message(
    3.54 +    PEP_SESSION session,
    3.55 +    const char *mimetext,
    3.56 +    size_t size,
    3.57 +    char** mime_plaintext,
    3.58 +    stringlist_t **keylist,
    3.59 +    PEP_rating *rating,
    3.60 +    PEP_decrypt_flags_t *flags,
    3.61 +    char** modified_src
    3.62 +);
    3.63 +
    3.64 +// MIME_encrypt_message() - encrypt a MIME message, with MIME output
    3.65 +//
    3.66 +//  parameters:
    3.67 +//      session (in)            session handle
    3.68 +//      mimetext (in)           MIME encoded text to encrypt
    3.69 +//      size (in)               size of input mime text
    3.70 +//      extra (in)              extra keys for encryption
    3.71 +//      mime_ciphertext (out)   encrypted, encoded message
    3.72 +//      enc_format (in)         encrypted format
    3.73 +//      flags (in)              flags to set special encryption features
    3.74 +//
    3.75 +//  return value:
    3.76 +//      PEP_STATUS_OK           if everything worked
    3.77 +//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    3.78 +//      PEP_CANNOT_CREATE_TEMP_FILE
    3.79 +//                              if there are issues with temp files; in
    3.80 +//                              this case errno will contain the underlying
    3.81 +//                              error
    3.82 +//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
    3.83 +//
    3.84 +//  caveat:
    3.85 +//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
    3.86 +//      will remain in the ownership of the caller
    3.87 +DYNAMIC_API PEP_STATUS MIME_encrypt_message(
    3.88 +    PEP_SESSION session,
    3.89 +    const char *mimetext,
    3.90 +    size_t size,
    3.91 +    stringlist_t* extra,
    3.92 +    char** mime_ciphertext,
    3.93 +    PEP_enc_format enc_format,
    3.94 +    PEP_encrypt_flags_t flags
    3.95 +);
    3.96 +
    3.97 +
    3.98 +// MIME_encrypt_message_for_self() - encrypt MIME message for user's identity only,
    3.99 +//                              ignoring recipients and other identities from
   3.100 +//                              the message, with MIME output
   3.101 +//  parameters:
   3.102 +//      session (in)            session handle
   3.103 +//      target_id (in)          self identity this message should be encrypted for
   3.104 +//      mimetext (in)           MIME encoded text to encrypt
   3.105 +//      size (in)               size of input mime text
   3.106 +//      extra (in)              extra keys for encryption
   3.107 +//      mime_ciphertext (out)   encrypted, encoded message
   3.108 +//      enc_format (in)         encrypted format
   3.109 +//      flags (in)              flags to set special encryption features
   3.110 +//
   3.111 +//  return value:
   3.112 +//      PEP_STATUS_OK           if everything worked
   3.113 +//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
   3.114 +//      PEP_CANNOT_CREATE_TEMP_FILE
   3.115 +//                              if there are issues with temp files; in
   3.116 +//                              this case errno will contain the underlying
   3.117 +//                              error
   3.118 +//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
   3.119 +//
   3.120 +//  caveat:
   3.121 +//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
   3.122 +//      will remain in the ownership of the caller
   3.123 +PEP_STATUS MIME_encrypt_message_for_self(
   3.124 +    PEP_SESSION session,
   3.125 +    pEp_identity* target_id,
   3.126 +    const char *mimetext,
   3.127 +    size_t size,
   3.128 +    stringlist_t* extra,
   3.129 +    char** mime_ciphertext,
   3.130 +    PEP_enc_format enc_format,
   3.131 +    PEP_encrypt_flags_t flags
   3.132 +);
   3.133 +
   3.134 +
   3.135 +
   3.136 +
   3.137          
   3.138  #endif
     4.1 --- a/test/src/util/test_util.cc	Tue Apr 09 09:36:39 2019 +0200
     4.2 +++ b/test/src/util/test_util.cc	Tue Apr 09 10:30:08 2019 +0200
     4.3 @@ -4,6 +4,8 @@
     4.4  #include "message_api.h"
     4.5  #include "test_util.h"
     4.6  #include "TestConstants.h"
     4.7 +#include "mime.h"
     4.8 +#include "message_api.h"
     4.9  
    4.10  #include <fstream>
    4.11  #include <sstream>
    4.12 @@ -408,8 +410,6 @@
    4.13      return ok;
    4.14  }
    4.15  
    4.16 -
    4.17 -
    4.18  int util_delete_filepath(const char *filepath, 
    4.19                           const struct stat *file_stat, 
    4.20                           int ftw_info, 
    4.21 @@ -429,3 +429,259 @@
    4.22      
    4.23      return retval;
    4.24  }
    4.25 +
    4.26 +static PEP_STATUS update_identity_recip_list(PEP_SESSION session,
    4.27 +                                      identity_list* list) {
    4.28 +
    4.29 +    PEP_STATUS status = PEP_STATUS_OK;
    4.30 +
    4.31 +    if (!session)
    4.32 +        return PEP_UNKNOWN_ERROR;
    4.33 +    
    4.34 +    identity_list* id_list_ptr = NULL;
    4.35 +        
    4.36 +    for (id_list_ptr = list; id_list_ptr; id_list_ptr = id_list_ptr->next) {
    4.37 +        pEp_identity* curr_identity = id_list_ptr->ident;
    4.38 +        if (curr_identity) {
    4.39 +            if (!is_me(session, curr_identity)) {
    4.40 +                char* name_bak = curr_identity->username;
    4.41 +                curr_identity->username = NULL;
    4.42 +                status = update_identity(session, curr_identity);
    4.43 +                if (name_bak && 
    4.44 +                    (EMPTYSTR(curr_identity->username) || strcmp(name_bak, curr_identity->username) != 0)) {
    4.45 +                    free(curr_identity->username);
    4.46 +                    curr_identity->username = name_bak;
    4.47 +                }                        
    4.48 +            }
    4.49 +            else
    4.50 +                status = _myself(session, curr_identity, false, false, true);
    4.51 +        if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
    4.52 +            return status;
    4.53 +        }
    4.54 +    }
    4.55 +    
    4.56 +    return PEP_STATUS_OK;                                  
    4.57 +}
    4.58 +
    4.59 +PEP_STATUS MIME_decrypt_message(
    4.60 +    PEP_SESSION session,
    4.61 +    const char *mimetext,
    4.62 +    size_t size,
    4.63 +    char** mime_plaintext,
    4.64 +    stringlist_t **keylist,
    4.65 +    PEP_rating *rating,
    4.66 +    PEP_decrypt_flags_t *flags,
    4.67 +    char** modified_src
    4.68 +)
    4.69 +{
    4.70 +    assert(mimetext);
    4.71 +    assert(mime_plaintext);
    4.72 +    assert(keylist);
    4.73 +    assert(rating);
    4.74 +    assert(flags);
    4.75 +    assert(modified_src);
    4.76 +
    4.77 +    if (!(mimetext && mime_plaintext && keylist && rating && flags && modified_src))
    4.78 +        return PEP_ILLEGAL_VALUE;
    4.79 +        
    4.80 +    PEP_STATUS status = PEP_STATUS_OK;
    4.81 +    PEP_STATUS decrypt_status = PEP_CANNOT_DECRYPT_UNKNOWN;
    4.82 +         
    4.83 +    message* tmp_msg = NULL;
    4.84 +    message* dec_msg = NULL;
    4.85 +    *mime_plaintext = NULL;
    4.86 +
    4.87 +    status = mime_decode_message(mimetext, size, &tmp_msg);
    4.88 +    if (status != PEP_STATUS_OK)
    4.89 +        goto pEp_error;
    4.90 +
    4.91 +    tmp_msg->dir = PEP_dir_incoming;
    4.92 +    // MIME decode message delivers only addresses. We need more.
    4.93 +    if (tmp_msg->from) {
    4.94 +        if (!is_me(session, tmp_msg->from))
    4.95 +            status = update_identity(session, (tmp_msg->from));
    4.96 +        else
    4.97 +            status = _myself(session, tmp_msg->from, false, false, true);
    4.98 +
    4.99 +        if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
   4.100 +            goto pEp_error;
   4.101 +    }
   4.102 +
   4.103 +    status = update_identity_recip_list(session, tmp_msg->to);
   4.104 +    if (status != PEP_STATUS_OK)
   4.105 +        goto pEp_error;
   4.106 +
   4.107 +    status = update_identity_recip_list(session, tmp_msg->cc);
   4.108 +    if (status != PEP_STATUS_OK)
   4.109 +        goto pEp_error;
   4.110 +
   4.111 +    status = update_identity_recip_list(session, tmp_msg->bcc);
   4.112 +    if (status != PEP_STATUS_OK)
   4.113 +        goto pEp_error;
   4.114 +
   4.115 +    decrypt_status = decrypt_message(session,
   4.116 +                                     tmp_msg,
   4.117 +                                     &dec_msg,
   4.118 +                                     keylist,
   4.119 +                                     rating,
   4.120 +                                     flags);
   4.121 +
   4.122 +
   4.123 +    if (!dec_msg && (decrypt_status == PEP_UNENCRYPTED || decrypt_status == PEP_VERIFIED)) {
   4.124 +        dec_msg = message_dup(tmp_msg);
   4.125 +    }
   4.126 +    
   4.127 +    if (decrypt_status > PEP_CANNOT_DECRYPT_UNKNOWN || !dec_msg)
   4.128 +    {
   4.129 +        status = decrypt_status;
   4.130 +        goto pEp_error;
   4.131 +    }
   4.132 +
   4.133 +    if (*flags & PEP_decrypt_flag_src_modified) {
   4.134 +        _mime_encode_message_internal(tmp_msg, false, modified_src, true);
   4.135 +        if (!modified_src) {
   4.136 +            *flags &= (~PEP_decrypt_flag_src_modified);
   4.137 +            decrypt_status = PEP_CANNOT_REENCRYPT; // Because we couldn't return it, I guess.
   4.138 +        }
   4.139 +    }
   4.140 +
   4.141 +    // FIXME: test with att
   4.142 +    status = _mime_encode_message_internal(dec_msg, false, mime_plaintext, true);
   4.143 +
   4.144 +    if (status == PEP_STATUS_OK)
   4.145 +    {
   4.146 +        free(tmp_msg);
   4.147 +        free(dec_msg);
   4.148 +        return decrypt_status;
   4.149 +    }
   4.150 +    
   4.151 +pEp_error:
   4.152 +    free_message(tmp_msg);
   4.153 +    free_message(dec_msg);
   4.154 +
   4.155 +    return status;
   4.156 +}
   4.157 +
   4.158 +PEP_STATUS MIME_encrypt_message(
   4.159 +    PEP_SESSION session,
   4.160 +    const char *mimetext,
   4.161 +    size_t size,
   4.162 +    stringlist_t* extra,
   4.163 +    char** mime_ciphertext,
   4.164 +    PEP_enc_format enc_format,
   4.165 +    PEP_encrypt_flags_t flags
   4.166 +)
   4.167 +{
   4.168 +    PEP_STATUS status = PEP_STATUS_OK;
   4.169 +    message* tmp_msg = NULL;
   4.170 +    message* enc_msg = NULL;
   4.171 +
   4.172 +    status = mime_decode_message(mimetext, size, &tmp_msg);
   4.173 +    if (status != PEP_STATUS_OK)
   4.174 +        goto pEp_error;
   4.175 +
   4.176 +    // MIME decode message delivers only addresses. We need more.
   4.177 +    if (tmp_msg->from) {
   4.178 +        char* own_id = NULL;
   4.179 +        status = get_default_own_userid(session, &own_id);
   4.180 +        free(tmp_msg->from->user_id);
   4.181 +        
   4.182 +        if (status != PEP_STATUS_OK || !own_id) {
   4.183 +            tmp_msg->from->user_id = strdup(PEP_OWN_USERID);
   4.184 +        }
   4.185 +        else {
   4.186 +            tmp_msg->from->user_id = own_id; // ownership transfer
   4.187 +        }
   4.188 +            
   4.189 +        status = myself(session, tmp_msg->from);
   4.190 +        if (status != PEP_STATUS_OK)
   4.191 +            goto pEp_error;
   4.192 +    }
   4.193 +    
   4.194 +    // Own identities can be retrieved here where they would otherwise
   4.195 +    // fail because we lack all other information. This is ok and even
   4.196 +    // desired. FIXME: IS it?
   4.197 +    status = update_identity_recip_list(session, tmp_msg->to);
   4.198 +    if (status != PEP_STATUS_OK)
   4.199 +        goto pEp_error;
   4.200 +    
   4.201 +    status = update_identity_recip_list(session, tmp_msg->cc);
   4.202 +    if (status != PEP_STATUS_OK)
   4.203 +        goto pEp_error;
   4.204 +    
   4.205 +    status = update_identity_recip_list(session, tmp_msg->bcc);
   4.206 +    if (status != PEP_STATUS_OK)
   4.207 +        goto pEp_error;
   4.208 +    
   4.209 +    // This isn't incoming, though... so we need to reverse the direction
   4.210 +    tmp_msg->dir = PEP_dir_outgoing;
   4.211 +    status = encrypt_message(session,
   4.212 +                             tmp_msg,
   4.213 +                             extra,
   4.214 +                             &enc_msg,
   4.215 +                             enc_format,
   4.216 +                             flags);
   4.217 +                             
   4.218 +    if (status != PEP_STATUS_OK)
   4.219 +        goto pEp_error;
   4.220 +
   4.221 +
   4.222 +    if (!enc_msg) {
   4.223 +        status = PEP_UNKNOWN_ERROR;
   4.224 +        goto pEp_error;
   4.225 +    }
   4.226 +
   4.227 +    status = _mime_encode_message_internal(enc_msg, false, mime_ciphertext, false);
   4.228 +
   4.229 +pEp_error:
   4.230 +    free_message(tmp_msg);
   4.231 +    free_message(enc_msg);
   4.232 +
   4.233 +    return status;
   4.234 +
   4.235 +}
   4.236 +
   4.237 +PEP_STATUS MIME_encrypt_message_for_self(
   4.238 +    PEP_SESSION session,
   4.239 +    pEp_identity* target_id,
   4.240 +    const char *mimetext,
   4.241 +    size_t size,
   4.242 +    stringlist_t* extra,
   4.243 +    char** mime_ciphertext,
   4.244 +    PEP_enc_format enc_format,
   4.245 +    PEP_encrypt_flags_t flags
   4.246 +)
   4.247 +{
   4.248 +    PEP_STATUS status = PEP_STATUS_OK;
   4.249 +    message* tmp_msg = NULL;
   4.250 +    message* enc_msg = NULL;
   4.251 +
   4.252 +    status = mime_decode_message(mimetext, size, &tmp_msg);
   4.253 +    if (status != PEP_STATUS_OK)
   4.254 +        goto pEp_error;
   4.255 +
   4.256 +    // This isn't incoming, though... so we need to reverse the direction
   4.257 +    tmp_msg->dir = PEP_dir_outgoing;
   4.258 +    status = encrypt_message_for_self(session,
   4.259 +                                      target_id,
   4.260 +                                      tmp_msg,
   4.261 +                                      extra,
   4.262 +                                      &enc_msg,
   4.263 +                                      enc_format,
   4.264 +                                      flags);
   4.265 +    if (status != PEP_STATUS_OK)
   4.266 +        goto pEp_error;
   4.267 + 
   4.268 +    if (!enc_msg) {
   4.269 +        status = PEP_UNKNOWN_ERROR;
   4.270 +        goto pEp_error;
   4.271 +    }
   4.272 +
   4.273 +    status = mime_encode_message(enc_msg, false, mime_ciphertext);
   4.274 +
   4.275 +pEp_error:
   4.276 +    free_message(tmp_msg);
   4.277 +    free_message(enc_msg);
   4.278 +
   4.279 +    return status;
   4.280 +}