Browse Source

merge "default" branch into "keysync" branch and resolve 2 minor merge conflicts. Please check whether the resolve was okay.

doc_update_sequoia
Roker 6 years ago
parent
commit
e9a6422c8d
13 changed files with 312 additions and 4 deletions
  1. +1
    -1
      src/cryptotech.c
  2. +23
    -0
      src/openpgp_compat.c
  3. +44
    -0
      src/openpgp_compat.h
  4. +1
    -0
      src/pEpEngine.c
  5. +1
    -1
      src/pEpEngine.h
  6. +95
    -0
      src/pgp_gpg.c
  7. +4
    -0
      src/pgp_gpg.h
  8. +57
    -1
      src/pgp_netpgp.c
  9. +4
    -0
      src/pgp_netpgp.h
  10. +7
    -0
      src/platform_unix.c
  11. +3
    -0
      src/platform_unix.h
  12. +1
    -1
      test/encrypt_for_identity_test.cc
  13. +71
    -0
      test/pgp_list_keys_test.cc

+ 1
- 1
src/cryptotech.c View File

@ -7,7 +7,7 @@
#include "pgp_netpgp.h"
#endif
#endif
//
#include <stdlib.h>
#include <memory.h>


+ 23
- 0
src/openpgp_compat.c View File

@ -0,0 +1,23 @@
#include "pEp_internal.h"
#include "dynamic_api.h"
#include "openpgp_compat.h"
DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
)
{
assert(session);
assert(keyinfo_list);
if (!(session && keyinfo_list))
return PEP_ILLEGAL_VALUE;
stringpair_list_t* _keyinfo_list = NULL;
PEP_STATUS retval = pgp_list_keyinfo(session, search_pattern, &_keyinfo_list);
if (retval == PEP_STATUS_OK)
*keyinfo_list = _keyinfo_list;
return retval;
}

+ 44
- 0
src/openpgp_compat.h View File

@ -0,0 +1,44 @@
// openpgp_compat.h
//
// These functions are the exposure of non-generic PGP-specific functionality (largely related to PGP
// keyrings) to adapters that need them without polluting the engine interface.
//
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "dynamic_api.h"
#include "stringpair.h"
#ifdef USE_GPG
#include "pgp_gpg.h"
#else
#ifdef USE_NETPGP
#include "pgp_netpgp.h"
#endif
#endif
// OpenPGP_list_keyinfo() - get a key/UID list for pattern matches in keyring (NULL
// to return entire keyring)
//
// parameters:
// session (in) session handle
// show_revoked (in) true if identities with revoked primary keys should also
// be listed; false if only valid keys should be shown
// keyinfo_list (out) list of identities for each available key
//
// caveat:
// keyinfo_list must be freed by the caller.
DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
);
#ifdef __cplusplus
}
#endif

+ 1
- 0
src/pEpEngine.c View File

@ -1279,6 +1279,7 @@ DYNAMIC_API PEP_STATUS find_keys(
keylist);
}
DYNAMIC_API PEP_STATUS generate_keypair(
PEP_SESSION session, pEp_identity *identity
)


+ 1
- 1
src/pEpEngine.h View File

@ -10,6 +10,7 @@ extern "C" {
#include "dynamic_api.h"
#include "stringlist.h"
#include "stringpair.h"
#include "timestamp.h"
#define PEP_VERSION "1.0" // protocol version
@ -660,7 +661,6 @@ DYNAMIC_API PEP_STATUS find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
);
// send_key() - send key(s) to keyserver
//
// parameters:


+ 95
- 0
src/pgp_gpg.c View File

