Browse Source

Merged in sequoia branch

generate_api
Krista Bennett 4 years ago
parent
commit
ed3f5eab20
13 changed files with 2457 additions and 7 deletions
  1. +6
    -1
      default.conf
  2. +7
    -2
      src/Makefile
  3. +4
    -0
      src/cryptotech.c
  4. +4
    -0
      src/openpgp_compat.h
  5. +135
    -0
      src/pEpEngine.h
  6. +15
    -0
      src/pEp_internal.h
  7. +2151
    -0
      src/pgp_sequoia.c
  8. +115
    -0
      src/pgp_sequoia.h
  9. +6
    -0
      src/pgp_sequoia_internal.h
  10. +3
    -1
      src/stringlist.c
  11. +9
    -2
      test/Makefile
  12. +1
    -1
      test/src/EngineTestSuite.cc
  13. +1
    -0
      test/src/engine_tests/TrustManipulationTests.cc

+ 6
- 1
default.conf View File

@ -204,7 +204,7 @@ SQLITE3_FROM_OS=placeholder
# gpgconf is not available for old version of GPG, for example GPG 2.0.30. Override this variable, if you compile the engine for such an old version.
GPG_CMD:=$(shell gpgconf --list-components | awk -F: '/^gpg:/ { print $$3; exit 0; }')
# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
# Selects OpenPGP implementation. must be either `GPG` or `NETPGP` or `SEQUOIA`
OPENPGP=GPG
# Path of libGPGME binary
@ -236,6 +236,11 @@ NETPGP_LIB=
NETPGP_INC=
#NETPGP_INC=-I$(PREFIX)/include
SEQUOIA_CFLAGS=$(shell pkg-config --cflags-only-other sequoia)
SEQUOIA_LDFLAGS=$(shell pkg-config --libs-only-L --libs-only-other sequoia)
SEQUOIA_LIB=$(shell pkg-config --libs-only-l sequoia)
SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia)
######### OpenPGP #########
# CppUnit library search flag


+ 7
- 2
src/Makefile View File

@ -35,15 +35,20 @@ ifdef SQLITE3_FROM_OS
endif
ifeq ($(OPENPGP),GPG)
NO_SOURCE+= pgp_netpgp.c
NO_SOURCE+= pgp_netpgp.c pgp_sequoia.c
CFLAGS+= -DUSE_GPG $(GPGME_INC) -DLIBGPGME=\"$(LIBGPGME)\"
LDFLAGS+= $(GPGME_LIB)
# No extra LDLIBS are needed here, because GPGME is dynamically loaded
else ifeq ($(OPENPGP),NETPGP)
NO_SOURCE+= pgp_gpg.c
NO_SOURCE+= pgp_gpg.c pgp_sequoia.c
CFLAGS+= -DUSE_NETPGP $(NETGPG_INC)
LDFLAGS+= $(NETGPG_LIB)
LDLIBS+= -lnetpgp -lcurl
else ifeq ($(OPENPGP),SEQUOIA)
NO_SOURCE+= pgp_gpg.c pgp_netpgp.c
CFLAGS+= -DUSE_SEQUOIA $(SEQUOIA_CFLAGS) $(SEQUOIA_INC)
LDFLAGS+= $(SEQUOIA_LDFLAGS)
LDLIBS+= $(SEQUOIA_LIB)
else
$(error Unknown OpenPGP library: $(OPENPGP))
endif


+ 4
- 0
src/cryptotech.c View File

@ -8,6 +8,10 @@
#else
#ifdef USE_NETPGP
#include "pgp_netpgp.h"
#else
#ifdef USE_SEQUOIA
#include "pgp_sequoia.h"
#endif
#endif
#endif
//


+ 4
- 0
src/openpgp_compat.h View File

