set PEP_ct_pEp if it's a pEp user
authorVolker Birk <vb@pep-project.org>
Thu, 30 Jun 2016 17:48:17 +0200
changeset 78121d47c8ae0ae
parent 776 c3428bcc5300
child 782 663f1d2c2f19
set PEP_ct_pEp if it's a pEp user
src/message_api.c
src/sync_fsm.h
test/message_api_test.cc
     1.1 --- a/src/message_api.c	Wed Jun 29 23:42:23 2016 +0200
     1.2 +++ b/src/message_api.c	Thu Jun 30 17:48:17 2016 +0200
     1.3 @@ -1181,6 +1181,35 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +static bool is_a_pEpmessage(const message *msg)
     1.8 +{
     1.9 +    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.10 +        if (strcasecmp(i->value->key, "X-pEp-Version") == 0)
    1.11 +            return true;
    1.12 +    }
    1.13 +    return false;
    1.14 +}
    1.15 +
    1.16 +// update comm_type to pEp_ct_pEp if needed
    1.17 +
    1.18 +static void _update_identity_for_incoming_message(
    1.19 +        PEP_SESSION session,
    1.20 +        const message *src
    1.21 +    )
    1.22 +{
    1.23 +    if (src->from && src->from->user_id && src->from->address) {
    1.24 +        update_identity(session, src->from);
    1.25 +        if (is_a_pEpmessage(src)
    1.26 +                && src->from->comm_type >= PEP_ct_OpenPGP_unconfirmed
    1.27 +                && src->from->comm_type != PEP_ct_pEp_unconfirmed
    1.28 +                && src->from->comm_type != PEP_ct_pEp)
    1.29 +        {
    1.30 +            src->from->comm_type |= PEP_ct_pEp_unconfirmed;
    1.31 +            update_identity(session, src->from);
    1.32 +        }
    1.33 +    }
    1.34 +}
    1.35 +
    1.36  DYNAMIC_API PEP_STATUS _decrypt_message(
    1.37          PEP_SESSION session,
    1.38          message *src,
    1.39 @@ -1217,9 +1246,7 @@
    1.40  
    1.41      // Update src->from in case we just imported a key
    1.42      // we would need to check signature
    1.43 -    if(src->from && src->from->user_id && src->from->address)
    1.44 -        update_identity(session, src->from);
    1.45 -
    1.46 +    _update_identity_for_incoming_message(session, src);
    1.47      PEP_cryptotech crypto = determine_encryption_format(src);
    1.48  
    1.49      *dst = NULL;
    1.50 @@ -1419,8 +1446,8 @@
    1.51  
    1.52              // Update msg->from in case we just imported a key
    1.53              // we would need to check signature
    1.54 -            if(msg->from && msg->from->user_id && msg->from->address)
    1.55 -                 update_identity(session, msg->from);
    1.56 +
    1.57 +            _update_identity_for_incoming_message(session, src);
    1.58              
    1.59              char *re_ptext = NULL;
    1.60              size_t re_psize;
     2.1 --- a/src/sync_fsm.h	Wed Jun 29 23:42:23 2016 +0200
     2.2 +++ b/src/sync_fsm.h	Thu Jun 30 17:48:17 2016 +0200
     2.3 @@ -68,7 +68,7 @@
     2.4  
     2.5  // driver
     2.6  
     2.7 -DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
     2.8 +PEP_STATUS fsm_DeviceState_inject(
     2.9          PEP_SESSION session,
    2.10          DeviceState_event event,
    2.11          Identity partner,
     3.1 --- a/test/message_api_test.cc	Wed Jun 29 23:42:23 2016 +0200
     3.2 +++ b/test/message_api_test.cc	Thu Jun 30 17:48:17 2016 +0200
     3.3 @@ -83,8 +83,14 @@
     3.4      assert(msg4);
     3.5      assert(keylist4);
     3.6      assert(color);
     3.7 +    PEP_comm_type ct = enc_msg2->from->comm_type;
     3.8 +    assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed);
     3.9 +
    3.10 +    free_stringpair_list(enc_msg2->opt_fields);
    3.11 +    enc_msg2->opt_fields = NULL;
    3.12  
    3.13      cout << "keys used:";
    3.14 +
    3.15      for (stringlist_t* kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
    3.16      {
    3.17          cout << " " << kl4->value;