1 #!/bin/sh 2 3 # 4 # Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 27 # @test 28 # @bug 6415696 29 # @requires os.family == "windows" 30 # @run shell KeytoolChangeAlias.sh 31 # @summary Test "keytool -changealias" using the Microsoft CryptoAPI provider. 32 # 33 # Run only on non-64-bit Windows platform. 34 35 # set a few environment variables so that the shell-script can run stand-alone 36 # in the source directory 37 if [ "${TESTSRC}" = "" ] ; then 38 TESTSRC="." 39 fi 40 41 if [ "${TESTCLASSES}" = "" ] ; then 42 TESTCLASSES="." 43 fi 44 45 if [ "${TESTJAVA}" = "" ] ; then 46 echo "TESTJAVA not set. Test cannot execute." 47 echo "FAILED!!!" 48 exit 1 49 fi 50 51 OS=`uname -s` 52 case "$OS" in 53 Windows* | CYGWIN* ) 54 55 # 'uname -m' does not give us enough information - 56 # should rely on $PROCESSOR_IDENTIFIER (as is done in Defs-windows.gmk), 57 # but JTREG does not pass this env variable when executing a shell script. 58 # 59 # execute test program - rely on it to exit if platform unsupported 60 61 echo "Creating the alias '246810' in the Windows-My store..." 62 ${TESTJAVA}/bin/keytool \ 63 -import \ 64 -storetype Windows-My \ 65 -file ${TESTSRC}/246810.cer \ 66 -alias 246810 \ 67 -noprompt 68 69 if [ $? -ne 0 ] ; then 70 exit $? 71 fi 72 73 echo "Removing the alias '13579', if it is already present..." 74 ${TESTJAVA}/bin/keytool \ 75 -list \ 76 -storetype Windows-My \ 77 -alias 13579 > /dev/null 2>&1 78 79 if [ $? ] ; then 80 ${TESTJAVA}/bin/keytool \ 81 -delete \ 82 -storetype Windows-My \ 83 -alias 13579 \ 84 -noprompt 85 fi 86 87 echo "Counting the entries in the store..." 88 count=`${TESTJAVA}/bin/keytool -list -storetype Windows-My | wc -l` 89 before=$count 90 91 echo "Changing the alias name from '246810' to '13579'..." 92 93 ${TESTJAVA}/bin/keytool \ 94 -changealias \ 95 -storetype Windows-My \ 96 -alias 246810 \ 97 -destalias 13579 98 99 if [ $? -ne 0 ] ; then 100 exit $? 101 fi 102 103 echo "Re-counting the entries in the store..." 104 count=`${TESTJAVA}/bin/keytool -list -storetype Windows-My | wc -l` 105 after=$count 106 107 if [ ! $before = $after ]; then 108 echo "error: unexpected number of entries in the Windows-MY store" 109 exit 101 110 fi 111 112 echo "Confirming that the new alias is present..." 113 ${TESTJAVA}/bin/keytool \ 114 -list \ 115 -storetype Windows-My \ 116 -alias 13579 > /dev/null 2>&1 117 118 if [ $? -ne 0 ] ; then 119 echo "error: cannot find the new alias name in the Windows-MY store" 120 exit 102 121 fi 122 123 echo "Removing the new alias '13579'..." 124 ${TESTJAVA}/bin/keytool \ 125 -delete \ 126 -storetype Windows-My \ 127 -alias 13579 > /dev/null 2>&1 128 129 echo done. 130 exit 0 131 ;; 132 133 * ) 134 echo "This test is not intended for '$OS' - passing test" 135 exit 0 136 ;; 137 esac 138 139 140