Tizen 2.0 Release
[external/libgnutls26.git] / tests / pkcs1-padding / pkcs1-pad
1 #!/bin/sh
2
3 # Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Free Software
4 # Foundation, Inc.
5 #
6 # Author: Simon Josefsson
7 #
8 # This file is part of GnuTLS.
9 #
10 # GnuTLS is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by the
12 # Free Software Foundation; either version 3 of the License, or (at
13 # your option) any later version.
14 #
15 # GnuTLS is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with GnuTLS; if not, write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 srcdir=${srcdir:-.}
25 CERTTOOL=${CERTTOOL:-../../src/certtool$EXEEXT}
26
27 # Check for datefudge
28 TSTAMP=`datefudge "2006-09-23" date -u +%s`
29 if test "$TSTAMP" != "1158962400"; then
30     echo "Cannot fake timestamps, please install datefudge..."
31     exit 77
32 fi
33
34 # Test 1, PKCS#1 pad digestAlgorithm.parameters
35
36 EXPECT1=3102
37
38 datefudge "2006-09-23" $CERTTOOL --verify-chain --infile $srcdir/pkcs1-pad-ok.pem | tee out1 >/dev/null 2>&1
39 datefudge "2006-09-23" $CERTTOOL --verify-chain --infile $srcdir/pkcs1-pad-broken.pem | tee out2 >/dev/null 2>&1
40
41 out1oks=`grep 'Verified.' out1 | wc -l | tr -d " "`
42 out2oks=`grep 'Verified.' out2 | wc -l | tr -d " "`
43 out1fails=`grep 'Not verified.' out1 | wc -l | tr -d " "`
44 out2fails=`grep 'Not verified.' out2 | wc -l | tr -d " "`
45
46 if test "$out1oks$out2oks$out1fails$out2fails" != "$EXPECT1"; then
47     echo out1 oks $out1oks fails $out1fails out2 oks $out2oks fails $out2fails
48     echo expected $EXPECT1
49     echo "PKCS1-PAD1 FAIL"
50     exit 1
51 fi
52
53 rm -f out1 out2
54
55 echo "PKCS1-PAD1 OK"
56
57 # Test 2, Bleichenbacher's Crypto 06 rump session
58
59 EXPECT2=2002
60
61 datefudge "2006-09-23" $CERTTOOL --verify-chain --infile $srcdir/pkcs1-pad-ok2.pem | tee out1 >/dev/null 2>&1
62 datefudge "2006-09-23" $CERTTOOL --verify-chain --infile $srcdir/pkcs1-pad-broken2.pem | tee out2 >/dev/null 2>&1
63
64 out1oks=`grep 'Verified.' out1 | wc -l | tr -d " "`
65 out2oks=`grep 'Verified.' out2 | wc -l | tr -d " "`
66 out1fails=`grep 'Not verified.' out1 | wc -l | tr -d " "`
67 out2fails=`grep 'Not verified.' out2 | wc -l | tr -d " "`
68
69 if test "$out1oks$out2oks$out1fails$out2fails" != "$EXPECT2"; then
70     echo out1 oks $out1oks fails $out1fails out2 oks $out2oks fails $out2fails
71     echo expected $EXPECT2
72     echo "PKCS1-PAD2 FAIL"
73     exit 1
74 fi
75
76 rm -f out1 out2
77
78 echo "PKCS1-PAD2 OK"
79
80 # Test 3, forged Starfield certificate,
81 # by Andrei Pyshkin, Erik Tews and Ralf-Philipp Weinmann.
82
83
84 EXPECT3=12
85
86 datefudge "2006-09-23" $CERTTOOL --verify-chain --infile $srcdir/pkcs1-pad-broken3.pem | tee out1 >/dev/null 2>&1
87
88 out1oks=`grep 'Verified.' out1 | wc -l | tr -d " "`
89 out1fails=`grep 'Not verified.' out1 | wc -l | tr -d " "`
90
91 if test "$out1oks$out1fails" != "$EXPECT3"; then
92     echo out1 oks $out1oks fails $out1fails
93     echo expected $EXPECT3
94     echo "PKCS1-PAD3 FAIL"
95     exit 1
96 fi
97
98 rm -f out1
99
100 echo "PKCS1-PAD3 OK"
101
102 # We're done.
103 exit 0