@ -1225,6 +1225,101 @@ PEP_STATUS pgp_export_keydata(
return PEP_STATUS_OK;
}
PEP_STATUS pgp_list_keyinfo(PEP_SESSION session, const char* pattern,
stringpair_list_t** keyinfo_list)
{
gpgme_error_t gpgme_error;
assert(session);
assert(keyinfo_list);
if (!session || !keyinfo_list)
return PEP_ILLEGAL_VALUE;
*keyinfo_list = NULL;
gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, 0);
gpgme_error = _GPGERR(gpgme_error);
switch(gpgme_error) {
case GPG_ERR_NO_ERROR:
break;
case GPG_ERR_INV_VALUE:
assert(0);
return PEP_UNKNOWN_ERROR;
default:
gpg.gpgme_op_keylist_end(session->ctx);
return PEP_GET_KEY_FAILED;
};
gpgme_key_t key;
stringpair_list_t* _keyinfo_list = new_stringpair_list(NULL);
stringpair_list_t* list_curr = _keyinfo_list;
stringpair_t* pair = NULL;
do {
gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
gpgme_error = _GPGERR(gpgme_error);
switch(gpgme_error) {
case GPG_ERR_EOF:
break;
case GPG_ERR_NO_ERROR:
assert(key);
assert(key->subkeys);
if (!key || !key->subkeys)
return PEP_GET_KEY_FAILED;
// first subkey is primary key
char* fpr = key->subkeys->fpr;
char* uid = key->uids->uid;
assert(fpr);
assert(uid); // ??
if (!fpr)
return PEP_GET_KEY_FAILED;
PEP_STATUS key_status = PEP_GET_KEY_FAILED;
bool key_revoked = false;
if (key->subkeys->revoked)
continue;
pair = new_stringpair(fpr, uid);
assert(pair);
if (pair) {
list_curr = stringpair_list_add(list_curr, pair);
pair = NULL;
assert(list_curr);
if (list_curr != NULL)
break;
else
free_stringpair(pair);
}
// else fallthrough (list_curr or pair wasn't allocateable)
case GPG_ERR_ENOMEM:
free_stringpair_list(_keyinfo_list);
gpg.gpgme_op_keylist_end(session->ctx);
return PEP_OUT_OF_MEMORY;
default:
gpg.gpgme_op_keylist_end(session->ctx);
return PEP_UNKNOWN_ERROR;
}
} while (gpgme_error != GPG_ERR_EOF);
if (_keyinfo_list->value == NULL) {
free_stringpair_list(_keyinfo_list);
_keyinfo_list = NULL;
}
*keyinfo_list = _keyinfo_list;
return PEP_STATUS_OK;
}
static void _switch_mode(pEpSession *session, gpgme_keylist_mode_t remove_mode,
gpgme_keylist_mode_t add_mode)
{


+ 4
- 0
src/pgp_gpg.h View File

@ -30,6 +30,10 @@ PEP_STATUS pgp_find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
);
PEP_STATUS pgp_list_keyinfo(
PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list
);
PEP_STATUS pgp_generate_keypair(
PEP_SESSION session, pEp_identity *identity
);


+ 57
- 1
src/pgp_netpgp.c View File

@ -1169,7 +1169,7 @@ static PEP_STATUS add_key_fpr_to_stringlist(void *arg, pgp_key_t *key)
return PEP_OUT_OF_MEMORY;
} else {
*keylist = stringlist_add(*keylist, newfprstr);
stringlist_add(*keylist, newfprstr);
free(newfprstr);
if (*keylist == NULL) {
return PEP_OUT_OF_MEMORY;
@ -1178,6 +1178,34 @@ static PEP_STATUS add_key_fpr_to_stringlist(void *arg, pgp_key_t *key)
return PEP_STATUS_OK;
}
static PEP_STATUS add_keyinfo_to_stringpair_list(void* arg, pgp_key_t *key) {
stringpair_list_t** keyinfo_list = (stringpair_list_t**)arg;
stringpair_t* pair = NULL;
char* id_fpr = NULL;
char* primary_userid = (char*)pgp_key_get_primary_userid(key);
bool key_revoked = false;
// PEP_STATUS key_status = pgp_key_revoked(session, id_fpr, &key_revoked);
// if (key_revoked || key_status == PEP_GET_KEY_FAILED)
// return PEP_STATUS_OK; // we just move on
fpr_to_str(&id_fpr, key->pubkeyfpr.fingerprint,
key->pubkeyfpr.length);
pair = new_stringpair(id_fpr, primary_userid);
if (pair == NULL)
return PEP_OUT_OF_MEMORY;
*keyinfo_list = stringpair_list_add(*keyinfo_list, pair);
free(id_fpr);
if (*keyinfo_list == NULL)
return PEP_OUT_OF_MEMORY;
return PEP_STATUS_OK;
}
PEP_STATUS pgp_find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
)
@ -1698,3 +1726,31 @@ unlock_netpgp:
return status;
}
PEP_STATUS pgp_list_keyinfo(
PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list)
{
if (!session || !keyinfo_list)
return PEP_UNKNOWN_ERROR;
if (pthread_mutex_lock(&netpgp_mutex))
{
return PEP_UNKNOWN_ERROR;
}
pgp_key_t *key;
PEP_STATUS result;
result = find_keys_do(pattern, &add_keyinfo_to_stringpair_list, (void*)keyinfo_list);
if (!keyinfo_list)
result = PEP_KEY_NOT_FOUND;
unlock_netpgp:
pthread_mutex_unlock(&netpgp_mutex);
return result;
}

