Both functions in, tests next. Note that there was some kludgy things in check_signed_... because we need to decouple some MIME remnant post-processing from all of the en/decrypt sign/verify functions. That should be fied with refactoring. fdik_sync
authorKrista Bennett <krista@pep-project.org>
Fri, 17 Mar 2017 14:30:40 +0100
branchfdik_sync
changeset 1680fecf772e5842
parent 1679 09e74df2e875
child 1683 55b11374209d
Both functions in, tests next. Note that there was some kludgy things in check_signed_... because we need to decouple some MIME remnant post-processing from all of the en/decrypt sign/verify functions. That should be fied with refactoring.
src/message_api.c
     1.1 --- a/src/message_api.c	Thu Mar 16 16:12:36 2017 +0100
     1.2 +++ b/src/message_api.c	Fri Mar 17 14:30:40 2017 +0100
     1.3 @@ -1081,6 +1081,36 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +// FIXME; We unfortunately will have to do something like this.
     1.8 +// PEP_cryptotech determine_signing_format(message *msg)
     1.9 +// {
    1.10 +//     assert(msg);
    1.11 +// 
    1.12 +//     if (is_PGP_message_text(msg->longmsg)) {
    1.13 +//         msg->enc_format = PEP_enc_pieces;
    1.14 +//         return PEP_crypt_OpenPGP;
    1.15 +//     }
    1.16 +//     else if (msg->attachments && msg->attachments->next &&
    1.17 +//             is_mime_type(msg->attachments, "application/pgp-encrypted") &&
    1.18 +//             is_PGP_message_text(msg->attachments->next->value)
    1.19 +//         ) {
    1.20 +//         msg->enc_format = PEP_enc_PGP_MIME;
    1.21 +//         return PEP_crypt_OpenPGP;
    1.22 +//     }
    1.23 +//     else if (msg->attachments && msg->attachments->next &&
    1.24 +//             is_mime_type(msg->attachments->next, "application/pgp-encrypted") &&
    1.25 +//             is_PGP_message_text(msg->attachments->value)
    1.26 +//         ) {
    1.27 +//         msg->enc_format = PEP_enc_PGP_MIME_Outlook1;
    1.28 +//         return PEP_crypt_OpenPGP;
    1.29 +//     }
    1.30 +//     else {
    1.31 +//         msg->enc_format = PEP_enc_none;
    1.32 +//         return PEP_crypt_none;
    1.33 +//     }
    1.34 +// }
    1.35 +// 
    1.36 +
    1.37  
    1.38  PEP_STATUS sign_message(PEP_SESSION session,
    1.39                          message *src,
    1.40 @@ -1777,28 +1807,35 @@
    1.41          }
    1.42      }
    1.43  
    1.44 -    if (detached_sig) {
    1.45 -        dsig_text = detached_sig->value;
    1.46 -        dsig_size = detached_sig->size;
    1.47 -        size_t ssize = 0;
    1.48 -        char* stext = NULL;
    1.49 -
    1.50 -        // FIXME
    1.51 -        status = _get_signed_text(ptext, psize, &stext, &ssize);
    1.52 -        stringlist_t *_verify_keylist = NULL;
    1.53 -
    1.54 -        if (ssize > 0 && stext) {
    1.55 -            status = cryptotech[crypto].verify_text(session, stext,
    1.56 -                                                    ssize, dsig_text, dsig_size,
    1.57 -                                                    &_verify_keylist);
    1.58 -
    1.59 -        }
    1.60 +    dsig_text = detached_sig->value;
    1.61 +    dsig_size = detached_sig->size;
    1.62 +    //FIXME: what if it's empty text? This is wrong. Find a better fix.
    1.63 +    bool use_longmsg_formatted = ((!src->longmsg || src->longmsg[0] == '\0') &&
    1.64 +                                  src->longmsg_formatted &&
    1.65 +                                  src->longmsg_formatted[0] != '\0'); 
    1.66 +    char* stext = (use_longmsg_formatted ? src->longmsg_formatted : src->longmsg);
    1.67 +    size_t ssize = strlen(stext);
    1.68 +
    1.69 +    // FIXME
    1.70 +    //const char* plaintext = (src->longmsg ? src->longmsg : src->longmsg_formatted); // OK?
    1.71 +    //status = _get_signed_text(plaintext, strlen(plaintext), &stext, &ssize);
    1.72 +    //FIXME: this is again about MIME. We need to make sure MIME/mail issues are sanitised out
    1.73 +    // before we get this far
    1.74 +    stringlist_t *_verify_keylist = NULL;
    1.75 +
    1.76 +    if (ssize > 0 && stext) {
    1.77 +        // FIXME!!!!!!!!!!!!!!!!!!!!!
    1.78 +        status = cryptotech[PEP_crypt_OpenPGP].verify_text(session, stext,
    1.79 +                                                ssize, dsig_text, dsig_size,
    1.80 +                                                &_verify_keylist);
    1.81 +
    1.82      }
    1.83 -    if (status != PEP_VERIFIED && status != PEP_VERIFIED_AND_TRUSTED) {
    1.84 -        status = cryptotech[crypto].verify_text(session, stext,
    1.85 -                                                ssize, NULL, NULL,
    1.86 -                                                &_verify_keylist);        
    1.87 -    }
    1.88 +
    1.89 +    // if (status != PEP_VERIFIED && status != PEP_VERIFIED_AND_TRUSTED) {
    1.90 +    //     status = cryptotech[crypto].verify_text(session, stext,
    1.91 +    //                                             ssize, NULL, NULL,
    1.92 +    //                                             &_verify_keylist);        
    1.93 +    // }
    1.94      
    1.95      if (status == PEP_VERIFIED || status == PEP_VERIFIED_AND_TRUSTED) {
    1.96          // FIXME: free stext et al ??
    1.97 @@ -1810,7 +1847,7 @@
    1.98              return PEP_UNKNOWN_ERROR; // Still would be a bug...
    1.99          }
   1.100          // FIXME - check stringlist_t ownership
   1.101 -        signing_key_ptr == strdup(retfpr);
   1.102 +        signing_key_ptr = strdup(retfpr);
   1.103      }
   1.104  
   1.105      return status;