1 # |
|
2 # Copyright (c) 2013, 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 8008296 |
|
26 # @summary confirm that keytool correctly imports user passwords |
|
27 # |
|
28 # @run shell StorePasswordsByShell.sh |
|
29 |
|
30 # set a few environment variables so that the shell-script can run stand-alone |
|
31 # in the source directory |
|
32 if [ "${TESTSRC}" = "" ] ; then |
|
33 TESTSRC="." |
|
34 fi |
|
35 |
|
36 if [ "${TESTCLASSES}" = "" ] ; then |
|
37 TESTCLASSES="." |
|
38 fi |
|
39 |
|
40 if [ "${TESTJAVA}" = "" ] ; then |
|
41 echo "TESTJAVA not set. Test cannot execute." |
|
42 echo "FAILED!!!" |
|
43 exit 1 |
|
44 fi |
|
45 |
|
46 # set platform-dependent variables |
|
47 OS=`uname -s` |
|
48 case "$OS" in |
|
49 SunOS | Linux | Darwin | AIX) |
|
50 PATHSEP=":" |
|
51 FILESEP="/" |
|
52 ;; |
|
53 CYGWIN* ) |
|
54 PATHSEP=";" |
|
55 FILESEP="/" |
|
56 ;; |
|
57 Windows* ) |
|
58 PATHSEP=";" |
|
59 FILESEP="\\" |
|
60 ;; |
|
61 * ) |
|
62 echo "Unrecognized system!" |
|
63 exit 1; |
|
64 ;; |
|
65 esac |
|
66 |
|
67 PBE_ALGORITHMS="\ |
|
68 default-PBE-algorithm \ |
|
69 PBEWithMD5AndDES \ |
|
70 PBEWithSHA1AndDESede \ |
|
71 PBEWithSHA1AndRC2_40 \ |
|
72 PBEWithSHA1AndRC2_128 |
|
73 PBEWithSHA1AndRC4_40 \ |
|
74 PBEWithSHA1AndRC4_128 \ |
|
75 PBEWithHmacSHA1AndAES_128 \ |
|
76 PBEWithHmacSHA224AndAES_128 \ |
|
77 PBEWithHmacSHA256AndAES_128 \ |
|
78 PBEWithHmacSHA384AndAES_128 \ |
|
79 PBEWithHmacSHA512AndAES_128 \ |
|
80 PBEWithHmacSHA1AndAES_256 \ |
|
81 PBEWithHmacSHA224AndAES_256 \ |
|
82 PBEWithHmacSHA256AndAES_256 \ |
|
83 PBEWithHmacSHA384AndAES_256 \ |
|
84 PBEWithHmacSHA512AndAES_256" |
|
85 |
|
86 USER_PWD="hello1\n" |
|
87 ALIAS_PREFIX="this entry is protected by " |
|
88 COUNTER=0 |
|
89 |
|
90 # cleanup |
|
91 rm mykeystore.p12 > /dev/null 2>&1 |
|
92 |
|
93 echo |
|
94 for i in $PBE_ALGORITHMS; do |
|
95 |
|
96 if [ $i = "default-PBE-algorithm" ]; then |
|
97 KEYALG="" |
|
98 else |
|
99 KEYALG="-keyalg ${i}" |
|
100 fi |
|
101 |
|
102 if [ $COUNTER -lt 5 ]; then |
|
103 IMPORTPASSWORD="-importpassword" |
|
104 else |
|
105 IMPORTPASSWORD="-importpass" |
|
106 fi |
|
107 |
|
108 echo "Storing user password (protected by ${i})" |
|
109 echo "${USER_PWD}" | \ |
|
110 ${TESTJAVA}${FILESEP}bin${FILESEP}keytool ${TESTTOOLVMOPTS} ${IMPORTPASSWORD} \ |
|
111 -storetype pkcs12 -keystore mykeystore.p12 -storepass changeit \ |
|
112 -alias "${ALIAS_PREFIX}${i}" ${KEYALG} > /dev/null 2>&1 |
|
113 if [ $? -ne 0 ]; then |
|
114 echo Error |
|
115 else |
|
116 echo OK |
|
117 COUNTER=`expr ${COUNTER} + 1` |
|
118 fi |
|
119 done |
|
120 echo |
|
121 |
|
122 COUNTER2=`${TESTJAVA}${FILESEP}bin${FILESEP}keytool ${TESTTOOLVMOPTS} -list -storetype pkcs12 \ |
|
123 -keystore mykeystore.p12 -storepass changeit | grep -c "${ALIAS_PREFIX}"` |
|
124 |
|
125 RESULT="stored ${COUNTER} user passwords, detected ${COUNTER2} user passwords" |
|
126 if [ $COUNTER -ne $COUNTER2 -o $COUNTER -lt 11 ]; then |
|
127 echo "ERROR: $RESULT" |
|
128 exit 1 |
|
129 else |
|
130 echo "OK: $RESULT" |
|
131 exit 0 |
|
132 fi |
|