source: trunk/test/testrun_1b.sh@ 163

Last change on this file since 163 was 163, checked in by katerina, 17 years ago

Add gpg fingerprint test to testsuite.

File size: 10.1 KB
RevLine 
[1]1#! /bin/sh
2
[27]3#
4# Copyright Rainer Wichmann (2006)
5#
6# License Information:
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20#
[1]21
[163]22MAXTEST=5; export MAXTEST
[19]23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
[1]25
[19]26testrun1b_internal ()
[1]27{
[19]28 BUILDOPTS="$1"
[1]29 #
30 # test standalone compilation
31 #
[19]32 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
[1]33 #
34 if test -r "Makefile"; then
[22]35 $MAKE distclean >/dev/null >&1
[1]36 fi
37 #
[159]38 # Bootstrapping
[1]39 #
[159]40 ${TOP_SRCDIR}/configure >/dev/null 2>/dev/null
41 if test x$? = x0; then
42 [ -z "$verbose" ] || log_msg_ok "configure (bootstrap)...";
43 $MAKE > /dev/null 2>&1
44 if test x$? = x0; then
45 [ -z "$verbose" ] || log_msg_ok "make (bootstrap)...";
46 else
47 [ -z "$quiet" ] && log_msg_fail "make (bootstrap)...";
48 return 1
49 fi
50
51 else
52 [ -z "$quiet" ] && log_msg_fail "configure (bootstrap)...";
53 return 1
54 fi
[1]55 #
56 #
[159]57 ${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null | \
58 egrep 'use existing [./[:alnum:]]+ for gpg checksum' >/dev/null
59 #
60 #
[1]61 if test x$? = x0; then
[19]62 [ -z "$verbose" ] || log_msg_ok "configure...";
[22]63 $MAKE > /dev/null 2>&1
[1]64 if test x$? = x0; then
[19]65 [ -z "$verbose" ] || log_msg_ok "make...";
[1]66 else
[19]67 [ -z "$quiet" ] && log_msg_fail "make...";
68 return 1
[1]69 fi
70
71 else
[19]72 [ -z "$quiet" ] && log_msg_fail "configure...";
73 return 1
[1]74 fi
75
[19]76 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
[1]77
[19]78 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
79 if [ $? -eq 0 ]; then
[159]80 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
[19]81 mv "./testrc.gpg.asc" "$RCFILE"
82 else
[159]83 tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
[19]84 mv "./testrc.gpg.asc" "$RCFILE"
85 fi
86 if test x$? = x0; then
87 [ -z "$verbose" ] || log_msg_ok "extract gpg signed files...";
88 else
89 [ -z "$quiet" ] && log_msg_fail "extract gpg signed files...";
90 return 1
91 fi
92
[52]93 if test "x$2" = "x"; then
94 :
95 else
96 CONVERT="$2"
97 if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
98 [ -z "$verbose" ] || log_msg_ok "convert..."
99 "${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
100 else
101 [ -z "$quiet" ] && log_msg_fail "cannot find file stealth_template.jpg"
102 return 1
103 fi
104 if [ $? -ne 0 ]; then
105 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
106 return 1
107 fi
108
109 [ -z "$verbose" ] || log_msg_ok "hide..."
110 ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
111 if [ $? -ne 0 ]; then
112 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
113 return 1
114 fi
115
116 mv -f stealth_template.ps "$RCFILE"
117 if [ $? -ne 0 ]; then
118 [ -z "$quiet" ] && log_msg_fail "mv -f stealth_template.ps $RCFILE";
119 return 1
120 fi
121
122 fi
123
[1]124 rm -f ./.samhain_file
125 rm -f ./.samhain_log
126 rm -f ./.samhain_lock
127
[19]128 ./samhain -t init -p none -l info
[1]129
130 if test x$? = x0; then
[19]131 [ -z "$verbose" ] || log_msg_ok "init...";
132 else
133 [ -z "$quiet" ] && log_msg_fail "init...";
134 return 1
135 fi
[1]136
[19]137 mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
138}
[1]139
[19]140do_test_1b () {
141
142 ./samhain -t check -p none -l info
143
144 if test x$? = x0; then
145 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
146 if [ $? -ne 0 ]; then
147 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
148 return 1
[1]149 fi
[19]150 [ -z "$verbose" ] || log_msg_ok "check...";
151 else
152 [ -z "$quiet" ] && log_msg_fail "check...";
153 return 1
154 fi
155 #
156 tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
157 if [ $tmp -ne 2 ]; then
158 [ -z "$verbose" ] || log_msg_fail "/etc";
[60]159 return 1
[19]160 fi
161 tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
[60]162 if [ $tmp -ne 8 ]; then
[19]163 [ -z "$verbose" ] || log_msg_fail "checking";
[60]164 return 1
[19]165 fi
[60]166 egrep "ADDED" $LOGFILE >/dev/null 2>&1
167 if [ $? -eq 0 ]; then
168 [ -z "$verbose" ] || log_msg_fail "init was incomplete";
169 return 1
170 fi
[19]171 #
172 return 0
[1]173}
174
[19]175do_test_1b_2 () {
[1]176
[19]177 rm -f $PW_DIR/test_log_prelude
[1]178
[20]179 "$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
[19]180 PID=$!
[1]181
[51]182 five_sec_sleep
[20]183
184 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
[19]185
186 if test x$? = x0; then
187 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
188 if [ $? -ne 0 ]; then
189 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
190 kill $PID
191 return 1
192 fi
193 [ -z "$verbose" ] || log_msg_ok "check...";
194 else
195 [ -z "$quiet" ] && log_msg_fail "check...";
196 kill $PID
197 return 1
198 fi
199 #
200 tmp=`egrep 'File original:.*name=etc.*path=/etc' test_log_prelude 2>/dev/null | wc -l`
[81]201 if [ $tmp -lt 1 ]; then
[19]202 [ -z "$verbose" ] || log_msg_fail "/etc";
203 fi
204 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
[81]205 if [ $tmp -lt 1 ]; then
[19]206 [ -z "$verbose" ] || log_msg_fail "checking";
207 fi
208 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
[81]209 if [ $tmp -lt 1 ]; then
[19]210 [ -z "$verbose" ] || log_msg_fail "checking";
211 fi
212 #
213 kill $PID
214 return 0
215}
[1]216
[19]217testrun1b ()
218{
219 log_start "RUN STANDALONE W/STEALTH W/GPG"
220 GPG=`find_path gpg`
221 if [ -z "$GPG" ]; then
222 log_skip 1 $MAXTEST 'gpg not found in $PATH'
223 log_skip 2 $MAXTEST 'gpg not found in $PATH'
[100]224 log_skip 3 $MAXTEST 'gpg not found in $PATH'
[19]225 else
226 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
227 if [ $? -ne 0 ]; then
228 log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
229 log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
[100]230 log_skip 3 $MAXTEST 'public PGP key 0x0F571F6C not present'
[163]231 log_skip 4 $MAXTEST 'public PGP key 0x0F571F6C not present'
232 log_skip 5 $MAXTEST 'public PGP key 0x0F571F6C not present'
[19]233 else
[52]234 #
235 # ------------- first test -------------
236 #
[163]237 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
[52]238 testrun1b_internal "${BUILDOPTS}"
[19]239 do_test_1b
240 if [ $? -eq 0 ]; then
241 log_ok 1 $MAXTEST 'gpg signed config/database files'
242 else
243 log_fail 1 $MAXTEST 'gpg signed config/database files'
244 fi
[52]245
246
247 #
248 # ------------- second test -------------
249 #
[163]250 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
251 testrun1b_internal "${BUILDOPTS}"
252 do_test_1b
253 if [ $? -eq 0 ]; then
254 log_ok 2 $MAXTEST 'gpg signed config/database files'
255 else
256 log_fail 2 $MAXTEST 'gpg signed config/database files'
257 fi
258
259
260 #
261 # ------------- third test -------------
262 #
263 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --with-fp=EF6CEF54701A0AFDB86AF4C31AAD26C80F571F6C --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
264 testrun1b_internal "${BUILDOPTS}"
265 do_test_1b
266 if [ $? -eq 0 ]; then
267 log_ok 3 $MAXTEST 'gpg signed config/database files'
268 else
269 log_fail 3 $MAXTEST 'gpg signed config/database files'
270 fi
271
272
273 #
274 # ------------- fourth test -------------
275 #
[52]276 PRECONV=`find_path convert`
277 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
278 CONVERT="${PRECONV}"
279
280 if [ -z "$CONVERT" ]; then
281 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
282 else
[159]283 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
[52]284 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
285 do_test_1b
286 if [ $? -eq 0 ]; then
[163]287 log_ok 4 $MAXTEST 'gpg signed config/database files'
[52]288 else
[163]289 log_fail 4 $MAXTEST 'gpg signed config/database files'
[52]290 fi
291 fi
292
293
294 #
[163]295 # ------------- fifth test -------------
[52]296 #
[97]297 if test -f /usr/local/lib/libprelude.so
[96]298 then
299 LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
300 export LD_LIBRARY_PATH
301 fi
302 #
[19]303 PM=`find_path prelude-manager`
304 if [ -z "$PM" ]; then
[163]305 log_skip 5 $MAXTEST 'prelude-manager not found in $PATH'
[19]306 elif [ -z "$doall" ]; then
[163]307 log_skip 5 $MAXTEST 'logging to prelude (or use --really-all)'
[19]308 else
[159]309 BUILDOPTS="--quiet $TRUST --enable-debug --with-prelude --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
[20]310 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
[19]311 do_test_1b_2
312 if [ $? -eq 0 ]; then
[163]313 log_ok 5 $MAXTEST 'logging to prelude'
[19]314 else
[163]315 log_fail 5 $MAXTEST 'logging to prelude'
[19]316 fi
317 fi
318 fi
319 fi
320 log_end "RUN STANDALONE W/STEALTH W/GPG"
321 return 0
322}
[1]323
Note: See TracBrowser for help on using the repository browser.