merge sync IOSAD-111
authorDirk Zimmermann <dz@pep.security>
Fri, 03 May 2019 15:42:36 +0200
branchIOSAD-111
changeset 3618d486cda725b1
parent 3613 f330f7da89c5
parent 3617 3d6f394c9a6c
child 3619 dab3207c2d7d
merge sync
     1.1 --- a/src/message_api.c	Fri May 03 12:41:06 2019 +0200
     1.2 +++ b/src/message_api.c	Fri May 03 15:42:36 2019 +0200
     1.3 @@ -2896,23 +2896,30 @@
     1.4  }
     1.5  
     1.6  static PEP_STATUS import_priv_keys_from_decrypted_msg(PEP_SESSION session,
     1.7 -                                                      message* src, 
     1.8                                                        message* msg,
     1.9                                                        bool* imported_keys,
    1.10                                                        bool* imported_private,
    1.11 -                                                      identity_list** private_il) {
    1.12 -                                                          
    1.13 +                                                      identity_list** private_il)
    1.14 +{
    1.15 +    assert(msg && imported_keys && imported_private);
    1.16 +    if (!(msg && imported_keys && imported_private))
    1.17 +        return PEP_ILLEGAL_VALUE;
    1.18 +
    1.19      PEP_STATUS status = PEP_STATUS_OK;
    1.20 -    
    1.21 +    *imported_keys = NULL;
    1.22 +    *imported_private = false;
    1.23 +    if (private_il)
    1.24 +        *private_il = NULL;
    1.25 +
    1.26      // check for private key in decrypted message attachment while importing
    1.27      identity_list *_private_il = NULL;
    1.28 -    *imported_keys = import_attached_keys(session, msg, &_private_il);
    1.29 -    
    1.30 -    if (_private_il && identity_list_length(_private_il) == 1 &&
    1.31 -        _private_il->ident->address)
    1.32 -        *imported_private = true;
    1.33 -
    1.34 -    if (private_il && imported_private) {
    1.35 +
    1.36 +    bool _imported_keys = import_attached_keys(session, msg, &_private_il);
    1.37 +    bool _imported_private = false;
    1.38 +    if (_private_il && _private_il->ident && _private_il->ident->address)
    1.39 +        _imported_private = true;
    1.40 +
    1.41 +    if (private_il && _imported_private) {
    1.42          // the private identity list should NOT be subject to myself() or
    1.43          // update_identity() at this point.
    1.44          // If the receiving app wants them to be in the trust DB, it
    1.45 @@ -2922,27 +2929,31 @@
    1.46          char* own_id = NULL;
    1.47          status = get_default_own_userid(session, &own_id);
    1.48          
    1.49 -        if (status != PEP_STATUS_OK) {
    1.50 -            free(own_id);
    1.51 -            own_id = NULL;
    1.52 -        }
    1.53 -        
    1.54 -        identity_list* il = _private_il;
    1.55 -        for ( ; il; il = il->next) {
    1.56 +        for (identity_list* il = _private_il; il; il = il->next) {
    1.57              if (own_id) {
    1.58                  free(il->ident->user_id);
    1.59                  il->ident->user_id = strdup(own_id);
    1.60 +                assert(il->ident->user_id);
    1.61 +                if (!il->ident->user_id) {
    1.62 +                    status = PEP_OUT_OF_MEMORY;
    1.63 +                    break;
    1.64 +                }
    1.65              }
    1.66              il->ident->me = true;
    1.67          }
    1.68 -        *private_il = _private_il;
    1.69 -        
    1.70          free(own_id);
    1.71 +        if (!status)
    1.72 +            *private_il = _private_il;
    1.73      }
    1.74 -    else
    1.75 +    else {
    1.76          free_identity_list(_private_il);
    1.77 +    }
    1.78   
    1.79 -    
    1.80 +    if (!status) {
    1.81 +        *imported_keys = _imported_keys;
    1.82 +        *imported_private = _imported_private;
    1.83 +    }
    1.84 +
    1.85      return status;
    1.86  }
    1.87  
    1.88 @@ -3243,7 +3254,7 @@
    1.89  
    1.90  }
    1.91  
    1.92 -DYNAMIC_API PEP_STATUS _decrypt_message(
    1.93 +static PEP_STATUS _decrypt_message(
    1.94          PEP_SESSION session,
    1.95          message *src,
    1.96          message **dst,
    1.97 @@ -3426,7 +3437,7 @@
    1.98                  //
    1.99                  // We are importing from the decrypted outermost message now.
   1.100                  //
   1.101 -                status = import_priv_keys_from_decrypted_msg(session, src, msg,
   1.102 +                status = import_priv_keys_from_decrypted_msg(session, msg,
   1.103                                                               &imported_keys,
   1.104                                                               &imported_private_key_address,
   1.105                                                               private_il);
   1.106 @@ -3553,7 +3564,7 @@
   1.107                                              private_il = NULL;
   1.108                                              
   1.109                                              // import keys from decrypted INNER source
   1.110 -                                            status = import_priv_keys_from_decrypted_msg(session, src, inner_message,
   1.111 +                                            status = import_priv_keys_from_decrypted_msg(session, inner_message,
   1.112                                                                                           &imported_keys,
   1.113                                                                                           &imported_private_key_address,
   1.114                                                                                           private_il);
     2.1 --- a/sync/gen_message_func.ysl2	Fri May 03 12:41:06 2019 +0200
     2.2 +++ b/sync/gen_message_func.ysl2	Fri May 03 15:42:36 2019 +0200
     2.3 @@ -117,6 +117,8 @@
     2.4      free(session->«yml:lcase(@name)»_state.common.signature_fpr);
     2.5      free_stringlist(session->own_«yml:lcase(@name)»_state.own_keys);
     2.6      free_identity_list(session->own_«yml:lcase(@name)»_state.own_identities);
     2.7 +    session->own_«yml:lcase(@name)»_state.own_keys = NULL;
     2.8 +    session->own_«yml:lcase(@name)»_state.own_identities = NULL;
     2.9  
    2.10  ||
    2.11  for "fsm"