trystore.sh revision 9330:8b1f1c2a400f
1273138Sjkim#
2273138Sjkim# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3273138Sjkim# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4273138Sjkim#
5273138Sjkim# This code is free software; you can redistribute it and/or modify it
6273138Sjkim# under the terms of the GNU General Public License version 2 only, as
7273138Sjkim# published by the Free Software Foundation.
8273138Sjkim#
9273138Sjkim# This code is distributed in the hope that it will be useful, but WITHOUT
10273138Sjkim# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11273138Sjkim# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12273138Sjkim# version 2 for more details (a copy is included in the LICENSE file that
13273138Sjkim# accompanied this code).
14273138Sjkim#
15273138Sjkim# You should have received a copy of the GNU General Public License version
16273138Sjkim# 2 along with this work; if not, write to the Free Software Foundation,
17273138Sjkim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18273138Sjkim#
19273138Sjkim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20273138Sjkim# or visit www.oracle.com if you need additional information or have any
21273138Sjkim# questions.
22273138Sjkim#
23273138Sjkim
24273138Sjkim# @test
25273138Sjkim# @bug 7047200
26273138Sjkim# @summary keytool can try save to a byte array before overwrite the file
27273138Sjkim
28273138Sjkimif [ "${TESTJAVA}" = "" ] ; then
29273138Sjkim  JAVAC_CMD=`which javac`
30273138Sjkim  TESTJAVA=`dirname $JAVAC_CMD`/..
31273138Sjkimfi
32273138Sjkim
33273138Sjkim# set platform-dependent variables
34273138SjkimOS=`uname -s`
35273138Sjkimcase "$OS" in
36273138Sjkim  Windows_* )
37273138Sjkim    FS="\\"
38273138Sjkim    ;;
39273138Sjkim  * )
40273138Sjkim    FS="/"
41273138Sjkim    ;;
42273138Sjkimesac
43273138Sjkim
44273138Sjkimrm trystore.jks 2> /dev/null
45273138Sjkim
46273138SjkimKEYTOOL="${TESTJAVA}${FS}bin${FS}keytool -storetype jks -keystore trystore.jks -keyalg rsa"
47273138Sjkim$KEYTOOL -genkeypair -alias a -dname CN=A -storepass changeit -keypass changeit
48273138Sjkim$KEYTOOL -genkeypair -alias b -dname CN=B -storepass changeit -keypass changeit
49273138Sjkim
50273138Sjkim# We use -protected for JKS keystore. This is illegal so the command should
51273138Sjkim# fail. Then we can check if the keystore is damaged.
52273138Sjkim
53273138Sjkim$KEYTOOL -genkeypair -protected -alias b -delete -debug
54273138Sjkim
55273138Sjkimif [ $? = 0 ]; then
56273138Sjkim    echo "What? -protected works for JKS?"
57273138Sjkim    exit 1
58273138Sjkimfi
59273138Sjkim
60273138Sjkim$KEYTOOL -list -storepass changeit
61273138Sjkim
62273138Sjkimif [ $? != 0 ]; then
63273138Sjkim    echo "Keystore file damaged"
64273138Sjkim    exit 2
65273138Sjkimfi
66273138Sjkim