@ -24,6 +24,10 @@ extern "C" {
#else
#ifdef USE_NETPGP
#include "pgp_netpgp.h"
#else
#ifdef USE_SEQUOIA
#include "pgp_sequoia.h"
#endif
#endif
#endif


+ 135
- 0
src/pEpEngine.h View File

@ -162,6 +162,100 @@ void free_Sync_event(SYNC_EVENT ev);
typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
static inline const char *pep_status_to_string(PEP_STATUS status) {
switch (status) {
case PEP_STATUS_OK: return "PEP_STATUS_OK";
case PEP_INIT_CANNOT_LOAD_GPGME: return "PEP_INIT_CANNOT_LOAD_GPGME";
case PEP_INIT_GPGME_INIT_FAILED: return "PEP_INIT_GPGME_INIT_FAILED";
case PEP_INIT_NO_GPG_HOME: return "PEP_INIT_NO_GPG_HOME";
case PEP_INIT_NETPGP_INIT_FAILED: return "PEP_INIT_NETPGP_INIT_FAILED";
case PEP_INIT_CANNOT_DETERMINE_GPG_VERSION: return "PEP_INIT_CANNOT_DETERMINE_GPG_VERSION";
case PEP_INIT_UNSUPPORTED_GPG_VERSION: return "PEP_INIT_UNSUPPORTED_GPG_VERSION";
case PEP_INIT_CANNOT_CONFIG_GPG_AGENT: return "PEP_INIT_CANNOT_CONFIG_GPG_AGENT";
case PEP_INIT_SQLITE3_WITHOUT_MUTEX: return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
case PEP_INIT_CANNOT_OPEN_DB: return "PEP_INIT_CANNOT_OPEN_DB";
case PEP_INIT_CANNOT_OPEN_SYSTEM_DB: return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
case PEP_UNKNOWN_DB_ERROR: return "PEP_UNKNOWN_DB_ERROR";
case PEP_KEY_NOT_FOUND: return "PEP_KEY_NOT_FOUND";
case PEP_KEY_HAS_AMBIG_NAME: return "PEP_KEY_HAS_AMBIG_NAME";
case PEP_GET_KEY_FAILED: return "PEP_GET_KEY_FAILED";
case PEP_CANNOT_EXPORT_KEY: return "PEP_CANNOT_EXPORT_KEY";
case PEP_CANNOT_EDIT_KEY: return "PEP_CANNOT_EDIT_KEY";
case PEP_KEY_UNSUITABLE: return "PEP_KEY_UNSUITABLE";
case PEP_MALFORMED_KEY_RESET_MSG: return "PEP_MALFORMED_KEY_RESET_MSG";
case PEP_KEY_NOT_RESET: return "PEP_KEY_NOT_RESET";
case PEP_CANNOT_FIND_IDENTITY: return "PEP_CANNOT_FIND_IDENTITY";
case PEP_CANNOT_SET_PERSON: return "PEP_CANNOT_SET_PERSON";
case PEP_CANNOT_SET_PGP_KEYPAIR: return "PEP_CANNOT_SET_PGP_KEYPAIR";
case PEP_CANNOT_SET_IDENTITY: return "PEP_CANNOT_SET_IDENTITY";
case PEP_CANNOT_SET_TRUST: return "PEP_CANNOT_SET_TRUST";
case PEP_KEY_BLACKLISTED: return "PEP_KEY_BLACKLISTED";
case PEP_CANNOT_FIND_PERSON: return "PEP_CANNOT_FIND_PERSON";
case PEP_CANNOT_FIND_ALIAS: return "PEP_CANNOT_FIND_ALIAS";
case PEP_CANNOT_SET_ALIAS: return "PEP_CANNOT_SET_ALIAS";
case PEP_UNENCRYPTED: return "PEP_UNENCRYPTED";
case PEP_VERIFIED: return "PEP_VERIFIED";
case PEP_DECRYPTED: return "PEP_DECRYPTED";
case PEP_DECRYPTED_AND_VERIFIED: return "PEP_DECRYPTED_AND_VERIFIED";
case PEP_DECRYPT_WRONG_FORMAT: return "PEP_DECRYPT_WRONG_FORMAT";
case PEP_DECRYPT_NO_KEY: return "PEP_DECRYPT_NO_KEY";
case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH: return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
case PEP_VERIFY_NO_KEY: return "PEP_VERIFY_NO_KEY";
case PEP_VERIFIED_AND_TRUSTED: return "PEP_VERIFIED_AND_TRUSTED";
case PEP_CANNOT_REENCRYPT: return "PEP_CANNOT_REENCRYPT";
case PEP_CANNOT_DECRYPT_UNKNOWN: return "PEP_CANNOT_DECRYPT_UNKNOWN";
case PEP_TRUSTWORD_NOT_FOUND: return "PEP_TRUSTWORD_NOT_FOUND";
case PEP_TRUSTWORDS_FPR_WRONG_LENGTH: return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
case PEP_TRUSTWORDS_DUPLICATE_FPR: return "PEP_TRUSTWORDS_DUPLICATE_FPR";
case PEP_CANNOT_CREATE_KEY: return "PEP_CANNOT_CREATE_KEY";
case PEP_CANNOT_SEND_KEY: return "PEP_CANNOT_SEND_KEY";
case PEP_PHRASE_NOT_FOUND: return "PEP_PHRASE_NOT_FOUND";
case PEP_SEND_FUNCTION_NOT_REGISTERED: return "PEP_SEND_FUNCTION_NOT_REGISTERED";
case PEP_CONTRAINTS_VIOLATED: return "PEP_CONTRAINTS_VIOLATED";
case PEP_CANNOT_ENCODE: return "PEP_CANNOT_ENCODE";
case PEP_SYNC_NO_NOTIFY_CALLBACK: return "PEP_SYNC_NO_NOTIFY_CALLBACK";
case PEP_SYNC_ILLEGAL_MESSAGE: return "PEP_SYNC_ILLEGAL_MESSAGE";
case PEP_SYNC_NO_INJECT_CALLBACK: return "PEP_SYNC_NO_INJECT_CALLBACK";
case PEP_SYNC_NO_CHANNEL: return "PEP_SYNC_NO_CHANNEL";
case PEP_SYNC_CANNOT_ENCRYPT: return "PEP_SYNC_CANNOT_ENCRYPT";
case PEP_SYNC_NO_MESSAGE_SEND_CALLBACK: return "PEP_SYNC_NO_MESSAGE_SEND_CALLBACK";
case PEP_CANNOT_INCREASE_SEQUENCE: return "PEP_CANNOT_INCREASE_SEQUENCE";
case PEP_STATEMACHINE_ERROR: return "PEP_STATEMACHINE_ERROR";
case PEP_NO_TRUST: return "PEP_NO_TRUST";
case PEP_STATEMACHINE_INVALID_STATE: return "PEP_STATEMACHINE_INVALID_STATE";
case PEP_STATEMACHINE_INVALID_EVENT: return "PEP_STATEMACHINE_INVALID_EVENT";
case PEP_STATEMACHINE_INVALID_CONDITION: return "PEP_STATEMACHINE_INVALID_CONDITION";
case PEP_STATEMACHINE_INVALID_ACTION: return "PEP_STATEMACHINE_INVALID_ACTION";
case PEP_STATEMACHINE_INHIBITED_EVENT: return "PEP_STATEMACHINE_INHIBITED_EVENT";
case PEP_STATEMACHINE_CANNOT_SEND: return "PEP_STATEMACHINE_CANNOT_SEND";
case PEP_COMMIT_FAILED: return "PEP_COMMIT_FAILED";
case PEP_MESSAGE_CONSUME: return "PEP_MESSAGE_CONSUME";
case PEP_MESSAGE_IGNORE: return "PEP_MESSAGE_IGNORE";
case PEP_RECORD_NOT_FOUND: return "PEP_RECORD_NOT_FOUND";
case PEP_CANNOT_CREATE_TEMP_FILE: return "PEP_CANNOT_CREATE_TEMP_FILE";
case PEP_ILLEGAL_VALUE: return "PEP_ILLEGAL_VALUE";
case PEP_BUFFER_TOO_SMALL: return "PEP_BUFFER_TOO_SMALL";
case PEP_OUT_OF_MEMORY: return "PEP_OUT_OF_MEMORY";
case PEP_UNKNOWN_ERROR: return "PEP_UNKNOWN_ERROR";
case PEP_VERSION_MISMATCH: return "PEP_VERSION_MISMATCH";
default: return "unknown status code";
}
}
// INIT_STATUS init() - initialize pEpEngine for a thread
//
@ -535,6 +629,47 @@ typedef enum _PEP_comm_type {
PEP_ct_pEp = 0xff
} PEP_comm_type;
static inline const char *pep_comm_type_to_string(PEP_comm_type ct) {
switch (ct) {
case PEP_ct_unknown: return "unknown";
case PEP_ct_no_encryption: return "no_encryption";
case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
case PEP_ct_key_not_found: return "key_not_found";
case PEP_ct_key_expired: return "key_expired";
case PEP_ct_key_revoked: return "key_revoked";
case PEP_ct_key_b0rken: return "key_b0rken";
case PEP_ct_my_key_not_included: return "my_key_not_included";
case PEP_ct_security_by_obscurity: return "security_by_obscurity";
case PEP_ct_b0rken_crypto: return "b0rken_crypto";
case PEP_ct_key_too_short: return "key_too_short";
case PEP_ct_compromised: return "compromised";
case PEP_ct_mistrusted: return "mistrusted";
case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
case PEP_ct_to_be_checked: return "to_be_checked";
case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
case PEP_ct_confirmed: return "confirmed";
case PEP_ct_confirmed_encryption: return "confirmed_encryption";
case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
case PEP_ct_SMIME: return "SMIME";
case PEP_ct_CMS: return "CMS";
case PEP_ct_strong_encryption: return "strong_encryption";
case PEP_ct_OpenPGP: return "OpenPGP";
case PEP_ct_OTR: return "OTR";
case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
case PEP_ct_pEp: return "pEp";
default: return "invalid comm type";
}
}
typedef enum _identity_flags {
// the first octet flags are app defined settings
PEP_idf_not_for_sync = 0x0001, // don't use this identity for sync


+ 15
- 0
src/pEp_internal.h View File

@ -91,16 +91,20 @@
#include "pEpEngine.h"
// If not specified, build for GPG
#ifndef USE_SEQUOIA
#ifndef USE_NETPGP
#ifndef USE_GPG
#define USE_GPG
#endif
#endif
#endif
#ifdef USE_GPG
#include "pgp_gpg_internal.h"
#elif defined(USE_NETPGP)
#include "pgp_netpgp_internal.h"
#elif defined(USE_SEQUOIA)
#include "pgp_sequoia_internal.h"
#endif
#include "keymanagement.h"
@ -123,6 +127,17 @@ struct _pEpSession {
gpgme_ctx_t ctx;
#elif defined(USE_NETPGP)
pEpNetPGPSession ctx;
#elif defined(USE_SEQUOIA)
sq_context_t ctx;
sq_store_t store;
sqlite3 *key_db;
sqlite3_stmt *begin_transaction;
sqlite3_stmt *commit_transaction;
sqlite3_stmt *rollback_transaction;
sqlite3_stmt *tsk_save_insert_primary;
sqlite3_stmt *tsk_save_insert_subkeys;
sqlite3_stmt *tsk_all;
sqlite3_stmt *tsk_find_by_keyid;
#endif
PEP_cryptotech_t *cryptotech;


+ 2151
- 0
src/pgp_sequoia.c
File diff suppressed because it is too large
View File


+ 115
- 0
src/pgp_sequoia.h View File

@ -0,0 +1,115 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#include "pEpEngine.h"
PEP_STATUS pgp_init(PEP_SESSION session, bool in_first);
void pgp_release(PEP_SESSION session, bool out_last);
PEP_STATUS pgp_decrypt_and_verify(
PEP_SESSION session, const char *ctext, size_t csize,
const char *dsigtext, size_t dsigsize,
char **ptext, size_t *psize, stringlist_t **keylist,
char** filename_ptr
);
PEP_STATUS pgp_encrypt_and_sign(
PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
size_t psize, char **ctext, size_t *csize
);
PEP_STATUS pgp_sign_only(
PEP_SESSION session, const char* fpr, const char *ptext,
size_t psize, char **stext, size_t *ssize
);
PEP_STATUS pgp_encrypt_only(
PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
size_t psize, char **ctext, size_t *csize
);
PEP_STATUS pgp_verify_text(
PEP_SESSION session, const char *text, size_t size,
const char *signature, size_t sig_size, stringlist_t **keylist
);
PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr);
PEP_STATUS pgp_export_keydata(
PEP_SESSION session, const char *fpr, char **key_data, size_t *size,
bool secret
);
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
);
PEP_STATUS pgp_get_key_rating(
PEP_SESSION session,
const char *fpr,
PEP_comm_type *comm_type
);
PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
size_t size, identity_list **private_idents);
PEP_STATUS pgp_import_private_keydata(PEP_SESSION session, const char *key_data,
size_t size, identity_list **private_idents);
PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern);
PEP_STATUS pgp_send_key(PEP_SESSION session, const char *pattern);
PEP_STATUS pgp_renew_key(
PEP_SESSION session,
const char *fpr,
const timestamp *ts
);
PEP_STATUS pgp_revoke_key(
PEP_SESSION session,
const char *fpr,
const char *reason
);
PEP_STATUS pgp_key_expired(
PEP_SESSION session,
const char *fpr,
const time_t when,
bool *expired
);
PEP_STATUS pgp_key_revoked(
PEP_SESSION session,
const char *fpr,
bool *revoked
);
PEP_STATUS pgp_key_created(
PEP_SESSION session,
const char *fpr,
time_t *created
);
PEP_STATUS pgp_contains_priv_key(
PEP_SESSION session,
const char *fpr,
bool *has_private);
PEP_STATUS pgp_find_private_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
);
PEP_STATUS pgp_binary(const char **path);
#define PGP_BINARY_PATH pgp_binary

