Skip to content

Commit

Permalink
Merge pull request ibmruntimes#826 from jasonkatonica/katonica/issue4…
Browse files Browse the repository at this point in the history
…58/jrefilescorrupt

Tolerate OpenJCEPlus FIPS binaries within jlink
  • Loading branch information
keithc-ca authored Aug 22, 2024
2 parents 305699f + 7c45986 commit 556bad6
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
* ===========================================================================
*/
package jdk.tools.jlink.internal.plugins;

import java.io.InputStream;
Expand Down Expand Up @@ -104,9 +109,7 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
stripBin);
in.transformAndCopy((resource) -> {
ResourcePoolEntry res = resource;
if ((resource.type() == ResourcePoolEntry.Type.NATIVE_LIB &&
resource.path().endsWith(SHARED_LIBS_EXT)) ||
resource.type() == ResourcePoolEntry.Type.NATIVE_CMD) {
if (shouldStrip(resource)) {
Optional<StrippedDebugInfoBinary> strippedBin = builder.build(resource);
if (strippedBin.isPresent()) {
StrippedDebugInfoBinary sb = strippedBin.get();
Expand All @@ -131,6 +134,35 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
return out.build();
}

/**
* Method to determine if a particular resource should be stripped.
*
* Particular paths are added here to handle libraries within the openjceplus module.
* The FIPS certified library located in the C/icc directory is sensitive to
* any modifications to the native library. Performing any modifications to the library
* in any way, causes the FIPS library to fail to load due to a self verification check made.
*
* @param resource the resource to examine for stripping eligibility
* @return return true if stripping should be done on a particular resource, false otherwise
*/
private static boolean shouldStrip(ResourcePoolEntry resource) {
switch (resource.type()) {
case NATIVE_CMD:
return true;
case NATIVE_LIB:
String path = resource.path();
if (path.endsWith(SHARED_LIBS_EXT)) {
if (!(resource.moduleName().equals("openjceplus") && path.contains("/C/icc/"))) {
return true;
}
}
break;
default:
break;
}
return false;
}

private void logError(ResourcePoolEntry resource, String msgKey) {
String msg = getMessage(msgKey,
NAME,
Expand Down

0 comments on commit 556bad6

Please sign in to comment.