src/message_api.c
branchENGINE-633
changeset 4079 da3b0627a59c
parent 4077 7061fa6755ba
child 4080 2f2d566db998
     1.1 --- a/src/message_api.c	Sun Sep 22 15:02:37 2019 +0200
     1.2 +++ b/src/message_api.c	Sun Sep 22 21:41:35 2019 +0200
     1.3 @@ -1030,7 +1030,7 @@
     1.4      if (status != PEP_STATUS_OK)
     1.5          goto pEp_error;
     1.6  
     1.7 -    if (free_ptext){
     1.8 +    if (free_ptext){ 
     1.9          free(ptext);
    1.10          free_ptext=0;
    1.11      }
    1.12 @@ -1084,6 +1084,91 @@
    1.13      return status;
    1.14  }
    1.15  
    1.16 +static PEP_STATUS sign_PGP_MIME(
    1.17 +    PEP_SESSION session,
    1.18 +    const message *src,
    1.19 +    const char* sign_fpr,
    1.20 +    message *dst
    1.21 +    )
    1.22 +{
    1.23 +    PEP_STATUS status = PEP_STATUS_OK;
    1.24 +    char *stext = NULL;
    1.25 +    char *mimetext = NULL;
    1.26 +    size_t ssize;
    1.27 +    assert(dst->longmsg == NULL);
    1.28 +    dst->enc_format = PEP_enc_none;
    1.29 +
    1.30 +    if (src->shortmsg)
    1.31 +        dst->shortmsg = strdup(src->shortmsg);
    1.32 +        
    1.33 +    message *_src = calloc(1, sizeof(message));
    1.34 +    assert(_src);
    1.35 +    if (_src == NULL)
    1.36 +        goto enomem;
    1.37 +    _src->longmsg = src->longmsg;
    1.38 +    _src->longmsg_formatted = src->longmsg_formatted;
    1.39 +    _src->attachments = src->attachments;
    1.40 +    _src->enc_format = PEP_enc_none;
    1.41 +    
    1.42 +    // These vars are here to be clear, and because I don't know how this may change in the near future.
    1.43 +    status = _mime_encode_message_internal(_src, true, &mimetext, true, true);
    1.44 +    assert(status == PEP_STATUS_OK);
    1.45 +    if (status != PEP_STATUS_OK)
    1.46 +        goto pEp_error;
    1.47 +
    1.48 +    free(_src);
    1.49 +    _src = NULL;
    1.50 +    assert(mimetext);
    1.51 +    if (EMPTYSTR(mimetext))
    1.52 +        goto pEp_error;
    1.53 +        
    1.54 +    PEP_HASH_ALGO micalg = UNKNOWN_HASH_ALGO;
    1.55 +        
    1.56 +    status = sign_only(session, mimetext,
    1.57 +                       strlen(mimetext),
    1.58 +                       sign_fpr, 
    1.59 +                       &stext, &ssize, &micalg);
    1.60 +        
    1.61 +    if (stext == NULL)
    1.62 +        goto pEp_error;
    1.63 +
    1.64 +    dst->longmsg = strdup(mimetext);
    1.65 +    assert(dst->longmsg);
    1.66 +    if (dst->longmsg == NULL)
    1.67 +        goto enomem;
    1.68 +
    1.69 +    const char* micalg_string = get_micalg_string(micalg);
    1.70 +    if (!micalg_string) {
    1.71 +        status = PEP_UNKNOWN_ERROR;
    1.72 +        goto pEp_error;    
    1.73 +    }
    1.74 +        
    1.75 +    char *v = strdup(micalg_string);
    1.76 +    assert(v);
    1.77 +    if (v == NULL)
    1.78 +        goto enomem;
    1.79 +
    1.80 +    bloblist_t *_a = new_bloblist(v, strlen(v), "multipart/signed", NULL);
    1.81 +    if (_a == NULL)
    1.82 +        goto enomem;
    1.83 +    dst->attachments = _a;
    1.84 +
    1.85 +    _a = bloblist_add(_a, stext, ssize, "application/pgp-signature",
    1.86 +        "file://signature.asc");
    1.87 +    if (_a == NULL)
    1.88 +        goto enomem;
    1.89 +
    1.90 +    return PEP_STATUS_OK;
    1.91 +
    1.92 +enomem:
    1.93 +    status = PEP_OUT_OF_MEMORY;
    1.94 +
    1.95 +pEp_error:
    1.96 +    free(_src);
    1.97 +    free(stext);
    1.98 +    return status;
    1.99 +}
   1.100 +
   1.101  /*
   1.102  static bool _has_PGP_MIME_format(message* msg) {
   1.103      if (!msg || !msg->attachments || !msg->attachments->next)