diff --git a/lib/fko_client_timeout.c b/lib/fko_client_timeout.c index f36e41ae..ecdb503d 100644 --- a/lib/fko_client_timeout.c +++ b/lib/fko_client_timeout.c @@ -74,7 +74,7 @@ fko_set_spa_client_timeout(fko_ctx_t ctx, const int timeout) break; } } - else /* Timeout is 0, which means no timeout. */ + else /* Timeout is 0, which means ignore it. */ { switch(ctx->message_type) { diff --git a/lib/fko_digest.c b/lib/fko_digest.c index 4d2d315b..8b52e1de 100644 --- a/lib/fko_digest.c +++ b/lib/fko_digest.c @@ -79,11 +79,20 @@ fko_set_raw_spa_digest_type(fko_ctx_t ctx, const short raw_digest_type) int fko_get_spa_digest_type(fko_ctx_t ctx, short *digest_type) { +#if HAVE_LIBFIU + fiu_return_on("fko_get_spa_digest_type_init", + FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) return(FKO_ERROR_CTX_NOT_INITIALIZED); +#if HAVE_LIBFIU + fiu_return_on("fko_get_spa_digest_type_val", + FKO_ERROR_INVALID_DATA); +#endif + if(digest_type == NULL) return(FKO_ERROR_INVALID_DATA); @@ -97,6 +106,10 @@ fko_get_spa_digest_type(fko_ctx_t ctx, short *digest_type) int fko_get_raw_spa_digest_type(fko_ctx_t ctx, short *raw_digest_type) { +#if HAVE_LIBFIU + fiu_return_on("fko_get_raw_spa_digest_type_init", + FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) @@ -115,9 +128,19 @@ set_digest(char *data, char **digest, short digest_type, int *digest_len) data_len = strnlen(data, MAX_SPA_ENCODED_MSG_SIZE); +#if HAVE_LIBFIU + fiu_return_on("set_digest_toobig", + FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_TOOBIG); +#endif + if(data_len == MAX_SPA_ENCODED_MSG_SIZE) return(FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_TOOBIG); +#if HAVE_LIBFIU + fiu_return_on("set_digest_invalidtype", FKO_ERROR_INVALID_DIGEST_TYPE); + fiu_return_on("set_digest_calloc", FKO_ERROR_MEMORY_ALLOCATION); +#endif + switch(digest_type) { case FKO_DIGEST_MD5: @@ -188,6 +211,9 @@ set_digest(char *data, char **digest, short digest_type, int *digest_len) int fko_set_spa_digest(fko_ctx_t ctx) { +#if HAVE_LIBFIU + fiu_return_on("fko_set_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) @@ -198,6 +224,10 @@ fko_set_spa_digest(fko_ctx_t ctx) if(ctx->encoded_msg == NULL) return(FKO_ERROR_MISSING_ENCODED_DATA); +#if HAVE_LIBFIU + fiu_return_on("fko_set_spa_digest_encoded", FKO_ERROR_MISSING_ENCODED_DATA); +#endif + return set_digest(ctx->encoded_msg, &ctx->digest, ctx->digest_type, &ctx->digest_len); } @@ -205,6 +235,9 @@ fko_set_spa_digest(fko_ctx_t ctx) int fko_set_raw_spa_digest(fko_ctx_t ctx) { +#if HAVE_LIBFIU + fiu_return_on("fko_set_raw_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) @@ -215,6 +248,10 @@ fko_set_raw_spa_digest(fko_ctx_t ctx) if(ctx->encrypted_msg == NULL) return(FKO_ERROR_MISSING_ENCODED_DATA); +#if HAVE_LIBFIU + fiu_return_on("fko_set_raw_spa_digest_val", FKO_ERROR_MISSING_ENCODED_DATA); +#endif + return set_digest(ctx->encrypted_msg, &ctx->raw_digest, ctx->raw_digest_type, &ctx->raw_digest_len); } @@ -222,11 +259,17 @@ fko_set_raw_spa_digest(fko_ctx_t ctx) int fko_get_spa_digest(fko_ctx_t ctx, char **md) { +#if HAVE_LIBFIU + fiu_return_on("fko_get_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) return(FKO_ERROR_CTX_NOT_INITIALIZED); +#if HAVE_LIBFIU + fiu_return_on("fko_get_spa_digest_val", FKO_ERROR_INVALID_DATA); +#endif if(md == NULL) return(FKO_ERROR_INVALID_DATA); @@ -238,6 +281,9 @@ fko_get_spa_digest(fko_ctx_t ctx, char **md) int fko_get_raw_spa_digest(fko_ctx_t ctx, char **md) { +#if HAVE_LIBFIU + fiu_return_on("fko_get_raw_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED); +#endif /* Must be initialized */ if(!CTX_INITIALIZED(ctx)) diff --git a/server/fw_util_iptables.c b/server/fw_util_iptables.c index dc8f5df4..2141f8ca 100644 --- a/server/fw_util_iptables.c +++ b/server/fw_util_iptables.c @@ -797,6 +797,10 @@ fw_config_init(fko_srv_options_t * const opts) */ strlcpy(fwc.fw_command, opts->config[CONF_FIREWALL_EXE], sizeof(fwc.fw_command)); +#if HAVE_LIBFIU + fiu_return_on("fw_config_init", 0); +#endif + /* Pull the fwknop chain config info and setup our internal * config struct. The IPT_INPUT is the only one that is * required. The rest are optional. diff --git a/test/fko-wrapper/fko_wrapper.c b/test/fko-wrapper/fko_wrapper.c index 96fa01fc..9f755366 100644 --- a/test/fko-wrapper/fko_wrapper.c +++ b/test/fko-wrapper/fko_wrapper.c @@ -220,16 +220,16 @@ test_loop_compounded(void) fko_new(&ctx); - res = fko_set_spa_client_timeout(ctx, i); - if (res != FKO_SUCCESS) - printf("fko_set_spa_client_timeout(): %s\n", fko_errstr(res)); - for (j=-1; j [qr/write bytes mismatch/] }, + + ### rand tags { 'category' => 'fault injection', 'subcategory' => 'client', @@ -170,6 +172,8 @@ "--fault-injection-tag fko_set_rand_value_calloc2", 'positive_output_matches' => [qr/Unable to allocate memory/] }, + + ### username tags { 'category' => 'fault injection', 'subcategory' => 'client', @@ -188,6 +192,57 @@ "--fault-injection-tag fko_set_username_strdup2", 'positive_output_matches' => [qr/Unable to allocate memory/] }, + + ### append_b64 tags + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag append_b64_toobig', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag append_b64_toobig", + 'positive_output_matches' => [qr/FKO_ERROR_INVALID_DATA_ENCODE_MESSAGE_TOOBIG/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag append_b64_calloc', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag append_b64_calloc", + 'positive_output_matches' => [qr/Unable to allocate memory/] + }, + + ### fko_encode_spa_data tags + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag fko_encode_spa_data_init', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag fko_encode_spa_data_init", + 'positive_output_matches' => [qr/FKO Context is not initialized/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag fko_encode_spa_data_valid', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag fko_encode_spa_data_valid", + 'positive_output_matches' => [qr/Missing or incomplete SPA data/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag fko_encode_spa_data_calloc', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag fko_encode_spa_data_calloc", + 'positive_output_matches' => [qr/Unable to allocate memory/] + }, + + ### timestamp tags { 'category' => 'fault injection', 'subcategory' => 'client', @@ -206,6 +261,8 @@ "--fault-injection-tag fko_set_timestamp_val", 'positive_output_matches' => [qr/FKO_ERROR_INVALID_DATA_TIMESTAMP_VALIDFAIL/] }, + + ### digest type { 'category' => 'fault injection', 'subcategory' => 'client', @@ -224,6 +281,54 @@ "--fault-injection-tag set_spa_digest_type_val", 'positive_output_matches' => [qr/FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_VALIDFAIL/] }, + + ### set digest + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag fko_set_spa_digest_init', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag fko_set_spa_digest_init", + 'positive_output_matches' => [qr/FKO Context is not initialized/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag fko_set_spa_digest_encoded', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag fko_set_spa_digest_encoded", + 'positive_output_matches' => [qr/There is no encoded data to process/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag set_digest_toobig', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag set_digest_toobig", + 'positive_output_matches' => [qr/FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_TOOBIG/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag set_digest_invalidtype', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag set_digest_invalidtype", + 'positive_output_matches' => [qr/Invalid digest type/] + }, + { + 'category' => 'fault injection', + 'subcategory' => 'client', + 'detail' => 'tag set_digest_calloc', + 'function' => \&fault_injection_tag, + 'cmdline' => "$default_client_hmac_args " . + "--fault-injection-tag set_digest_calloc", + 'positive_output_matches' => [qr/Unable to allocate memory/] + }, + { 'category' => 'fault injection', 'subcategory' => 'client', @@ -280,9 +385,7 @@ }, ### fwknopd injections - - - + ### username tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -312,6 +415,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### timestamp tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -341,6 +445,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### message type tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -369,6 +474,8 @@ 'server_positive_output_matches' => [qr/Args contain invalid data/], 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + + ### message tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -398,7 +505,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, - + ### nat access tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -428,6 +535,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### server auth tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -457,6 +565,87 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### raw digest type tags + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_raw_spa_digest_type_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_raw_spa_digest_type_init", + 'server_positive_output_matches' => [qr/FKO Context is not initialized/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + + ### digest type tags + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_spa_digest_type_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_spa_digest_type_init --test", + ### --test above since tag only triggered when dumping context + 'server_positive_output_matches' => [qr/FKO Context is not initialized/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_spa_digest_type_val', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_spa_digest_type_val --test", + ### --test above since tag only triggered when dumping context + 'server_positive_output_matches' => [qr/Args contain invalid data/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + + ### digest tags + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_spa_digest_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_spa_digest_init --test", + ### --test above since tag only triggered when dumping context + 'server_positive_output_matches' => [qr/FKO Context is not initialized/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_spa_digest_val', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_spa_digest_val --test", + ### --test above since tag only triggered when dumping context + 'server_positive_output_matches' => [qr/Args contain invalid data/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + + ### client timeout tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -486,6 +675,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### version tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -515,6 +705,7 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### digest type tags { 'category' => 'fault injection', 'subcategory' => 'server', @@ -544,4 +735,48 @@ 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, }, + ### raw digest tags + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_set_raw_spa_digest_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_set_raw_spa_digest_init", + 'server_positive_output_matches' => [qr/FKO Context is not initialized/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fko_get_raw_spa_digest_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => $default_client_hmac_args, + 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fko_get_raw_spa_digest_init", + 'server_positive_output_matches' => [qr/FKO Context is not initialized/], + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + + ### fw_config_init + { + 'category' => 'fault injection', + 'subcategory' => 'server', + 'detail' => 'tag fw_config_init', + 'function' => \&fault_injection_tag, + 'no_ip_check' => 1, + 'client_pkt_tries' => 1, + 'cmdline' => "$fwknopdCmd -c $cf{'disable_aging'} -a $cf{'hmac_access'} " . + "-d $default_digest_file -p $default_pid_file $intf_str " . + "--fault-injection-tag fw_config_init", + 'fw_rule_created' => $REQUIRE_NO_NEW_RULE, + }, + );