Add DefaultSecurityProviderConfig with Bouncy Castle disabled #861
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request address issue #782 with a new
DefaultSecurityProviderConfig
that extendsDefaultConfig
and disables Bouncy Castle Security Provider registration in a static initializer.As described in the referenced issue,
SecurityUtils.isBouncyCastleRegistered()
checks current Security Providers and attempts to register Bouncy Castle according to the default settings. TheDefaultConfig
class checks the status of Bouncy Castle registration to determine whether to configure standard factories, but this introduces unnecessary coupling between Bouncy Castle registration and standard algorithm factories.Changes in this pull request include removing the
SecurityUtils.isBouncyCastleRegistered()
check from theDefaultConfig
constructor and registering all factories. TheinitCipherFactories()
method already attempts to initialize configured Cipher Factories and disables factories when the corresponding cipher algorithm is not supported. The random factories do not depend on Bouncy Castle registration, and the Key File Provider factories may or may not need Bouncy Castle depending on the particular key protection algorithms. Removing the dependence of Bouncy Castle registration allows the rest of the library to attempt security operations as needed with the potential to support other Security Providers. It is important to note that theDefaultConfig
will attempt to register the Bouncy Castle Provider when calling otherSecurityUtils
methods, but removing the registered check avoids tight coupling to the particular provider.With the changes to
DefaultConfig
, the newDefaultSecurityProviderConfig
includes a static initializer to callSecurityUtils.setRegisterBouncyCastle(false)
. This changes subsequent behavior and thus expectsjava.security
settings or other external components to setup the providers necessary.SecurityUtils.setRegisterBouncyCastle()
could be called without the introduction of a new configuration class, but new class provides a clear indication of expected behavior, and simple replacement forDefaultConfig
when necessary. Additional adjustments include removingSecurityUtils.isBouncyCastleRegistered()
from several locations where it should not be required.