|
1 | 1 | /* |
2 | | - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -260,28 +260,46 @@ public static boolean hasSA() { |
260 | 260 | return true; |
261 | 261 | } |
262 | 262 |
|
263 | | - /** |
264 | | - * Return true if the test JDK is hardened, otherwise false. Only valid on OSX. |
265 | | - */ |
266 | | - public static boolean isHardenedOSX() throws IOException { |
267 | | - // We only care about hardened binaries for 10.14 and later (actually 10.14.5, but |
268 | | - // for simplicity we'll also include earlier 10.14 versions). |
269 | | - if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { |
270 | | - return false; // assume not hardened |
271 | | - } |
272 | | - |
273 | | - // Find the path to the java binary. |
| 263 | + private static Process launchCodesignOnJavaBinary() throws IOException { |
274 | 264 | String jdkPath = System.getProperty("java.home"); |
275 | 265 | Path javaPath = Paths.get(jdkPath + "/bin/java"); |
276 | 266 | String javaFileName = javaPath.toAbsolutePath().toString(); |
277 | 267 | if (Files.notExists(javaPath)) { |
278 | 268 | throw new FileNotFoundException("Could not find file " + javaFileName); |
279 | 269 | } |
280 | | - |
281 | | - // Run codesign on the java binary. |
282 | 270 | ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName); |
283 | 271 | pb.redirectErrorStream(true); // redirect stderr to stdout |
284 | 272 | Process codesignProcess = pb.start(); |
| 273 | + return codesignProcess; |
| 274 | + } |
| 275 | + |
| 276 | + public static boolean hasOSXPlistEntries() throws IOException { |
| 277 | + Process codesignProcess = launchCodesignOnJavaBinary(); |
| 278 | + BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); |
| 279 | + String line; |
| 280 | + while ((line = is.readLine()) != null) { |
| 281 | + System.out.println("STDOUT: " + line); |
| 282 | + if (line.indexOf("Info.plist=not bound") != -1) { |
| 283 | + return false; |
| 284 | + } |
| 285 | + if (line.indexOf("Info.plist entries=") != -1) { |
| 286 | + return true; |
| 287 | + } |
| 288 | + } |
| 289 | + System.out.println("No matching Info.plist entry was found"); |
| 290 | + return false; |
| 291 | + } |
| 292 | + |
| 293 | + /** |
| 294 | + * Return true if the test JDK is hardened, otherwise false. Only valid on OSX. |
| 295 | + */ |
| 296 | + public static boolean isHardenedOSX() throws IOException { |
| 297 | + // We only care about hardened binaries for 10.14 and later (actually 10.14.5, but |
| 298 | + // for simplicity we'll also include earlier 10.14 versions). |
| 299 | + if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { |
| 300 | + return false; // assume not hardened |
| 301 | + } |
| 302 | + Process codesignProcess = launchCodesignOnJavaBinary(); |
285 | 303 | BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); |
286 | 304 | String line; |
287 | 305 | boolean isHardened = false; |
|
0 commit comments