Tizen 2.0 Release
[external/libgnutls26.git] / tests / openpgp-certs / testcerts
1 #!/bin/sh
2
3 # Copyright (C) 2010 Free Software Foundation, Inc.
4 #
5 # Author: Nikos Mavrogiannopoulos
6 #
7 # This file is part of GnuTLS.
8 #
9 # GnuTLS is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation; either version 3 of the License, or (at
12 # your option) any later version.
13 #
14 # GnuTLS is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with GnuTLS; if not, write to the Free Software Foundation,
21 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23 srcdir="${srcdir:-.}"
24 SERV="${SERV:-../../src/gnutls-serv} -q"
25 CLI="${CLI:-../../src/gnutls-cli}"
26 PORT="${PORT:-5557}"
27 DEBUG=""
28 unset RETCODE
29
30 if test "${WINDIR}" != "";then
31   exit 77
32 fi 
33
34 fail() {
35    echo "Failure: $1" >&2
36    RETCODE=${RETCODE:-${2:-1}}
37 }
38
39 echo "Checking OpenPGP certificate verification"
40
41 $SERV -p $PORT --pgpcertfile $srcdir/srv-public-127.0.0.1-signed.gpg --pgpkeyfile $srcdir/srv-secret.gpg >/dev/null 2>&1 & PID=$!
42 trap "kill $PID" 1 15 2
43
44 # give the server a chance to initialize
45 sleep 2
46
47 #gnutls currently only considers PGP certificates verified only if
48 #all user IDs in the certificate were signed.
49
50 #$CLI -p $PORT 127.0.0.1 --pgpkeyring ca-public.gpg </dev/null >/dev/null || \
51 #  fail "Connection to verified IP address should have succeeded! (error code $?)" $?
52
53 $CLI $DEBUG -p $PORT 127.0.0.2 --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null 2>&1 && \
54   fail "Connection to unrecognized IP address should have failed!"
55
56 $CLI $DEBUG -p $PORT localhost --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null 2>&1 && \
57   fail "Connection to unverified (but present) 'localhost' should have failed!"
58
59 kill $PID
60 wait
61
62 $SERV -p $PORT --pgpcertfile $srcdir/srv-public-localhost-signed.gpg --pgpkeyfile $srcdir/srv-secret.gpg >/dev/null 2>&1 & PID=$!
63 trap "kill $PID" 1 15 2
64
65 # give the server a chance to initialize
66 sleep 2
67
68 echo | $CLI $DEBUG -p $PORT 127.0.0.1 --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null 2>&1 && \
69   fail "Connection to unverified IP address should have failed! (error code $?)" $?
70
71 $CLI $DEBUG -p $PORT 127.0.0.2 --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null 2>&1 && \
72   fail "Connection to unrecognized IP address should have failed!"
73
74 #see reason above
75 #$CLI -p $PORT localhost --pgpkeyring ca-public.gpg </dev/null >/dev/null || \
76 #  fail "Connection to verified 'localhost' should have succeded! (error code $?)" $?
77
78 kill $PID
79 wait
80
81 $SERV -p $PORT --pgpcertfile $srcdir/srv-public-all-signed.gpg --pgpkeyfile $srcdir/srv-secret.gpg >/dev/null 2>&1 & PID=$!
82 trap "kill $PID" 1 15 2
83
84 # give the server a chance to initialize
85 sleep 2
86 echo | $CLI $DEBUG -p $PORT 127.0.0.1 --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null || \
87   fail "Connection to signed PGP certificate should have succeeded! (error code $?)" $?
88
89 $CLI $DEBUG -p $PORT 127.0.0.2 --pgpkeyring $srcdir/ca-public.gpg </dev/null >/dev/null && \
90   fail "Connection to unrecognized IP address should have failed!"
91
92 kill $PID
93 wait
94
95 exit ${RETCODE:-0}