Added get_message_trustwords()
authorEdouard Tisserant <edouard@pep-project.org>
Mon, 23 Jan 2017 22:48:20 +0100
changeset 1553e2d7706e2ff5
parent 1552 f67918d42218
child 1554 a62835de9daf
Added get_message_trustwords()
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Fri Jan 20 19:47:01 2017 +0100
     1.2 +++ b/src/message_api.c	Mon Jan 23 22:48:20 2017 +0100
     1.3 @@ -2354,6 +2354,113 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +DYNAMIC_API PEP_STATUS get_message_trustwords(
     1.8 +    PEP_SESSION session, 
     1.9 +    message *msg,
    1.10 +    stringlist_t *keylist,
    1.11 +    pEp_identity* received_by,
    1.12 +    const char* lang, char **words, bool full
    1.13 +)
    1.14 +{
    1.15 +    assert(session);
    1.16 +    assert(msg);
    1.17 +    assert(received_by);
    1.18 +    assert(received_by->address);
    1.19 +    assert(lang);
    1.20 +    assert(words);
    1.21 +
    1.22 +    if (!(session && 
    1.23 +          msg &&
    1.24 +          received_by && 
    1.25 +          received_by->address && 
    1.26 +          lang && 
    1.27 +          words))
    1.28 +        return PEP_ILLEGAL_VALUE;
    1.29 +    
    1.30 +    pEp_identity* partner;
    1.31 +     
    1.32 +    PEP_STATUS status = PEP_STATUS_OK;
    1.33 +    
    1.34 +    *words = NULL;
    1.35 +
    1.36 +    // We want fingerprint of key that did sign the message
    1.37 +
    1.38 +    if (keylist == NULL) {
    1.39 +
    1.40 +        // Message is to be decrypted
    1.41 +        message *dst;
    1.42 +        stringlist_t *_keylist = keylist;
    1.43 +        PEP_rating rating;
    1.44 +        PEP_decrypt_flags_t flags;
    1.45 +        status = decrypt_message( session, msg, &dst, &_keylist, &rating, &flags);
    1.46 +
    1.47 +        if (status != PEP_STATUS_OK) {
    1.48 +            free_message(dst);
    1.49 +            free_stringlist(_keylist);
    1.50 +            return status;
    1.51 +        }
    1.52 +
    1.53 +        if (dst && dst->from && _keylist) {
    1.54 +            partner = identity_dup(dst->from); 
    1.55 +            if(partner){
    1.56 +                free(partner->fpr);
    1.57 +                partner->fpr = strdup(_keylist->value);
    1.58 +                if (partner->fpr == NULL)
    1.59 +                    status = PEP_OUT_OF_MEMORY;
    1.60 +            } else {
    1.61 +                status = PEP_OUT_OF_MEMORY;
    1.62 +            }
    1.63 +        } else {
    1.64 +            status = PEP_UNKNOWN_ERROR;
    1.65 +        }
    1.66 +
    1.67 +        free_message(dst);
    1.68 +        free_stringlist(_keylist);
    1.69 +
    1.70 +    } else {
    1.71 +
    1.72 +        // Message already decrypted
    1.73 +        if (keylist->value) {
    1.74 +            partner = identity_dup(msg->from); 
    1.75 +            if(partner){
    1.76 +                free(partner->fpr);
    1.77 +                partner->fpr = strdup(keylist->value);
    1.78 +                if (partner->fpr == NULL)
    1.79 +                    status = PEP_OUT_OF_MEMORY;
    1.80 +            } else {
    1.81 +                status = PEP_OUT_OF_MEMORY;
    1.82 +            }
    1.83 +        } else {
    1.84 +            status = PEP_ILLEGAL_VALUE;
    1.85 +        }
    1.86 +    }
    1.87 +
    1.88 +    if (status != PEP_STATUS_OK) {
    1.89 +        free_identity(partner);
    1.90 +        return status;
    1.91 +    }
    1.92 +   
    1.93 +    // Find own identity corresponding to given account address.
    1.94 +    // In that case we want default key attached to own identity
    1.95 +    pEp_identity *stored_identity = NULL;
    1.96 +    status = get_identity(session,
    1.97 +                          received_by->address,
    1.98 +                          PEP_OWN_USERID,
    1.99 +                          &stored_identity);
   1.100 +
   1.101 +    if (status != PEP_STATUS_OK) {
   1.102 +        free_identity(stored_identity);
   1.103 +        return status;
   1.104 +    }
   1.105 +
   1.106 +    // get the trustwords
   1.107 +    size_t wsize;
   1.108 +    status = get_trustwords(session, 
   1.109 +                            partner, received_by, 
   1.110 +                            lang, words, &wsize, full);
   1.111 +
   1.112 +    return status;
   1.113 +}
   1.114  
   1.115  DYNAMIC_API PEP_STATUS MIME_decrypt_message(
   1.116      PEP_SESSION session,
     2.1 --- a/src/message_api.h	Fri Jan 20 19:47:01 2017 +0100
     2.2 +++ b/src/message_api.h	Mon Jan 23 22:48:20 2017 +0100
     2.3 @@ -339,6 +339,41 @@
     2.4      const char* lang, char **words, size_t *wsize, bool full
     2.5  );
     2.6  
     2.7 +// get_message_trustwords() - get full trustwords string for message sender and reciever identities 
     2.8 +//
     2.9 +//    parameters:
    2.10 +//        session (in)        session handle
    2.11 +//        msg (in)            message to get sender identity from
    2.12 +//        keylist (in)        NULL if message to be decrypted,
    2.13 +//                            keylist returned by decrypt_message() otherwise
    2.14 +//        received_by (in)    identity for account receiving message can't be NULL
    2.15 +//        lang (in)           C string with ISO 639-1 language code
    2.16 +//        words (out)         pointer to C string with all trustwords UTF-8 encoded,
    2.17 +//                            separated by a blank each
    2.18 +//                            NULL if language is not supported or trustword
    2.19 +//                            wordlist is damaged or unavailable
    2.20 +//        full (in)           if true, generate ALL trustwords for these identities.
    2.21 +//                            else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
    2.22 +//                            subset in next version)
    2.23 +//
    2.24 +//    return value:
    2.25 +//        PEP_STATUS_OK            trustwords retrieved
    2.26 +//        PEP_OUT_OF_MEMORY        out of memory
    2.27 +//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
    2.28 +//        error status of decrypt_message() if decryption fails.
    2.29 +//
    2.30 +//    caveat:
    2.31 +//        the word pointer goes to the ownership of the caller
    2.32 +//        the caller is responsible to free() it (on Windoze use pEp_free())
    2.33 +//
    2.34 +DYNAMIC_API PEP_STATUS get_message_trustwords(
    2.35 +    PEP_SESSION session, 
    2.36 +    message *msg,
    2.37 +    stringlist_t *keylist,
    2.38 +    pEp_identity* received_by,
    2.39 +    const char* lang, char **words, bool full
    2.40 +);
    2.41 +
    2.42  #ifdef __cplusplus
    2.43  }
    2.44  #endif