4562N/A#
4562N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4562N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4562N/A#
4562N/A# This code is free software; you can redistribute it and/or modify it
4562N/A# under the terms of the GNU General Public License version 2 only, as
4562N/A# published by the Free Software Foundation.
4562N/A#
4562N/A# This code is distributed in the hope that it will be useful, but WITHOUT
4562N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4562N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4562N/A# version 2 for more details (a copy is included in the LICENSE file that
4562N/A# accompanied this code).
4562N/A#
4562N/A# You should have received a copy of the GNU General Public License version
4562N/A# 2 along with this work; if not, write to the Free Software Foundation,
4562N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4562N/A#
4562N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4562N/A# or visit www.oracle.com if you need additional information or have any
4562N/A# questions.
4562N/A#
4562N/A
4562N/A# @test
4562N/A# @bug 7047200
4562N/A# @summary keytool can try save to a byte array before overwrite the file
4562N/A
4562N/Aif [ "${TESTJAVA}" = "" ] ; then
4562N/A JAVAC_CMD=`which javac`
4562N/A TESTJAVA=`dirname $JAVAC_CMD`/..
4562N/Afi
4562N/A
4562N/A# set platform-dependent variables
4562N/AOS=`uname -s`
4562N/Acase "$OS" in
4562N/A Windows_* )
4562N/A FS="\\"
4562N/A ;;
4562N/A * )
4562N/A FS="/"
4562N/A ;;
4562N/Aesac
4562N/A
4562N/Arm trystore.jks 2> /dev/null
4562N/A
4562N/AKEYTOOL="${TESTJAVA}${FS}bin${FS}keytool -storetype jks -keystore trystore.jks"
4562N/A$KEYTOOL -genkeypair -alias a -dname CN=A -storepass changeit -keypass changeit
4562N/A$KEYTOOL -genkeypair -alias b -dname CN=B -storepass changeit -keypass changeit
4562N/A
4562N/A# We use -protected for JKS keystore. This is illegal so the command should
4562N/A# fail. Then we can check if the keystore is damaged.
4562N/A
4562N/A$KEYTOOL -genkeypair -protected -alias b -delete -debug
4562N/A
4562N/Aif [ $? = 0 ]; then
4562N/A echo "What? -protected works for JKS?"
4562N/A exit 1
4562N/Afi
4562N/A
4562N/A$KEYTOOL -list -storepass changeit
4562N/A
4562N/Aif [ $? != 0 ]; then
4562N/A echo "Keystore file damaged"
4562N/A exit 2
4562N/Afi