Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 gene
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all

sun/security/tools/keytool/NssTest.java 8295343 linux-all
sun/security/tools/keytool/NssTest.java 8295343,8204203 linux-all,windows-all
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343 linux-all
sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-all
sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all
Expand Down
41 changes: 28 additions & 13 deletions test/jdk/sun/security/pkcs11/PKCS11Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -347,6 +348,22 @@ public static String getNSSLibDir() throws Exception {
}

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) {
Expand All @@ -358,21 +375,20 @@ static String getNSSLibDir(String library) throws Exception {
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() {
Expand Down Expand Up @@ -466,20 +482,19 @@ static double getNSSInfo(String library) {
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;
if (library.compareTo("nss3") == 0 && nss3_version > -1)
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;

Expand Down
12 changes: 9 additions & 3 deletions test/jdk/sun/security/tools/keytool/KeyToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
*/

/*
*
*
* @summary Testing keytool
* @test
* @author weijun.wang
* @summary Testing keytool
*
* Run through autotest.sh and manualtest.sh
*
Expand Down Expand Up @@ -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;
Expand All @@ -68,6 +73,7 @@
import jdk.test.lib.util.FileUtils;
import sun.security.util.ObjectIdentifier;


public class KeyToolTest {

// The stdout and stderr outputs after a keytool run
Expand Down
63 changes: 63 additions & 0 deletions test/jdk/sun/security/tools/keytool/NssTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
130 changes: 0 additions & 130 deletions test/jdk/sun/security/tools/keytool/autotest.sh

This file was deleted.

Loading