23
23
24
24
package jdk .test .lib .security ;
25
25
26
+ import java .io .IOException ;
26
27
import java .nio .file .Path ;
27
28
import jdk .test .lib .Platform ;
28
29
import jdk .test .lib .process .ProcessTools ;
@@ -49,42 +50,40 @@ public class OpensslArtifactFetcher {
49
50
*
50
51
* @return openssl binary path of the current version
51
52
* @throws SkippedException if a valid version of OpenSSL cannot be found
53
+ * or if OpenSSL is not available on the target platform
52
54
*/
53
55
public static String getOpensslPath () {
54
56
String path = getOpensslFromSystemProp (OPENSSL_BUNDLE_VERSION );
55
57
if (path != null ) {
58
+ System .out .println ("Using OpenSSL from system property." );
56
59
return path ;
57
60
}
61
+
58
62
path = getDefaultSystemOpensslPath (OPENSSL_BUNDLE_VERSION );
59
63
if (path != null ) {
64
+ System .out .println ("Using OpenSSL from system." );
60
65
return path ;
61
66
}
67
+
62
68
if (Platform .isX64 ()) {
63
69
if (Platform .isLinux ()) {
64
- path = fetchOpenssl (LINUX_X64 .class );
70
+ return fetchOpenssl (LINUX_X64 .class );
65
71
} else if (Platform .isOSX ()) {
66
- path = fetchOpenssl (MACOSX_X64 .class );
72
+ return fetchOpenssl (MACOSX_X64 .class );
67
73
} else if (Platform .isWindows ()) {
68
- path = fetchOpenssl (WINDOWS_X64 .class );
74
+ return fetchOpenssl (WINDOWS_X64 .class );
69
75
}
70
76
} else if (Platform .isAArch64 ()) {
71
77
if (Platform .isLinux ()) {
72
- path = fetchOpenssl (LINUX_AARCH64 .class );
78
+ return fetchOpenssl (LINUX_AARCH64 .class );
73
79
}
74
80
if (Platform .isOSX ()) {
75
- path = fetchOpenssl (MACOSX_AARCH64 .class );
81
+ return fetchOpenssl (MACOSX_AARCH64 .class );
76
82
}
77
83
}
78
84
79
- if (!verifyOpensslVersion (path , OPENSSL_BUNDLE_VERSION )) {
80
- String exMsg = "Can't find the version: "
81
- + OpensslArtifactFetcher .getTestOpensslBundleVersion ()
82
- + " of openssl binary on this machine, please install"
83
- + " and set openssl path with property 'test.openssl.path'" ;
84
- throw new SkippedException (exMsg );
85
- } else {
86
- return path ;
87
- }
85
+ throw new SkippedException (String .format ("No OpenSSL %s found for %s/%s" ,
86
+ OPENSSL_BUNDLE_VERSION , Platform .getOsName (), Platform .getOsArch ()));
88
87
}
89
88
90
89
private static String getOpensslFromSystemProp (String version ) {
@@ -120,9 +119,13 @@ private static boolean verifyOpensslVersion(String path, String version) {
120
119
}
121
120
122
121
private static String fetchOpenssl (Class <?> clazz ) {
123
- return ArtifactResolver .fetchOne (clazz )
124
- .resolve ("openssl" , "bin" , "openssl" )
125
- .toString ();
122
+ try {
123
+ return ArtifactResolver .fetchOne (clazz )
124
+ .resolve ("openssl" , "bin" , "openssl" )
125
+ .toString ();
126
+ } catch (IOException exc ) {
127
+ throw new SkippedException ("Could not find openssl" , exc );
128
+ }
126
129
}
127
130
128
131
// retrieve the provider directory path from <OPENSSL_HOME>/bin/openssl
0 commit comments