Merge with sync sequoia_windows
authorThomas
Thu, 04 Jul 2019 08:08:00 +0200
branchsequoia_windows
changeset 3895eeb2f18965e1
parent 3888 99d255a8dc60
parent 3894 9dbd6ed542da
child 3903 abaab1748cc1
Merge with sync
src/pgp_sequoia.c
     1.1 --- a/build-mac/pEpEngine.xcodeproj/project.pbxproj	Thu Jun 27 15:40:53 2019 +0200
     1.2 +++ b/build-mac/pEpEngine.xcodeproj/project.pbxproj	Thu Jul 04 08:08:00 2019 +0200
     1.3 @@ -1155,7 +1155,7 @@
     1.4  				ONLY_ACTIVE_ARCH = YES;
     1.5  				OTHER_CFLAGS = "-DSQLITE3_FROM_OS";
     1.6  				SDKROOT = iphoneos;
     1.7 -				VALID_ARCHS = "arm64 armv7s armv7";
     1.8 +				VALID_ARCHS = "$(VALID_ARCHS) x86_64";
     1.9  			};
    1.10  			name = Debug;
    1.11  		};
    1.12 @@ -1214,7 +1214,7 @@
    1.13  				OTHER_CFLAGS = "-DSQLITE3_FROM_OS";
    1.14  				SDKROOT = iphoneos;
    1.15  				VALIDATE_PRODUCT = YES;
    1.16 -				VALID_ARCHS = "arm64 armv7s armv7";
    1.17 +				VALID_ARCHS = "$(VALID_ARCHS) x86_64";
    1.18  			};
    1.19  			name = Release;
    1.20  		};
     2.1 --- a/src/identity_list.c	Thu Jun 27 15:40:53 2019 +0200
     2.2 +++ b/src/identity_list.c	Thu Jul 04 08:08:00 2019 +0200
     2.3 @@ -108,6 +108,23 @@
     2.4      return list_curr->next;
     2.5  }
     2.6  
     2.7 +// returns *head* of list
     2.8 +DYNAMIC_API identity_list* identity_list_join(identity_list *first_list, identity_list *second_list) {
     2.9 +    if (!first_list) {
    2.10 +        if (!second_list)
    2.11 +            return NULL;
    2.12 +        return second_list;
    2.13 +    }
    2.14 +    if (second_list) {
    2.15 +        identity_list* list_curr = first_list;
    2.16 +        while (list_curr->next)
    2.17 +            list_curr = list_curr->next;    
    2.18 +            
    2.19 +        list_curr->next = second_list;
    2.20 +    }        
    2.21 +    return first_list;    
    2.22 +}
    2.23 +
    2.24  DYNAMIC_API int identity_list_length(const identity_list *id_list)
    2.25  {
    2.26      int len = 0;
     3.1 --- a/src/identity_list.h	Thu Jun 27 15:40:53 2019 +0200
     3.2 +++ b/src/identity_list.h	Thu Jul 04 08:08:00 2019 +0200
     3.3 @@ -63,6 +63,16 @@
     3.4  
     3.5  DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
     3.6  
     3.7 +// identity_list_add - join second identity_list to the first.
     3.8 +//
     3.9 +//  parameters:
    3.10 +//      first_list (in)             identity_list to add to
    3.11 +//      second_list (in)            identity list to add
    3.12 +//
    3.13 +//  return value:
    3.14 +//      pointer to the HEAD of the new list, or NULL if both lists are empty.
    3.15 +//
    3.16 +DYNAMIC_API identity_list *identity_list_join(identity_list *first_list, identity_list* second_list);
    3.17  
    3.18  // identity_list_length() - get length of identity_list
    3.19  //
    3.20 @@ -73,9 +83,7 @@
    3.21  //      length of identity_list in number of elements
    3.22  
    3.23  DYNAMIC_API int identity_list_length(const identity_list *id_list);
    3.24 -
    3.25 -
    3.26 +    
    3.27  #ifdef __cplusplus
    3.28  }
    3.29  #endif
    3.30 -
     4.1 --- a/src/keymanagement.c	Thu Jun 27 15:40:53 2019 +0200
     4.2 +++ b/src/keymanagement.c	Thu Jul 04 08:08:00 2019 +0200
     4.3 @@ -495,7 +495,7 @@
     4.4          stored_ident->fpr = NULL;
     4.5          stored_ident->comm_type = PEP_ct_key_not_found;        
     4.6      }
     4.7 -    else {
     4.8 +    else { // no key returned, but status ok?
     4.9          if (stored_ident->comm_type == PEP_ct_unknown)
    4.10              stored_ident->comm_type = PEP_ct_key_not_found;
    4.11      }
     5.1 --- a/src/pEpEngine.h	Thu Jun 27 15:40:53 2019 +0200
     5.2 +++ b/src/pEpEngine.h	Thu Jul 04 08:08:00 2019 +0200
     5.3 @@ -60,6 +60,7 @@
     5.4      PEP_KEY_IMPORTED                                = 0x0220,
     5.5      PEP_NO_KEY_IMPORTED                             = 0x0221,
     5.6      PEP_KEY_IMPORT_STATUS_UNKNOWN                   = 0x0222,
     5.7 +    PEP_SOME_KEYS_IMPORTED                          = 0x0223,
     5.8      
     5.9      PEP_CANNOT_FIND_IDENTITY                        = 0x0301,
    5.10      PEP_CANNOT_SET_PERSON                           = 0x0381,
     6.1 --- a/src/pgp_sequoia.c	Thu Jun 27 15:40:53 2019 +0200
     6.2 +++ b/src/pgp_sequoia.c	Thu Jul 04 08:08:00 2019 +0200
     6.3 @@ -1868,7 +1868,22 @@
     6.4      return status;
     6.5  }
     6.6  
     6.7 -PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
     6.8 +static unsigned int count_keydata_parts(const char* key_data) {
     6.9 +    unsigned int retval = 0;
    6.10 +    
    6.11 +    const char* pgp_begin = "-----BEGIN PGP";
    6.12 +    size_t prefix_len = strlen(pgp_begin);
    6.13 +    while (key_data) {
    6.14 +        key_data = strstr(key_data, pgp_begin);
    6.15 +        if (key_data) {
    6.16 +            retval++;
    6.17 +            key_data += prefix_len;
    6.18 +        }
    6.19 +    }
    6.20 +    return retval;
    6.21 + }
    6.22 +
    6.23 +PEP_STATUS _pgp_import_keydata(PEP_SESSION session, const char *key_data,
    6.24                                size_t size, identity_list **private_idents)
    6.25  {
    6.26      PEP_STATUS status = PEP_NO_KEY_IMPORTED;
    6.27 @@ -2000,6 +2015,71 @@
    6.28      return status;
    6.29  }
    6.30  
    6.31 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
    6.32 +                              size_t size, identity_list **private_idents)
    6.33 +{
    6.34 +    unsigned int keycount = count_keydata_parts(key_data);
    6.35 +    if (keycount < 2)
    6.36 +        return(_pgp_import_keydata(session, key_data, size, private_idents));
    6.37 +
    6.38 +    const char* pgp_begin = "-----BEGIN PGP";
    6.39 +    size_t prefix_len = strlen(pgp_begin);
    6.40 +        
    6.41 +    unsigned int i;
    6.42 +    const char* curr_begin;
    6.43 +    size_t curr_size;
    6.44 +    
    6.45 +    identity_list* collected_idents = NULL;        
    6.46 +    
    6.47 +    PEP_STATUS retval = PEP_KEY_IMPORTED;
    6.48 +    
    6.49 +    for (i = 0, curr_begin = key_data; i < keycount; i++) {
    6.50 +        const char* next_begin = strstr(curr_begin + prefix_len, pgp_begin);
    6.51 +        if (next_begin)
    6.52 +            curr_size = next_begin - curr_begin;
    6.53 +        else
    6.54 +            curr_size = (key_data + size) - curr_begin;
    6.55 +        
    6.56 +        PEP_STATUS curr_status = _pgp_import_keydata(session, curr_begin, curr_size, private_idents);
    6.57 +        if (private_idents && *private_idents) {
    6.58 +            if (!collected_idents)
    6.59 +                collected_idents = *private_idents;
    6.60 +            else 
    6.61 +                identity_list_join(collected_idents, *private_idents);
    6.62 +            *private_idents = NULL;    
    6.63 +        }
    6.64 +        
    6.65 +        if (curr_status != retval) {
    6.66 +            switch (curr_status) {
    6.67 +                case PEP_NO_KEY_IMPORTED:
    6.68 +                case PEP_KEY_NOT_FOUND:
    6.69 +                case PEP_UNKNOWN_ERROR:
    6.70 +                    switch (retval) {
    6.71 +                        case PEP_KEY_IMPORTED:
    6.72 +                            retval = PEP_SOME_KEYS_IMPORTED;
    6.73 +                            break;
    6.74 +                        case PEP_UNKNOWN_ERROR:
    6.75 +                            retval = curr_status;
    6.76 +                            break;
    6.77 +                        default:
    6.78 +                            break;
    6.79 +                    }
    6.80 +                    break;
    6.81 +                case PEP_KEY_IMPORTED:
    6.82 +                    retval = PEP_SOME_KEYS_IMPORTED;
    6.83 +                default:
    6.84 +                    break;
    6.85 +            }        
    6.86 +        }        
    6.87 +        curr_begin = next_begin;     
    6.88 +    }
    6.89 +    
    6.90 +    if (private_idents)
    6.91 +        *private_idents = collected_idents;
    6.92 +    
    6.93 +    return retval;    
    6.94 +}
    6.95 +
    6.96  PEP_STATUS pgp_export_keydata(
    6.97          PEP_SESSION session, const char *fpr, char **key_data, size_t *size,
    6.98          bool secret)
    6.99 @@ -2512,6 +2592,22 @@
   6.100  
   6.101      // Is the TPK live?
   6.102      *expired = !pgp_tpk_alive_at(tpk, when);
   6.103 +#ifdef TRACING
   6.104 +    {
   6.105 +        char buffer[26];
   6.106 +        time_t now = time(NULL);
   6.107 +
   6.108 +        if (when == now || when == now - 1) {
   6.109 +            sprintf(buffer, "now");
   6.110 +        } else {
   6.111 +            struct tm tm;
   6.112 +            gmtime_r(&when, &tm);
   6.113 +            strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
   6.114 +        }
   6.115 +
   6.116 +        T("TPK is %slive as of %s", *expired ? "not " : "", buffer);
   6.117 +    }
   6.118 +#endif
   6.119      if (*expired)
   6.120          goto out;
   6.121  
   6.122 @@ -2542,9 +2638,15 @@
   6.123  
   6.124      *expired = !(can_encrypt && can_sign && can_certify);
   6.125  
   6.126 +    T("Key can%s encrypt, can%s sign, can%s certify => %sexpired",
   6.127 +      can_encrypt ? "" : "not",
   6.128 +      can_sign ? "" : "not",
   6.129 +      can_certify ? "" : "not",
   6.130 +      *expired ? "" : "not ");
   6.131 +
   6.132   out:
   6.133      pgp_tpk_free(tpk);
   6.134 -    T("(%s) -> %s", fpr, pEp_status_to_string(status));
   6.135 +    T("(%s) -> %s (expired: %d)", fpr, pEp_status_to_string(status), *expired);
   6.136      return status;
   6.137  }
   6.138  
     7.1 --- a/src/status_to_string.h	Thu Jun 27 15:40:53 2019 +0200
     7.2 +++ b/src/status_to_string.h	Thu Jul 04 08:08:00 2019 +0200
     7.3 @@ -35,6 +35,7 @@
     7.4      case PEP_KEY_IMPORTED: return "PEP_KEY_IMPORTED";
     7.5      case PEP_NO_KEY_IMPORTED: return "PEP_NO_KEY_IMPORTED";
     7.6      case PEP_KEY_IMPORT_STATUS_UNKNOWN: return "PEP_KEY_IMPORT_STATUS_UNKNOWN";
     7.7 +    case PEP_SOME_KEYS_IMPORTED: return "PEP_SOME_KEYS_IMPORTED";
     7.8      
     7.9      case PEP_CANNOT_FIND_IDENTITY: return "PEP_CANNOT_FIND_IDENTITY";
    7.10      case PEP_CANNOT_SET_PERSON: return "PEP_CANNOT_SET_PERSON";