#!/bin/sh

dir="${SRCROOT}/src/apps"
cmd="${dir}/CA.sh"

SH="/bin/sh"
if test "$OSTYPE" = msdosdjgpp; then
    PATH="../apps\;$PATH"
else
    PATH="../apps:$PATH"
fi
export SH PATH

SSLEAY_CONFIG="-config CAss.cnf"
export SSLEAY_CONFIG

OPENSSL="${TARGET_BUILD_DIR}/openssl"
export OPENSSL

/bin/rm -fr demoCA
$SH ${cmd} -newca <<EOF
EOF

if [ $? != 0 ]; then
	exit 1;
fi

SSLEAY_CONFIG="-config Uss.cnf"
export SSLEAY_CONFIG
$SH ${cmd}  -newreq
if [ $? != 0 ]; then
	exit 1;
fi


SSLEAY_CONFIG="-config ${dir}/openssl.cnf"
export SSLEAY_CONFIG
$SH ${cmd} -sign  <<EOF
y
y
EOF
if [ $? != 0 ]; then
	exit 1;
fi


$SH ${cmd} -verify newcert.pem
if [ $? != 0 ]; then
	exit 1;
fi

/bin/rm -fr demoCA newcert.pem newreq.pem
#usage: CA -newcert|-newreq|-newca|-sign|-verify

