1178825Sdfr#!/bin/sh
2178825Sdfr#
3178825Sdfr# Copyright (c) 2004 - 2005 Kungliga Tekniska H�gskolan
4178825Sdfr# (Royal Institute of Technology, Stockholm, Sweden). 
5178825Sdfr# All rights reserved. 
6178825Sdfr#
7178825Sdfr# Redistribution and use in source and binary forms, with or without 
8178825Sdfr# modification, are permitted provided that the following conditions 
9178825Sdfr# are met: 
10178825Sdfr#
11178825Sdfr# 1. Redistributions of source code must retain the above copyright 
12178825Sdfr#    notice, this list of conditions and the following disclaimer. 
13178825Sdfr#
14178825Sdfr# 2. Redistributions in binary form must reproduce the above copyright 
15178825Sdfr#    notice, this list of conditions and the following disclaimer in the 
16178825Sdfr#    documentation and/or other materials provided with the distribution. 
17178825Sdfr#
18178825Sdfr# 3. Neither the name of the Institute nor the names of its contributors 
19178825Sdfr#    may be used to endorse or promote products derived from this software 
20178825Sdfr#    without specific prior written permission. 
21178825Sdfr#
22178825Sdfr# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
23178825Sdfr# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
24178825Sdfr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
25178825Sdfr# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
26178825Sdfr# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
27178825Sdfr# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
28178825Sdfr# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
29178825Sdfr# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
30178825Sdfr# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
31178825Sdfr# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
32178825Sdfr# SUCH DAMAGE. 
33178825Sdfr#
34178825Sdfr# $Id: test_nist.in 21787 2007-08-02 08:50:24Z lha $
35178825Sdfr#
36178825Sdfr
37178825Sdfrsrcdir="@srcdir@"
38178825Sdfrobjdir="@objdir@"
39178825Sdfrnistdir=${objdir}/PKITS_data
40178825Sdfrnistzip=${srcdir}/data/PKITS_data.zip
41178825Sdfr
42178825Sdfrlimit="${1:-nolimit}"
43178825Sdfr
44178825Sdfrstat="--statistic-file=${objdir}/statfile"
45178825Sdfr
46178825Sdfrhxtool="${TESTS_ENVIRONMENT} ./hxtool ${stat}"
47178825Sdfr
48178825Sdfr# nistzip is not distributed part of the distribution
49178825Sdfrtest -f "$nistzip" || exit 77
50178825Sdfr
51178825Sdfrif ${hxtool} info | grep 'rsa: hcrypto null RSA' > /dev/null ; then
52178825Sdfr    exit 77
53178825Sdfrfi
54178825Sdfrif ${hxtool} info | grep 'rand: not available' > /dev/null ; then
55178825Sdfr    exit 77
56178825Sdfrfi
57178825Sdfr
58178825Sdfrecho "nist tests, version 2"
59178825Sdfr
60178825Sdfrif [ ! -d "$nistdir" ] ; then
61178825Sdfr    ( mkdir "$nistdir" && unzip -d "${nistdir}" "${nistzip}" ) >/dev/null || \
62178825Sdfr	{ rm -rf "$nistdir" ; exit 1; }
63178825Sdfrfi
64178825Sdfr
65178825Sdfrec=
66178825Sdfrname=
67178825Sdfrdescription=
68178825Sdfrwhile read result cert other ; do
69178825Sdfr    if expr "$result" : "#" > /dev/null; then
70178825Sdfr	name=${cert}
71178825Sdfr	description="${other}"
72178825Sdfr	continue
73178825Sdfr    fi
74178825Sdfr    
75178825Sdfr    test nolimit != "${limit}" && ! expr "$name" : "$limit" > /dev/null && continue
76178825Sdfr
77178825Sdfr    test "$result" = "end" && break
78178825Sdfr
79178825Sdfr    args=
80178825Sdfr    args="$args cert:FILE:$nistdir/certs/$cert"
81178825Sdfr    args="$args chain:DIR:$nistdir/certs"
82178825Sdfr    args="$args anchor:FILE:$nistdir/certs/TrustAnchorRootCertificate.crt"
83178825Sdfr#    args="$args crl:FILE:$nistdir/crls/TrustAnchorRootCRL.crl"
84178825Sdfr
85178825Sdfr    for a in $nistdir/crls/*.crl; do
86178825Sdfr	args="$args crl:FILE:$a"
87178825Sdfr    done
88178825Sdfr
89178825Sdfr    cmd="${hxtool} verify $args"
90178825Sdfr    eval ${cmd} > /dev/null
91178825Sdfr    res=$?
92178825Sdfr
93178825Sdfr    case "${result},${res}" in
94178825Sdfr    0,0) r="PASSs";;
95178825Sdfr    0,*) r="FAILs";;
96178825Sdfr    [123],0) r="FAILf";;
97178825Sdfr    [123],*) r="PASSf";;
98178825Sdfr    *) echo="unknown result ${result},${res}" ; exit 1 ;;
99178825Sdfr    esac
100178825Sdfr    if grep "${name} FAIL" $srcdir/data/nist-result2 > /dev/null; then
101178825Sdfr	if expr "$r" : "PASS" >/dev/null; then
102178825Sdfr	    echo "${name} passed when expected not to"
103178825Sdfr	    echo "# ${description}" > nist2-passed-${name}.tmp
104178825Sdfr	    ec=1
105178825Sdfr	fi
106178825Sdfr    elif expr "$r" : "FAIL.*" >/dev/null ; then
107178825Sdfr	echo "$r ${name} ${description}"
108178825Sdfr	echo "# ${description}" > nist2-failed-${name}.tmp
109178825Sdfr	echo "$cmd" >> nist2-failed-${name}.tmp
110178825Sdfr	ec=1
111178825Sdfr    fi
112178825Sdfr
113178825Sdfrdone < $srcdir/data/nist-data2
114178825Sdfr
115178825Sdfr
116178825Sdfrecho "done!"
117178825Sdfr
118178825Sdfrexit $ec
119