jdk/test/sun/security/tools/keytool/p12importks.sh
author weijun
Fri, 25 Apr 2014 10:57:09 +0800
changeset 24116 9f9b4ba34aad
parent 21342 7bbb056a1c23
permissions -rw-r--r--
8040321: keytool and jarsigner tests doesn't pass though VM tools to tools Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16720
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     1
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     2
# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     4
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     7
# published by the Free Software Foundation.
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     8
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    13
# accompanied this code).
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    14
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    18
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    21
# questions.
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    22
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    23
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    24
# @test
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    25
# @bug 8010125
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    26
# @summary keytool -importkeystore could create a pkcs12 keystore with
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    27
#  different storepass and keypass
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    28
#
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    29
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    30
if [ "${TESTJAVA}" = "" ] ; then
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    31
  JAVAC_CMD=`which javac`
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    32
  TESTJAVA=`dirname $JAVAC_CMD`/..
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    33
fi
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    34
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    35
# set platform-dependent variables
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    36
OS=`uname -s`
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    37
case "$OS" in
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    38
  Windows_* )
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    39
    FS="\\"
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    40
    ;;
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    41
  * )
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    42
    FS="/"
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    43
    ;;
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    44
esac
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    45
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    46
LANG=C
24116
9f9b4ba34aad 8040321: keytool and jarsigner tests doesn't pass though VM tools to tools
weijun
parents: 21342
diff changeset
    47
KT="$TESTJAVA${FS}bin${FS}keytool ${TESTTOOLVMOPTS}"
16720
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    48
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    49
# Part 1: JKS keystore with same storepass and keypass
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    50
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    51
rm jks 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    52
$KT -genkeypair -keystore jks -storetype jks -alias me -dname CN=Me \
21342
7bbb056a1c23 8027026: Change keytool -genkeypair to use -keyalg RSA
weijun
parents: 16720
diff changeset
    53
	-keyalg rsa -storepass pass1111 -keypass pass1111 || exit 11
16720
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    54
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    55
# Cannot only change storepass
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    56
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    57
$KT -importkeystore -noprompt \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    58
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    59
    -srcstorepass pass1111 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    60
    -deststorepass pass2222 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    61
        && exit 12
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    62
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    63
# You can keep storepass unchanged
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    64
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    65
$KT -importkeystore -noprompt \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    66
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    67
    -srcstorepass pass1111 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    68
    -deststorepass pass1111 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    69
        || exit 13
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    70
$KT -certreq -storetype pkcs12 -keystore p12 -alias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    71
	-storepass pass1111 -keypass pass1111 || exit 14
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    72
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    73
# Or change storepass and keypass both
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    74
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    75
$KT -importkeystore -noprompt \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    76
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    77
    -srcstorepass pass1111 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    78
    -deststorepass pass2222 -destkeypass pass2222 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    79
        || exit 15
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    80
$KT -certreq -storetype pkcs12 -keystore p12 -alias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    81
	-storepass pass2222 -keypass pass2222 || exit 16
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    82
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    83
# Part 2: JKS keystore with different storepass and keypass
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    84
# Must import by alias (-srckeypass is not available when importing all)
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    85
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    86
rm jks 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    87
$KT -genkeypair -keystore jks -storetype jks -alias me -dname CN=Me \
21342
7bbb056a1c23 8027026: Change keytool -genkeypair to use -keyalg RSA
weijun
parents: 16720
diff changeset
    88
	-keyalg rsa -storepass pass1111 -keypass pass2222 || exit 21
16720
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    89
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    90
# Can use old keypass as new storepass so new storepass and keypass are same
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    91
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    92
$KT -importkeystore -noprompt -srcalias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    93
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    94
    -srcstorepass pass1111 -srckeypass pass2222  \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    95
	-deststorepass pass2222 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    96
	    || exit 22
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    97
$KT -certreq -storetype pkcs12 -keystore p12 -alias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    98
	-storepass pass2222 -keypass pass2222 || exit 23
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
    99
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   100
# Or specify both storepass and keypass to brand new ones
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   101
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   102
$KT -importkeystore -noprompt -srcalias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   103
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   104
    -srcstorepass pass1111 -srckeypass pass2222  \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   105
	-deststorepass pass3333 -destkeypass pass3333 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   106
	    || exit 24
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   107
$KT -certreq -storetype pkcs12 -keystore p12 -alias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   108
	-storepass pass3333 -keypass pass3333 || exit 25
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   109
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   110
# Anyway you cannot make new storepass and keypass different
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   111
rm p12 2> /dev/null
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   112
$KT -importkeystore -noprompt -srcalias me \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   113
    -srcstoretype jks -srckeystore jks -destkeystore p12 -deststoretype pkcs12 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   114
    -srcstorepass pass1111 -srckeypass pass2222  \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   115
	-deststorepass pass1111 \
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   116
	    && exit 26
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   117
0e7e9e6ed98a 8010125: keytool -importkeystore could create a pkcs12 keystore with different storepass and keypass
weijun
parents:
diff changeset
   118
exit 0