+ 6
- 0
src/pgp_sequoia_internal.h View File

@ -0,0 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#include <sequoia.h>

+ 3
- 1
src/stringlist.c View File

@ -145,7 +145,9 @@ DYNAMIC_API stringlist_t *stringlist_add_unique(
found = true;
list_curr = list_curr->next;
}
if(strcmp(list_curr->value,value)==0)
found = true;
if (!found) {
list_curr->next = new_stringlist(value);


+ 9
- 2
test/Makefile View File

@ -41,6 +41,13 @@ ifeq ($(BUILD_FOR),Linux)
endif
endif
ifeq ($(OPENPGP),SEQUOIA)
LDFLAGS+= $(SEQUOIA_LDFLAGS)
LDLIBS+= $(SEQUOIA_LIB)
CFLAGS+= $(SEQUOIA_CFLAGS)
INC_FLAGS+= $(SEQUOIA_INC)
endif
ifdef SQLITE3_FROM_OS
LDLIBS+= -lsqlite3
endif
@ -121,8 +128,8 @@ endif
.PHONY: test
test: all
$(TEST_DEBUGGER) ./$(TARGET)
ulimit -n 20000; $(TEST_DEBUGGER) ./$(TARGET)
.PHONY: clean
clean:
$(RM) $(TARGET) $(OBJS) $(DEPS)


+ 1
- 1
test/src/EngineTestSuite.cc View File

@ -125,7 +125,7 @@ void EngineTestSuite::set_full_env(const char* gpg_conf_copy_path, const char* g
temp_test_home = test_home + "/" + my_name;
int errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (errchk != 0)
if (errchk != 0 && errno != EEXIST)
throw std::runtime_error("Error creating a test directory.");
temp_test_home += "/" + to_string(on_test_number);


+ 1
- 0
test/src/engine_tests/TrustManipulationTests.cc View File

@ -88,6 +88,7 @@ void TrustManipulationTests::check_trust_manipulation() {
cout << "Hoorah, we now do not trust key 2. (We never liked key 2 anyway.)" << endl;
cout << "Now we call update_identity to see what gifts it gives us (should be key 1 with key 1's initial trust.)" << endl;
status = update_identity(session, user);
TEST_ASSERT_MSG((user->fpr), "user->fpr");
TEST_ASSERT_MSG((strcmp(user->fpr, keypair1) == 0), "strcmp(user->fpr, keypair1) == 0");
TEST_ASSERT_MSG((user->comm_type == PEP_ct_OpenPGP_unconfirmed), "user->comm_type == PEP_ct_OpenPGP_unconfirmed");
cout << "Yup, got key 1, and the trust status is PEP_ct_OpenPGP_unconfirmed." << endl;


Loading…
Cancel
Save