You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pEpEngine/src/pEp_internal.h

842 lines
22 KiB

/**
* @file pEp_internal.h
* @brief pEp internal structs, functions, defines, and values
* @license GNU General Public License 3.0 - see LICENSE.txt
*/
#ifndef PEP_INTERNAL_H
#define PEP_INTERNAL_H
// maximum attachment size to import as key 25MB, maximum of 20 attachments
#define MAX_KEY_SIZE (25 * 1024 * 1024)
#define MAX_KEYS_TO_IMPORT 20
9 years ago
#define KEY_EXPIRE_DELTA (60 * 60 * 24 * 365)
// this is 20 trustwords with 79 chars max
#define MAX_TRUSTWORDS_SPACE (20 * 80)
9 years ago
// XML parameters string
#define PARMS_MAX 32768
// maximum busy wait time in ms
#define BUSY_WAIT_TIME 5000
// default keyserver
#ifndef DEFAULT_KEYSERVER
4 years ago
#define DEFAULT_KEYSERVER "hkps://keys.openpgp.org"
#endif
// crashdump constants
#ifndef CRASHDUMP_DEFAULT_LINES
#define CRASHDUMP_DEFAULT_LINES 100
#endif
#define CRASHDUMP_MAX_LINES 32767
9 years ago
// p≡p full string, NUL-terminated
#ifndef PEP_SUBJ_STRING
#define PEP_SUBJ_STRING {0x70,0xE2,0x89,0xA1,0x70,0x00}
#define PEP_SUBJ_BYTELEN 5
#endif
#ifndef PEP_SUBJ_KEY
#define PEP_SUBJ_KEY "Subject: "
#define PEP_SUBJ_KEY_LC "subject: "
#define PEP_SUBJ_KEY_LEN 9
#endif
#ifndef PEP_MSG_WRAP_KEY
#define PEP_MSG_WRAP_KEY "pEp-Wrapped-Message-Info: "
#define PEP_MSG_WRAP_KEY_LC "pep-wrapped-message-info: "
#define PEP_MSG_WRAP_KEY_LEN 26
#endif
#ifndef X_PEP_MSG_WRAP_KEY
#define X_PEP_MSG_WRAP_KEY "X-pEp-Wrapped-Message-Info"
#endif
#ifndef X_PEP_SNDR_FPR_KEY
#define X_PEP_SNDR_FPR_KEY "X-pEp-Sender-FPR"
#endif
#ifndef X_PEP_MSG_VER_KEY
#define X_PEP_MSG_VER_KEY "X-pEp-Message-Version"
#endif
#define VER_1_0 "1.0"
#define VER_2_0 "2.0"
#define VER_2_1 "2.1"
#define VER_2_2 "2.2"
#include "platform.h"
9 years ago
#ifdef WIN32
#define KEYS_DB windoze_keys_db()
9 years ago
#define LOCAL_DB windoze_local_db()
#define SYSTEM_DB windoze_system_db()
#else // UNIX
#define _POSIX_C_SOURCE 200809L
#include <dlfcn.h>
#ifdef NDEBUG
9 years ago
#define LOCAL_DB unix_local_db()
#else
#define LOCAL_DB unix_local_db(false)
#define LOCAL_DB_RESET unix_local_db(true)
#endif
4 years ago
#ifdef ANDROID
#define SYSTEM_DB android_system_db()
#else
#define SYSTEM_DB unix_system_db()
9 years ago
#endif
#endif
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
9 years ago
#ifdef SQLITE3_FROM_OS
#include <sqlite3.h>
#else
9 years ago
#include "sqlite3.h"
#endif
9 years ago
#include "pEpEngine.h"
#include "key_reset.h"
#include "pEpEngine_internal.h"
#include "key_reset_internal.h"
#include "group_internal.h"
#include "keymanagement_internal.h"
#include "message_api_internal.h"
// If not specified, build for Sequoia
#ifndef USE_SEQUOIA
#define USE_SEQUOIA
#endif
#if defined(USE_SEQUOIA)
#include "pgp_sequoia_internal.h"
9 years ago
#endif
#include "../asn.1/Distribution.h"
#include "../asn.1/Sync.h"
8 years ago
#include "keymanagement.h"
9 years ago
#include "cryptotech.h"
#include "transport.h"
5 years ago
#include "sync_api.h"
5 years ago
#include "Sync_func.h"
9 years ago
8 years ago
#define NOT_IMPLEMENTED assert(0); return PEP_UNKNOWN_ERROR;
9 years ago
struct _pEpSession;
typedef struct _pEpSession pEpSession;
/**
* @struct _pEpSession
*
* @brief TODO
*
*/
struct _pEpSession {
9 years ago
const char *version;
5 years ago
messageToSend_t messageToSend;
#if defined(USE_SEQUOIA)
sqlite3 *key_db;
struct {
sqlite3_stmt *begin_transaction;
sqlite3_stmt *commit_transaction;
sqlite3_stmt *rollback_transaction;
sqlite3_stmt *cert_find;
sqlite3_stmt *tsk_find;
sqlite3_stmt *cert_find_by_keyid;
sqlite3_stmt *tsk_find_by_keyid;
sqlite3_stmt *cert_find_by_email;
sqlite3_stmt *tsk_find_by_email;
sqlite3_stmt *cert_all;
sqlite3_stmt *tsk_all;
sqlite3_stmt *cert_save_insert_primary;
sqlite3_stmt *cert_save_insert_subkeys;
sqlite3_stmt *cert_save_insert_userids;
sqlite3_stmt *delete_keypair;
} sq_sql;
pgp_policy_t policy;
9 years ago
#endif
PEP_cryptotech_t *cryptotech;
PEP_CIPHER_SUITE cipher_suite;
char* curr_passphrase;
bool new_key_pass_enable;
char* generation_passphrase;
PEP_transport_t *transports;
9 years ago
9 years ago
sqlite3 *db;
sqlite3 *system_db;
sqlite3_stmt *log;
sqlite3_stmt *trustword;
9 years ago
sqlite3_stmt *get_identity;
sqlite3_stmt *get_identity_without_trust_check;
sqlite3_stmt *get_identities_by_address;
sqlite3_stmt *get_identities_by_userid;
sqlite3_stmt *get_identities_by_main_key_id;
sqlite3_stmt *replace_identities_fpr;
sqlite3_stmt *replace_main_user_fpr;
sqlite3_stmt *replace_main_user_fpr_if_equal;
sqlite3_stmt *get_main_user_fpr;
sqlite3_stmt *set_default_identity_fpr;
sqlite3_stmt *get_default_identity_fpr;
sqlite3_stmt *refresh_userid_default_key;
sqlite3_stmt *delete_key;
sqlite3_stmt *remove_fpr_as_identity_default;
sqlite3_stmt *remove_fpr_as_user_default;
9 years ago
sqlite3_stmt *set_person;
sqlite3_stmt *update_person;
sqlite3_stmt *delete_person;
sqlite3_stmt *exists_person;
5 years ago
sqlite3_stmt *set_as_pEp_user;
sqlite3_stmt *is_pEp_user;
sqlite3_stmt *upgrade_pEp_version_by_user_id;
sqlite3_stmt *add_into_social_graph;
sqlite3_stmt *get_own_address_binding_from_contact;
sqlite3_stmt *set_revoke_contact_as_notified;
sqlite3_stmt *get_contacted_ids_from_revoke_fpr;
sqlite3_stmt *was_id_for_revoke_contacted;
sqlite3_stmt *has_id_contacted_address;
sqlite3_stmt *get_last_contacted;
// sqlite3_stmt *set_device_group;
// sqlite3_stmt *get_device_group;
9 years ago
sqlite3_stmt *set_pgp_keypair;
ENGINE-866 feature branch merge (squashed commit) of functionality to set the sticky bit for manually imported keys, to query for that bit in the trust database, and prevention of automatic reset of sticky keys by key reset when devices leave a device group. Squashed commit of the following: commit c64d850dc4bfe5a9dfd54aa94eea08a75ff69191 Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:29:32 2021 +0100 ENGINE-866: doc'd bit getter function commit ad725b5b7c742300a6a182ad8b058db23dbc3cfb Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:23:49 2021 +0100 ENGINE-866: Key reset tested on mixed sticky and not sticky keys and does what it should. commit 0ffbdde7b598c7c3fff5d797e732dec07685f9be Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:13:53 2021 +0100 ENGINE-866: Add boolean for whether to set the sticky bit or not with set_own_imported_key. the adapter should filter this out for apps, I guess, according to Volker commit 23fec59a9a4ede0682a9ebcb9a61e78456e7d8d4 Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 14:53:19 2021 +0100 ENGINE-866: Test and use the sticky bit commit 562239fda874623c40893c382a8f82df9e002ef5 Author: Krista Bennett <krista@pep.foundation> Date: Thu Feb 25 16:47:47 2021 +0100 ENGINE-866: moved bit from key to trust, created set_own_imported_key to replace set_own_key FOR MAIL APPS (does NOT replace it for key reset, as the new function can generate a passphrase error, whereas set_own_key cannot), and did an initial test to ensure the setter/getter functions work on the DB. commit 594133cfdee966adbaa66c62133ede1ca917bca0 Author: Krista Bennett <krista@pep.foundation> Date: Wed Feb 24 11:16:21 2021 +0100 Commented out the or'd identity.flags / pgp_keypair.flags in the sql code for the get_identity functions; we've never HAD a pgp_keypair flag before, so it never hurt before, but at this point, we're going to introduce them, and I don't want trouble. If fdik wants them or'd, fine, we'll have to change the values in the keyflags to be disjoint from the identity flags so they can coexist, but for now, they are out. commit 99831445b3e22e1386aa0f86414fdb6939e5ebaf Merge: 8ba53ece d1664cf5 Author: Krista Bennett <krista@pep.foundation> Date: Wed Feb 24 10:15:53 2021 +0100 Merge branch 'master' into ENGINE-866 commit 8ba53ece06773168a9188373d1be5f13d99b2f6e Merge: 168e2cf9 c52f4d39 Author: Krista Bennett <krista@pep.foundation> Date: Mon Feb 22 20:06:08 2021 +0100 Merged in engine_sql changes commit 168e2cf9578b12157b98da8b26e598f0a1448d9e Author: Krista Bennett <krista@pep.foundation> Date: Mon Feb 22 19:03:35 2021 +0100 ENGINE-866: Added sticky bit in database for manually set keys
2 years ago
sqlite3_stmt *set_pgp_keypair_flags;
sqlite3_stmt *unset_pgp_keypair_flags;
sqlite3_stmt *set_identity_entry;
sqlite3_stmt *update_identity_entry;
sqlite3_stmt *exists_identity_entry;
sqlite3_stmt *force_set_identity_username;
sqlite3_stmt *set_identity_flags;
sqlite3_stmt *unset_identity_flags;
sqlite3_stmt *set_ident_enc_format;
sqlite3_stmt *set_pEp_version;
sqlite3_stmt *clear_trust_info;
9 years ago
sqlite3_stmt *set_trust;
sqlite3_stmt *update_trust;
sqlite3_stmt *exists_trust_entry;
5 years ago
sqlite3_stmt *update_trust_to_pEp;
sqlite3_stmt *update_trust_for_fpr;
9 years ago
sqlite3_stmt *get_trust;
sqlite3_stmt *get_trust_by_userid;
sqlite3_stmt *least_trust;
ENGINE-866 feature branch merge (squashed commit) of functionality to set the sticky bit for manually imported keys, to query for that bit in the trust database, and prevention of automatic reset of sticky keys by key reset when devices leave a device group. Squashed commit of the following: commit c64d850dc4bfe5a9dfd54aa94eea08a75ff69191 Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:29:32 2021 +0100 ENGINE-866: doc'd bit getter function commit ad725b5b7c742300a6a182ad8b058db23dbc3cfb Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:23:49 2021 +0100 ENGINE-866: Key reset tested on mixed sticky and not sticky keys and does what it should. commit 0ffbdde7b598c7c3fff5d797e732dec07685f9be Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 15:13:53 2021 +0100 ENGINE-866: Add boolean for whether to set the sticky bit or not with set_own_imported_key. the adapter should filter this out for apps, I guess, according to Volker commit 23fec59a9a4ede0682a9ebcb9a61e78456e7d8d4 Author: Krista Bennett <krista@pep.foundation> Date: Fri Feb 26 14:53:19 2021 +0100 ENGINE-866: Test and use the sticky bit commit 562239fda874623c40893c382a8f82df9e002ef5 Author: Krista Bennett <krista@pep.foundation> Date: Thu Feb 25 16:47:47 2021 +0100 ENGINE-866: moved bit from key to trust, created set_own_imported_key to replace set_own_key FOR MAIL APPS (does NOT replace it for key reset, as the new function can generate a passphrase error, whereas set_own_key cannot), and did an initial test to ensure the setter/getter functions work on the DB. commit 594133cfdee966adbaa66c62133ede1ca917bca0 Author: Krista Bennett <krista@pep.foundation> Date: Wed Feb 24 11:16:21 2021 +0100 Commented out the or'd identity.flags / pgp_keypair.flags in the sql code for the get_identity functions; we've never HAD a pgp_keypair flag before, so it never hurt before, but at this point, we're going to introduce them, and I don't want trouble. If fdik wants them or'd, fine, we'll have to change the values in the keyflags to be disjoint from the identity flags so they can coexist, but for now, they are out. commit 99831445b3e22e1386aa0f86414fdb6939e5ebaf Merge: 8ba53ece d1664cf5 Author: Krista Bennett <krista@pep.foundation> Date: Wed Feb 24 10:15:53 2021 +0100 Merge branch 'master' into ENGINE-866 commit 8ba53ece06773168a9188373d1be5f13d99b2f6e Merge: 168e2cf9 c52f4d39 Author: Krista Bennett <krista@pep.foundation> Date: Mon Feb 22 20:06:08 2021 +0100 Merged in engine_sql changes commit 168e2cf9578b12157b98da8b26e598f0a1448d9e Author: Krista Bennett <krista@pep.foundation> Date: Mon Feb 22 19:03:35 2021 +0100 ENGINE-866: Added sticky bit in database for manually set keys
2 years ago
sqlite3_stmt *update_key_sticky_bit_for_user;
sqlite3_stmt *is_key_sticky_for_user;
sqlite3_stmt *mark_compromised;
sqlite3_stmt *reset_trust;
sqlite3_stmt *crashdump;
sqlite3_stmt *languagelist;
sqlite3_stmt *i18n_token;
sqlite3_stmt *replace_userid;
7 years ago
// Keys
sqlite3_stmt *own_key_is_listed;
sqlite3_stmt *is_own_address;
7 years ago
sqlite3_stmt *own_identities_retrieve;
sqlite3_stmt *own_keys_retrieve;
sqlite3_stmt *key_identities_retrieve;
sqlite3_stmt *get_user_default_key;
sqlite3_stmt *get_all_keys_for_user;
sqlite3_stmt *get_default_own_userid;
// groups
sqlite3_stmt *create_group;
sqlite3_stmt *enable_group;
sqlite3_stmt *disable_group;
sqlite3_stmt *exists_group_entry;
sqlite3_stmt *group_add_member;
sqlite3_stmt *group_delete_member;
sqlite3_stmt *group_join;
sqlite3_stmt *leave_group;
sqlite3_stmt *set_group_member_status;
sqlite3_stmt *get_all_members;
sqlite3_stmt *get_active_members;
sqlite3_stmt *get_active_groups;
sqlite3_stmt *get_all_groups;
sqlite3_stmt *add_own_membership_entry;
sqlite3_stmt *get_own_membership_status;
sqlite3_stmt *retrieve_own_membership_info_for_group_and_ident;
sqlite3_stmt *retrieve_own_membership_info_for_group;
sqlite3_stmt *get_group_manager;
sqlite3_stmt *is_invited_group_member;
sqlite3_stmt *is_active_group_member;
sqlite3_stmt *is_group_active;
// sqlite3_stmt *set_own_key;
8 years ago
7 years ago
// sequence value
7 years ago
sqlite3_stmt *sequence_value1;
sqlite3_stmt *sequence_value2;
7 years ago
// revoked keys
sqlite3_stmt *set_revoked;
sqlite3_stmt *get_revoked;
sqlite3_stmt *get_replacement_fpr;
// mistrusted
sqlite3_stmt* add_mistrusted_key;
sqlite3_stmt* is_mistrusted_key;
sqlite3_stmt* delete_mistrusted_key;
// aliases
sqlite3_stmt *get_userid_alias_default;
sqlite3_stmt *add_userid_alias;
// callbacks
notifyHandshake_t notifyHandshake;
5 years ago
inject_sync_event_t inject_sync_event;
retrieve_next_sync_event_t retrieve_next_sync_event;
ensure_passphrase_t ensure_passphrase;
7 years ago
5 years ago
// pEp Sync
void *sync_management;
void *sync_obj;
5 years ago
struct Sync_state_s sync_state;
// void* sync_state_payload;
// char sync_uuid[37];
// time_t LastCannotDecrypt;
// time_t LastUpdateRequest;
7 years ago
7 years ago
// runtime config
bool passive_mode;
bool unencrypted_subject;
bool service_log;
3 years ago
#ifndef NDEBUG
int debug_color;
#endif
};
8 years ago
/**
* <!-- init_transport_system() -->
*
* @brief TODO
*
2 years ago
* @param[in] session session handle
* @param[in] in_first bool
*
2 years ago
* @retval PEP_STATUS_OK
*/
PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
/**
* <!-- release_transport_system() -->
*
* @brief TODO
*
2 years ago
* @param[in] session session handle
* @param[in] out_last bool
*
*/
void release_transport_system(PEP_SESSION session, bool out_last);
8 years ago
/**
* @internal
*
* <!-- encrypt_only() -->
*
* @brief TODO
*
2 years ago
* @param[in] session session handle
* @param[in] keylist const stringlist_t*
* @param[in] ptext const char*
* @param[in] psize size_t
* @param[in] ctext char**
* @param[in] csize size_t*
*
* @warning NOT to be exposed to the outside!!!!!
*/
PEP_STATUS encrypt_only(
PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
size_t psize, char **ctext, size_t *csize
);
/**
* <!-- decorate_message() -->
*
* @brief TODO
*
* @param[in] msg message*
* @param[in] rating PEP_rating
* @param[in] keylist stringlist_t*
* @param[in] add_version bool
* @param[in] clobber bool
*
*/
void decorate_message(
PEP_SESSION session,
message *msg,
PEP_rating rating,
stringlist_t *keylist,
bool add_version,
bool clobber);
#if defined(NDEBUG) || defined(NOLOG)
#define DEBUG_LOG(TITLE, ENTITY, DESC)
#else
#ifdef ANDROID
#include <android/log.h>
#define LOG_MORE(...) __android_log_print(ANDROID_LOG_DEBUG, "pEpEngine", " %s :: %s :: %s :: %s ", __VA_ARGS__);
#else
#include <stdio.h>
#define LOG_MORE(...) fprintf(stderr, "pEpEngine DEBUG_LOG('%s','%s','%s','%s')\n", __VA_ARGS__);
#endif
#define DEBUG_LOG(TITLE, ENTITY, DESC) {\
log_event(session, (TITLE), (ENTITY), (DESC), "debug " __FILE__ ":" S_LINE);\
LOG_MORE((TITLE), (ENTITY), (DESC), __FILE__ ":" S_LINE)\
}
#endif
/**
* @enum normalize_hex_res_t
*
* @brief TODO
*
*/
typedef enum _normalize_hex_rest_t {
accept_hex,
ignore_hex,
reject_hex
} normalize_hex_res_t;
/**
* <!-- _normalize_hex() -->
*
* @brief TODO
*
* @param[in] hex char*
*
2 years ago
* @retval accept_hex
* @retval irgnore_hex
* @retval reject_hex
*/
static inline normalize_hex_res_t _normalize_hex(char *hex)
{
if (*hex >= '0' && *hex <= '9')
return accept_hex;
if (*hex >= 'A' && *hex <= 'F') {
*hex += 'a' - 'A';
return accept_hex;
}
if (*hex >= 'a' && *hex <= 'f')
return accept_hex;
if (*hex == ' ')
return ignore_hex;
return reject_hex;
}
// Space tolerant and case insensitive fingerprint string compare
/**
* <!-- _compare_fprs() -->
*
* @brief TODO
*
* @param[in] fpra const char*
* @param[in] fpras size_t
* @param[in] fprb const char*
* @param[in] fprbs size_t
* @param[in] comparison int*
*
2 years ago
* @retval PEP_STATUS_OK
* @retval PEP_ILLEGAL_VALUE illegal parameter values
* @retval PEP_TRUSTWORDS_FPR_WRONG_LENGTH
*/
static inline PEP_STATUS _compare_fprs(
const char* fpra,
size_t fpras,
const char* fprb,
size_t fprbs,
int* comparison)
{
size_t ai = 0;
size_t bi = 0;
size_t significant = 0;
int _comparison = 0;
const int _FULL_FINGERPRINT_LENGTH = 40;
// First compare every non-ignored chars until an end is reached
while(ai < fpras && bi < fprbs)
{
char fprac = fpra[ai];
char fprbc = fprb[bi];
normalize_hex_res_t fprah = _normalize_hex(&fprac);
normalize_hex_res_t fprbh = _normalize_hex(&fprbc);
if(fprah == reject_hex || fprbh == reject_hex)
return PEP_ILLEGAL_VALUE;
if ( fprah == ignore_hex )
{
ai++;
}
else if ( fprbh == ignore_hex )
{
bi++;
}
else
{
if(fprac != fprbc && _comparison == 0 )
{
_comparison = fprac > fprbc ? 1 : -1;
}
significant++;
ai++;
bi++;
}
}
// Bail out if we didn't got enough significnt chars
if (significant != _FULL_FINGERPRINT_LENGTH )
return PEP_TRUSTWORDS_FPR_WRONG_LENGTH;
// Then purge remaining chars, all must be ignored chars
while ( ai < fpras )
{
char fprac = fpra[ai];
normalize_hex_res_t fprah = _normalize_hex(&fprac);
if( fprah == reject_hex )
return PEP_ILLEGAL_VALUE;
if ( fprah != ignore_hex )
return PEP_TRUSTWORDS_FPR_WRONG_LENGTH;
ai++;
}
while ( bi < fprbs )
{
char fprbc = fprb[bi];
normalize_hex_res_t fprbh = _normalize_hex(&fprbc);
if( fprbh == reject_hex )
return PEP_ILLEGAL_VALUE;
if ( fprbh != ignore_hex )
return PEP_TRUSTWORDS_FPR_WRONG_LENGTH;
bi++;
}
*comparison = _comparison;
return PEP_STATUS_OK;
}
/**
* <!-- _same_fpr() -->
*
* @brief TODO
*
* @param[in] fpra const char*
* @param[in] fpras size_t
* @param[in] fprb const char*
* @param[in] fprbs size_t
*
2 years ago
* @retval 0 on equal fingerprints
* @retval non-zero if not equal
*/
static inline int _same_fpr(
const char* fpra,
size_t fpras,
const char* fprb,
size_t fprbs
)
{
// illegal values are ignored, and considered not same.
int comparison = 1;
_compare_fprs(fpra, fpras, fprb, fprbs, &comparison);
return comparison == 0;
}
// size is the length of the bytestr that's coming in. This is really only intended
// for comparing two full strings. If charstr's length is different from bytestr_size,
// we'll return a non-zero value.
/**
* @internal
*
* <!-- _unsigned_signed_strcmp() -->
*
* @brief Compare an unsigned sequence of bytes with the input string.
* This is really only intended for comparing two full strings.
* If charstr's length is different from bytestr_size,
* we'll return a non-zero value.
*
* @param[in] bytestr byte string (unsigned char data)
* @param[in] charstr character string (NUL-terminated)
* @param[in] bytestr_size length of byte string passed in
*
* @retval 0 if equal
* @retval non-zero if not equal
*
*/
static inline int _unsigned_signed_strcmp(const unsigned char* bytestr, const char* charstr, int bytestr_size) {
int charstr_len = strlen(charstr);
if (charstr_len != bytestr_size)
return -1; // we don't actually care except that it's non-zero
return memcmp(bytestr, charstr, bytestr_size);
}
// This is just a horrible example of C type madness. UTF-8 made me do it.
/**
* <!-- _pEp_subj_copy() -->
*
* @brief TODO
*
*
*/
5 years ago
static inline char* _pEp_subj_copy() {
#ifndef WIN32
5 years ago
unsigned char pEpstr[] = PEP_SUBJ_STRING;
void* retval = calloc(1, sizeof(unsigned char)*PEP_SUBJ_BYTELEN + 1);
5 years ago
memcpy(retval, pEpstr, PEP_SUBJ_BYTELEN);
return (char*)retval;
#else
return strdup("pEp");
#endif
}
/**
* <!-- is_me() -->
*
* @brief TODO
*
2 years ago
* @param[in] session session handle
* @param[in] test_ident const pEp_identity*
*
2 years ago
* @retval true
* @retval false
*/
static inline bool is_me(PEP_SESSION session, const pEp_identity* test_ident) {
bool retval = false;
if (test_ident && test_ident->user_id) {
char* def_id = NULL;
get_default_own_userid(session, &def_id);
if (test_ident->me ||
(def_id && strcmp(def_id, test_ident->user_id) == 0)) {
retval = true;
}
free(def_id);
}
return retval;
}
/**
* <!-- pEp_version_numeric() -->