untested commit, first impl of top-level sign_message func, compiles but definitely doesn't run (no sign_text() for crypt and friends) fdik_sync
authorKrista Grothoff <krista@pep-project.org>
Wed, 15 Mar 2017 14:16:43 +0100
branchfdik_sync
changeset 1672d4820ecaf7a2
parent 1671 78b34f2843d1
child 1673 559931685411
untested commit, first impl of top-level sign_message func, compiles but definitely doesn't run (no sign_text() for crypt and friends)
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Wed Mar 15 11:02:01 2017 +0100
     1.2 +++ b/src/message_api.c	Wed Mar 15 14:16:43 2017 +0100
     1.3 @@ -1081,6 +1081,7 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +
     1.8  PEP_STATUS sign_message(PEP_SESSION session,
     1.9                          message *src,
    1.10                          message **dst
    1.11 @@ -1090,6 +1091,119 @@
    1.12          return PEP_ILLEGAL_VALUE;
    1.13          
    1.14      PEP_STATUS status = PEP_KEY_NOT_FOUND;                         
    1.15 +
    1.16 +    assert(session);
    1.17 +    assert(src);
    1.18 +    assert(dst);
    1.19 +
    1.20 +    if (!(session && src && dst))
    1.21 +        return PEP_ILLEGAL_VALUE;
    1.22 +
    1.23 +    if (src->dir == PEP_dir_incoming || !(src->from))
    1.24 +        return PEP_ILLEGAL_VALUE;
    1.25 +
    1.26 +    message * msg = NULL;
    1.27 +    stringlist_t * keys = NULL;
    1.28 +
    1.29 +    determine_encryption_format(src);
    1.30 +    if (src->enc_format != PEP_enc_none)
    1.31 +        return PEP_ILLEGAL_VALUE;
    1.32 +
    1.33 +    *dst = NULL;
    1.34 +
    1.35 +    status = myself(session, src->from);
    1.36 +    if (status != PEP_STATUS_OK)
    1.37 +        goto pep_error;
    1.38 +
    1.39 +    if (!src->from->fpr)
    1.40 +        return PEP_KEY_NOT_FOUND;
    1.41 +        
    1.42 +    keys = new_stringlist(src->from->fpr);
    1.43 +    if (keys == NULL)
    1.44 +        goto enomem;
    1.45 +
    1.46 +    msg = clone_to_empty_message(src);
    1.47 +    if (msg == NULL)
    1.48 +        goto enomem;
    1.49 +
    1.50 +    attach_own_key(session, src);
    1.51 +
    1.52 +    char *ptext = NULL;
    1.53 +    char *ctext = NULL;
    1.54 +    char *mimetext = NULL;
    1.55 +    size_t csize;
    1.56 +    assert(dst->longmsg == NULL);
    1.57 +    msg->enc_format = PEP_enc_none;
    1.58 +
    1.59 +    msg->shortmsg = strdup(src->shortmsg);
    1.60 +    assert(msg->shortmsg);
    1.61 +    if (msg->shortmsg == NULL)
    1.62 +        goto enomem;
    1.63 +    ptext = src->longmsg;
    1.64 +
    1.65 +    message *_src = calloc(1, sizeof(message));
    1.66 +    assert(_src);
    1.67 +    if (_src == NULL)
    1.68 +        goto enomem;
    1.69 +    _src->longmsg = ptext;
    1.70 +    _src->longmsg_formatted = src->longmsg_formatted;
    1.71 +    _src->attachments = src->attachments; // key will get attached here
    1.72 +    _src->enc_format = PEP_enc_none;
    1.73 +    status = mime_encode_message(_src, true, &mimetext);
    1.74 +    assert(status == PEP_STATUS_OK);
    1.75 +    if (status != PEP_STATUS_OK)
    1.76 +        goto pep_error;
    1.77 +
    1.78 +    free(_src);
    1.79 +    assert(mimetext);
    1.80 +    if (mimetext == NULL)
    1.81 +        goto pep_error;
    1.82 +
    1.83 +    status = sign_text(session, keys, mimetext, strlen(mimetext),
    1.84 +                       &ctext, &csize);
    1.85 +                       
    1.86 +    free(mimetext);
    1.87 +                       
    1.88 +    if (status == PEP_OUT_OF_MEMORY)
    1.89 +        goto enomem;
    1.90 +
    1.91 +    if (status != PEP_STATUS_OK || ctext == NULL)
    1.92 +       goto pep_error;
    1.93 +
    1.94 +    msg->longmsg = strndup(ctext, csize);
    1.95 +    assert(msg->longmsg);
    1.96 +    if (msg->longmsg == NULL)
    1.97 +        goto enomem;
    1.98 +
    1.99 +    free_stringlist(keys);
   1.100 +
   1.101 +    if (msg && msg->shortmsg == NULL) {
   1.102 +        msg->shortmsg = strdup(src->shortmsg);
   1.103 +        assert(msg->shortmsg);
   1.104 +        if (msg->shortmsg == NULL)
   1.105 +            goto enomem;
   1.106 +    }
   1.107 +
   1.108 +    if (msg) {
   1.109 +        decorate_message(msg, PEP_rating_undefined, NULL);
   1.110 +        if (src->id) {
   1.111 +            msg->id = strdup(src->id);
   1.112 +            assert(msg->id);
   1.113 +            if (msg->id == NULL)
   1.114 +                goto enomem;
   1.115 +        }
   1.116 +    }
   1.117 +
   1.118 +    *dst = msg;
   1.119 +    return status;
   1.120 +
   1.121 +enomem:
   1.122 +    status = PEP_OUT_OF_MEMORY;
   1.123 +
   1.124 +pep_error:
   1.125 +    free_stringlist(keys);
   1.126 +    free_message(msg);
   1.127 +
   1.128      return status;
   1.129  }
   1.130  
   1.131 @@ -1102,7 +1216,7 @@
   1.132          return PEP_ILLEGAL_VALUE;
   1.133   
   1.134      PEP_STATUS status = PEP_VERIFY_NO_KEY;
   1.135 -    signing_key_ptr = NULL:
   1.136 +    signing_key_ptr = NULL;
   1.137      return status;                              
   1.138  }
   1.139  
     2.1 --- a/src/message_api.h	Wed Mar 15 11:02:01 2017 +0100
     2.2 +++ b/src/message_api.h	Wed Mar 15 14:16:43 2017 +0100
     2.3 @@ -25,7 +25,7 @@
     2.4  
     2.5  PEP_STATUS check_signed_message(PEP_SESSION session,
     2.6                                  message *src,
     2.7 -                                char* signing_key);
     2.8 +                                char** signing_key);
     2.9  
    2.10  PEP_cryptotech determine_encryption_format(message *msg);
    2.11  void add_opt_field(message *msg, const char *name, const char *value);