xref: /netbsd-src/crypto/external/bsd/netpgp/dist/tst (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1#! /bin/sh
2
3# function to mark a test as good or bad
4marktest() {
5	local lnum=$1
6	local lgood=$2
7	if [ $lgood -eq $lnum ]; then
8		passed=$(expr $passed + 1)
9		echo "$lnum	yes" >> passed
10	else
11		echo "$lnum	no" >> passed
12	fi
13}
14
15while [ $# -gt 0 ]; do
16	case "$1" in
17	-v)
18		set -x
19		;;
20	*)
21		break
22		;;
23	esac
24	shift
25done
26
27env USETOOLS=no MAKEOBJDIRPREFIX=/usr/obj/i386 sh -c 'cd ../libmj && \
28	make cleandir ; \
29	su root -c "make includes"; \
30	make ; \
31	su root -c "make install"'
32env USETOOLS=no MAKEOBJDIRPREFIX=/usr/obj/i386 sh -c 'cd ../lib && \
33	make cleandir ; \
34	su root -c "make includes"; \
35	make ; \
36	su root -c "make install"'
37env USETOOLS=no MAKEOBJDIRPREFIX=/usr/obj/i386 sh -c 'cd ../netpgp && \
38	make cleandir ; \
39	make ; \
40	su root -c "make install"'
41env USETOOLS=no MAKEOBJDIRPREFIX=/usr/obj/i386 sh -c 'cd ../netpgpkeys && \
42	make cleandir ; \
43	make ; \
44	su root -c "make install"'
45env USETOOLS=no MAKEOBJDIRPREFIX=/usr/obj/i386 sh -c 'cd ../netpgpverify && \
46	make cleandir ; \
47	make ; \
48	su root -c "make install"'
49
50passed=0
51total=36
52rm -f passed
53date > passed
54echo "======> sign/verify 180938 file"
55cp configure a
56/usr/bin/netpgp --sign a
57/usr/bin/netpgp --verify a.gpg && good=1
58marktest 1 $good
59echo "======> attempt to verify an unsigned file"
60/usr/bin/netpgp --verify a || good=2
61marktest 2 $good
62echo "======> encrypt/decrypt 10809 file"
63cp src/netpgp/netpgp.1 b
64/usr/bin/netpgp --encrypt b
65/usr/bin/netpgp --decrypt b.gpg
66diff src/netpgp/netpgp.1 b && good=3
67marktest 3 $good
68echo "======> encrypt/decrypt 180938 file"
69cp configure c
70/usr/bin/netpgp --encrypt c
71/usr/bin/netpgp --decrypt c.gpg
72diff configure c && good=4
73marktest 4 $good
74echo "======> encrypt/decrypt bigass file"
75cat configure configure configure configure configure configure > d
76ls -l d
77cp d e
78/usr/bin/netpgp --encrypt d
79/usr/bin/netpgp --decrypt d.gpg
80diff e d && good=5
81marktest 5 $good
82echo "======> sign/verify detached signature file"
83cat configure configure configure configure configure configure > f
84/usr/bin/netpgp --sign --detached f
85ls -l f f.sig
86/usr/bin/netpgp --verify f.sig && good=6
87marktest 6 $good
88echo "======> cat signature - verified cat command"
89/usr/bin/netpgp --cat a.gpg > a2
90diff a a2 && good=7
91marktest 7 $good
92echo "======> another cat signature - verified cat command"
93/usr/bin/netpgp --cat --output=a3 a.gpg
94diff a a3 && good=8
95marktest 8 $good
96echo "======> netpgp list-packets test"
97/usr/bin/netpgp --list-packets || good=9
98marktest 9 $good
99echo "======> version information"
100/usr/bin/netpgp --version && good=10
101marktest 10 $good
102echo "======> netpgpverify file"
103/usr/bin/netpgpverify a.gpg && good=11
104marktest 11 $good
105echo "======> attempt to verify an unsigned file"
106/usr/bin/netpgpverify a || good=12
107marktest 12 $good
108echo "======> sign/verify detached signature file"
109ls -l f f.sig
110/usr/bin/netpgpverify f.sig && good=13
111marktest 13 $good
112echo "======> another verify signature - verified cat command"
113/usr/bin/netpgpverify --output=a3 a.gpg
114diff a a3 && good=14
115marktest 14 $good
116echo "======> list keys"
117/usr/bin/netpgpkeys --list-keys && good=15
118marktest 15 $good
119echo "======> version information"
120/usr/bin/netpgpverify --version && good=16
121marktest 16 $good
122echo "======> find specific key information"
123/usr/bin/netpgpkeys --get-key c0596823 agc@netbsd.org && good=17
124marktest 17 $good
125echo "======> ascii armoured signature"
126cp Makefile.am g
127/usr/bin/netpgp --sign --armor g && good=18
128marktest 18 $good
129echo "======> ascii armoured sig detection and verification"
130/usr/bin/netpgp --verify g.asc && good=19
131marktest 19 $good
132echo "======> ascii armoured signature of large file"
133cp Makefile.in g
134/usr/bin/netpgp --sign --armor g && good=20
135marktest 20 $good
136echo "======> ascii armoured sig detection and verification of large file"
137/usr/bin/netpgp --verify g.asc && good=21
138marktest 21 $good
139echo "======> verify memory by recognising ascii armour"
140/usr/bin/netpgp --cat < g.asc > g2
141diff g g2 && good=22
142marktest 22 $good
143echo "======> list ssh host RSA public key"
144/usr/bin/netpgpkeys --ssh --sshkeyfile=/etc/ssh/ssh_host_rsa_key.pub --list-keys && good=23
145marktest 23 $good
146echo "======> sign/verify file with ssh host keys"
147cp configure a
148sudo /usr/bin/netpgp --ssh --sshkeyfile=/etc/ssh/ssh_host_rsa_key.pub --sign a
149sudo chmod 644 a.gpg
150/usr/bin/netpgp --verify --ssh --sshkeyfile=/etc/ssh/ssh_host_rsa_key.pub a.gpg && good=24
151marktest 24 $good
152echo "======> pipeline and memory encrypt/decrypt"
153/usr/bin/netpgp --encrypt < a | /usr/bin/netpgp --decrypt > a4
154diff a a4 && good=25
155marktest 25 $good
156echo "======> pipeline and memory sign/verify"
157/usr/bin/netpgp --sign < a | /usr/bin/netpgp --cat > a5
158diff a a5 && good=26
159marktest 26 $good
160echo "======> verify within a duration"
161cp Makefile.am h
162/usr/bin/netpgp --sign --duration 6m --detached h
163/usr/bin/netpgp --verify h.sig && good=27
164marktest 27 $good
165echo "======> invalid signature - expired"
166rm -f h.sig
167/usr/bin/netpgp --sign --duration 2 --detached h
168sleep 3
169/usr/bin/netpgp --verify h.sig || good=28
170marktest 28 $good
171echo "======> list signatures and subkey signatures"
172/usr/bin/netpgpkeys --list-sigs && good=29
173marktest 29 $good
174echo "======> generate a new RSA key"
175/usr/bin/netpgpkeys --generate-key && good=30
176marktest 30 $good
177echo "======> ascii detached armoured signature"
178cp Makefile.am i
179/usr/bin/netpgp --sign --armor --detached i && good=31
180marktest 31 $good
181echo "======> ascii detached armoured sig detection and verification"
182/usr/bin/netpgp --verify i.asc && good=32
183marktest 32 $good
184echo "======> host ssh fingerprint and netpgp fingerprint"
185netpgpkey=$(/usr/bin/netpgpkeys --ssh --sshkeyfile=/etc/ssh/ssh_host_rsa_key.pub --list-keys --hash=md5 | awk 'NR == 3 { print $3 $4 $5 $6 $7 $8 $9 $10 }')
186sshkey=$(/usr/bin/ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub | awk '{ gsub(":", "", $2); print $2 }')
187echo "host sshkey \"$sshkey\" = netpgpkey \"$netpgpkey\""
188[ $sshkey = $netpgpkey ] && good=33
189marktest 33 $good
190echo "======> user ssh fingerprint and netpgp fingerprint"
191netpgpkey=$(/usr/bin/netpgpkeys --ssh --list-keys --hash=md5 | awk 'NR == 3 { print $3 $4 $5 $6 $7 $8 $9 $10 }')
192sshkey=$(/usr/bin/ssh-keygen -l -f /home/agc/.ssh/id_rsa.pub | awk '{ gsub(":", "", $2); print $2 }')
193echo "user sshkey \"$sshkey\" = netpgpkey \"$netpgpkey\""
194[ $sshkey = $netpgpkey ] && good=34
195marktest 34 $good
196echo "======> single key listing"
197/usr/bin/netpgpkeys -l agc && good=35
198marktest 35 $good
199echo "======> pipeline and memory encrypt/decrypt with specified cipher"
200/usr/bin/netpgp -e --cipher camellia128 < a | /usr/bin/netpgp -d > a6
201diff a a6 && good=36
202marktest 36 $good
203rm -f a a.gpg b b.gpg c c.gpg d d.gpg e f f.sig g g.asc g2 a2 a3 a4 a5 a6 h h.sig i i.asc
204echo "Passed ${passed}/${total} tests"
205