ENGINE-420: input checks done, but need to check old revision for attachment encryption details, so shelving changes ENGINE-420
authorKrista Bennett <krista@pep-project.org>
Wed, 11 Apr 2018 15:29:12 +0200
branchENGINE-420
changeset 25907067ba51ec76
parent 2589 3c5db90b50e8
child 2591 6f54f095b7ec
ENGINE-420: input checks done, but need to check old revision for attachment encryption details, so shelving changes
src/message_api.c
     1.1 --- a/src/message_api.c	Thu Apr 05 16:13:14 2018 +0200
     1.2 +++ b/src/message_api.c	Wed Apr 11 15:29:12 2018 +0200
     1.3 @@ -1812,6 +1812,90 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +
     1.8 +DYNAMIC_API PEP_STATUS encrypt_message_and_add_priv_key(
     1.9 +        PEP_SESSION session,
    1.10 +        message *src,
    1.11 +        message **dst,
    1.12 +        const char* to_fpr,
    1.13 +        PEP_enc_format enc_format
    1.14 +    )
    1.15 +{
    1.16 +    assert(session);
    1.17 +    assert(src);
    1.18 +    assert(dst);
    1.19 +    assert(to_fpr);
    1.20 +    
    1.21 +    if (!session || !src || !dst || !to_fpr)
    1.22 +        return PEP_ILLEGAL_VALUE;
    1.23 +        
    1.24 +    if (enc_format == PEP_enc_none)
    1.25 +        return PEP_ILLEGAL_VALUE;
    1.26 +    
    1.27 +    if (src->cc || src->bcc)
    1.28 +        return PEP_ILLEGAL_VALUE;
    1.29 +        
    1.30 +    if (!src->to || src->to->next)
    1.31 +        return PEP_ILLEGAL_VALUE;
    1.32 +        
    1.33 +    if (!src->from->address || !src->to->ident || !src->to->ident->address)
    1.34 +        return PEP_ILLEGAL_VALUE;
    1.35 +            
    1.36 +    if (!strcasecmp(src->from->address, src->to->ident->address) == 0)
    1.37 +        return PEP_ILLEGAL_VALUE;
    1.38 +    
    1.39 +    char* own_id = NULL;
    1.40 +    char* default_id = NULL;
    1.41 +    
    1.42 +    PEP_STATUS status = get_default_own_userid(session, &own_id);
    1.43 +    
    1.44 +    if (!own_id)
    1.45 +        return PEP_UNKNOWN_ERROR; // Probably a DB error at this point
    1.46 +        
    1.47 +    if (src->from->user_id) {
    1.48 +        if (strcmp(src->from->user_id, own_id) != 0) {
    1.49 +            status = get_userid_alias_default(session, src->from->user_id, &default_id);
    1.50 +            if (status != PEP_STATUS_OK || !default_id || strcmp(default_id, own_id) != 0) {
    1.51 +                status = PEP_ILLEGAL_VALUE;
    1.52 +                goto pep_free;
    1.53 +            }
    1.54 +        }        
    1.55 +    }
    1.56 +    
    1.57 +    // Ok, we are at least marginally sure the initial stuff is ok.
    1.58 +        
    1.59 +    // Let's get our own, normal identity
    1.60 +    pEp_identity* own_identity = NULL;
    1.61 +    status = get_identity(session, src->to->ident->address, own_id, own_identity);    
    1.62 +
    1.63 +    if (status != PEP_STATUS_OK)
    1.64 +        goto pep_free;
    1.65 +
    1.66 +    // Ok, now we know the address is an own address. All good. Then...
    1.67 +    char* own_private_fpr = own_identity->fpr;
    1.68 +    own_identity->fpr = strdup(to_fpr);
    1.69 +    
    1.70 +    status = get_trust(session, own_identity);
    1.71 +    
    1.72 +    if (status != PEP_STATUS_OK)
    1.73 +        goto pep_free;
    1.74 +        
    1.75 +    if ((own_identity->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed) {
    1.76 +        status = PEP_ILLEGAL_VALUE;
    1.77 +        goto pep_free;
    1.78 +    }
    1.79 +                
    1.80 +    // Ok, so all the things are now allowed.
    1.81 +    // So let's get our own private key and roll with it.
    1.82 +                
    1.83 +                
    1.84 +pep_free:
    1.85 +    free(own_id);
    1.86 +    free(default_id);
    1.87 +    return status;
    1.88 +}
    1.89 +
    1.90 +
    1.91  DYNAMIC_API PEP_STATUS encrypt_message_for_self(
    1.92          PEP_SESSION session,
    1.93          pEp_identity* target_id,