summaryrefslogtreecommitdiffstats
path: root/checks/checkit
blob: 09cf7ac8db582eb561f3b88754cf01889e35644e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
#  Script for G10 testing
#---------------------------------------------------------

#--------------------------------
#------ constants ---------------
#--------------------------------

usrname1="one"
usrpass1="def"
usrname2="two"
usrpass2="abc"
plain_files="plain-1 plain-2 plain-3"
data_files=""
exp_files=""


#--------------------------------
#------ utility functions -------
#--------------------------------

fatal () {
    echo "$pgmname: fatal:" $* >&2
    exit 1;
}

error () {
    echo "$pgmname:" $* >&2
    exit 1
}

info () {
    echo "$pgmname:" $* >&2
}

chdir () {
    cd $1 || fatal "cannot cd to $1"
}

cleanup () {
    rm $data_files x y z 2>/dev/null
    echo "#empty" >./.g10/options
}


run_g10 () {
    eval HOME=. ../g10/g10 $*
    if [ $? != 0 ] ; then
	g10_err=$?
	echo "(HOME=. ../g10/g10 $*) failed" >&2
	error "g10 failed: $g10_err" >&2
    fi
}

#--------------------------------
#-------- main program ----------
#--------------------------------

set -e
pgmname=$(basename $0)
#trap cleanup EXIT SIGHUP SIGINT SIGQUIT


# some checks
[ -d "./.g10" ] || fatal "subdirectory .g10 missing"
for i in $plain_files; do
    [ -f $i ] || fatal "$i: missing"
done
for i in $exp_files; do
    [ -f $i ] || fatal "$i: script missing"
done
# create the keyrings

cat <<EOF  >./.g10/options
no-greeting
no-secmem-warning
batch
EOF

# print the G10 version
run_g10 --version
# intialize the trustdb

info Checking decryption
for i in $plain_files ; do
    echo "$usrpass1" | run_g10 --passphrase-fd 0 -o y --yes $i.asc
    cmp $i y || error "$i: mismatch"
done

#info Checking cleartext signatures
## There is a minor glitch, which appends a lf to the cleartext.
## I do not consider that a bug, but I have to use the head .. mimic.
## It is not clear what should happen to leading LFs, we must
## change the defintion of cleartext, so that only 1 empty line
## must follow the headers, but some specs say: any number of empty lines ..
## clean-sat removes leading LFs
## I know that this does not work for random data files (due to large lines
## or what ever) - I hope we can live with it.
#for i in $plain_files; do
#    echo "$usrpass1" | run_g10 --passphrase-fd 0 -sat -o x --yes $i
#    run_g10 -o y --yes x
#    ../tools/clean-sat < $i > z
#    head -c $[ $(cat y | wc -c) - 1 ] y | diff - z || error "$i: mismatch"
#done

info Creating some random data files
for i in 500 9000 32000 80000; do
    head -c $i /dev/urandom >data-$i
    data_files="$data_files data-$i"
done

#info Checking armored signatures
#for i in $plain_files $data_files ; do
#    echo "$usrpass1" | run_g10 --passphrase-fd 0 -sa -o x --yes $i
#    run_g10 -o y --yes x
#    cmp $i y || error "$i: mismatch"
#done
#
#info Checking signatures
#for i in $plain_files $data_files; do
#    echo "$usrpass1" | run_g10 --passphrase-fd 0 -s -o x --yes $i
#    run_g10 -o y --yes x
#    cmp $i y || error "$i: mismatch"
#done


info Checking armored encryption
for i in $plain_files $data_files ; do
    info "file $i"
    run_g10 -v -ea -o x --yes -r "$usrname2" $i
    run_g10 -v -o y --yes x
    cmp $i y || error "$i: mismatch"
done

info Checking armored encryption with a pipe
for i in $plain_files $data_files ; do
    info "file $i"
    run_g10 -ea --yes -r "$usrname2" < $i | tee x \
    | run_g10 -o y --yes
    cmp $i y || error "$i: mismatch"
    run_g10 --yes < x > y
    cmp $i y || error "$i: mismatch"
done

info Checking encryption
for i in $plain_files $data_files ; do
    run_g10 -e -o x --yes -r "$usrname2" $i
    run_g10 -o y --yes x
    cmp $i y || error "$i: mismatch"
done

info Checking encryption with a pipe
for i in $plain_files $data_files ; do
    run_g10 -e --yes -r "$usrname2" < $i \
    | run_g10 --yes > y
    cmp $i y || error "$i: mismatch"
done


info Checking signing and encryption
for i in $plain_files $data_files ; do
    echo "$usrpass1" \
    | run_g10 --passphrase-fd 0 -se -o x --yes -r "$usrname2" $i
    run_g10 -o y --yes x
    cmp $i y || error "$i: mismatch"
done

info Checking armored signing and encryption
for i in $plain_files $data_files ; do
    echo "$usrpass1" \
    | run_g10 --passphrase-fd 0 -sae -o x --yes -r "$usrname2" $i
    run_g10 -o y --yes x
    cmp $i y || error "$i: mismatch"
done


info Checking armored detached signatures
for i in $plain_files $data_files ; do
    echo "$usrpass1" | run_g10 --passphrase-fd 0 -sab -o x --yes $i
    run_g10 -o /dev/null --yes x  <$i || error "$i: bad signature"
done

info Checking detached signatures
for i in $plain_files $data_files ; do
    echo "$usrpass1" | run_g10 --passphrase-fd 0 -sb -o x --yes $i
    run_g10 -o /dev/null --yes x  <$i || error "$i: bad signature"
done


info Checking detached signatures of multiple files
i="$plain_files $data_files"
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sb -o x --yes $i
cat $i | run_g10 -o /dev/null --yes x || error "$i: bad signature"

info Checking armored detached signatures of multiple files
i="$plain_files $data_files"
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sab -o x --yes $i
cat $i | run_g10 -o /dev/null --yes x || error "$i: bad signature"


info "All tests passed."
exit 0