@@ -202,6 +202,69 @@ private static Stream<Arguments> patternMatches_propertiesList() {
202202 return tests .build ();
203203 }
204204
205+ private static Stream <Arguments > patternMatches_strongAlgorithms () {
206+ Stream .Builder <Arguments > tests = Stream .builder ();
207+
208+ // 1 - Test property - base profile with securerandom.strongAlgorithms loads successfully.
209+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms" ,
210+ System .getProperty ("test.src" ) + "/property-java.security" ,
211+ "(?s)(?=.*OpenJCEPlusFIPS)(?=.*SUN)(?=.*SunJSSE)" ,
212+ 0 ));
213+ // 2 - Test property - securerandom.strongAlgorithms property with multiple algorithms.
214+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MultipleEntries" ,
215+ System .getProperty ("test.src" ) + "/property-java.security" ,
216+ "securerandom\\ .strongAlgorithms: SHA512DRBG:OpenJCEPlusFIPS, SHA256DRBG:OpenJCEPlusFIPS" ,
217+ 0 ));
218+ // 3 - Test property - securerandom.strongAlgorithms append algorithm in extended profile.
219+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Extension_1" ,
220+ System .getProperty ("test.src" ) + "/property-java.security" ,
221+ "securerandom\\ .strongAlgorithms: SHA512DRBG:OpenJCEPlusFIPS, SHA256DRBG:OpenJCEPlusFIPS" ,
222+ 0 ));
223+ // 4 - Test property - securerandom.strongAlgorithms remove algorithm in extended profile.
224+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Extension_2" ,
225+ System .getProperty ("test.src" ) + "/property-java.security" ,
226+ "securerandom\\ .strongAlgorithms: (NativePRNGBlocking:SUN|Windows-PRNG:SunMSCAPI),DRBG:SUN" ,
227+ 0 ));
228+ // 5 - Test property - securerandom.strongAlgorithms invalid algorithm.
229+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidFormat" ,
230+ System .getProperty ("test.src" ) + "/property-java.security" ,
231+ "FAILED: No strong SecureRandom impls available: .*" ,
232+ 0 ));
233+ // 6 - Test property - securerandom.strongAlgorithms missing algorithm.
234+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MissingAlgo" ,
235+ System .getProperty ("test.src" ) + "/property-java.security" ,
236+ "FAILED: No strong SecureRandom impls available: .*" ,
237+ 0 ));
238+ // 7 - Test property - securerandom.strongAlgorithms missing provider.
239+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MissingProvider" ,
240+ System .getProperty ("test.src" ) + "/property-java.security" ,
241+ "FAILED: missing provider" ,
242+ 0 ));
243+ // 8 - Test property - set invalid provider.
244+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidProvider" ,
245+ System .getProperty ("test.src" ) + "/property-java.security" ,
246+ "FAILED: No strong SecureRandom impls available: .*" ,
247+ 0 ));
248+ // 9 - Test property - securerandom.strongAlgorithms when only algorithm is present.
249+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Specify-Algo-Only" ,
250+ System .getProperty ("test.src" ) + "/property-java.security" ,
251+ "securerandom\\ .strongAlgorithms: SHA(256|512)DRBG$" ,
252+ 0 ));
253+ // 10 - Test property - invalid algorithm.
254+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidAlgorithm" ,
255+ System .getProperty ("test.src" ) + "/property-java.security" ,
256+ "FAILED: No strong SecureRandom impls available: .*" ,
257+ 0 ));
258+ // 11 - Test property - securerandom.strongAlgorithms misspelled property name.
259+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MisspelledPropertyName" ,
260+ System .getProperty ("test.src" ) + "/property-java.security" ,
261+ "The property names: RestrictedSecurity.Test-Profile-strongAlgorithms-MisspelledPropertyName.securerandom.strongAlgorithmsWrong "
262+ + "in profile RestrictedSecurity.Test-Profile-strongAlgorithms-MisspelledPropertyName \\ (or a base profile\\ ) are not recognized" ,
263+ 1 ));
264+
265+ return tests .build ();
266+ }
267+
205268 private static Stream <Arguments > patternMatches_systemProperties () {
206269 return Stream .of (
207270 // 1 - Test property - base profile with javax.net.ssl.keyStore loads successfully.
@@ -256,6 +319,19 @@ public void shouldContain_propertiesList(String customprofile, String securityPr
256319 outputAnalyzer .shouldHaveExitValue (exitValue ).shouldMatch (expected );
257320 }
258321
322+ @ ParameterizedTest
323+ @ MethodSource ("patternMatches_strongAlgorithms" )
324+ public void shouldContain_strongAlgorithms (String customprofile , String securityPropertyFile , String expected , int exitValue ) throws Exception {
325+ OutputAnalyzer outputAnalyzer = ProcessTools .executeTestJava (
326+ "-Dsemeru.fips=true" ,
327+ "-Dsemeru.customprofile=" + customprofile ,
328+ "-Djava.security.properties=" + securityPropertyFile ,
329+ "TestProperties"
330+ );
331+ outputAnalyzer .reportDiagnosticSummary ();
332+ outputAnalyzer .shouldHaveExitValue (exitValue ).shouldMatch (expected );
333+ }
334+
259335 @ ParameterizedTest
260336 @ MethodSource ("patternMatches_systemProperties" )
261337 public void shouldContain_systemProperties (String customprofile , String securityPropertyFile , String expected , int exitValue ) throws Exception {
@@ -278,6 +354,18 @@ private static boolean isProviderPresent(String providerName) {
278354 return false ;
279355 }
280356
357+ private static void testStrongAlgorithms () {
358+ String strongAlgorithms = Security .getProperty ("securerandom.strongAlgorithms" );
359+ if ((strongAlgorithms != null ) && !strongAlgorithms .isEmpty ()) {
360+ try {
361+ java .security .SecureRandom .getInstanceStrong ();
362+ System .out .println ("securerandom.strongAlgorithms: " + strongAlgorithms );
363+ } catch (java .security .NoSuchAlgorithmException | IllegalArgumentException e ) {
364+ System .out .println ("FAILED: " + e .getMessage ());
365+ }
366+ }
367+ }
368+
281369 private static void testSystemProperties () {
282370 // Test javax.net.ssl.keyStore system property.
283371 String keyStore = System .getProperty ("javax.net.ssl.keyStore" );
@@ -299,6 +387,7 @@ public static void main(String[] args) {
299387 System .out .println ("Provider Name: " + provider .getName ());
300388 System .out .println ("Provider Version: " + provider .getVersionStr ());
301389 }
390+ testStrongAlgorithms ();
302391 testSystemProperties ();
303392 } catch (Exception e ) {
304393 System .out .println (e );
0 commit comments