+ 4
- 0
src/pgp_netpgp.h View File

@ -30,6 +30,10 @@ PEP_STATUS pgp_find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
);
PEP_STATUS pgp_list_keyinfo(
PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list
);
PEP_STATUS pgp_generate_keypair(
PEP_SESSION session, pEp_identity *identity
);


+ 7
- 0
src/platform_unix.c View File

@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <regex.h>
#include "platform_unix.h"
@ -123,6 +124,12 @@ size_t strlcat(char* dst, const char* src, size_t size) {
return retval;
}
// FIXME: This may cause problems - this is a quick compatibility fix for netpgp code
int regnexec(const regex_t* preg, const char* string,
size_t len, size_t nmatch, regmatch_t pmatch[], int eflags) {
return regexec(preg, string, nmatch, pmatch, eflags);
}
#endif
const char *unix_local_db(void)


+ 3
- 0
src/platform_unix.h View File

@ -5,6 +5,7 @@
#include <unistd.h>
#include <strings.h>
#include <sys/select.h>
#include <regex.h>
#include <uuid/uuid.h>
#ifdef __cplusplus
@ -44,6 +45,8 @@ extern char* SystemDB;
#if !defined(BSD) && !defined(__APPLE__)
size_t strlcpy(char* dst, const char* src, size_t size);
size_t strlcat(char* dst, const char* src, size_t size);
int regnexec(const regex_t* preg, const char* string,
size_t len, size_t nmatch, regmatch_t pmatch[], int eflags);
#endif
#ifndef _UUID_STRING_T


+ 1
- 1
test/encrypt_for_identity_test.cc View File

@ -90,7 +90,7 @@ int main() {
for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
{
cout << "\t " << kl4->value << endl;
assert(strcmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
cout << "Encrypted for Alice! Yay! It worked!" << endl;
}
cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;


+ 71
- 0
test/pgp_list_keys_test.cc View File

@ -0,0 +1,71 @@
#include <iostream>
#include <string>
#include <assert.h>
#include "pEpEngine.h"
#include "stringpair.h"
#include "openpgp_compat.h"
using namespace std;
void print_stringpair_list(stringpair_list_t* spl) {
for ( ; spl != NULL; spl = spl->next) {
if (spl->value) {
cout << "Key:" << endl;
if (spl->value->key)
cout << "\tFPR: " << spl->value->key << endl;
if (spl->value->value)
cout << "\tUID: " << spl->value->value << endl;
}
}
}
int main() {
cout << "\n*** openpgp_compat test ***\n\n";
PEP_SESSION session;
cout << "calling init()\n";
PEP_STATUS status1 = init(&session);
assert(status1 == PEP_STATUS_OK);
assert(session);
cout << "init() completed.\n";
cout << "Listing all the keys:" << endl;
stringpair_list_t* all_the_ids = NULL;
OpenPGP_list_keyinfo(session, "", &all_the_ids);
print_stringpair_list(all_the_ids);
free_stringpair_list(all_the_ids);
cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
all_the_ids = NULL;
OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
print_stringpair_list(all_the_ids);
free_stringpair_list(all_the_ids);
cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
stringlist_t* all_the_keys;
find_keys(session, "pEp Test", &all_the_keys);
stringlist_t* i;
for (i = all_the_keys; i; i = i->next) {
cout << i->value << endl;
}
free_stringlist(all_the_keys);
cout << "**********************" << endl << endl << "Checking FPR" << endl;
all_the_ids = NULL;
OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
print_stringpair_list(all_the_ids);
free_stringpair_list(all_the_ids);
cout << "**********************" << endl << endl << "Checking on nothing" << endl;
all_the_ids = NULL;
OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
print_stringpair_list(all_the_ids);
free_stringpair_list(all_the_ids);
cout << "calling release()\n";
release(session);
return 0;
}

Loading…
Cancel
Save