1998-02-11 23:22:09 +00:00
|
|
|
#!/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"
|
|
|
|
}
|
|
|
|
|
1998-02-12 14:39:08 +00:00
|
|
|
cleanup () {
|
|
|
|
rm $data_files x y z 2>/dev/null
|
|
|
|
echo "#empty" >./.g10/options
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-11 23:22:09 +00:00
|
|
|
run_g10 () {
|
|
|
|
eval HOME=. ../g10/g10 $*
|
1998-02-12 14:39:08 +00:00
|
|
|
if [ $? != 0 ] ; then
|
|
|
|
g10_err=$?
|
|
|
|
echo "(HOME=. ../g10/g10 $*) failed" >&2
|
|
|
|
error "g10 failed: $g10_err" >&2
|
|
|
|
fi
|
1998-02-11 23:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#--------------------------------
|
|
|
|
#-------- main program ----------
|
|
|
|
#--------------------------------
|
|
|
|
|
|
|
|
set -e
|
|
|
|
pgmname=$(basename $0)
|
1998-02-12 14:39:08 +00:00
|
|
|
#trap cleanup EXIT SIGHUP SIGINT SIGQUIT
|
|
|
|
|
1998-02-11 23:22:09 +00:00
|
|
|
|
|
|
|
# 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
|
1998-02-12 14:39:08 +00:00
|
|
|
# create the keyrings
|
1998-02-11 23:22:09 +00:00
|
|
|
|
|
|
|
cat <<EOF >./.g10/options
|
|
|
|
no-greeting
|
|
|
|
no-secmem-warning
|
|
|
|
batch
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# print the G10 version
|
|
|
|
run_g10 --version
|
1998-02-12 14:39:08 +00:00
|
|
|
# intialize the trustdb
|
1998-02-11 23:22:09 +00:00
|
|
|
|
1998-02-12 14:39:08 +00:00
|
|
|
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"
|
1998-02-11 23:22:09 +00:00
|
|
|
done
|
|
|
|
|
1998-02-12 14:39:08 +00:00
|
|
|
#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
|
|
|
|
|
1998-02-11 23:22:09 +00:00
|
|
|
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
|
|
|
|
|
1998-02-12 14:39:08 +00:00
|
|
|
#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
|
1998-02-11 23:22:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
info Checking armored encryption
|
|
|
|
for i in $plain_files $data_files ; do
|
1998-02-12 14:39:08 +00:00
|
|
|
info "file $i"
|
|
|
|
run_g10 -v -ea -o x --yes -r "$usrname2" $i
|
|
|
|
run_g10 -v -o y --yes x
|
1998-02-11 23:22:09 +00:00
|
|
|
cmp $i y || error "$i: mismatch"
|
|
|
|
done
|
|
|
|
|
|
|
|
info Checking armored encryption with a pipe
|
|
|
|
for i in $plain_files $data_files ; do
|
1998-02-12 14:39:08 +00:00
|
|
|
info "file $i"
|
1998-02-11 23:22:09 +00:00
|
|
|
run_g10 -ea --yes -r "$usrname2" < $i | tee x \
|
1998-02-12 14:39:08 +00:00
|
|
|
| run_g10 -o y --yes
|
1998-02-11 23:22:09 +00:00
|
|
|
cmp $i y || error "$i: mismatch"
|
1998-02-12 14:39:08 +00:00
|
|
|
run_g10 --yes < x > y
|
1998-02-11 23:22:09 +00:00
|
|
|
cmp $i y || error "$i: mismatch"
|
|
|
|
done
|
|
|
|
|
|
|
|
info Checking encryption
|
|
|
|
for i in $plain_files $data_files ; do
|
1998-02-12 14:39:08 +00:00
|
|
|
run_g10 -e -o x --yes -r "$usrname2" $i
|
|
|
|
run_g10 -o y --yes x
|
1998-02-11 23:22:09 +00:00
|
|
|
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 \
|
1998-02-12 14:39:08 +00:00
|
|
|
| run_g10 --yes > y
|
1998-02-11 23:22:09 +00:00
|
|
|
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
|
1998-02-12 14:39:08 +00:00
|
|
|
run_g10 -o y --yes x
|
1998-02-11 23:22:09 +00:00
|
|
|
cmp $i y || error "$i: mismatch"
|
|
|
|
done
|
|
|
|
|
|
|
|
info Checking armored signing and encryption
|
|
|
|
for i in $plain_files $data_files ; do
|
|
|
|
echo "$usrpass1" \
|
1998-02-12 14:39:08 +00:00
|
|
|
| run_g10 --passphrase-fd 0 -sae -o x --yes -r "$usrname2" $i
|
|
|
|
run_g10 -o y --yes x
|
1998-02-11 23:22:09 +00:00
|
|
|
cmp $i y || error "$i: mismatch"
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
info Checking armored detached signatures
|
|
|
|
for i in $plain_files $data_files ; do
|
1998-02-12 14:39:08 +00:00
|
|
|
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sab -o x --yes $i
|
1998-02-11 23:22:09 +00:00
|
|
|
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
|
1998-02-12 14:39:08 +00:00
|
|
|
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sb -o x --yes $i
|
1998-02-11 23:22:09 +00:00
|
|
|
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"
|
1998-02-12 14:39:08 +00:00
|
|
|
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sb -o x --yes $i
|
1998-02-11 23:22:09 +00:00
|
|
|
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"
|
1998-02-12 14:39:08 +00:00
|
|
|
echo "$usrpass1" | run_g10 --passphrase-fd 0 -sab -o x --yes $i
|
1998-02-11 23:22:09 +00:00
|
|
|
cat $i | run_g10 -o /dev/null --yes x || error "$i: bad signature"
|
|
|
|
|
|
|
|
|
|
|
|
info "All tests passed."
|
|
|
|
exit 0
|
|
|
|
|