1#!/bin/sh
2#
3# Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved.
4#
5# Licensed under the Apache License 2.0 (the "License").  You may not use
6# this file except in compliance with the License.  You can obtain a copy
7# in the file LICENSE in the source distribution or at
8# https://www.openssl.org/source/license.html
9
10#
11# OpenSSL external testing using the OQS provider
12#
13set -e
14
15PWD="$(pwd)"
16
17SRCTOP="$(cd $SRCTOP; pwd)"
18BLDTOP="$(cd $BLDTOP; pwd)"
19
20if [ "$SRCTOP" != "$BLDTOP" ] ; then
21    echo "Out of tree builds not supported with oqsprovider test!"
22    exit 1
23fi
24
25O_EXE="$BLDTOP/apps"
26O_BINC="$BLDTOP/include"
27O_SINC="$SRCTOP/include"
28O_LIB="$BLDTOP"
29
30unset OPENSSL_CONF
31
32export PATH="$O_EXE:$PATH"
33export LD_LIBRARY_PATH="$O_LIB:$LD_LIBRARY_PATH"
34export OPENSSL_ROOT_DIR="$O_LIB"
35
36# Check/Set openssl version
37OPENSSL_VERSION=`openssl version | cut -f 2 -d ' '`
38
39echo "------------------------------------------------------------------"
40echo "Testing OpenSSL using oqsprovider:"
41echo "   CWD:                $PWD"
42echo "   SRCTOP:             $SRCTOP"
43echo "   BLDTOP:             $BLDTOP"
44echo "   OPENSSL_ROOT_DIR:   $OPENSSL_ROOT_DIR"
45echo "   OpenSSL version:    $OPENSSL_VERSION"
46echo "------------------------------------------------------------------"
47
48if [ ! -d $SRCTOP/oqs-provider/.local ]; then
49# this version of oqsprovider dependent on v0.11.0 of liboqs, so set this;
50# also be sure to use this openssl for liboqs-internal OpenSSL use;
51# see all libops config options listed at
52# https://github.com/open-quantum-safe/liboqs/wiki/Customizing-liboqs
53(
54       cd $SRCTOP/oqs-provider \
55           && git clone --depth 1 --branch 0.11.0 https://github.com/open-quantum-safe/liboqs.git \
56           && cd liboqs \
57           && mkdir build \
58           && cd build \
59           && cmake -DOPENSSL_ROOT_DIR=$OPENSSL_ROOT_DIR -DCMAKE_INSTALL_PREFIX=$SRCTOP/oqs-provider/.local .. \
60           && make \
61           && make install
62   )
63fi
64
65echo "   CWD:                $PWD"
66liboqs_DIR=$SRCTOP/oqs-provider/.local cmake $SRCTOP/oqs-provider -DOPENSSL_ROOT_DIR="$OPENSSL_ROOT_DIR" -B _build && cmake --build _build
67export CTEST_OUTPUT_ON_FAILURE=1
68export HARNESS_OSSL_PREFIX=''
69export OPENSSL_APP="$O_EXE/openssl"
70export OPENSSL_MODULES=$PWD/_build/lib
71export OQS_PROVIDER_TESTSCRIPTS=$SRCTOP/oqs-provider/scripts
72export OPENSSL_CONF=$OQS_PROVIDER_TESTSCRIPTS/openssl-ca.cnf
73# Be verbose if harness is verbose:
74# Fixup for oqsprovider release snafu:
75cp $SRCTOP/test/recipes/95-test_external_oqsprovider_data/oqsprovider-pkcs12gen.sh $SRCTOP/oqs-provider/scripts/
76$SRCTOP/oqs-provider/scripts/runtests.sh -V
77