Browse Source

Sequoia fix - we can now import multiple concatenated armoured keys. Returns PEP_SOME_KEYS_IMPORTED if only some keyfiles work out.

ENGINE-641
parent
commit
26329e9b5f
5 changed files with 111 additions and 5 deletions
  1. +17
    -0
      src/identity_list.c
  2. +11
    -3
      src/identity_list.h
  3. +1
    -1
      src/keymanagement.c
  4. +1
    -0
      src/pEpEngine.h
  5. +81
    -1
      src/pgp_sequoia.c

+ 17
- 0
src/identity_list.c View File

@ -108,6 +108,23 @@ DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identit
return list_curr->next;
}
// returns *head* of list
DYNAMIC_API identity_list* identity_list_join(identity_list *first_list, identity_list *second_list) {
if (!first_list) {
if (!second_list)
return NULL;
return second_list;
}
if (second_list) {
identity_list* list_curr = first_list;
while (list_curr->next)
list_curr = list_curr->next;
list_curr->next = second_list;
}
return first_list;
}
DYNAMIC_API int identity_list_length(const identity_list *id_list)
{
int len = 0;


+ 11
- 3
src/identity_list.h View File

@ -63,6 +63,16 @@ DYNAMIC_API void free_identity_list(identity_list *id_list);
DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
// identity_list_add - join second identity_list to the first.
//
// parameters:
// first_list (in) identity_list to add to
// second_list (in) identity list to add
//
// return value:
// pointer to the HEAD of the new list, or NULL if both lists are empty.
//
DYNAMIC_API identity_list *identity_list_join(identity_list *first_list, identity_list* second_list);
// identity_list_length() - get length of identity_list
//
@ -73,9 +83,7 @@ DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identit
// length of identity_list in number of elements
DYNAMIC_API int identity_list_length(const identity_list *id_list);
#ifdef __cplusplus
}
#endif

+ 1
- 1
src/keymanagement.c View File

@ -495,7 +495,7 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
stored_ident->fpr = NULL;
stored_ident->comm_type = PEP_ct_key_not_found;
}
else {
else { // no key returned, but status ok?
if (stored_ident->comm_type == PEP_ct_unknown)
stored_ident->comm_type = PEP_ct_key_not_found;
}


+ 1
- 0
src/pEpEngine.h View File

@ -60,6 +60,7 @@ typedef enum {
PEP_KEY_IMPORTED = 0x0220,
PEP_NO_KEY_IMPORTED = 0x0221,
PEP_KEY_IMPORT_STATUS_UNKNOWN = 0x0222,
PEP_SOME_KEYS_IMPORTED = 0x0223,
PEP_CANNOT_FIND_IDENTITY = 0x0301,
PEP_CANNOT_SET_PERSON = 0x0381,


+ 81
- 1
src/pgp_sequoia.c View File

@ -1854,7 +1854,22 @@ PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr_raw)
return status;
}
PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
static unsigned int count_keydata_parts(const char* key_data) {
unsigned int retval = 0;
const char* pgp_begin = "-----BEGIN PGP";
size_t prefix_len = strlen(pgp_begin);
while (key_data) {
key_data = strstr(key_data, pgp_begin);
if (key_data) {
retval++;
key_data += prefix_len;
}
}
return retval;
}
PEP_STATUS _pgp_import_keydata(PEP_SESSION session, const char *key_data,
size_t size, identity_list **private_idents)
{
PEP_STATUS status = PEP_NO_KEY_IMPORTED;
@ -1986,6 +2001,71 @@ PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
return status;
}
PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
size_t size, identity_list **private_idents)
{
unsigned int keycount = count_keydata_parts(key_data);
if (keycount < 2)
return(_pgp_import_keydata(session, key_data, size, private_idents));
const char* pgp_begin = "-----BEGIN PGP";
size_t prefix_len = strlen(pgp_begin);
unsigned int i;
const char* curr_begin;
size_t curr_size;
identity_list* collected_idents = NULL;
PEP_STATUS retval = PEP_KEY_IMPORTED;
for (i = 0, curr_begin = key_data; i < keycount; i++) {
const char* next_begin = strstr(curr_begin + prefix_len, pgp_begin);
if (next_begin)
curr_size = next_begin - curr_begin;
else
curr_size = (key_data + size) - curr_begin;
PEP_STATUS curr_status = _pgp_import_keydata(session, curr_begin, curr_size, private_idents);
if (private_idents && *private_idents) {
if (!collected_idents)
collected_idents = *private_idents;
else
identity_list_join(collected_idents, *private_idents);
*private_idents = NULL;
}
if (curr_status != retval) {
switch (curr_status) {
case PEP_NO_KEY_IMPORTED:
case PEP_KEY_NOT_FOUND:
case PEP_UNKNOWN_ERROR:
switch (retval) {
case PEP_KEY_IMPORTED:
retval = PEP_SOME_KEYS_IMPORTED;
break;
case PEP_UNKNOWN_ERROR:
retval = curr_status;
break;
default:
break;
}
break;
case PEP_KEY_IMPORTED:
retval = PEP_SOME_KEYS_IMPORTED;
default:
break;
}
}
curr_begin = next_begin;
}
if (private_idents)
*private_idents = collected_idents;
return retval;
}
PEP_STATUS pgp_export_keydata(
PEP_SESSION session, const char *fpr, char **key_data, size_t *size,
bool secret)


Loading…
Cancel
Save