aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-10 21:25:43 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-10 21:25:43 -0900
commit6e44f6dc838f4fa81bdd50241435feeec255a836 (patch)
tree619126ecdd9ad43f740921b59040dadc23a46f62
parentfb1b057592a57c69b2ad27bcc81eef0c2bfe890d (diff)
downloadotputils-6e44f6dc838f4fa81bdd50241435feeec255a836.tar.gz
otputils-6e44f6dc838f4fa81bdd50241435feeec255a836.tar.bz2
otputils-6e44f6dc838f4fa81bdd50241435feeec255a836.tar.xz
otputils-6e44f6dc838f4fa81bdd50241435feeec255a836.zip
otp-data-generate.sh: adding script
-rw-r--r--Makefile.am1
-rwxr-xr-xtests/otp-data-generate.sh155
2 files changed, 156 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index abf3499..18f1193 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -111,6 +111,7 @@ EXTRA_DIST = $(noinst_HEADERS) \
111 lib/libotputil/libotputil.sym \ 111 lib/libotputil/libotputil.sym \
112 lib/libotputil/lrfc6238-totp.h \ 112 lib/libotputil/lrfc6238-totp.h \
113 lib/libotputil/lrfc6238-totp.c \ 113 lib/libotputil/lrfc6238-totp.c \
114 tests/otp-data-generate.sh \
114 tests/otp-dicts/otp-dicts.h \ 115 tests/otp-dicts/otp-dicts.h \
115 tests/test-otputil-hotp.sh \ 116 tests/test-otputil-hotp.sh \
116 tests/test-otputil-totp.sh 117 tests/test-otputil-totp.sh
diff --git a/tests/otp-data-generate.sh b/tests/otp-data-generate.sh
new file mode 100755
index 0000000..58bee26
--- /dev/null
+++ b/tests/otp-data-generate.sh
@@ -0,0 +1,155 @@
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
32
33my_field()
34{
35 cut -b${1} \
36 |sed \
37 -e 's/^_\{1,\}//g' \
38 -e 's/_\{1,\}$//g' \
39 -e 's/_/ /g'
40}
41
42my_payload()
43{
44 PAYLOAD_LINE=$(awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' $0)
45 TOTAL_LINES=$(($(wc -l "$0" |awk '{print$1}')+1))
46 if test "x${PAYLOAD_LINE}" == "x${TOTAL_LINES}";then
47 return 0;
48 fi
49 tail -n+${PAYLOAD_LINE} $0 \
50 |egrep -v '^[[:space:]]{0,}#|^[[:space:]]{0,}$' \
51 |sed -e 's/[[:space:]]/_/g'
52 return 0;
53}
54
55my_raw()
56{
57 sed \
58 -e 's/\([a-f0-9]\{2\}\)\([a-f0-9]\{2\}\)/0x\1, 0x\2, /gi' \
59 -e 's/ \{1,\}/ /g' \
60 -e 's/, $//g'
61}
62
63my_word_convert()
64{
65 WORD_HASH="${1}"
66 shift;
67 ALTWORDS=""
68
69 for WORD in ${@};do
70 ALTWORD="$(./tests/otp-data-convert ${WORD_HASH} ${WORD})"
71 if test -z "${ALTWORD}";then
72 return 1;
73 fi
74 ALTWORDS="${ALTWORDS} ${ALTWORD}"
75 done
76 echo "${ALTWORDS}" |sed -e 's/^ \{1,\}//g' -e 's/ \{1,\}$//g'
77}
78
79for REC in $(my_payload);do
80 REC_HASH="$( echo "${REC}" |my_field 1-4 )"
81 REC_PASS="$( echo "${REC}" |my_field 6-20 )"
82 REC_SEED="$( echo "${REC}" |my_field 22-28 )"
83 REC_CNT="$( echo "${REC}" |my_field 30-31 )"
84 REC_HEX="$( echo "${REC}" |my_field 34-52 )"
85 REC_SIX="$( echo "${REC}" |my_field 54- )"
86 REC_RAW="$( echo "${REC}" |my_field 32-52 |my_raw )"
87 REC_MD4="$( my_word_convert md4 ${REC_SIX})"
88 REC_MD5="$( my_word_convert md5 ${REC_SIX})"
89 REC_SHA1="$( my_word_convert sha1 ${REC_SIX})"
90 cat << ' EOF' \
91 |sed \
92 -e "s/@HASH@/${REC_HASH}/g" \
93 -e "s/@PASS@/${REC_PASS}/g" \
94 -e "s/@SEED@/${REC_SEED}/g" \
95 -e "s/@COUNT@/${REC_CNT}/g" \
96 -e "s/@HEX@/${REC_HEX}/g" \
97 -e "s/@SIX@/${REC_SIX}/g" \
98 -e "s/@MD4@/${REC_MD4}/g" \
99 -e "s/@MD5@/${REC_MD5}/g" \
100 -e "s/@SHA1@/${REC_SHA1}/g" \
101 -e "s/@RAW@/${REC_RAW}/g"
102 {
103 .method = OTPUTIL_MD_@HASH@,
104 .pass = "@PASS@",
105 .seed = "@SEED@",
106 .count = @COUNT@,
107 .hex = "@HEX@",
108 .six = "@SIX@",
109 .alt_md4 = "@MD4@",
110 .alt_md5 = "@MD5@",
111 .alt_sha1 = "@SHA1@",
112 .dat.bv_val = (uint8_t []){ @RAW@ },
113 .dat.bv_len = 8,
114 },
115 EOF
116done
117
118exit 0
119# end of script
120__PAYLOAD_BELOW__
121
122# RFC 2289 Appendix C - OTP Verification Examples: MD4 ENCODINGS
123MD4 This is a test. TeSt 0 D185 4218 EBBB 0B51 ROME MUG FRED SCAN LIVE LACE
124MD4 This is a test. TeSt 1 6347 3EF0 1CD0 B444 CARD SAD MINI RYE COL KIN
125MD4 This is a test. TeSt 99 C5E6 1277 6E6C 237A NOTE OUT IBIS SINK NAVE MODE
126MD4 AbCdEfGhIjK alpha1 0 5007 6F47 EB1A DE4E AWAY SEN ROOK SALT LICE MAP
127MD4 AbCdEfGhIjK alpha1 1 65D2 0D19 49B5 F7AB CHEW GRIM WU HANG BUCK SAID
128MD4 AbCdEfGhIjK alpha1 99 D150 C82C CE6F 62D1 ROIL FREE COG HUNK WAIT COCA
129MD4 OTP's are good correct 0 849C 79D4 F6F5 5388 FOOL STEM DONE TOOL BECK NILE
130MD4 OTP's are good correct 1 8C09 92FB 2508 47B1 GIST AMOS MOOT AIDS FOOD SEEM
131MD4 OTP's are good correct 99 3F3B F4B4 145F D74B TAG SLOW NOV MIN WOOL KENO
132
133# RFC 2289 Appendix C - OTP Verification Examples: MD5 ENCODINGS
134MD5 This is a test. TeSt 0 9E87 6134 D904 99DD INCH SEA ANNE LONG AHEM TOUR
135MD5 This is a test. TeSt 1 7965 E054 36F5 029F EASE OIL FUM CURE AWRY AVIS
136MD5 This is a test. TeSt 99 50FE 1962 C496 5880 BAIL TUFT BITS GANG CHEF THY
137MD5 AbCdEfGhIjK alpha1 0 8706 6DD9 644B F206 FULL PEW DOWN ONCE MORT ARC
138MD5 AbCdEfGhIjK alpha1 1 7CD3 4C10 40AD D14B FACT HOOF AT FIST SITE KENT
139MD5 AbCdEfGhIjK alpha1 99 5AA3 7A81 F212 146C BODE HOP JAKE STOW JUT RAP
140MD5 OTP's are good correct 0 F205 7539 43DE 4CF9 ULAN NEW ARMY FUSE SUIT EYED
141MD5 OTP's are good correct 1 DDCD AC95 6F23 4937 SKIM CULT LOB SLAM POE HOWL
142MD5 OTP's are good correct 99 B203 E28F A525 BE47 LONG IVY JULY AJAR BOND LEE
143
144# RFC 2289 Appendix C - OTP Verification Examples: SHA1 ENCODINGS
145SHA1 This is a test. TeSt 0 BB9E 6AE1 979D 8FF4 MILT VARY MAST OK SEES WENT
146SHA1 This is a test. TeSt 1 63D9 3663 9734 385B CART OTTO HIVE ODE VAT NUT
147SHA1 This is a test. TeSt 99 87FE C776 8B73 CCF9 GAFF WAIT SKID GIG SKY EYED
148SHA1 AbCdEfGhIjK alpha1 0 AD85 F658 EBE3 83C9 LEST OR HEEL SCOT ROB SUIT
149SHA1 AbCdEfGhIjK alpha1 1 D07C E229 B5CF 119B RITE TAKE GELD COST TUNE RECK
150SHA1 AbCdEfGhIjK alpha1 99 27BC 7103 5AAF 3DC6 MAY STAR TIN LYON VEDA STAN
151SHA1 OTP's are good correct 0 D51F 3E99 BF8E 6F0B RUST WELT KICK FELL TAIL FRAU
152SHA1 OTP's are good correct 1 82AE B52D 9437 74E4 FLIT DOSE ALSO MEW DRUM DEFY
153SHA1 OTP's are good correct 99 4F29 6A74 FE15 67EC AURA ALOE HURL WING BERG WAIT
154
155# end of payload