@@ -202,6 +202,71 @@ 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+ if (isProviderPresent ("OpenJCEPlusFIPS" )) {
209+ // 1 - Test property - base profile with securerandom.strongAlgorithms loads successfully.
210+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms" ,
211+ System .getProperty ("test.src" ) + "/property-java.security" ,
212+ "(?s)(?=.*OpenJCEPlusFIPS)(?=.*SUN)(?=.*SunJSSE)" ,
213+ 0 ));
214+ // 2 - Test property - securerandom.strongAlgorithms property with multiple algorithms.
215+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MultipleEntries" ,
216+ System .getProperty ("test.src" ) + "/property-java.security" ,
217+ "securerandom\\ .strongAlgorithms: SHA512DRBG:OpenJCEPlusFIPS, SHA256DRBG:OpenJCEPlusFIPS" ,
218+ 0 ));
219+ // 3 - Test property - securerandom.strongAlgorithms append algorithm in extended profile.
220+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Extension_1" ,
221+ System .getProperty ("test.src" ) + "/property-java.security" ,
222+ "securerandom\\ .strongAlgorithms: SHA512DRBG:OpenJCEPlusFIPS, SHA256DRBG:OpenJCEPlusFIPS" ,
223+ 0 ));
224+ // 4 - Test property - securerandom.strongAlgorithms remove algorithm in extended profile.
225+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Extension_2" ,
226+ System .getProperty ("test.src" ) + "/property-java.security" ,
227+ "securerandom\\ .strongAlgorithms: (?=.*NativePRNGBlocking:SUN)(?=.*DRBG:SUN)" ,
228+ 0 ));
229+ // 5 - Test property - securerandom.strongAlgorithms invalid algorithm.
230+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidFormat" ,
231+ System .getProperty ("test.src" ) + "/property-java.security" ,
232+ "FAILED: No strong SecureRandom impls available: .*" ,
233+ 0 ));
234+ // 6 - Test property - securerandom.strongAlgorithms missing algorithm.
235+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MissingAlgo" ,
236+ System .getProperty ("test.src" ) + "/property-java.security" ,
237+ "FAILED: No strong SecureRandom impls available: .*" ,
238+ 0 ));
239+ // 7 - Test property - securerandom.strongAlgorithms missing provider.
240+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MissingProvider" ,
241+ System .getProperty ("test.src" ) + "/property-java.security" ,
242+ "FAILED: missing provider" ,
243+ 0 ));
244+ // 8 - Test property - set invalid provider.
245+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidProvider" ,
246+ System .getProperty ("test.src" ) + "/property-java.security" ,
247+ "FAILED: No strong SecureRandom impls available: .*" ,
248+ 0 ));
249+ // 9 - Test property - securerandom.strongAlgorithms when only algorithm is present.
250+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-Specify-Algo-Only" ,
251+ System .getProperty ("test.src" ) + "/property-java.security" ,
252+ "securerandom\\ .strongAlgorithms: SHA(256|512)DRBG$" ,
253+ 0 ));
254+ // 10 - Test property - invalid algorithm.
255+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-InvalidAlgorithm" ,
256+ System .getProperty ("test.src" ) + "/property-java.security" ,
257+ "FAILED: No strong SecureRandom impls available: .*" ,
258+ 0 ));
259+ // 11 - Test property - securerandom.strongAlgorithms misspelled property name.
260+ tests .add (Arguments .of ("Test-Profile-strongAlgorithms-MisspelledPropertyName" ,
261+ System .getProperty ("test.src" ) + "/property-java.security" ,
262+ "The property names: RestrictedSecurity.Test-Profile-strongAlgorithms-MisspelledPropertyName.securerandom.strongAlgorithmsWrong "
263+ + "in profile RestrictedSecurity.Test-Profile-strongAlgorithms-MisspelledPropertyName \\ (or a base profile\\ ) are not recognized" ,
264+ 1 ));
265+ }
266+
267+ return tests .build ();
268+ }
269+
205270 private static Stream <Arguments > patternMatches_systemProperties () {
206271 return Stream .of (
207272 // 1 - Test property - base profile with javax.net.ssl.keyStore loads successfully.
@@ -256,6 +321,19 @@ public void shouldContain_propertiesList(String customprofile, String securityPr
256321 outputAnalyzer .shouldHaveExitValue (exitValue ).shouldMatch (expected );
257322 }
258323
324+ @ ParameterizedTest
325+ @ MethodSource ("patternMatches_strongAlgorithms" )
326+ public void shouldContain_strongAlgorithms (String customprofile , String securityPropertyFile , String expected , int exitValue ) throws Exception {
327+ OutputAnalyzer outputAnalyzer = ProcessTools .executeTestJava (
328+ "-Dsemeru.fips=true" ,
329+ "-Dsemeru.customprofile=" + customprofile ,
330+ "-Djava.security.properties=" + securityPropertyFile ,
331+ "TestProperties"
332+ );
333+ outputAnalyzer .reportDiagnosticSummary ();
334+ outputAnalyzer .shouldHaveExitValue (exitValue ).shouldMatch (expected );
335+ }
336+
259337 @ ParameterizedTest
260338 @ MethodSource ("patternMatches_systemProperties" )
261339 public void shouldContain_systemProperties (String customprofile , String securityPropertyFile , String expected , int exitValue ) throws Exception {
@@ -278,6 +356,20 @@ private static boolean isProviderPresent(String providerName) {
278356 return false ;
279357 }
280358
359+ private static void testStrongAlgorithms () {
360+ if (isProviderPresent ("OpenJCEPlusFIPS" )) {
361+ String strongAlgorithms = Security .getProperty ("securerandom.strongAlgorithms" );
362+ if ((strongAlgorithms != null ) && !strongAlgorithms .isEmpty ()) {
363+ try {
364+ java .security .SecureRandom .getInstanceStrong ();
365+ System .out .println ("securerandom.strongAlgorithms: " + strongAlgorithms );
366+ } catch (java .security .NoSuchAlgorithmException | IllegalArgumentException e ) {
367+ System .out .println ("FAILED: " + e .getMessage ());
368+ }
369+ }
370+ }
371+ }
372+
281373 private static void testSystemProperties () {
282374 // Test javax.net.ssl.keyStore system property.
283375 String keyStore = System .getProperty ("javax.net.ssl.keyStore" );
@@ -299,6 +391,7 @@ public static void main(String[] args) {
299391 System .out .println ("Provider Name: " + provider .getName ());
300392 System .out .println ("Provider Version: " + provider .getVersionStr ());
301393 }
394+ testStrongAlgorithms ();
302395 testSystemProperties ();
303396 } catch (Exception e ) {
304397 System .out .println (e );
0 commit comments