aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-17 11:21:01 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-17 11:21:01 -0900
commit4370c8aaf8d1ee9e078696c16a016557fdfe8be4 (patch)
tree97ec47d90ea42a651c63e63fc99e394542d7f69c
parent169310b7bfce5e45c1abfaf4938e3176c70597d2 (diff)
downloadotputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.gz
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.bz2
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.xz
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.zip
tests: adding test-otputil-otp.sh
-rw-r--r--Makefile.am11
-rw-r--r--tests/otp-data-dump.c239
-rwxr-xr-xtests/test-otputil-otp.sh129
3 files changed, 379 insertions, 0 deletions
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 \
83 src/otp-altdict \ 83 src/otp-altdict \
84 src/otputil \ 84 src/otputil \
85 tests/otp-data-convert \ 85 tests/otp-data-convert \
86 tests/otp-data-dump \
86 tests/test-dict-otp \ 87 tests/test-dict-otp \
87 tests/test-hotp \ 88 tests/test-hotp \
88 tests/test-otp \ 89 tests/test-otp \
@@ -141,6 +142,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-strictwarnings \
141if ENABLE_MAINTAINER 142if ENABLE_MAINTAINER
142 noinst_PROGRAMS += src/otp-altdict 143 noinst_PROGRAMS += src/otp-altdict
143 noinst_PROGRAMS += tests/otp-data-convert 144 noinst_PROGRAMS += tests/otp-data-convert
145 noinst_PROGRAMS += tests/otp-data-dump
144endif 146endif
145if ENABLE_EXAMPLES 147if ENABLE_EXAMPLES
146 noinst_PROGRAMS += examples/totp-example 148 noinst_PROGRAMS += examples/totp-example
@@ -158,6 +160,7 @@ endif
158if ENABLE_TESTS 160if ENABLE_TESTS
159 TESTS += tests/test-dict-otp 161 TESTS += tests/test-dict-otp
160 TESTS += tests/test-otputil-hotp.sh 162 TESTS += tests/test-otputil-hotp.sh
163 TESTS += tests/test-otputil-otp.sh
161 TESTS += tests/test-otputil-totp.sh 164 TESTS += tests/test-otputil-totp.sh
162 TESTS += tests/test-hotp 165 TESTS += tests/test-hotp
163 TESTS += tests/test-otp 166 TESTS += tests/test-otp
@@ -237,6 +240,14 @@ tests_otp_data_convert_SOURCES = tests/otp-data-convert.c \
237 tests/otp-dicts/rfc2289-sha1.c 240 tests/otp-dicts/rfc2289-sha1.c
238 241
239 242
243# macros for tests/otp-data-dump
244tests_otp_data_dump_DEPENDENCIES = Makefile $(noinst_LIBRARIES) $(lib_LTLIBRARIES)
245tests_otp_data_dump_LDADD = $(AM_LIBS) $(noinst_LIBRARIES) $(lib_LTLIBRARIES)
246tests_otp_data_dump_SOURCES = tests/otp-data.c \
247 tests/otp-data.h \
248 tests/otp-data-dump.c
249
250
240# macros for tests/test-dict-otp 251# macros for tests/test-dict-otp
241tests_test_dict_otp_DEPENDENCIES = Makefile $(noinst_LIBRARIES) $(lib_LTLIBRARIES) 252tests_test_dict_otp_DEPENDENCIES = Makefile $(noinst_LIBRARIES) $(lib_LTLIBRARIES)
242tests_test_dict_otp_LDADD = $(AM_LIBS) $(noinst_LIBRARIES) $(lib_LTLIBRARIES) 253tests_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 @@
1/*
2 * OTP Utilities
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of David M. Syzdek nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30/*
31 * @file tests/otp-data-dump.c
32 */
33#define _TESTS_OTP_DATA_DUMP_C 1
34
35///////////////
36// //
37// Headers //
38// //
39///////////////
40#pragma mark - Headers
41
42#include <otputil_compat.h>
43
44#ifdef HAVE_CONFIG_H
45# include <config.h>
46#endif
47
48#include <errno.h>
49#include <assert.h>
50#include <getopt.h>
51#include <stdio.h>
52#include <string.h>
53#include <strings.h>
54#include <inttypes.h>
55
56#include <otputil.h>
57
58#include "otp-data.h"
59
60
61///////////////////
62// //
63// Definitions //
64// //
65///////////////////
66#pragma mark - Definitions
67
68#ifndef PROGRAM_NAME
69#define PROGRAM_NAME "otp-data-dump"
70#endif
71#ifndef PACKAGE_BUGREPORT
72#define PACKAGE_BUGREPORT "david@syzdek.net"
73#endif
74#ifndef PACKAGE_COPYRIGHT
75#define PACKAGE_COPYRIGHT ""
76#endif
77#ifndef PACKAGE_NAME
78#define PACKAGE_NAME ""
79#endif
80#ifndef PACKAGE_VERSION
81#define PACKAGE_VERSION ""
82#endif
83
84
85/////////////////
86// //
87// Variables //
88// //
89/////////////////
90#pragma mark - Variables
91
92static int verbose = 0;
93static int quiet = 0;
94
95
96//////////////////
97// //
98// Prototypes //
99// //
100//////////////////
101#pragma mark - Prototypes
102
103int
104main(
105 int argc,
106 char * argv[] );
107
108
109/////////////////
110// //
111// Functions //
112// //
113/////////////////
114#pragma mark - Functions
115
116int
117main(
118 int argc,
119 char * argv[] )
120{
121 int c;
122 int opt_index;
123 int pos;
124 int len_hash;
125 int len_pass;
126 int len_seed;
127 int len_hex;
128 int len_six;
129 int len_alt;
130 int len;
131 const char * str;
132 const otptest_t * rec;
133
134 // getopt options
135 static const char * short_opt = "hqVv";
136 static struct option long_opt[] =
137 {
138 {"help", no_argument, NULL, 'h' },
139 {"quiet", no_argument, NULL, 'q' },
140 {"silent", no_argument, NULL, 'q' },
141 {"version", no_argument, NULL, 'V' },
142 {"verbose", no_argument, NULL, 'v' },
143 { NULL, 0, NULL, 0 }
144 };
145
146 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
147 {
148 switch(c)
149 {
150 case -1: /* no more arguments */
151 case 0: /* long options toggles */
152 break;
153
154 case 'h':
155 printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME);
156 printf("OPTIONS:\n");
157 printf(" -h, --help print this help and exit\n");
158 printf(" -q, --quiet, --silent do not print messages\n");
159 printf(" -V, --version print version number and exit\n");
160 printf(" -v, --verbose print verbose messages\n");
161 printf("\n");
162 return(0);
163
164 case 'q':
165 quiet++;
166 break;
167
168 case 'V':
169 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
170 printf("Written by David M. Syzdek.\n");
171 return(0);
172
173 case 'v':
174 verbose++;
175 break;
176
177 case '?':
178 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
179 return(1);
180
181 default:
182 fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
183 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
184 return(1);
185 };
186 };
187
188 len_hash = 0;
189 len_pass = 0;
190 len_seed = 0;
191 len_hex = 0;
192 len_six = 0;
193 len_alt = 0;
194 for(pos = 0; ((otp_test_data[pos].pass)); pos++)
195 {
196 rec = &otp_test_data[pos];
197 str = otputil_md2str(rec->method);
198 len_hash = ((len = (int)strlen(str)) > len_hash) ? len : len_hash;
199 len_pass = ((len = (int)strlen(rec->pass)) > len_pass) ? len : len_pass;
200 len_seed = ((len = (int)strlen(rec->seed)) > len_seed) ? len : len_seed;
201 len_hex = ((len = (int)strlen(rec->hex)) > len_hex) ? len : len_hex;
202 len_six = ((len = (int)strlen(rec->six)) > len_six) ? len : len_six;
203 len_alt = ((len = (int)strlen(rec->alt_md4)) > len_alt) ? len : len_alt;
204 len_alt = ((len = (int)strlen(rec->alt_md5)) > len_alt) ? len : len_alt;
205 len_alt = ((len = (int)strlen(rec->alt_sha1)) > len_alt) ? len : len_alt;
206 };
207 len_hash++;
208 len_pass++;
209 len_seed++;
210 len_hex++;
211 len_six++;
212 len_alt++;
213
214 for(pos = 0; ((otp_test_data[pos].pass)); pos++)
215 {
216 rec = &otp_test_data[pos];
217 str = otputil_md2str(rec->method);
218 printf("%-*s:", len_hash, str);
219 printf("%-*s:", len_pass, rec->pass);
220 printf("%-*s:", len_seed, rec->seed);
221 printf("%-3i:", rec->count);
222 printf("%-*s:", len_hex, rec->hex);
223 printf("%-*s:", len_six, rec->six);
224 switch(rec->method)
225 {
226 case OTPUTIL_MD_MD4: str = rec->alt_md4; break;
227 case OTPUTIL_MD_MD5: str = rec->alt_md5; break;
228 case OTPUTIL_MD_SHA1: str = rec->alt_sha1; break;
229 default: str = ""; break;
230 };
231 printf("%-*s:", len_alt, str);
232 printf("\n");
233 };
234
235 return(0);
236}
237
238
239/* 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 @@
1#!/bin/sh
2#
3# OTP Utilities
4# Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# * Neither the name of David M. Syzdek nor the
16# names of its contributors may be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO
21# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
23# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29# SUCH DAMAGE.
30#
31
32my_field()
33{
34 cut -d: -f${1} \
35 |sed \
36 -e 's/^-\{1,\}//g' \
37 -e 's/-\{1,\}$//g' \
38 -e 's/-/ /g'
39}
40
41my_payload()
42{
43 PAYLOAD_LINE=$(awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' $0)
44 TOTAL_LINES=$(($(wc -l "$0" |awk '{print$1}')+1))
45 if test "x${PAYLOAD_LINE}" == "x${TOTAL_LINES}";then
46 return 0;
47 fi
48 tail -n+${PAYLOAD_LINE} $0 \
49 |egrep -v '^[[:space:]]{0,}#|^[[:space:]]{0,}$' \
50 |sed -e 's/[[:space:]]/-/g'
51 return 0;
52}
53
54REC_ERR=0;
55
56for REC in $(my_payload);do
57 REC_HASH="$( echo "${REC}" |my_field 1 )"
58 REC_PASS="$( echo "${REC}" |my_field 2 )"
59 REC_SEED="$( echo "${REC}" |my_field 3 )"
60 REC_SEQ="$( echo "${REC}" |my_field 4 )"
61 REC_HEX="$( echo "${REC}" |my_field 5 )"
62 REC_SIX="$( echo "${REC}" |my_field 6 )"
63 REC_ALT="$( echo "${REC}" |my_field 7 )"
64
65 ./src/otputil -vv \
66 "otp-${REC_HASH}" \
67 "${REC_SEQ}" \
68 "${REC_SEED}" \
69 "${REC_HEX}" \
70 -P "${REC_PASS}" \
71 || REC_ERR=$((${REC_ERR}+1))
72
73 ./src/otputil -vv \
74 "otp-${REC_HASH}" \
75 "${REC_SEQ}" \
76 "${REC_SEED}" \
77 "${REC_SIX}" \
78 -P "${REC_PASS}" \
79 || REC_ERR=$((${REC_ERR}+1))
80
81 if test -z "${REC_ALT}";then
82 continue;
83 fi
84 ./src/otputil -vv \
85 "otp-${REC_HASH}" \
86 "${REC_SEQ}" \
87 "${REC_SEED}" \
88 "${REC_ALT}" \
89 -P "${REC_PASS}" \
90 || REC_ERR=$((${REC_ERR}+1))
91done
92
93echo "${REC_ERR} error(s) encountered"
94
95if test ${REC_ERR} -ne 0;then
96 exit 1;
97fi
98exit 0
99# end of script
100__PAYLOAD_BELOW__
101md5 :A_Valid_Pass_Phrase :AValidSeed :99 :85C4 3EE0 3857 765B :FOWL KID MASH DEAD DUAL OAF :Fot Acle Amu J ln Sax :
102md4 :This is a test. :TeSt :0 :D185 4218 EBBB 0B51 :ROME MUG FRED SCAN LIVE LACE :AER Il ERE Fao iso NIG :
103md4 :This is a test. :TeSt :1 :6347 3EF0 1CD0 B444 :CARD SAD MINI RYE COL KIN :CVA ISN Oys Mau ably hs :
104md4 :This is a test. :TeSt :99 :C5E6 1277 6E6C 237A :NOTE OUT IBIS SINK NAVE MODE :TEM TAX alo LEY God Hei :
105md4 :AbCdEfGhIjK :alpha1 :0 :5007 6F47 EB1A DE4E :AWAY SEN ROOK SALT LICE MAP :bw JER GLB kob cep MFA :
106md4 :AbCdEfGhIjK :alpha1 :1 :65D2 0D19 49B5 F7AB :CHEW GRIM WU HANG BUCK SAID :Dmd shf FALA boc que Lib :
107md4 :AbCdEfGhIjK :alpha1 :99 :D150 C82C CE6F 62D1 :ROIL FREE COG HUNK WAIT COCA :MIM IQS MHZ THO vr Hy :
108md4 :OTP's are good :correct :0 :849C 79D4 F6F5 5388 :FOOL STEM DONE TOOL BECK NILE :GOO fi IMP Hep EYRY QAT :
109md4 :OTP's are good :correct :1 :8C09 92FB 2508 47B1 :GIST AMOS MOOT AIDS FOOD SEEM :Cva Ys pw ios foy GOA :
110md4 :OTP's are good :correct :99 :3F3B F4B4 145F D74B :TAG SLOW NOV MIN WOOL KENO :Hup anet Ks kye Dur CTF :
111md5 :This is a test. :TeSt :0 :9E87 6134 D904 99DD :INCH SEA ANNE LONG AHEM TOUR :moid cuvy cise agal Bwr lax :
112md5 :This is a test. :TeSt :1 :7965 E054 36F5 029F :EASE OIL FUM CURE AWRY AVIS :bhat aces Ador pf Doat mi :
113md5 :This is a test. :TeSt :99 :50FE 1962 C496 5880 :BAIL TUFT BITS GANG CHEF THY :che Cob Mba Ods Cai bogs :
114md5 :AbCdEfGhIjK :alpha1 :0 :8706 6DD9 644B F206 :FULL PEW DOWN ONCE MORT ARC :esca Fod peh crt Eyl Bael :
115md5 :AbCdEfGhIjK :alpha1 :1 :7CD3 4C10 40AD D14B :FACT HOOF AT FIST SITE KENT :Ghi Pcp Ta didy tod ile :
116md5 :AbCdEfGhIjK :alpha1 :99 :5AA3 7A81 F212 146C :BODE HOP JAKE STOW JUT RAP :Fri Arcs bels tss Csi Cors :
117md5 :OTP's are good :correct :0 :F205 7539 43DE 4CF9 :ULAN NEW ARMY FUSE SUIT EYED :gaw kos apr tx Bs fels :
118md5 :OTP's are good :correct :1 :DDCD AC95 6F23 4937 :SKIM CULT LOB SLAM POE HOWL :ber frat ute Fcs bsf dyn :
119md5 :OTP's are good :correct :99 :B203 E28F A525 BE47 :LONG IVY JULY AJAR BOND LEE :agal Cmd frg Lewd in Duny :
120sha1 :This is a test. :TeSt :0 :BB9E 6AE1 979D 8FF4 :MILT VARY MAST OK SEES WENT :Gid hup Ai ex Ide aft :
121sha1 :This is a test. :TeSt :1 :63D9 3663 9734 385B :CART OTTO HIVE ODE VAT NUT :chi dft Rv avie arg Lld :
122sha1 :This is a test. :TeSt :99 :87FE C776 8B73 CCF9 :GAFF WAIT SKID GIG SKY EYED :allo Mc oof Dogs Gre fack :
123sha1 :AbCdEfGhIjK :alpha1 :0 :AD85 F658 EBE3 83C9 :LEST OR HEEL SCOT ROB SUIT :csi crs Adit ecg Cdr Yi :
124sha1 :AbCdEfGhIjK :alpha1 :1 :D07C E229 B5CF 119B :RITE TAKE GELD COST TUNE RECK :bs ph Saz fsb bute Meu :
125sha1 :AbCdEfGhIjK :alpha1 :99 :27BC 7103 5AAF 3DC6 :MAY STAR TIN LYON VEDA STAN :Arx Ios Fax n daw Kan :
126sha1 :OTP's are good :correct :0 :D51F 3E99 BF8E 6F0B :RUST WELT KICK FELL TAIL FRAU :gur Ami cebu nv Goe Iof :
127sha1 :OTP's are good :correct :1 :82AE B52D 9437 74E4 :FLIT DOSE ALSO MEW DRUM DEFY :Gis ctf pfg Kex fro Cuda :
128sha1 :OTP's are good :correct :99 :4F29 6A74 FE15 67EC :AURA ALOE HURL WING BERG WAIT :Moul oos Ci anni Awin Mc :
129# end of payload