Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SHA-256 and MD5 MessageDigest to CRIUSecProvider #91

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
4 changes: 4 additions & 0 deletions closed/GensrcJ9JCL.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $(eval $(call SetupCopyFiles,COPY_OVERLAY_FILES, \
SRC := $(TOPDIR), \
DEST := $(SUPPORT_OUTPUTDIR)/overlay, \
FILES := \
src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java \
src/java.base/share/classes/java/io/PrintStream.java \
src/java.base/share/classes/java/lang/ClassValue.java \
src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java \
Expand All @@ -51,7 +52,10 @@ $(eval $(call SetupCopyFiles,COPY_OVERLAY_FILES, \
src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java \
src/java.base/share/classes/sun/security/jca/ProviderConfig.java \
src/java.base/share/classes/sun/security/jca/ProviderList.java \
src/java.base/share/classes/sun/security/provider/DigestBase.java \
src/java.base/share/classes/sun/security/provider/SecureRandom.java \
src/java.base/unix/classes/java/lang/ProcessEnvironment.java \
src/java.base/unix/classes/sun/security/provider/NativePRNG.java \
))

IncludeIfUnsure := -includeIfUnsure -noWarnIncludeIf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*[INCLUDE-IF CRIU_SUPPORT]*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
* (c) Copyright IBM Corp. 2022, 2023 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,9 @@
package openj9.internal.criu;

import java.security.Provider;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Consumer;

/**
* The CRIUSECProvider is a security provider that is used as follows when CRIU
Expand All @@ -39,26 +42,47 @@ public final class CRIUSECProvider extends Provider {

private static final long serialVersionUID = -3240458633432287743L;

private static final Map<Object, Consumer<Object>> actions = new WeakHashMap<>();

@SuppressWarnings("unchecked")
public static <T> void doOnRestart(T object, Consumer<T> action) {
if (InternalCRIUSupport.isCheckpointAllowed()) {
synchronized (actions) {
// This unchecked cast is safe because the action
// is only applied the supplied object.
actions.put(object, (Consumer<Object>) action);
}
}
}

public CRIUSECProvider() {
super("CRIUSEC", "1", "CRIUSEC Provider");

String packageName = CRIUSECProvider.class.getPackage().getName() + ".";

String[] aliases = new String[] { "SHA",
"SHA1",
"OID.1.3.14.3.2.26",
"1.3.14.3.2.26" };

// SHA1PRNG is the default name needed by the jdk, but SHA1 is not used, rather it reads directly from /dev/random.
putService(new Service(this, "MessageDigest", "SHA-1", packageName + "SHA", java.util.Arrays.asList(aliases), null));
putService(new Service(this, "SecureRandom", "SHA1PRNG", packageName + "NativePRNG", null, null));
putService(new Service(this, "MessageDigest", "SHA-1", "sun.security.provider.SHA", java.util.Arrays.asList(aliases), null));
putService(new Service(this, "MessageDigest", "SHA-256", "sun.security.provider.SHA2$SHA256", null, null));
putService(new Service(this, "MessageDigest", "MD5", "sun.security.provider.MD5", null, null));
putService(new Service(this, "Mac", "HmacSHA256", "com.sun.crypto.provider.HmacCore$HmacSHA256", null, null));
putService(new Service(this, "SecureRandom", "SHA1PRNG", "sun.security.provider.NativePRNG$CRIUNativePRNG", null, null));
}

/**
* Resets the security digests.
* Reset security algorithms.
*/
public static void resetCRIUSEC() {
NativePRNG.clearRNGState();
DigestBase.resetDigests();
synchronized (actions) {
for (Map.Entry<Object, Consumer<Object>> entry : actions.entrySet()) {
Object object = entry.getKey();

if (object != null) {
entry.getValue().accept(object);
}
}
}
}
}

This file was deleted.

Loading