Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/keytool/StorePasswordsByShell.sh
38853 views
#1# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223# @test24# @bug 800829625# @summary confirm that keytool correctly imports user passwords26#27# @run shell StorePasswordsByShell.sh2829# set a few environment variables so that the shell-script can run stand-alone30# in the source directory31if [ "${TESTSRC}" = "" ] ; then32TESTSRC="."33fi3435if [ "${TESTCLASSES}" = "" ] ; then36TESTCLASSES="."37fi3839if [ "${TESTJAVA}" = "" ] ; then40echo "TESTJAVA not set. Test cannot execute."41echo "FAILED!!!"42exit 143fi4445# set platform-dependent variables46OS=`uname -s`47case "$OS" in48SunOS | Linux | Darwin | AIX)49PATHSEP=":"50FILESEP="/"51;;52CYGWIN* )53PATHSEP=";"54FILESEP="/"55;;56Windows* )57PATHSEP=";"58FILESEP="\\"59;;60* )61echo "Unrecognized system!"62exit 1;63;;64esac6566PBE_ALGORITHMS="\67default-PBE-algorithm \68PBEWithMD5AndDES \69PBEWithSHA1AndDESede \70PBEWithSHA1AndRC2_40 \71PBEWithSHA1AndRC2_12872PBEWithSHA1AndRC4_40 \73PBEWithSHA1AndRC4_128 \74PBEWithHmacSHA1AndAES_128 \75PBEWithHmacSHA224AndAES_128 \76PBEWithHmacSHA256AndAES_128 \77PBEWithHmacSHA384AndAES_128 \78PBEWithHmacSHA512AndAES_128 \79PBEWithHmacSHA1AndAES_256 \80PBEWithHmacSHA224AndAES_256 \81PBEWithHmacSHA256AndAES_256 \82PBEWithHmacSHA384AndAES_256 \83PBEWithHmacSHA512AndAES_256"8485USER_PWD="hello1\n"86ALIAS_PREFIX="this entry is protected by "87COUNTER=08889# cleanup90rm mykeystore.p12 > /dev/null 2>&19192echo93for i in $PBE_ALGORITHMS; do9495if [ $i = "default-PBE-algorithm" ]; then96KEYALG=""97else98KEYALG="-keyalg ${i}"99fi100101if [ $COUNTER -lt 5 ]; then102IMPORTPASSWORD="-importpassword"103else104IMPORTPASSWORD="-importpass"105fi106107echo "Storing user password (protected by ${i})"108echo "${USER_PWD}" | \109${TESTJAVA}${FILESEP}bin${FILESEP}keytool ${IMPORTPASSWORD} \110-storetype pkcs12 -keystore mykeystore.p12 -storepass changeit \111-alias "${ALIAS_PREFIX}${i}" ${KEYALG} > /dev/null 2>&1112if [ $? -ne 0 ]; then113echo Error114else115echo OK116COUNTER=`expr ${COUNTER} + 1`117fi118done119echo120121COUNTER2=`${TESTJAVA}${FILESEP}bin${FILESEP}keytool -list -storetype pkcs12 \122-keystore mykeystore.p12 -storepass changeit | grep -c "${ALIAS_PREFIX}"`123124RESULT="stored ${COUNTER} user passwords, detected ${COUNTER2} user passwords"125if [ $COUNTER -ne $COUNTER2 -o $COUNTER -lt 11 ]; then126echo "ERROR: $RESULT"127exit 1128else129echo "OK: $RESULT"130exit 0131fi132133134