1 #
   2 # Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.
   8 #
   9 # This code is distributed in the hope that it will be useful, but WITHOUT
  10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 # version 2 for more details (a copy is included in the LICENSE file that
  13 # accompanied this code).
  14 #
  15 # You should have received a copy of the GNU General Public License version
  16 # 2 along with this work; if not, write to the Free Software Foundation,
  17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 #
  19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 # or visit www.oracle.com if you need additional information or have any
  21 # questions.
  22 #
  23 
  24 # @test
  25 # @bug 6599979
  26 # @summary Ensure that re-assigning the alias works
  27 #
  28 # @library /test/lib ..
  29 # @build SecretKeysBasic
  30 # @run shell SecretKeysBasic.sh
  31 #
  32 # To run by hand:
  33 #    %sh SecretKeysBasic.sh
  34 #
  35 # Note:
  36 #    . test only runs on solaris at the moment
  37 
  38 # set a few environment variables so that the shell-script can run stand-alone
  39 # in the source directory
  40 
  41 # if running by hand on windows, change TESTSRC and TESTCLASSES to "."
  42 if [ "${TESTSRC}" = "" ] ; then
  43     TESTSRC=`pwd`
  44 fi
  45 if [ "${TESTCLASSES}" = "" ] ; then
  46     TESTCLASSES=`pwd`
  47 fi
  48 if [ "${TESTJAVA}" = "" ] ; then
  49     JAVAC_CMD=`which javac`
  50     TESTJAVA=`dirname $JAVAC_CMD`/..
  51 fi
  52 echo TESTSRC=${TESTSRC}
  53 echo TESTCLASSES=${TESTCLASSES}
  54 echo TESTJAVA=${TESTJAVA}
  55 echo CPAPPEND=${CPAPPEND}
  56 echo ""
  57 
  58 #DEBUG=sunpkcs11,pkcs11keystore
  59 
  60 echo DEBUG=${DEBUG}
  61 echo ""
  62 
  63 OS=`uname -s`
  64 case "$OS" in
  65   SunOS )
  66     FS="/"
  67     PS=":"
  68     OS_VERSION=`uname -r`
  69     case "${OS_VERSION}" in
  70       5.1* )
  71         SOFTTOKEN_DIR=${TESTCLASSES}
  72         export SOFTTOKEN_DIR
  73         TOKENS="nss solaris"
  74         ;;
  75       * )
  76         # SunPKCS11-Solaris Test only runs on Solaris 5.10 and later
  77         TOKENS="nss"
  78         ;;
  79     esac
  80     ;;
  81   Windows_* )
  82     FS="\\"
  83     PS=";"
  84     TOKENS="nss"
  85     ;;
  86   CYGWIN* )
  87     FS="/"
  88     PS=";"
  89     TOKENS="nss"
  90     ;;
  91   * )
  92     FS="/"
  93     PS=":"
  94     TOKENS="nss"
  95     ;;
  96 esac
  97 
  98 CP="cp -f"
  99 RM="rm -rf"
 100 MKDIR="mkdir -p"
 101 CHMOD="chmod"
 102 
 103 
 104 STATUS=0
 105 for token in ${TOKENS}
 106 do
 107 
 108 if [ ${token} = "nss" ]
 109 then
 110     # make cert/key DBs writable if token is NSS
 111     ${CP} ${TESTSRC}${FS}..${FS}nss${FS}db${FS}cert8.db ${TESTCLASSES}
 112     ${CHMOD} +w ${TESTCLASSES}${FS}cert8.db
 113 
 114     ${CP} ${TESTSRC}${FS}..${FS}nss${FS}db${FS}key3.db ${TESTCLASSES}
 115     ${CHMOD} +w ${TESTCLASSES}${FS}key3.db
 116     USED_FILE_LIST="${TESTCLASSES}${FS}cert8.db ${TESTCLASSES}${FS}key3.db"
 117 elif [ ${token} = "solaris" ]
 118 then
 119     # copy keystore into write-able location
 120     if [ -d ${TESTCLASSES}${FS}pkcs11_softtoken ]
 121     then
 122         echo "Removing old pkcs11_keystore, creating new pkcs11_keystore"
 123 
 124         echo ${RM} ${TESTCLASSES}${FS}pkcs11_softtoken
 125         ${RM} ${TESTCLASSES}${FS}pkcs11_softtoken
 126     fi
 127     echo ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}private
 128     ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}private
 129 
 130     echo ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}public
 131     ${MKDIR} ${TESTCLASSES}${FS}pkcs11_softtoken${FS}public
 132 
 133     echo ${CP} ${TESTSRC}${FS}BasicData${FS}pkcs11_softtoken${FS}objstore_info \
 134     ${TESTCLASSES}${FS}pkcs11_softtoken
 135     ${CP} ${TESTSRC}${FS}BasicData${FS}pkcs11_softtoken${FS}objstore_info \
 136     ${TESTCLASSES}${FS}pkcs11_softtoken
 137 
 138     echo ${CHMOD} +w ${TESTCLASSES}${FS}pkcs11_softtoken${FS}objstore_info
 139     ${CHMOD} 600 ${TESTCLASSES}${FS}pkcs11_softtoken${FS}objstore_info
 140     USED_FILE_LIST="${TESTCLASSES}${FS}pkcs11_softtoken"
 141 fi
 142 
 143 # run test
 144 cd ${TESTSRC}
 145 ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} \
 146         -DDIR=${TESTSRC}${FS}BasicData${FS} \
 147         -classpath \
 148         ${TESTCLASSES}${PS}${TESTCLASSES}${FS}..${PS}${TESTSRC}${FS}loader.jar${PS}${CPAPPEND} \
 149         -DCUSTOM_DB_DIR=${TESTCLASSES} \
 150         -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}BasicData${FS}p11-${token}.txt \
 151         -DNO_DEFAULT=true \
 152         -DNO_DEIMOS=true \
 153         -DTOKEN=${token} \
 154         -Djava.security.debug=${DEBUG} \
 155         SecretKeysBasic
 156 
 157 #       -DCUSTOM_P11_CONFIG=${TESTSRC}${FS}BasicData${FS}p11-${token}.txt \
 158 
 159 # save error status
 160 if [ $? != 0 ]
 161 then
 162     echo "Test against " ${token} " Failed!"
 163     STATUS=1
 164 fi
 165 
 166 # clean up
 167 ${RM} ${USED_FILE_LIST}
 168 
 169 done
 170 
 171 # return
 172 exit ${STATUS}