Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class KeytoolOpensslInteropTest {
public static void main(String[] args) throws Throwable {
boolean generatePKCS12 = Boolean.parseBoolean(args[0]);
if (generatePKCS12) {
String opensslPath = OpensslArtifactFetcher.getOpensslPath();
String opensslPath = OpensslArtifactFetcher.getOpensslPathWithProviderPathPresent();
generateInitialKeystores(opensslPath);
testWithJavaCommands();
testWithOpensslCommands(opensslPath);
Expand Down
83 changes: 72 additions & 11 deletions test/lib/jdk/test/lib/security/OpensslArtifactFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

import java.io.IOException;
import java.nio.file.Path;
import java.io.*;
import java.nio.*;
import java.nio.file.*;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.artifacts.Artifact;
import jdk.test.lib.artifacts.ArtifactResolver;
import jtreg.SkippedException;
Expand All @@ -52,19 +56,49 @@ public class OpensslArtifactFetcher {
* @throws SkippedException if a valid version of OpenSSL cannot be found
* or if OpenSSL is not available on the target platform
*/
public static String getOpensslPath() {
public static String getOpensslPath() {
String path = getOpensslFromSystemProp(OPENSSL_BUNDLE_VERSION);
if (path != null) {
System.out.println("Using OpenSSL from system property.");
return path;
}

path = getDefaultSystemOpensslPath(OPENSSL_BUNDLE_VERSION);
if (path != null) {
System.out.println("Using OpenSSL from system.");
System.out.println("Using OpenSSL from System Installed Library:"+path);
return path;
}
path = getArtifactsFromArtifactory();
if(path == null) {
throw new SkippedException(String.format("No OpenSSL %s found for %s/%s",
OPENSSL_BUNDLE_VERSION, Platform.getOsName(), Platform.getOsArch()));
}
System.out.println("Artifacts Path is"+path);
return path;
}

public static String getOpensslPathWithProviderPathPresent() {
String path = getOpensslFromSystemProp(OPENSSL_BUNDLE_VERSION);
if (path != null) {
System.out.println("Using OpenSSL from system property.");
return path;
}
path = getDefaultSystemOpensslPathWithProviderPathPresent(OPENSSL_BUNDLE_VERSION);
if (path != null) {
System.out.println("Using OpenSSL from System Installed Library:"+path);
return path;
}
path = getArtifactsFromArtifactory();
if(path == null) {
throw new SkippedException(String.format("No OpenSSL %s found for %s/%s",
OPENSSL_BUNDLE_VERSION, Platform.getOsName(), Platform.getOsArch()));
}
System.out.println("Artifacts Path is"+path);
return path;
}

private static String getArtifactsFromArtifactory() {
System.out.println("reached this point");
String returnValue = null;
if (Platform.isX64()) {
if (Platform.isLinux()) {
return fetchOpenssl(LINUX_X64.class);
Expand All @@ -81,9 +115,7 @@ public static String getOpensslPath() {
return fetchOpenssl(MACOSX_AARCH64.class);
}
}

throw new SkippedException(String.format("No OpenSSL %s found for %s/%s",
OPENSSL_BUNDLE_VERSION, Platform.getOsName(), Platform.getOsArch()));
return returnValue;
}

private static String getOpensslFromSystemProp(String version) {
Expand All @@ -96,18 +128,38 @@ private static String getOpensslFromSystemProp(String version) {
}

private static String getDefaultSystemOpensslPath(String version) {
if (verifyOpensslVersion("openssl", version)) {
return "openssl";
} else if (verifyOpensslVersion("/usr/local/bin/openssl", version)) {
return "/usr/local/bin/openssl";
String absolutePath = getOpenSslAbsolutePath();
if (verifyOpensslVersion(absolutePath, version)) {
return absolutePath;
}
return null;
}

private static String getDefaultSystemOpensslPathWithProviderPathPresent(String version) {
String absolutePath = getDefaultSystemOpensslPath(version);
if (absolutePath != null && isProviderPathPresent(absolutePath) != null) {
return absolutePath;
}
return null;
}

private static String getOpenSslAbsolutePath() {
String absolutePath = null;
try {
OutputAnalyzer outputAnalyzer = ProcessTools.executeProcess("which","openssl");
absolutePath = outputAnalyzer.getOutput();
System.out.println("absolutePath:"+absolutePath);
} catch(Throwable t) {
t.printStackTrace();
}
return absolutePath;
}

private static boolean verifyOpensslVersion(String path, String version) {
if (path != null) {
try {
ProcessTools.executeCommand(path, "version")
System.out.println("path is:"+path+"version is "+version);
ProcessTools.executeCommand(path.trim(),"version")
.shouldHaveExitValue(0)
.shouldContain(version);
return true;
Expand Down Expand Up @@ -138,6 +190,15 @@ public static Path getProviderPath(String opensslPath) {
return openSslRootPath.resolve(libDir, "ossl-modules");
}

private static Path isProviderPathPresent(String opensslAbsolutePath) {
Path osslModulesPath = getProviderPath(opensslAbsolutePath);
if(Files.exists(osslModulesPath)) {
return osslModulesPath;
} else {
return null;
}
}

public static String getTestOpensslBundleVersion() {
return OPENSSL_BUNDLE_VERSION;
}
Expand Down