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