Skip to content

Commit

Permalink
[GR-31008] Disable experimental FIPS mode.
Browse files Browse the repository at this point in the history
PullRequest: graal/8814
  • Loading branch information
cstancu committed May 12, 2021
2 parents 4470d70 + 8d780a1 commit b1b6ac0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,22 @@ final class Target_sun_security_jca_ProviderConfig_ProviderLoader {
static Target_sun_security_jca_ProviderConfig_ProviderLoader INSTANCE;
}

/**
* This only applies to JDK8 and JDK11. Experimental FIPS mode in the SunJSSE Provider was removed
* in JDK-8217835. Going forward it is recommended to configure FIPS 140 compliant cryptography
* providers by using the usual JCA providers configuration mechanism.
*/
@SuppressWarnings("unused")
@TargetClass(value = sun.security.ssl.SunJSSE.class, onlyWith = JDK11OrEarlier.class)
final class Target_sun_security_ssl_SunJSSE {

@Substitute
private Target_sun_security_ssl_SunJSSE(java.security.Provider cryptoProvider, String providerName) {
throw VMError.unsupportedFeature("Experimental FIPS mode in the SunJSSE Provider is deprecated (JDK-8217835)." +
" To register a FIPS provider use the supported java.security.Security.addProvider() API.");
}
}

/** Dummy class to have a class with the file's name. */
public final class SecuritySubstitutions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
public void afterRegistration(AfterRegistrationAccess a) {
ModuleSupport.exportAndOpenPackageToClass("java.base", "sun.security.x509", false, getClass());
ModuleSupport.openModuleByClass(Security.class, getClass());
disableExperimentalFipsMode(a);
}

/**
* The SunJSSE provider had a experimental feature that bound to a FIPS crypto provider. This
* has been removed in JDK-8217835. We disabled explicitly here by calling SunJSSE.isFIPS(). If
* it was already enabled that's an error.
*/
private static void disableExperimentalFipsMode(AfterRegistrationAccess a) {
if (JavaVersionUtil.JAVA_SPEC <= 11) {
try {
Boolean isFIPS = (Boolean) method(a, "sun.security.ssl.SunJSSE", "isFIPS").invoke(null);
VMError.guarantee(!isFIPS, "SunJSSE is already initialized in experimental FIPS mode.");
} catch (IllegalAccessException | InvocationTargetException e) {
VMError.shouldNotReachHere(e);
}
}
}

@Override
Expand Down

0 comments on commit b1b6ac0

Please sign in to comment.