diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index 5903a63d..01ebacd5 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -209,8 +209,9 @@ try_url(struct url *url, fko_cli_options_t *options) } else { - fprintf(stderr, "Invalid IP (%s) in HTTP response:\n\n%s\n", - ndx, http_response); + fprintf(stderr, + "[-] From http://%s%s\n Invalid IP (%s) in HTTP response:\n\n%s\n", + url->host, url->path, ndx, http_response); return(-1); } } diff --git a/python/README b/python/README index d98a55e4..86eafbb2 100644 --- a/python/README +++ b/python/README @@ -53,7 +53,7 @@ print "Timestamp:", fko.timestamp() print "Username:", fko.username() print "Digest Type (value):", fko.digest_type() print "Digest Type (string):", fko.digest_type_str() -print "Digest:", fko.digest() +print "Digest:", fko.spa_digest() print "SPA Message:", fko.spa_message() diff --git a/python/fko.py b/python/fko.py index f9cf5194..3e6a3f04 100644 --- a/python/fko.py +++ b/python/fko.py @@ -69,7 +69,7 @@ FKO_DIGEST_SHA256 = 3 FKO_DIGEST_SHA384 = 4 FKO_DIGEST_SHA512 = 5 -"""Digest type constants +"""Hmac type constants """ FKO_HMAC_INVALID_DATA = -1 FKO_HMAC_UNKNOWN = 0 @@ -482,7 +482,7 @@ class Fko: else: return _fko.get_spa_encryption_mode(self.ctx) - def spa_hmac_type(self, val=None): + def hmac_type(self, val=None): """Get or set the spa_hmac_type This is an integer value. If no argument is given, the current value diff --git a/python/fkomodule.c b/python/fkomodule.c index 1ae8d8c3..954b543b 100644 --- a/python/fkomodule.c +++ b/python/fkomodule.c @@ -1258,7 +1258,7 @@ key_gen(PyObject *self, PyObject *args) int hmac_type; int res; - if(!PyArg_ParseTuple(args, "s#s#i", &key_b64, &key_b64_len, + if(!PyArg_ParseTuple(args, "s#s#ih", &key_b64, &key_b64_len, &hmac_key_b64, &hmac_key_b64_len, &hmac_type)) return NULL; diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index 36e14810..65ef49c7 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -1,4 +1,8 @@ #!/usr/bin/perl -w +# +# This is the main driver program for the fwknop test suite. Test definitions +# are imported from the tests/ directory. +# use Cwd; use File::Copy; @@ -146,6 +150,8 @@ my $valgrind_cov_dir = 'valgrind-coverage'; our $spoof_ip = '1.2.3.4'; my $perl_mod_fko_dir = 'FKO'; +my $python_fko_dir = 'python_fko'; +my $python_script = 'fko-python.py'; our $cmd_exec_test_file = '/tmp/fwknoptest'; my $default_key = 'fwknoptest'; @@ -162,6 +168,7 @@ my @test_files = ( "$tests_dir/rijndael_backwards_compatibility.pl", "$tests_dir/rijndael_hmac.pl", "$tests_dir/perl_FKO_module.pl", + "$tests_dir/python_fko.pl", "$tests_dir/gpg_no_pw.pl", "$tests_dir/gpg.pl", ); @@ -180,6 +187,7 @@ our @rijndael_fuzzing = (); ### from tests/rijndael_fuzzing.pl our @gpg_no_pw = (); ### from tests/gpg_now_pw.pl our @gpg = (); ### from tests/gpg.pl our @perl_FKO_module = (); ### from tests/perl_FKO_module.pl +our @python_fko = (); ### from tests/python_fko.pl our @rijndael_backwards_compatibility = (); ### from tests/rijndael_backwards_compatibility.pl my $passed = 0; @@ -226,6 +234,7 @@ my $enable_profile_coverage_check = 0; my $enable_make_distcheck = 0; my $enable_perl_module_checks = 0; my $enable_perl_module_fuzzing_spa_pkt_generation = 0; +my $enable_python_module_checks = 0; my $enable_openssl_compatibility_tests = 0; my $openssl_success_ctr = 0; my $openssl_failure_ctr = 0; @@ -285,6 +294,7 @@ exit 1 unless GetOptions( 'exclude=s' => \$test_exclude, ### synonym 'enable-perl-module-checks' => \$enable_perl_module_checks, 'enable-perl-module-pkt-generation' => \$enable_perl_module_fuzzing_spa_pkt_generation, + 'enable-python-module-checks' => \$enable_python_module_checks, 'fuzzing-pkts-file=s' => \$fuzzing_pkts_file, 'fuzzing-pkts-append' => \$fuzzing_pkts_append, 'fuzzing-test-tag=s' => \$fuzzing_test_tag, @@ -318,6 +328,7 @@ if ($enable_all) { $enable_make_distcheck = 1; $enable_client_ip_resolve_test = 1; $enable_perl_module_checks = 1; + $enable_python_module_checks = 1; $enable_openssl_compatibility_tests = 1; } @@ -431,6 +442,7 @@ my @tests = ( @rijndael_fuzzing, @rijndael_hmac, @perl_FKO_module, + @python_fko, @gpg_no_pw, @gpg, ); @@ -561,7 +573,7 @@ if ($enable_openssl_compatibility_tests) { } if ($fuzzing_ctr > 0) { &logr("[+] $fuzzing_success_ctr/$fuzzing_failure_ctr/$fuzzing_ctr " . - "Fuzzing test passed/failed/executed\n"); + "Fuzzing tests passed/failed/executed\n"); } &logr("[+] $passed/$failed/$executed test buckets passed/failed/executed\n\n"); @@ -1177,6 +1189,56 @@ sub gpg_pinentry_check() { return $rv; } +sub python_fko_compile_install() { + my $test_hr = shift; + + my $rv = 1; + + if (-d $python_fko_dir) { + rmtree $python_fko_dir or die $!; + } + mkdir $python_fko_dir or die "[*] Could not mkdir $python_fko_dir: $!"; + + my $curr_pwd = cwd() or die $!; + + chdir '../python' or die $!; + + &run_cmd("python setup.py build", $cmd_out_tmp, + "../test/$curr_test_file"); + &run_cmd("python setup.py install --prefix=../test/$python_fko_dir", + $cmd_out_tmp, "../test/$curr_test_file"); + + chdir $curr_pwd or die $!; + + return $rv; +} + +sub python_fko_basic_exec() { + my $test_hr = shift; + + my $rv = 1; + + my $site_dir = "$python_fko_dir/lib"; + + for my $dir (glob("$site_dir/python*")) { + $site_dir = $dir; + last; + } + $site_dir .= '/site-packages'; + + unless (-d $site_dir) { + &write_test_file("[-] $site_dir directory dir does not exist.\n", + $curr_test_file); + return 0; + } + + $rv = &run_cmd("LD_LIBRARY_PATH=$lib_dir " . + "PYTHONPATH=$site_dir ./$python_script", $cmd_out_tmp, + $curr_test_file); + + return $rv; +} + sub perl_fko_module_compile_install() { my $test_hr = shift; @@ -4353,6 +4415,14 @@ sub init() { push @tests_to_exclude, qr/perl FKO module/; } + if ($enable_python_module_checks) { + die "[*] The python test script: $python_script doesn't exist ", + "or is not executable." + unless -e $python_script and -x $python_script; + } else { + push @tests_to_exclude, qr/python fko extension/; + } + if ($enable_perl_module_fuzzing_spa_pkt_generation) { push @tests_to_include, qr/perl FKO module/; if ($fuzzing_class eq 'bogus data') { diff --git a/test/tests/python_fko.pl b/test/tests/python_fko.pl new file mode 100644 index 00000000..8400db04 --- /dev/null +++ b/test/tests/python_fko.pl @@ -0,0 +1,17 @@ +@python_fko = ( + { + 'category' => 'python fko extension', + 'subcategory' => 'compile/install', + 'detail' => 'to: ./python_fko/', + 'function' => \&python_fko_compile_install, + 'fatal' => $NO + }, + { + 'category' => 'python fko extension', + 'subcategory' => 'basic exec', + 'detail' => 'import and use fko', + 'function' => \&python_fko_basic_exec, + 'fatal' => $NO + }, + +);