From 4370c8aaf8d1ee9e078696c16a016557fdfe8be4 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Tue, 17 Jan 2023 11:21:01 -0900 Subject: tests: adding test-otputil-otp.sh --- Makefile.am | 11 +++ tests/otp-data-dump.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test-otputil-otp.sh | 129 +++++++++++++++++++++++++ 3 files changed, 379 insertions(+) create mode 100644 tests/otp-data-dump.c create mode 100755 tests/test-otputil-otp.sh diff --git a/Makefile.am b/Makefile.am index cc1aeb6..159ef9e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,7 @@ EXTRA_PROGRAMS = examples/totp-example \ src/otp-altdict \ src/otputil \ tests/otp-data-convert \ + tests/otp-data-dump \ tests/test-dict-otp \ tests/test-hotp \ tests/test-otp \ @@ -141,6 +142,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-strictwarnings \ if ENABLE_MAINTAINER noinst_PROGRAMS += src/otp-altdict noinst_PROGRAMS += tests/otp-data-convert + noinst_PROGRAMS += tests/otp-data-dump endif if ENABLE_EXAMPLES noinst_PROGRAMS += examples/totp-example @@ -158,6 +160,7 @@ endif if ENABLE_TESTS TESTS += tests/test-dict-otp TESTS += tests/test-otputil-hotp.sh + TESTS += tests/test-otputil-otp.sh TESTS += tests/test-otputil-totp.sh TESTS += tests/test-hotp TESTS += tests/test-otp @@ -237,6 +240,14 @@ tests_otp_data_convert_SOURCES = tests/otp-data-convert.c \ tests/otp-dicts/rfc2289-sha1.c +# macros for tests/otp-data-dump +tests_otp_data_dump_DEPENDENCIES = Makefile $(noinst_LIBRARIES) $(lib_LTLIBRARIES) +tests_otp_data_dump_LDADD = $(AM_LIBS) $(noinst_LIBRARIES) $(lib_LTLIBRARIES) +tests_otp_data_dump_SOURCES = tests/otp-data.c \ + tests/otp-data.h \ + tests/otp-data-dump.c + + # macros for tests/test-dict-otp tests_test_dict_otp_DEPENDENCIES = Makefile $(noinst_LIBRARIES) $(lib_LTLIBRARIES) tests_test_dict_otp_LDADD = $(AM_LIBS) $(noinst_LIBRARIES) $(lib_LTLIBRARIES) diff --git a/tests/otp-data-dump.c b/tests/otp-data-dump.c new file mode 100644 index 0000000..d4da2d8 --- /dev/null +++ b/tests/otp-data-dump.c @@ -0,0 +1,239 @@ +/* + * OTP Utilities + * Copyright (C) 2022 David M. Syzdek . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of David M. Syzdek nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * @file tests/otp-data-dump.c + */ +#define _TESTS_OTP_DATA_DUMP_C 1 + +/////////////// +// // +// Headers // +// // +/////////////// +#pragma mark - Headers + +#include + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "otp-data.h" + + +/////////////////// +// // +// Definitions // +// // +/////////////////// +#pragma mark - Definitions + +#ifndef PROGRAM_NAME +#define PROGRAM_NAME "otp-data-dump" +#endif +#ifndef PACKAGE_BUGREPORT +#define PACKAGE_BUGREPORT "david@syzdek.net" +#endif +#ifndef PACKAGE_COPYRIGHT +#define PACKAGE_COPYRIGHT "" +#endif +#ifndef PACKAGE_NAME +#define PACKAGE_NAME "" +#endif +#ifndef PACKAGE_VERSION +#define PACKAGE_VERSION "" +#endif + + +///////////////// +// // +// Variables // +// // +///////////////// +#pragma mark - Variables + +static int verbose = 0; +static int quiet = 0; + + +////////////////// +// // +// Prototypes // +// // +////////////////// +#pragma mark - Prototypes + +int +main( + int argc, + char * argv[] ); + + +///////////////// +// // +// Functions // +// // +///////////////// +#pragma mark - Functions + +int +main( + int argc, + char * argv[] ) +{ + int c; + int opt_index; + int pos; + int len_hash; + int len_pass; + int len_seed; + int len_hex; + int len_six; + int len_alt; + int len; + const char * str; + const otptest_t * rec; + + // getopt options + static const char * short_opt = "hqVv"; + static struct option long_opt[] = + { + {"help", no_argument, NULL, 'h' }, + {"quiet", no_argument, NULL, 'q' }, + {"silent", no_argument, NULL, 'q' }, + {"version", no_argument, NULL, 'V' }, + {"verbose", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } + }; + + while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) + { + switch(c) + { + case -1: /* no more arguments */ + case 0: /* long options toggles */ + break; + + case 'h': + printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME); + printf("OPTIONS:\n"); + printf(" -h, --help print this help and exit\n"); + printf(" -q, --quiet, --silent do not print messages\n"); + printf(" -V, --version print version number and exit\n"); + printf(" -v, --verbose print verbose messages\n"); + printf("\n"); + return(0); + + case 'q': + quiet++; + break; + + case 'V': + printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION); + printf("Written by David M. Syzdek.\n"); + return(0); + + case 'v': + verbose++; + break; + + case '?': + fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + return(1); + + default: + fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c); + fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + return(1); + }; + }; + + len_hash = 0; + len_pass = 0; + len_seed = 0; + len_hex = 0; + len_six = 0; + len_alt = 0; + for(pos = 0; ((otp_test_data[pos].pass)); pos++) + { + rec = &otp_test_data[pos]; + str = otputil_md2str(rec->method); + len_hash = ((len = (int)strlen(str)) > len_hash) ? len : len_hash; + len_pass = ((len = (int)strlen(rec->pass)) > len_pass) ? len : len_pass; + len_seed = ((len = (int)strlen(rec->seed)) > len_seed) ? len : len_seed; + len_hex = ((len = (int)strlen(rec->hex)) > len_hex) ? len : len_hex; + len_six = ((len = (int)strlen(rec->six)) > len_six) ? len : len_six; + len_alt = ((len = (int)strlen(rec->alt_md4)) > len_alt) ? len : len_alt; + len_alt = ((len = (int)strlen(rec->alt_md5)) > len_alt) ? len : len_alt; + len_alt = ((len = (int)strlen(rec->alt_sha1)) > len_alt) ? len : len_alt; + }; + len_hash++; + len_pass++; + len_seed++; + len_hex++; + len_six++; + len_alt++; + + for(pos = 0; ((otp_test_data[pos].pass)); pos++) + { + rec = &otp_test_data[pos]; + str = otputil_md2str(rec->method); + printf("%-*s:", len_hash, str); + printf("%-*s:", len_pass, rec->pass); + printf("%-*s:", len_seed, rec->seed); + printf("%-3i:", rec->count); + printf("%-*s:", len_hex, rec->hex); + printf("%-*s:", len_six, rec->six); + switch(rec->method) + { + case OTPUTIL_MD_MD4: str = rec->alt_md4; break; + case OTPUTIL_MD_MD5: str = rec->alt_md5; break; + case OTPUTIL_MD_SHA1: str = rec->alt_sha1; break; + default: str = ""; break; + }; + printf("%-*s:", len_alt, str); + printf("\n"); + }; + + return(0); +} + + +/* end of source file */ diff --git a/tests/test-otputil-otp.sh b/tests/test-otputil-otp.sh new file mode 100755 index 0000000..09a534c --- /dev/null +++ b/tests/test-otputil-otp.sh @@ -0,0 +1,129 @@ +#!/bin/sh +# +# OTP Utilities +# Copyright (C) 2022 David M. Syzdek . +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of David M. Syzdek nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +my_field() +{ + cut -d: -f${1} \ + |sed \ + -e 's/^-\{1,\}//g' \ + -e 's/-\{1,\}$//g' \ + -e 's/-/ /g' +} + +my_payload() +{ + PAYLOAD_LINE=$(awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' $0) + TOTAL_LINES=$(($(wc -l "$0" |awk '{print$1}')+1)) + if test "x${PAYLOAD_LINE}" == "x${TOTAL_LINES}";then + return 0; + fi + tail -n+${PAYLOAD_LINE} $0 \ + |egrep -v '^[[:space:]]{0,}#|^[[:space:]]{0,}$' \ + |sed -e 's/[[:space:]]/-/g' + return 0; +} + +REC_ERR=0; + +for REC in $(my_payload);do + REC_HASH="$( echo "${REC}" |my_field 1 )" + REC_PASS="$( echo "${REC}" |my_field 2 )" + REC_SEED="$( echo "${REC}" |my_field 3 )" + REC_SEQ="$( echo "${REC}" |my_field 4 )" + REC_HEX="$( echo "${REC}" |my_field 5 )" + REC_SIX="$( echo "${REC}" |my_field 6 )" + REC_ALT="$( echo "${REC}" |my_field 7 )" + + ./src/otputil -vv \ + "otp-${REC_HASH}" \ + "${REC_SEQ}" \ + "${REC_SEED}" \ + "${REC_HEX}" \ + -P "${REC_PASS}" \ + || REC_ERR=$((${REC_ERR}+1)) + + ./src/otputil -vv \ + "otp-${REC_HASH}" \ + "${REC_SEQ}" \ + "${REC_SEED}" \ + "${REC_SIX}" \ + -P "${REC_PASS}" \ + || REC_ERR=$((${REC_ERR}+1)) + + if test -z "${REC_ALT}";then + continue; + fi + ./src/otputil -vv \ + "otp-${REC_HASH}" \ + "${REC_SEQ}" \ + "${REC_SEED}" \ + "${REC_ALT}" \ + -P "${REC_PASS}" \ + || REC_ERR=$((${REC_ERR}+1)) +done + +echo "${REC_ERR} error(s) encountered" + +if test ${REC_ERR} -ne 0;then + exit 1; +fi +exit 0 +# end of script +__PAYLOAD_BELOW__ +md5 :A_Valid_Pass_Phrase :AValidSeed :99 :85C4 3EE0 3857 765B :FOWL KID MASH DEAD DUAL OAF :Fot Acle Amu J ln Sax : +md4 :This is a test. :TeSt :0 :D185 4218 EBBB 0B51 :ROME MUG FRED SCAN LIVE LACE :AER Il ERE Fao iso NIG : +md4 :This is a test. :TeSt :1 :6347 3EF0 1CD0 B444 :CARD SAD MINI RYE COL KIN :CVA ISN Oys Mau ably hs : +md4 :This is a test. :TeSt :99 :C5E6 1277 6E6C 237A :NOTE OUT IBIS SINK NAVE MODE :TEM TAX alo LEY God Hei : +md4 :AbCdEfGhIjK :alpha1 :0 :5007 6F47 EB1A DE4E :AWAY SEN ROOK SALT LICE MAP :bw JER GLB kob cep MFA : +md4 :AbCdEfGhIjK :alpha1 :1 :65D2 0D19 49B5 F7AB :CHEW GRIM WU HANG BUCK SAID :Dmd shf FALA boc que Lib : +md4 :AbCdEfGhIjK :alpha1 :99 :D150 C82C CE6F 62D1 :ROIL FREE COG HUNK WAIT COCA :MIM IQS MHZ THO vr Hy : +md4 :OTP's are good :correct :0 :849C 79D4 F6F5 5388 :FOOL STEM DONE TOOL BECK NILE :GOO fi IMP Hep EYRY QAT : +md4 :OTP's are good :correct :1 :8C09 92FB 2508 47B1 :GIST AMOS MOOT AIDS FOOD SEEM :Cva Ys pw ios foy GOA : +md4 :OTP's are good :correct :99 :3F3B F4B4 145F D74B :TAG SLOW NOV MIN WOOL KENO :Hup anet Ks kye Dur CTF : +md5 :This is a test. :TeSt :0 :9E87 6134 D904 99DD :INCH SEA ANNE LONG AHEM TOUR :moid cuvy cise agal Bwr lax : +md5 :This is a test. :TeSt :1 :7965 E054 36F5 029F :EASE OIL FUM CURE AWRY AVIS :bhat aces Ador pf Doat mi : +md5 :This is a test. :TeSt :99 :50FE 1962 C496 5880 :BAIL TUFT BITS GANG CHEF THY :che Cob Mba Ods Cai bogs : +md5 :AbCdEfGhIjK :alpha1 :0 :8706 6DD9 644B F206 :FULL PEW DOWN ONCE MORT ARC :esca Fod peh crt Eyl Bael : +md5 :AbCdEfGhIjK :alpha1 :1 :7CD3 4C10 40AD D14B :FACT HOOF AT FIST SITE KENT :Ghi Pcp Ta didy tod ile : +md5 :AbCdEfGhIjK :alpha1 :99 :5AA3 7A81 F212 146C :BODE HOP JAKE STOW JUT RAP :Fri Arcs bels tss Csi Cors : +md5 :OTP's are good :correct :0 :F205 7539 43DE 4CF9 :ULAN NEW ARMY FUSE SUIT EYED :gaw kos apr tx Bs fels : +md5 :OTP's are good :correct :1 :DDCD AC95 6F23 4937 :SKIM CULT LOB SLAM POE HOWL :ber frat ute Fcs bsf dyn : +md5 :OTP's are good :correct :99 :B203 E28F A525 BE47 :LONG IVY JULY AJAR BOND LEE :agal Cmd frg Lewd in Duny : +sha1 :This is a test. :TeSt :0 :BB9E 6AE1 979D 8FF4 :MILT VARY MAST OK SEES WENT :Gid hup Ai ex Ide aft : +sha1 :This is a test. :TeSt :1 :63D9 3663 9734 385B :CART OTTO HIVE ODE VAT NUT :chi dft Rv avie arg Lld : +sha1 :This is a test. :TeSt :99 :87FE C776 8B73 CCF9 :GAFF WAIT SKID GIG SKY EYED :allo Mc oof Dogs Gre fack : +sha1 :AbCdEfGhIjK :alpha1 :0 :AD85 F658 EBE3 83C9 :LEST OR HEEL SCOT ROB SUIT :csi crs Adit ecg Cdr Yi : +sha1 :AbCdEfGhIjK :alpha1 :1 :D07C E229 B5CF 119B :RITE TAKE GELD COST TUNE RECK :bs ph Saz fsb bute Meu : +sha1 :AbCdEfGhIjK :alpha1 :99 :27BC 7103 5AAF 3DC6 :MAY STAR TIN LYON VEDA STAN :Arx Ios Fax n daw Kan : +sha1 :OTP's are good :correct :0 :D51F 3E99 BF8E 6F0B :RUST WELT KICK FELL TAIL FRAU :gur Ami cebu nv Goe Iof : +sha1 :OTP's are good :correct :1 :82AE B52D 9437 74E4 :FLIT DOSE ALSO MEW DRUM DEFY :Gis ctf pfg Kex fro Cuda : +sha1 :OTP's are good :correct :99 :4F29 6A74 FE15 67EC :AURA ALOE HURL WING BERG WAIT :Moul oos Ci anni Awin Mc : +# end of payload -- cgit v1.2.3