ENGINE-214: first run at encrypt/decrypt with wrapper info in plaintext. Compiles, but hangs during runtime. And so begins the long debugging haul... ENGINE-214
authorKrista Bennett <krista@pep-project.org>
Thu, 05 Oct 2017 11:41:16 +0200
branchENGINE-214
changeset 21359efe970213f2
parent 2131 334139882a97
child 2136 a56043e01864
ENGINE-214: first run at encrypt/decrypt with wrapper info in plaintext. Compiles, but hangs during runtime. And so begins the long debugging haul...
src/message_api.c
     1.1 --- a/src/message_api.c	Tue Oct 03 17:00:37 2017 +0200
     1.2 +++ b/src/message_api.c	Thu Oct 05 11:41:16 2017 +0200
     1.3 @@ -532,7 +532,7 @@
     1.4      const char* msg_wrap_info = (flags & PEP_encrypt_flag_no_wrap_message ? 
     1.5                                   "OUTER" : "INNER");
     1.6      
     1.7 -    ptext = encapsulate_message_wrap_info(const char *msg_wrap_info, src->longmsg);
     1.8 +    ptext = encapsulate_message_wrap_info(msg_wrap_info, src->longmsg);
     1.9          
    1.10      message *_src = calloc(1, sizeof(message));
    1.11      assert(_src);
    1.12 @@ -1894,7 +1894,7 @@
    1.13      return false;
    1.14  }
    1.15  
    1.16 -static PEP_STATUS unencapsulate_hidden_fields(message* src, message* msg
    1.17 +static PEP_STATUS unencapsulate_hidden_fields(message* src, message* msg,
    1.18                                                char** msg_wrap_info) {
    1.19      unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.20      PEP_STATUS status = PEP_STATUS_OK;
    1.21 @@ -1912,15 +1912,18 @@
    1.22              //     _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0)
    1.23              if (is_a_pEpmessage(src))
    1.24              {
    1.25 -                char * shortmsg;
    1.26 -                char * longmsg;
    1.27 -                int r = separate_short_and_long(msg->longmsg, 
    1.28 -                                                &shortmsg, 
    1.29 -                                                *msg_wrap_info,
    1.30 -                                                &longmsg);
    1.31 +                char * shortmsg = NULL;
    1.32 +                char * longmsg = NULL;
    1.33                  
    1.34 -                if (r == -1)
    1.35 -                    return PEP_OUT_OF_MEMORY;
    1.36 +                if (msg->longmsg) {
    1.37 +                    int r = separate_short_and_long(msg->longmsg, 
    1.38 +                                                    &shortmsg, 
    1.39 +                                                    msg_wrap_info,
    1.40 +                                                    &longmsg);
    1.41 +                
    1.42 +                    if (r == -1)
    1.43 +                        return PEP_OUT_OF_MEMORY;
    1.44 +                }
    1.45  
    1.46                  // We only use the shortmsg in version 1.0 messages; if it occurs where we
    1.47                  // didn't replace the subject, we ignore this all
    1.48 @@ -2308,15 +2311,65 @@
    1.49                  NOT_IMPLEMENTED
    1.50          }
    1.51  
    1.52 -        char* wrap_info = NULL:
    1.53 -        status = unencapsulate_hidden_fields(src, msg, &wrap_info);
    1.54 -        
    1.55          if (status == PEP_OUT_OF_MEMORY)
    1.56              goto enomem;
    1.57              
    1.58          if (status != PEP_STATUS_OK)
    1.59              goto pep_error;
    1.60  
    1.61 +        if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.62 +            char* wrap_info = NULL;
    1.63 +            status = unencapsulate_hidden_fields(src, msg, &wrap_info);
    1.64 +            
    1.65 +            // FIXME: replace with enums, check status
    1.66 +            if (wrap_info) {
    1.67 +                if (strcmp(wrap_info, "OUTER") == 0) {
    1.68 +                    // this only occurs in with a direct outer wrapper
    1.69 +                    // where the actual content is in the inner wrapper
    1.70 +                    
    1.71 +                    bloblist_t* actual_message = msg->attachments;
    1.72 +                    
    1.73 +                    while (actual_message) {
    1.74 +                        char* mime_type = actual_message->mime_type;
    1.75 +                        if (mime_type) {
    1.76 +                            if (strcmp("message/rfc822", mime_type) == 0)
    1.77 +                                break;
    1.78 +                        }
    1.79 +                        actual_message = actual_message->next;
    1.80 +                    }
    1.81 +                    
    1.82 +                    if (actual_message) {
    1.83 +                        message* inner_message = NULL;
    1.84 +                        status = mime_decode_message(actual_message->value, 
    1.85 +                                                     actual_message->size, 
    1.86 +                                                     &inner_message);
    1.87 +                        if (status != PEP_STATUS_OK)
    1.88 +                            GOTO(pep_error);
    1.89 +                            
    1.90 +                        free_stringlist(*keylist);
    1.91 +                        *keylist == NULL;
    1.92 +                        
    1.93 +                        free_message(*dst);
    1.94 +                        
    1.95 +                        *dst = NULL;
    1.96 +                        *rating = PEP_rating_undefined;
    1.97 +                        *flags = 0;
    1.98 +
    1.99 +                        message* inner_dec_msg = NULL;
   1.100 +                        
   1.101 +                        PEP_STATUS decrypt_status = decrypt_message(session,
   1.102 +                                                                    inner_message,
   1.103 +                                                                    &inner_dec_msg,
   1.104 +                                                                    keylist,
   1.105 +                                                                    rating,
   1.106 +                                                                    flags);
   1.107 +                        *dst = inner_dec_msg;
   1.108 +                        return decrypt_status;
   1.109 +                    }
   1.110 +                }
   1.111 +            }
   1.112 +        }
   1.113 +        
   1.114          *rating = decrypt_rating(decrypt_status);
   1.115  
   1.116          /* Ok, now we have a keylist used for decryption/verification.