Skip to content

Set Default SecureRandom Algorithm - #1580

Open
johnpeck-us-ibm wants to merge 1 commit into
IBM:mainfrom
johnpeck-us-ibm:SecureRandomFix
Open

Set Default SecureRandom Algorithm #1580
johnpeck-us-ibm wants to merge 1 commit into
IBM:mainfrom
johnpeck-us-ibm:SecureRandomFix

Conversation

@johnpeck-us-ibm

@johnpeck-us-ibm johnpeck-us-ibm commented Jul 8, 2026

Copy link
Copy Markdown
Member

Add code to be able to set the Default SecureRandom algorithm from provider.

fixes: #1553

Signed-off-by: johnpeck-us-ibm johnpeck@us.ibm.com

Comment thread src/main/java/com/ibm/crypto/plus/provider/OpenJCEPlusFIPS.java
Comment thread src/test/java/ibm/jceplus/junit/tests/TestProviderServices.java Outdated
Comment thread src/test/java/ibm/jceplus/junit/tests/TestProviderServices.java
Comment thread PROVIDER_CONFIG_FORMAT.md Outdated
@johnpeck-us-ibm
johnpeck-us-ibm force-pushed the SecureRandomFix branch 2 times, most recently from 8a4f265 to 632c68b Compare July 23, 2026 16:21
assertTrue (acceptableValues.contains(secureRandom.getAlgorithm()), "SecureRandom not SunJCE - " + secureRandom.getAlgorithm());

//Now Put OpenJCEPlus first in the list.
Provider provider = (Provider) Class.forName("com.ibm.crypto.plus.provider.OpenJCEPlus").getDeclaredConstructor().newInstance();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using reflection here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have too, It is just one of a few ways this can be done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to do Provider provider = new com.ibm.crypto.plus.provider.OpenJCEPlus();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ether way works. This does follow how we do it in our test code though.

assertTrue (acceptableValues.contains(secureRandom.getAlgorithm()), "SecureRandom not SunJCE");

//Now Put OpenJCEPlus first in the list.
Provider provider = (Provider) Class.forName("com.ibm.crypto.plus.provider.OpenJCEPlusFIPS").getDeclaredConstructor().newInstance();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have too, It is just one of a few ways this can be done.

Comment thread PROVIDER_CONFIG_FORMAT.md
Comment thread PROVIDER_CONFIG_FORMAT.md
- **name**: Unique identifier for the provider (required)
- **description**: Human-readable description of the provider (required)
- **default**: Whether to load default provider attributes (optional, values: `true`, `false`, `1`, `0`)
- **securerandomdefault**: Determines which Secure Random Algorithm is the default one if this provider is first in the provider list

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also document that if it's not set, it defaults to a value? That is if we decide that we won't honour user-specifies order if it's not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not determine the one that will be selected. It is random. So, not sure what to say here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm getting this right, when someone doesn't specify this in the configuration, this defaults to SHA256DRBG. Should we mention this in this md file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As indicated in the comment with out this setting the default could be either SHA256DRBG or SHA512DRBG what is selected is random. It could be either one.

@jasonkatonica jasonkatonica left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/test/java/ibm/jceplus/junit/tests/TestProviderServices.java

@taoliult taoliult left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add code to be able to set the Default SecureRandom algorithm from provider.

fixes: IBM#1553

Signed-off-by: johnpeck-us-ibm <johnpeck@us.ibm.com>

@JinhangZhang JinhangZhang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent SecureRandom registration and usage

5 participants