Blame tests/cert-tests/certtool-eddsa

Packit Service 4684c1
#!/bin/sh
Packit Service 4684c1
Packit Service 4684c1
# Copyright (C) 2014 Nikos Mavrogiannopoulos
Packit Service 4684c1
#
Packit Service 4684c1
# This file is part of GnuTLS.
Packit Service 4684c1
#
Packit Service 4684c1
# GnuTLS is free software; you can redistribute it and/or modify it
Packit Service 4684c1
# under the terms of the GNU General Public License as published by the
Packit Service 4684c1
# Free Software Foundation; either version 3 of the License, or (at
Packit Service 4684c1
# your option) any later version.
Packit Service 4684c1
#
Packit Service 4684c1
# GnuTLS is distributed in the hope that it will be useful, but
Packit Service 4684c1
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
# General Public License for more details.
Packit Service 4684c1
#
Packit Service 4684c1
# You should have received a copy of the GNU General Public License
Packit Service 4684c1
# along with GnuTLS; if not, write to the Free Software Foundation,
Packit Service 4684c1
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit Service 4684c1
Packit Service 4684c1
#set -e
Packit Service 4684c1
Packit Service 4684c1
srcdir="${srcdir:-.}"
Packit Service 4684c1
CERTTOOL="${CERTTOOL:-../../src/certtool${EXEEXT}}"
Packit Service 4684c1
KEYFILE=eddsa-privkey.$$.tmp
Packit Service 4684c1
TMPFILE=eddsa.$$.tmp
Packit Service 4684c1
TMPFILE2=eddsa2.$$.tmp
Packit Service 4684c1
Packit Service 4684c1
if ! test -x "${CERTTOOL}"; then
Packit Service 4684c1
	exit 77
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
if ! test -z "${VALGRIND}"; then
Packit Service 4684c1
	VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND}"
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
if test "${GNUTLS_FORCE_FIPS_MODE}" = 1;then
Packit Service 4684c1
	exit 77
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
. "${srcdir}/../scripts/common.sh"
Packit Service 4684c1
Packit Service 4684c1
# Test certificate in draft-ietf-curdle-pkix-04
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" -i --infile "${srcdir}/data/cert-eddsa.pem" --outfile "${TMPFILE}"
Packit Service 4684c1
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "There was an issue parsing the certificate"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
check_if_equal ${TMPFILE} "${srcdir}/data/cert-eddsa.pem" "Not After:"
Packit Service 4684c1
if test $? != 0;then
Packit Service 4684c1
	echo "Error in parsing EdDSA cert"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
# Test public key in draft-ietf-curdle-pkix-04
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --pubkey-info --infile "${srcdir}/data/pubkey-eddsa.pem" --outfile "${TMPFILE}"
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "Could not read an EdDSA public key"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
check_if_equal ${TMPFILE} "${srcdir}/data/pubkey-eddsa.pem"
Packit Service 4684c1
if test $? != 0;then
Packit Service 4684c1
	echo "Error in parsing EdDSA public key"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
# Create an RSA-PSS private key, restricted to the use with RSA-PSS
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --generate-privkey --pkcs8 --password '' \
Packit Service 4684c1
        --key-type eddsa --outfile "$KEYFILE"
Packit Service 4684c1
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "Could not generate an EdDSA key"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" -k --password '' --infile "$KEYFILE"
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "Could not read generated an EdDSA key"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
# Create an EdDSA certificate from an EdDSA private key
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --generate-self-signed \
Packit Service 4684c1
	--pkcs8 --load-privkey "$KEYFILE" --password '' \
Packit Service 4684c1
	--template "${srcdir}/templates/template-test.tmpl" \
Packit Service 4684c1
	--outfile "${TMPFILE}"
Packit Service 4684c1
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "Could not generate an EdDSA certificate from an EdDSA key"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --verify --load-ca-certificate "${TMPFILE}" --infile "${TMPFILE}"
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "There was an issue verifying the generated certificate (1)"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
# Create an EdDSA certificate from an RSA key
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --generate-certificate --key-type eddsa \
Packit Service 4684c1
	    --load-privkey ${KEYFILE} \
Packit Service 4684c1
	    --load-ca-privkey "${srcdir}/../../doc/credentials/x509/ca-key.pem" \
Packit Service 4684c1
	    --load-ca-certificate "${srcdir}/../../doc/credentials/x509/ca.pem" \
Packit Service 4684c1
	    --template "${srcdir}/templates/template-test.tmpl" \
Packit Service 4684c1
	    --outfile "${TMPFILE}" 2>/dev/null
Packit Service 4684c1
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "Could not generate an EdDSA certificate $i"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --verify --load-ca-certificate "${srcdir}/../../doc/credentials/x509/ca.pem" --infile "${TMPFILE}"
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "There was an issue verifying the generated certificate (2)"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
rm -f "${TMPFILE}" "${TMPFILE2}"
Packit Service 4684c1
rm -f "${KEYFILE}"
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
check_for_datefudge
Packit Service 4684c1
Packit Service 4684c1
# Test certificate chain using Ed25519
Packit Service 4684c1
datefudge "2017-7-6" \
Packit Service 4684c1
${VALGRIND} "${CERTTOOL}" --verify-chain --infile ${srcdir}/data/chain-eddsa.pem
Packit Service 4684c1
Packit Service 4684c1
if test $? != 0; then
Packit Service 4684c1
	echo "There was an issue verifying the Ed25519 chain"
Packit Service 4684c1
	exit 1
Packit Service 4684c1
fi
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
exit 0