8209546: Make sun/security/tools/keytool/autotest.sh to support macosx
Refactor autotest.sh to java test and remove standard.sh Reviewed-by: weijun
This commit is contained in:
parent
f8d007dbf0
commit
afe05800ac
@ -679,6 +679,7 @@ sun/security/pkcs11/tls/TestLeadingZeroesP11.java 8204203 windows-
|
||||
sun/security/pkcs11/tls/TestMasterSecret.java 8204203 windows-all
|
||||
sun/security/pkcs11/tls/TestPRF.java 8204203 windows-all
|
||||
sun/security/pkcs11/tls/TestPremaster.java 8204203 windows-all
|
||||
sun/security/tools/keytool/NssTest.java 8204203 windows-all
|
||||
|
||||
############################################################################
|
||||
|
||||
|
@ -27,11 +27,14 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.KeyPairGenerator;
|
||||
@ -304,6 +307,22 @@ public abstract class PKCS11Test {
|
||||
}
|
||||
|
||||
static String getNSSLibDir(String library) throws Exception {
|
||||
Path libPath = getNSSLibPath(library);
|
||||
if (libPath == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String libDir = String.valueOf(libPath.getParent()) + File.separatorChar;
|
||||
System.out.println("nssLibDir: " + libDir);
|
||||
System.setProperty("pkcs11test.nss.libdir", libDir);
|
||||
return libDir;
|
||||
}
|
||||
|
||||
private static Path getNSSLibPath() throws Exception {
|
||||
return getNSSLibPath(nss_library);
|
||||
}
|
||||
|
||||
static Path getNSSLibPath(String library) throws Exception {
|
||||
String osid = getOsId();
|
||||
String[] nssLibDirs = getNssLibPaths(osid);
|
||||
if (nssLibDirs == null) {
|
||||
@ -315,21 +334,20 @@ public abstract class PKCS11Test {
|
||||
System.out.println("Warning: NSS not supported on this platform, skipping test");
|
||||
return null;
|
||||
}
|
||||
String nssLibDir = null;
|
||||
|
||||
Path nssLibPath = null;
|
||||
for (String dir : nssLibDirs) {
|
||||
if (new File(dir).exists() &&
|
||||
new File(dir + System.mapLibraryName(library)).exists()) {
|
||||
nssLibDir = dir;
|
||||
System.out.println("nssLibDir: " + nssLibDir);
|
||||
System.setProperty("pkcs11test.nss.libdir", nssLibDir);
|
||||
Path libPath = Paths.get(dir).resolve(System.mapLibraryName(library));
|
||||
if (Files.exists(libPath)) {
|
||||
nssLibPath = libPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nssLibDir == null) {
|
||||
if (nssLibPath == null) {
|
||||
System.out.println("Warning: can't find NSS librarys on this machine, skipping test");
|
||||
return null;
|
||||
}
|
||||
return nssLibDir;
|
||||
return nssLibPath;
|
||||
}
|
||||
|
||||
private static String getOsId() {
|
||||
@ -420,7 +438,7 @@ public abstract class PKCS11Test {
|
||||
boolean found = false;
|
||||
String s = null;
|
||||
int i = 0;
|
||||
String libfile = "";
|
||||
Path libfile = null;
|
||||
|
||||
if (library.compareTo("softokn3") == 0 && softoken3_version > -1)
|
||||
return softoken3_version;
|
||||
@ -428,12 +446,11 @@ public abstract class PKCS11Test {
|
||||
return nss3_version;
|
||||
|
||||
try {
|
||||
String libdir = getNSSLibDir();
|
||||
if (libdir == null) {
|
||||
libfile = getNSSLibPath();
|
||||
if (libfile == null) {
|
||||
return 0.0;
|
||||
}
|
||||
libfile = libdir + System.mapLibraryName(library);
|
||||
try (FileInputStream is = new FileInputStream(libfile)) {
|
||||
try (InputStream is = Files.newInputStream(libfile)) {
|
||||
byte[] data = new byte[1000];
|
||||
int read = 0;
|
||||
|
||||
|
@ -22,10 +22,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @summary Testing keytool
|
||||
* @test
|
||||
* @author weijun.wang
|
||||
* @summary Testing keytool
|
||||
*
|
||||
* Run through autotest.sh and manualtest.sh
|
||||
*
|
||||
@ -54,6 +53,12 @@
|
||||
*
|
||||
* ATTENTION:
|
||||
* NSS PKCS11 config file are changed, DSA not supported now.
|
||||
*
|
||||
* @library /test/lib
|
||||
* @modules java.base/sun.security.tools.keytool
|
||||
* java.base/sun.security.util
|
||||
* java.base/sun.security.x509
|
||||
* @run main/othervm/timeout=600 -Dfile KeyToolTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Files;
|
||||
@ -68,6 +73,7 @@ import java.security.cert.X509Certificate;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
|
||||
|
||||
public class KeyToolTest {
|
||||
|
||||
// The stdout and stderr outputs after a keytool run
|
||||
|
63
test/jdk/sun/security/tools/keytool/NssTest.java
Normal file
63
test/jdk/sun/security/tools/keytool/NssTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary It tests (almost) all keytool behaviors with NSS.
|
||||
* @library /test/lib /test/jdk/sun/security/pkcs11
|
||||
* @modules java.base/sun.security.tools.keytool
|
||||
* java.base/sun.security.util
|
||||
* java.base/sun.security.x509
|
||||
* @run main/othervm/timeout=600 NssTest
|
||||
*/
|
||||
public class NssTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Path libPath = PKCS11Test.getNSSLibPath("softokn3");
|
||||
if (libPath == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println("Using NSS lib at " + libPath);
|
||||
|
||||
copyFiles();
|
||||
System.setProperty("nss", "");
|
||||
System.setProperty("nss.lib", String.valueOf(libPath));
|
||||
KeyToolTest.main(args);
|
||||
}
|
||||
|
||||
private static void copyFiles() throws IOException {
|
||||
Path srcPath = Paths.get(System.getProperty("test.src"));
|
||||
Files.copy(srcPath.resolve("p11-nss.txt"), Paths.get("p11-nss.txt"));
|
||||
|
||||
Path dbPath = srcPath.getParent().getParent()
|
||||
.resolve("pkcs11").resolve("nss").resolve("db");
|
||||
Files.copy(dbPath.resolve("cert8.db"), Paths.get("cert8.db"));
|
||||
Files.copy(dbPath.resolve("key3.db"), Paths.get("key3.db"));
|
||||
Files.copy(dbPath.resolve("secmod.db"), Paths.get("secmod.db"));
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# @test
|
||||
# @summary (almost) all keytool behaviors
|
||||
# @author Weijun Wang
|
||||
# @library /test/lib
|
||||
# @build jdk.test.lib.util.FileUtils
|
||||
# @run shell/timeout=600 autotest.sh
|
||||
# This test is only executed on several platforms
|
||||
#
|
||||
# set a few environment variables so that the shell-script can run stand-alone
|
||||
# in the source directory
|
||||
if [ "${TESTSRC}" = "" ] ; then
|
||||
TESTSRC="."
|
||||
fi
|
||||
if [ "${TESTCLASSES}" = "" ] ; then
|
||||
TESTCLASSES="."
|
||||
fi
|
||||
if [ "${TESTJAVA}" = "" ] ; then
|
||||
echo "TESTJAVA not set. Test cannot execute."
|
||||
echo "FAILED!!!"
|
||||
exit 1
|
||||
fi
|
||||
if [ "${COMPILEJAVA}" = "" ]; then
|
||||
COMPILEJAVA="${TESTJAVA}"
|
||||
fi
|
||||
|
||||
find_one() {
|
||||
for TARGET_FILE in $@; do
|
||||
if [ -e "$TARGET_FILE" ]; then
|
||||
echo $TARGET_FILE
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
FS="/"
|
||||
${TESTJAVA}${FS}bin${FS}java -XshowSettings:properties -version 2> allprop
|
||||
cat allprop | grep sun.arch.data.model | grep 32
|
||||
if [ "$?" != "0" ]; then
|
||||
B32=false
|
||||
else
|
||||
B32=true
|
||||
fi
|
||||
|
||||
# set platform-dependent variables
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
SunOS )
|
||||
FS="/"
|
||||
LIBNAME="/usr/lib/mps/`isainfo -n`/libsoftokn3.so"
|
||||
;;
|
||||
Linux )
|
||||
if [ $B32 = true ]; then
|
||||
LIBNAME=`find_one \
|
||||
"/usr/lib32/libsoftokn3.so" \
|
||||
"/usr/lib32/nss/libsoftokn3.so" \
|
||||
"/usr/lib/libsoftokn3.so" \
|
||||
"/usr/lib/i386-linux-gnu/nss/libsoftokn3.so" \
|
||||
"/usr/lib/nss/libsoftokn3.so"`
|
||||
else
|
||||
LIBNAME=`find_one \
|
||||
"/usr/lib64/libsoftokn3.so" \
|
||||
"/usr/lib/x86_64-linux-gnu/nss/libsoftokn3.so" \
|
||||
"/usr/lib/nss/libsoftokn3.so"`
|
||||
fi
|
||||
;;
|
||||
* )
|
||||
echo "Will not run test on: ${OS}"
|
||||
exit 0;
|
||||
;;
|
||||
esac
|
||||
case "$OS" in
|
||||
Windows_* | CYGWIN* )
|
||||
PS=";"
|
||||
;;
|
||||
* )
|
||||
PS=":"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$LIBNAME" = "" ]; then
|
||||
echo "Cannot find libsoftokn3.so"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Using NSS lib at $LIBNAME"
|
||||
|
||||
EXTRAOPTS="--add-exports java.base/sun.security.tools.keytool=ALL-UNNAMED \
|
||||
--add-exports java.base/sun.security.util=ALL-UNNAMED \
|
||||
--add-exports java.base/sun.security.x509=ALL-UNNAMED"
|
||||
${COMPILEJAVA}${FS}bin${FS}javac -classpath ${TESTCLASSPATH} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file \
|
||||
${TESTSRC}${FS}KeyToolTest.java || exit 10
|
||||
|
||||
NSS=${TESTSRC}${FS}..${FS}..${FS}pkcs11${FS}nss
|
||||
|
||||
cp ${TESTSRC}${FS}p11-nss.txt .
|
||||
cp ${NSS}${FS}db${FS}cert8.db .
|
||||
cp ${NSS}${FS}db${FS}key3.db .
|
||||
cp ${NSS}${FS}db${FS}secmod.db .
|
||||
|
||||
chmod u+w key3.db
|
||||
chmod u+w cert8.db
|
||||
echo | ${TESTJAVA}${FS}bin${FS}java -classpath .${PS}${TESTCLASSPATH} ${TESTVMOPTS} ${EXTRAOPTS} -Dnss \
|
||||
-Dnss.lib=${LIBNAME} \
|
||||
KeyToolTest
|
||||
status=$?
|
||||
|
||||
exit $status
|
@ -1,81 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# @test
|
||||
# @summary (almost) all keytool behaviors
|
||||
# @author Weijun Wang
|
||||
# @library /test/lib
|
||||
# @build jdk.test.lib.util.FileUtils
|
||||
# @run shell/timeout=600 standard.sh
|
||||
# @key intermittent
|
||||
|
||||
# This test is always excecuted.
|
||||
#
|
||||
# set a few environment variables so that the shell-script can run stand-alone
|
||||
# in the source directory
|
||||
if [ "${TESTSRC}" = "" ] ; then
|
||||
TESTSRC="."
|
||||
fi
|
||||
if [ "${TESTCLASSES}" = "" ] ; then
|
||||
TESTCLASSES="."
|
||||
fi
|
||||
if [ "${TESTJAVA}" = "" ] ; then
|
||||
JAVAC_CMD=`which javac`
|
||||
TESTJAVA=`dirname $JAVAC_CMD`/..
|
||||
COMPILEJAVA="${TESTJAVA}"
|
||||
fi
|
||||
|
||||
# set platform-dependent variables
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
SunOS | Linux | Darwin | AIX | CYGWIN* )
|
||||
FS="/"
|
||||
;;
|
||||
Windows_* )
|
||||
FS="\\"
|
||||
;;
|
||||
* )
|
||||
echo "Unrecognized system!"
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
case "$OS" in
|
||||
Windows_* | CYGWIN* )
|
||||
PS=";"
|
||||
;;
|
||||
* )
|
||||
PS=":"
|
||||
;;
|
||||
esac
|
||||
|
||||
EXTRAOPTS="--add-exports java.base/sun.security.tools.keytool=ALL-UNNAMED \
|
||||
--add-exports java.base/sun.security.util=ALL-UNNAMED \
|
||||
--add-exports java.base/sun.security.x509=ALL-UNNAMED"
|
||||
|
||||
${COMPILEJAVA}${FS}bin${FS}javac -classpath ${TESTCLASSPATH} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . -XDignore.symbol.file ${TESTSRC}${FS}KeyToolTest.java || exit 10
|
||||
|
||||
echo | ${TESTJAVA}${FS}bin${FS}java -classpath .${PS}${TESTCLASSPATH} ${TESTVMOPTS} ${EXTRAOPTS} -Dfile KeyToolTest
|
||||
status=$?
|
||||
|
||||
exit $status
|
||||
|
Loading…
x
Reference in New Issue
Block a user