From a88c8e086c1ddc54f60e4c5a23b291dceed9ab92 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 12 Mar 2019 15:18:06 +0100 Subject: [PATCH] feat: no more netpgp when using rpgp --- meson.build | 17 ++++++++++------- src/dc_pgp.c | 22 +++++++++++++++++----- src/dc_receive_imf.c | 19 ++++++++----------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/meson.build b/meson.build index 8c7a6fbb..a8dae8db 100644 --- a/meson.build +++ b/meson.build @@ -107,13 +107,6 @@ else etpan = etpan_proj.get_variable('dep') endif -# netpgp is always bundled -netpgp_proj = subproject('netpgp', - default_options: ['static-pic-lib=true', - 'bzip2=disabled', - 'openssl-idea=disabled', - 'openssl-camellia=enabled']) -netpgp = netpgp_proj.get_variable('dep') if get_option('rpgp') # The rpgp pkg-config file is currently incorrect, so just try @@ -121,8 +114,18 @@ if get_option('rpgp') #rpgp = dependency('rpgp') rpgp = cc.find_library('rpgp') add_project_arguments('-DDC_USE_RPGP', language: 'c') + + netpgp = dependency('', required: false) else rpgp = dependency('', required: false) + + # netpgp is always bundled + netpgp_proj = subproject('netpgp', + default_options: ['static-pic-lib=true', + 'bzip2=disabled', + 'openssl-idea=disabled', + 'openssl-camellia=enabled']) + netpgp = netpgp_proj.get_variable('dep') endif diff --git a/src/dc_pgp.c b/src/dc_pgp.c index 88166d8b..629b4942 100644 --- a/src/dc_pgp.c +++ b/src/dc_pgp.c @@ -14,11 +14,12 @@ So, we do not see a simple alternative - but everyone is welcome to implement one :-) */ -#include -#include #include "dc_context.h" #ifdef DC_USE_RPGP #include +#else +#include +#include #endif #include "dc_key.h" #include "dc_keyring.h" @@ -26,10 +27,16 @@ one :-) */ #include "dc_hash.h" +#if DC_USE_RPGP +void dc_pgp_init(void) +{ +} + +#else + static int s_io_initialized = 0; static pgp_io_t s_io; - void dc_pgp_init(void) { if (s_io_initialized) { @@ -43,12 +50,17 @@ void dc_pgp_init(void) s_io_initialized = 1; } - +#endif void dc_pgp_exit(void) { } +#if DC_USE_RPGP + +void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes) {} + +#else void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes) { @@ -58,7 +70,7 @@ void dc_pgp_rand_seed(dc_context_t* context, const void* buf, size_t bytes) RAND_seed(buf, bytes); } - +#endif /* Split data from PGP Armored Data as defined in https://tools.ietf.org/html/rfc4880#section-6.2. The given buffer is modified and the returned pointers just point inside the modified buffer, diff --git a/src/dc_receive_imf.c b/src/dc_receive_imf.c index 539ceebe..6d6e4876 100644 --- a/src/dc_receive_imf.c +++ b/src/dc_receive_imf.c @@ -1,5 +1,9 @@ #include +#if DC_USE_RPGP +#include +#else #include +#endif #include "dc_context.h" #include "dc_mimeparser.h" #include "dc_mimefactory.h" @@ -396,7 +400,7 @@ static char* create_adhoc_grp_id(dc_context_t* context, dc_array_t* member_ids / char* addr = NULL; int i = 0; int iCnt = 0; - uint8_t* binary_hash = NULL; + rpgp_cvec* binary_hash = NULL; char* ret = NULL; dc_strbuilder_t member_cs; dc_strbuilder_init(&member_cs, 0); @@ -422,26 +426,19 @@ static char* create_adhoc_grp_id(dc_context_t* context, dc_array_t* member_ids / } /* make sha-256 from the string */ - { - pgp_hash_t hasher; - pgp_hash_sha256(&hasher); - hasher.init(&hasher); - hasher.add(&hasher, (const uint8_t*)member_cs.buf, strlen(member_cs.buf)); - binary_hash = malloc(hasher.size); - hasher.finish(&hasher, binary_hash); - } + binary_hash = rpgp_hash_sha256((const uint8_t*)member_cs.buf, strlen(member_cs.buf)); /* output the first 8 bytes as 16 hex-characters - CAVE: if the lenght changes here, also adapt dc_extract_grpid_from_rfc724_mid() */ ret = calloc(1, 256); for (i = 0; i < 8; i++) { - sprintf(&ret[i*2], "%02x", (int)binary_hash[i]); + sprintf(&ret[i*2], "%02x", (int)rpgp_cvec_data(binary_hash)[i]); } /* cleanup */ + if (binary_hash) { rpgp_cvec_drop(binary_hash);} dc_array_free_ptr(member_addrs); dc_array_unref(member_addrs); free(member_ids_str); - free(binary_hash); sqlite3_finalize(stmt); sqlite3_free(q3); free(member_cs.buf);