From 3a3a0d2722edab73dc8751fe562bc57122a8de13 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 13 Jan 2026 22:47:19 -0600 Subject: [PATCH] Progress: Continue adding GPGME support. I don't like a lot of things about GPGME, so do not enable it by default. I'm still uncertain how I want to structure the encryption support with gpgme. I plan on considering other encryption and checksum algorithms/libraries. For now just create an encrypt send step file. This is highly subject to change. This adds a new header called "encrypt" that will explicitly designate the encryption method used. --- data/build/tacocat/settings | 6 +- .../kevux/tools/tacocat/main/common/define.h | 2 +- .../kevux/tools/tacocat/main/common/string.c | 4 +- .../kevux/tools/tacocat/main/common/string.h | 10 +- .../program/kevux/tools/tacocat/main/common/type.c | 23 ++++- .../program/kevux/tools/tacocat/main/common/type.h | 26 +++-- sources/c/program/kevux/tools/tacocat/main/gpgme.c | 27 ++++- .../c/program/kevux/tools/tacocat/main/packet.c | 8 ++ .../program/kevux/tools/tacocat/main/print/gpgme.c | 5 +- .../program/kevux/tools/tacocat/main/print/gpgme.h | 4 +- .../c/program/kevux/tools/tacocat/main/process.c | 16 ++- .../kevux/tools/tacocat/main/send/step/encrypt.c | 109 +++++++++++++++++++++ .../kevux/tools/tacocat/main/send/step/encrypt.h | 61 ++++++++++++ .../kevux/tools/tacocat/main/send/step/file.c | 2 + .../kevux/tools/tacocat/main/send/step/packet.c | 27 +++-- .../kevux/tools/tacocat/main/send/step/size.c | 11 ++- .../c/program/kevux/tools/tacocat/main/tacocat.h | 1 + 17 files changed, 293 insertions(+), 49 deletions(-) create mode 100644 sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c create mode 100644 sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h diff --git a/data/build/tacocat/settings b/data/build/tacocat/settings index ded54bc..21628a7 100644 --- a/data/build/tacocat/settings +++ b/data/build/tacocat/settings @@ -31,7 +31,7 @@ version_file micro version_target minor modes android clang coverage debug fanalyzer flex_arrays gcc gpgme individual individual_thread level monolithic pinephone test thread threadless -modes_default debug gcc gpgme monolithic thread +modes_default debug gcc monolithic thread build_compiler gcc build_compiler-clang clang @@ -61,7 +61,7 @@ build_sources_headers common.h common/define.h common/enumeration.h common/strin build_sources_headers print/error.h print/message.h print/verbose.h print/warning.h build_sources_headers packet.h process.h receive.h send.h signal.h tacocat.h thread.h build_sources_headers receive/step/check.h receive/step/control.h receive/step/done.h receive/step/extract.h receive/step/find.h receive/step/next.h receive/step/packet.h receive/step/write.h -build_sources_headers send/step/build.h send/step/check.h send/step/done.h send/step/encode.h send/step/file.h send/step/header.h send/step/packet.h send/step/size.h send/step/wait.h +build_sources_headers send/step/build.h send/step/check.h send/step/done.h send/step/encode.h send/step/encrypt.h send/step/file.h send/step/header.h send/step/packet.h send/step/size.h send/step/wait.h build_sources_headers-gpgme gpgme.h print/gpgme.h @@ -69,7 +69,7 @@ build_sources_library common.c common/define.c common/enumeration.c common/strin build_sources_library print/error.c print/message.c print/verbose.c print/warning.c build_sources_library packet.c process.c receive.c send.c signal.c tacocat.c thread.c build_sources_library receive/step/check.c receive/step/control.c receive/step/done.c receive/step/extract.c receive/step/find.c receive/step/next.c receive/step/packet.c receive/step/write.c -build_sources_library send/step/build.c send/step/check.c send/step/done.c send/step/encode.c send/step/file.c send/step/header.c send/step/packet.c send/step/size.c send/step/wait.c +build_sources_library send/step/build.c send/step/check.c send/step/done.c send/step/encode.c send/step/encrypt.c send/step/file.c send/step/header.c send/step/packet.c send/step/size.c send/step/wait.c build_sources_library-gpgme gpgme.c print/gpgme.c diff --git a/sources/c/program/kevux/tools/tacocat/main/common/define.h b/sources/c/program/kevux/tools/tacocat/main/common/define.h index 98bc7ee..a98e064 100644 --- a/sources/c/program/kevux/tools/tacocat/main/common/define.h +++ b/sources/c/program/kevux/tools/tacocat/main/common/define.h @@ -72,7 +72,7 @@ extern "C" { #define kt_tacocat_max_buffer_d 0x10000000 // 0x10^0x5 * 0x100 (Which is 256 Megabytes (0x10^0x5 where the base unit is 16 rather than 10 or 2 (maybe call this xytes? Megaxytes?)). #define kt_tacocat_max_maintain_d 0x100000 // 0x10^5 (Which is 1 Megabyte in base 16 (1 Megaxyte (MX)). - #define kt_tacocat_packet_headers_d 0x9 + #define kt_tacocat_packet_headers_d 0xb #define kt_tacocat_packet_id_length_d 0x20 #define kt_tacocat_packet_minimum_d 0x11 #define kt_tacocat_packet_peek_d 0x40 diff --git a/sources/c/program/kevux/tools/tacocat/main/common/string.c b/sources/c/program/kevux/tools/tacocat/main/common/string.c index f0c3337..196d130 100644 --- a/sources/c/program/kevux/tools/tacocat/main/common/string.c +++ b/sources/c/program/kevux/tools/tacocat/main/common/string.c @@ -17,8 +17,10 @@ extern "C" { const f_string_static_t kt_tacocat_classic_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_classic_s, KT_TACOCAT_classic_s_length); const f_string_static_t kt_tacocat_digit_negative_one_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_digit_negative_one_s, KT_TACOCAT_digit_negative_one_s_length); const f_string_static_t kt_tacocat_done_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_done_s, KT_TACOCAT_done_s_length); - const f_string_static_t kt_tacocat_kevux_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_kevux_s, KT_TACOCAT_kevux_s_length); + const f_string_static_t kt_tacocat_encrypt_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_encrypt_s, KT_TACOCAT_encrypt_s_length); const f_string_static_t kt_tacocat_file_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_file_s, KT_TACOCAT_file_s_length); + const f_string_static_t kt_tacocat_gpgme_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_gpgme_s, KT_TACOCAT_gpgme_s_length); + const f_string_static_t kt_tacocat_kevux_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_kevux_s, KT_TACOCAT_kevux_s_length); const f_string_static_t kt_tacocat_network_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_network_s, KT_TACOCAT_network_s_length); const f_string_static_t kt_tacocat_network_or_socket_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_network_or_socket_s, KT_TACOCAT_network_or_socket_s_length); const f_string_static_t kt_tacocat_next_s = macro_f_string_static_t_initialize_3(KT_TACOCAT_next_s, KT_TACOCAT_next_s_length); diff --git a/sources/c/program/kevux/tools/tacocat/main/common/string.h b/sources/c/program/kevux/tools/tacocat/main/common/string.h index 4589f8b..d81a32d 100644 --- a/sources/c/program/kevux/tools/tacocat/main/common/string.h +++ b/sources/c/program/kevux/tools/tacocat/main/common/string.h @@ -70,7 +70,9 @@ extern "C" { #define KT_TACOCAT_classic_s "classic" #define KT_TACOCAT_digit_negative_one_s "-1" #define KT_TACOCAT_done_s "done" + #define KT_TACOCAT_encrypt_s "encrypt" #define KT_TACOCAT_file_s "file" + #define KT_TACOCAT_gpgme_s "gpgme" #define KT_TACOCAT_kevux_s "kevux" #define KT_TACOCAT_network_s "network" #define KT_TACOCAT_network_or_socket_s "network / socket" @@ -97,10 +99,12 @@ extern "C" { #define KT_TACOCAT_classic_s_length 7 #define KT_TACOCAT_digit_negative_one_s_length 2 #define KT_TACOCAT_done_s_length 4 + #define KT_TACOCAT_encrypt_s_length 7 #define KT_TACOCAT_file_s_length 4 + #define KT_TACOCAT_gpgme_s_length 5 #define KT_TACOCAT_kevux_s_length 5 #define KT_TACOCAT_network_s_length 7 - #define KT_TACOCAT_network_or_socket_s_length 16 + #define KT_TACOCAT_network_or_socket_s_length 17 #define KT_TACOCAT_next_s_length 4 #define KT_TACOCAT_receive_s_length 7 #define KT_TACOCAT_receive_done_s_length 12 @@ -124,8 +128,10 @@ extern "C" { extern const f_string_static_t kt_tacocat_classic_s; extern const f_string_static_t kt_tacocat_digit_negative_one_s; extern const f_string_static_t kt_tacocat_done_s; - extern const f_string_static_t kt_tacocat_kevux_s; + extern const f_string_static_t kt_tacocat_encrypt_s; extern const f_string_static_t kt_tacocat_file_s; + extern const f_string_static_t kt_tacocat_gpgme_s; + extern const f_string_static_t kt_tacocat_kevux_s; extern const f_string_static_t kt_tacocat_network_s; extern const f_string_static_t kt_tacocat_network_or_socket_s; extern const f_string_static_t kt_tacocat_next_s; diff --git a/sources/c/program/kevux/tools/tacocat/main/common/type.c b/sources/c/program/kevux/tools/tacocat/main/common/type.c index b77e389..52629c2 100644 --- a/sources/c/program/kevux/tools/tacocat/main/common/type.c +++ b/sources/c/program/kevux/tools/tacocat/main/common/type.c @@ -19,8 +19,13 @@ extern "C" { if (!main) return; fll_program_data_delete(&main->program); + kt_tacocat_cache_delete(&main->cache); kt_tacocat_setting_delete(&main->setting); + + #ifdef _en_gpgme_support_ + kt_tacocat_gpgme_delete(&main->gpgme); + #endif // _en_gpgme_support_ } #endif // _di_kt_tacocat_main_delete_ @@ -42,9 +47,7 @@ extern "C" { if (!gpgme) return; - gpgme_release(gpgme->control); - - // @todo + gpgme_release(gpgme->context); gpgme->version = f_string_empty_s.string; } @@ -178,6 +181,20 @@ extern "C" { if (array[i].headers.size) { f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &array[i].headers.array, &array[i].headers.used, &array[i].headers.size, &f_string_maps_delete_callback); } + + #ifdef _en_gpgme_support_ + if (array[i].encrypt_read) { + gpgme_data_release(array[i].encrypt_read); + + array[i].encrypt_read = 0; + } + + if (array[i].encrypt_write) { + gpgme_data_release(array[i].encrypt_write); + + array[i].encrypt_write = 0; + } + #endif // _en_gpgme_support_ } // for } diff --git a/sources/c/program/kevux/tools/tacocat/main/common/type.h b/sources/c/program/kevux/tools/tacocat/main/common/type.h index 5f9c144..f48f2f7 100644 --- a/sources/c/program/kevux/tools/tacocat/main/common/type.h +++ b/sources/c/program/kevux/tools/tacocat/main/common/type.h @@ -76,6 +76,9 @@ extern "C" { * * - abstruses: The abstruse header map array, used for building the headers when sending a response. * - headers: The map of the headers after being processed for use when buulding the headers when sending a response. + * + * - encrypt_read: The encryption payload data, dependent on algorithm, for reading/input. + * - encrypt_write: The encryption payload data, dependent on algorithm, for writing/output. */ #ifndef _di_kt_tacocat_socket_set_t_ typedef struct { @@ -128,6 +131,14 @@ extern "C" { f_abstruse_maps_t abstruses; f_string_maps_t headers; + + #ifdef _en_gpgme_support_ + gpgme_data_t encrypt_read; + gpgme_data_t encrypt_write; + #else + uint8_t encrypt_read; + uint8_t encrypt_write; + #endif // _en_gpgme_support_ } kt_tacocat_socket_set_t; #define kt_tacocat_socket_set_t_initialize { \ @@ -175,6 +186,8 @@ extern "C" { .write_state = fl_fss_payload_header_state_t_initialize, \ .abstruses = f_abstruse_maps_t_initialize, \ .headers = f_string_maps_t_initialize, \ + .encrypt_read = 0, \ + .encrypt_write = 0, \ } #define macro_kt_tacocat_socket_set_t_initialize_1(size_block_value) { \ @@ -222,6 +235,8 @@ extern "C" { .write_state = fl_fss_payload_header_state_t_initialize, \ .abstruses = f_abstruse_maps_t_initialize, \ .headers = f_string_maps_t_initialize, \ + .encrypt_read = 0, \ + .encrypt_write = 0, \ } #define macro_kt_tacocat_socket_set_t_initialize_2(size_block_value, write_state_value) { \ @@ -269,6 +284,8 @@ extern "C" { .write_state = write_state_value, \ .abstruses = f_abstruse_maps_t_initialize, \ .headers = f_string_maps_t_initialize, \ + .encrypt_read = 0, \ + .encrypt_write = 0, \ } #endif // _di_kt_tacocat_socket_set_t_ @@ -442,8 +459,7 @@ extern "C" { * The GPGME data. * * Properties: - * - control: The GPGME control data. - * - data: The GPGME regular data. + * - context: The GPGME context data. * - engine: The GPGME engine inforrmation data. * - error: The GPGME error data. * @@ -451,8 +467,7 @@ extern "C" { */ #if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_gpgme_t_) typedef struct { - gpgme_ctx_t control; - gpgme_data_t data; + gpgme_ctx_t context; gpgme_engine_info_t engine; gpgme_error_t error; @@ -460,8 +475,7 @@ extern "C" { } kt_tacocat_gpgme_t; #define kt_tacocat_gpgme_t_initialize { \ - .control = 0, \ - .data = 0, \ + .context = 0, \ .engine = 0, \ .error = 0, \ .version = f_string_empty_s.string, \ diff --git a/sources/c/program/kevux/tools/tacocat/main/gpgme.c b/sources/c/program/kevux/tools/tacocat/main/gpgme.c index d84ada4..457dc28 100644 --- a/sources/c/program/kevux/tools/tacocat/main/gpgme.c +++ b/sources/c/program/kevux/tools/tacocat/main/gpgme.c @@ -13,9 +13,9 @@ extern "C" { gpgme->version = gpgme_check_version(0); - gpgme->error = gpgme_new(&gpgme->control); + gpgme->error = gpgme_engine_check_version(GPGME_PROTOCOL_OPENPGP); - if (gpgme->error) { + if (gpgme->error != GPG_ERR_NO_ERROR) { main->setting.state.status = F_status_set_error(F_failure); kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d); @@ -23,9 +23,9 @@ extern "C" { return; } - gpgme->error = gpgme_engine_check_version(GPGME_PROTOCOL_OPENPGP); + gpgme->error = gpgme_get_engine_info(&gpgme->engine); - if (gpgme->error) { + if (gpgme->error != GPG_ERR_NO_ERROR) { main->setting.state.status = F_status_set_error(F_failure); kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d); @@ -33,6 +33,25 @@ extern "C" { return; } + gpgme->error = gpgme_new(&gpgme->context); + + if (gpgme->error != GPG_ERR_NO_ERROR) { + main->setting.state.status = F_status_set_error(F_failure); + + kt_tacocat_print_gpgme_error(&main->program.error, F_status_debug_source_d); + + return; + } + + // Enable ASCII armor. + gpgme_set_armor(gpgme->context, F_true); + + // Disable online access. + gpgme_set_offline(gpgme->context, F_true); + + // Is this necessary? + //err = gpgme_ctx_set_engine_info(ceofcontext, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, enginfo->home_dir); + main->setting.state.status = F_okay; } #endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_gpgme_setup_) diff --git a/sources/c/program/kevux/tools/tacocat/main/packet.c b/sources/c/program/kevux/tools/tacocat/main/packet.c index 48f70c2..aeb4fa2 100644 --- a/sources/c/program/kevux/tools/tacocat/main/packet.c +++ b/sources/c/program/kevux/tools/tacocat/main/packet.c @@ -118,6 +118,8 @@ extern "C" { f_range_t_initialize, f_range_t_initialize, f_range_t_initialize, + f_range_t_initialize, + f_range_t_initialize, }; f_status_t status = set->status = F_okay; @@ -135,6 +137,8 @@ extern "C" { f_fss_payload_object_salt_s, f_fss_payload_object_id_s, f_fss_payload_object_time_s, + f_fss_payload_object_signature_s, + kt_tacocat_encrypt_s, }; for (; i < set->objects_header.used; ++i) { @@ -326,6 +330,10 @@ extern "C" { } } + // @todo convert signature (9). + + // @todo convert encrypt (10). + // Convert the length (2), part (3), total (4), and salt (6). { f_number_unsigned_t number = 0; diff --git a/sources/c/program/kevux/tools/tacocat/main/print/gpgme.c b/sources/c/program/kevux/tools/tacocat/main/print/gpgme.c index 68b0a7c..e95d4c7 100644 --- a/sources/c/program/kevux/tools/tacocat/main/print/gpgme.c +++ b/sources/c/program/kevux/tools/tacocat/main/print/gpgme.c @@ -4,7 +4,7 @@ extern "C" { #endif -#ifndef _di_kt_tacocat_print_gpgme_error_ +#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_) f_status_t kt_tacocat_print_gpgme_error(fl_print_t * const print, const f_string_t debug) { if (!print || !print->custom) return F_status_set_error(F_output_not); @@ -28,12 +28,11 @@ extern "C" { fl_print_format(".%]%r", print->to, print->context, f_string_eol_s); - f_file_stream_unlock(print->to); return F_okay; } -#endif // _di_kt_tacocat_print_gpgme_error_ +#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_) #ifdef __cplusplus } // extern "C" diff --git a/sources/c/program/kevux/tools/tacocat/main/print/gpgme.h b/sources/c/program/kevux/tools/tacocat/main/print/gpgme.h index e83e160..f72cb19 100644 --- a/sources/c/program/kevux/tools/tacocat/main/print/gpgme.h +++ b/sources/c/program/kevux/tools/tacocat/main/print/gpgme.h @@ -40,9 +40,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_kt_tacocat_print_gpgme_error_ +#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_) extern f_status_t kt_tacocat_print_gpgme_error(fl_print_t * const print, const f_string_t debug); -#endif // _di_kt_tacocat_print_gpgme_error_ +#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_print_gpgme_error_) #ifdef __cplusplus } // extern "C" diff --git a/sources/c/program/kevux/tools/tacocat/main/process.c b/sources/c/program/kevux/tools/tacocat/main/process.c index 5ea2fb8..301b4b9 100644 --- a/sources/c/program/kevux/tools/tacocat/main/process.c +++ b/sources/c/program/kevux/tools/tacocat/main/process.c @@ -65,10 +65,6 @@ extern "C" { if (F_status_is_error_not(main->setting.state.status)) { main->setting.state.status = F_okay; } - - #ifdef _en_gpgme_support_ - kt_tacocat_gpgme_delete(&main->gpgme); - #endif // _en_gpgme_support_ } #endif // _di_kt_tacocat_process_main_ @@ -128,6 +124,18 @@ extern "C" { // Index 9 is the signature. + // Index 10 is the encryption. + set->abstruses.array[10].key = kt_tacocat_encrypt_s; + set->abstruses.array[10].value.type = f_abstruse_dynamic_e; + set->abstruses.array[10].value.is.a_dynamic = f_string_empty_s; + set->abstruses.array[10].value.is.a_dynamic.size = 0; + + if ((main->setting.flag & kt_tacocat_main_flag_encrypt_d) && (set->flag & kt_tacocat_socket_step_flag_send_d)) { + #ifdef _en_gpgme_support_ + set->abstruses.array[10].value.is.a_dynamic = kt_tacocat_gpgme_s; + #endif // _en_gpgme_support_ + } + { long salt = 0; diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c new file mode 100644 index 0000000..3a64f67 --- /dev/null +++ b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.c @@ -0,0 +1,109 @@ +#include "../../tacocat.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_) + void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set) { + + if (!main || !set || F_status_is_error(set->status)) return; + + if (set->encrypt_read) { + gpgme_data_release(set->encrypt_read); + + set->encrypt_read = 0; + } + + gpgme_error_t error = gpgme_data_new_from_fd(&set->encrypt_read, set->file.id); + + if (error != GPG_ERR_NO_ERROR) { + set->status = F_status_set_error(F_memory); + + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s); + + return; + } + + error = gpgme_data_set_encoding(set->encrypt_read, GPGME_DATA_ENCODING_ARMOR); + + if (error != GPG_ERR_NO_ERROR) { + set->status = F_status_set_error(F_failure); + + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s); + + return; + } + + // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t. + // GPGME provides no way to get the file size of the encrypted data, so load the file and determine the file size as it is loading. + off_t total = 0; + gpgme_ssize_t bytes = 1; + + for (char buffer[set->file.size_read + 1]; bytes > 0 && total <= F_number_t_size_unsigned_d; total += bytes) { + bytes = gpgme_data_read(set->encrypt_read, buffer, set->file.size_read); + } // for + + if (bytes == -1) { + set->status = F_status_set_error(F_failure); + + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s); + + return; + } + + if ((f_number_unsigned_t) total > F_number_t_size_unsigned_d) { + set->status = F_status_set_error(F_too_large); + + kt_tacocat_print_error_on_file_too_large(&main->program.error, set->name, kt_tacocat_send_s, set->network, F_number_t_size_unsigned_d, set->abstruses.array[4].value.is.a_unsigned); + + return; + } + + error = gpgme_data_rewind(set->encrypt_read); + + if (error != GPG_ERR_NO_ERROR) { + set->status = F_status_set_error(F_failure); + + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_read_s); + + return; + } + + set->abstruses.array[3].value.is.a_unsigned = 0; + set->size_total = (f_number_unsigned_t) total; + + if (total) { + if (set->size_total < set->file.size_read) { + set->abstruses.array[2].value.is.a_unsigned = set->size_total; + set->abstruses.array[4].value.is.a_unsigned = 1; + } + else { + set->abstruses.array[2].value.is.a_unsigned = set->file.size_read; + set->abstruses.array[4].value.is.a_unsigned = set->size_total / set->file.size_read; + + if (set->abstruses.array[4].value.is.a_unsigned % set->file.size_read) { + ++set->abstruses.array[4].value.is.a_unsigned; + } + } + } + else { + set->abstruses.array[2].value.is.a_unsigned = set->size_total; + set->abstruses.array[4].value.is.a_unsigned = 1; + } + } +#endif // defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_) + +#if !defined(_en_gpgme_support_) && !defined(_di_kt_tacocat_send_step_encrypt_size_) + void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set) { + + set->status = F_status_set_error(F_implement_not); + + // @todo replace this with an error on encryption unsupported. + kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name); + } +#endif // _di_kt_tacocat_send_step_encrypt_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h new file mode 100644 index 0000000..670c591 --- /dev/null +++ b/sources/c/program/kevux/tools/tacocat/main/send/step/encrypt.h @@ -0,0 +1,61 @@ +/** + * Kevux Tools - TacocaT + * + * Project: Kevux Tools + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides send step encrypt functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _kt_tacocat_send_step_encrypt_h +#define _kt_tacocat_send_step_encrypt_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the size step of a send request using encryption. + * + * This prints on error. + * + * @param main + * The main program and settings data. + * + * Must not be NULL. + * + * This does not alter main.setting.state.status, except on interrupt signal. + * @param set + * The socket set to process. + * + * Must not be NULL. + * + * This alters set.status: + * F_okay on success. + * + * F_done (with error bit) on error that cannot continue, such as out of memory. + * F_too_large (with error bit) on file too large. + * + * Errors (with error bit) from: f_memory_array_increase_by() + * + * Errors (with error bit) from: gpgme_data_new_from_fd() + * Errors (with error bit) from: gpgme_data_read() + * Errors (with error bit) from: gpgme_data_set_encoding() + * + * @see f_memory_array_increase_by() + * + * @see gpgme_data_new_from_fd() + * @see gpgme_data_read() + * @see gpgme_data_set_encoding() + */ +#ifndef _di_kt_tacocat_send_step_encrypt_size_ + extern void kt_tacocat_send_step_encrypt_size(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set); +#endif // _di_kt_tacocat_send_step_encrypt_size_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _kt_tacocat_send_step_encrypt_h diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/file.c b/sources/c/program/kevux/tools/tacocat/main/send/step/file.c index ccf3497..3fa7ac9 100644 --- a/sources/c/program/kevux/tools/tacocat/main/send/step/file.c +++ b/sources/c/program/kevux/tools/tacocat/main/send/step/file.c @@ -9,6 +9,8 @@ extern "C" { if (!main || !set || F_status_is_error(set->status)) return; + // @todo if (main->setting.flag & kt_tacocat_main_flag_encrypt_d) { + set->status = f_string_dynamic_append(f_fss_payload_object_payload_s, &set->buffer); if (F_status_is_error_not(set->status)) { diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/packet.c b/sources/c/program/kevux/tools/tacocat/main/send/step/packet.c index 1252eaa..3b5a973 100644 --- a/sources/c/program/kevux/tools/tacocat/main/send/step/packet.c +++ b/sources/c/program/kevux/tools/tacocat/main/send/step/packet.c @@ -9,30 +9,25 @@ extern "C" { if (!main || !set || F_status_is_error(set->status)) return; - { - size_t written = 0; + size_t written = 0; - { - const size_t original = set->socket.size_write; + const size_t original = set->socket.size_write; - set->socket.size_write = set->buffer.used; + set->socket.size_write = set->buffer.used; - set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (void *) set->buffer.string, &written); + set->status = f_socket_write_stream(&set->socket, f_socket_flag_signal_not_e, (void *) set->buffer.string, &written); - set->socket.size_write = original; + set->socket.size_write = original; - if (F_status_is_error(set->status)) { - kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_packet_s, set->network, set->status, set->name); + if (F_status_is_error(set->status)) { + kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, kt_tacocat_send_packet_s, set->network, set->status, set->name); - return; - } - } - - // @todo handle case when written < set->buffer.used, of which each pass. The entire buffer must be sent. May need another variable for say, set->size_process. - - set->size_done += written; + return; } + // @todo handle case when written < set->buffer.used, of which each pass. The entire buffer must be sent. May need another variable for say, set->size_process. + + set->size_done += written; set->step = kt_tacocat_socket_step_send_wait_e; set->status = F_okay; } diff --git a/sources/c/program/kevux/tools/tacocat/main/send/step/size.c b/sources/c/program/kevux/tools/tacocat/main/send/step/size.c index 88c1735..68c7fc2 100644 --- a/sources/c/program/kevux/tools/tacocat/main/send/step/size.c +++ b/sources/c/program/kevux/tools/tacocat/main/send/step/size.c @@ -13,20 +13,23 @@ extern "C" { set->status = f_file_open(set->name, F_file_mode_all_r_d, &set->file); if (F_status_is_error(set->status)) { - kt_tacocat_print_error_on_file_receive(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_open_s); + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_s, set->network, set->status, set->name, f_file_operation_open_s); return; } } - // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t. - { + if (main->setting.flag & kt_tacocat_main_flag_encrypt_d) { + kt_tacocat_send_step_encrypt_size(main, set); + } else { + + // Total is used here to explicitly pass a pointer of off_t rather than a pointer of size_t cast to an off_t. off_t total = 0; set->status = f_file_size_by_id(set->file, &total); if (F_status_is_error(set->status)) { - kt_tacocat_print_error_on_file_receive(&main->program.error, F_status_debug_source_d, kt_tacocat_send_size_s, set->network, set->status, set->name, f_file_operation_open_s); + kt_tacocat_print_error_on_file_send(&main->program.error, F_status_debug_source_d, kt_tacocat_send_size_s, set->network, set->status, set->name, f_file_operation_open_s); return; } diff --git a/sources/c/program/kevux/tools/tacocat/main/tacocat.h b/sources/c/program/kevux/tools/tacocat/main/tacocat.h index fcc12c9..2684a55 100644 --- a/sources/c/program/kevux/tools/tacocat/main/tacocat.h +++ b/sources/c/program/kevux/tools/tacocat/main/tacocat.h @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include -- 1.8.3.1